Last active
April 22, 2021 07:16
-
-
Save yujiorama/5681dbabd84a64ffb28431175f663586 to your computer and use it in GitHub Desktop.
oneliner
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
// | |
// usage: | |
// groovy LineShrink.groovy <target.java> | |
// java -jar ~/.m2/repository/org/codehaus/groovy/groovy/2.5.8/groovy-2.5.8.jar LineShrink.groovy <target.java> | |
// | |
def input = new File(args[0]) | |
def methodDefinitionStartPattern = /^\s{4}(public|protected|private)?\s{1,2}[a-zA-Z]{1}[^\s\(\)]+\s*[a-zA-Z]{1}[^\s\(\)]+\(.*$/ | |
def methodDefinitionEndPattern = /^\s{4}\}$/ | |
def inMethodDefinition = false | |
def lineCommentPattern = /^\s*\/\/.*$/ | |
def stack = [] | |
input.eachLine { line -> | |
if (line.trim().empty) { | |
return | |
} | |
if (inMethodDefinition) { | |
if (line ==~ lineCommentPattern) { | |
return | |
} | |
stack << line | |
def m = line =~ methodDefinitionEndPattern | |
if (m) { | |
println(stack.join("")) | |
stack = [] | |
inMethodDefinition = false | |
} | |
return | |
} | |
def m = line =~ methodDefinitionStartPattern | |
if (m) { | |
inMethodDefinition = true | |
stack << line | |
return | |
} | |
println(line) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment