Last active
February 13, 2023 20:48
-
-
Save rabestro/7dc9affe2f610d7c292bea2cd45c8c5e to your computer and use it in GitHub Desktop.
The script extracts the condition expressions from the Java code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/use/bin/env gawk --exec | |
# | |
# Copyright (c) 2023 Jegors Čemisovs | |
# License: Apache-2.0 license | |
# | |
# The script extracts if statements from Java code. | |
# | |
BEGIN { | |
RS = "[[:space:]]*[;{][[:space:]]*" | |
} | |
/^if[[:space:]]*\(/ { | |
print if_condition() | |
} | |
function if_condition( parenthesis,start,i,symbol,expresson) { | |
for (start = i = index($0, "("); i <= length($0) ; ++i){ | |
symbol = substr($0, i, 1) | |
if (symbol == "(") ++parenthesis | |
else if (symbol == ")") --parenthesis | |
if (!parenthesis) break | |
} | |
expresson = substr($0, start, 1 + i - start) | |
gsub(/[[:space:]]+/, " ", expresson) | |
return expresson | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment