Skip to content

Instantly share code, notes, and snippets.

@rabestro
Last active February 13, 2023 20:48
Show Gist options
  • Save rabestro/7dc9affe2f610d7c292bea2cd45c8c5e to your computer and use it in GitHub Desktop.
Save rabestro/7dc9affe2f610d7c292bea2cd45c8c5e to your computer and use it in GitHub Desktop.
The script extracts the condition expressions from the Java code
#!/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