Last active
December 15, 2015 19:38
-
-
Save jcarvalho/5312513 to your computer and use it in GitHub Desktop.
Generate Deprecated getXpto getters for Fenix Framework 2
This file contains 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
def source = new File("src/main/java") | |
def target = "target/generated-sources/dml-maven-plugin/" | |
def classes = new HashSet() | |
source.eachFileRecurse { file -> | |
if(!file.name.endsWith(".java")) return | |
file.text.split("\n").each { line -> | |
if(line.matches(".*extends[ \t\n][A-Za-z]+_Base.*")) classes.add(file.path) | |
} | |
} | |
classes.each { item -> | |
def targetFile = new File(target + (item.replace("src/main/java/", "").replace(".java", "") + "_Base.java")) | |
def sourceFile = new File(item) | |
def methods = [:] | |
targetFile.text.split("\n").each { line -> | |
if(!line.contains("public java.util.Set")) return | |
def values = line.replace("Set() {", "").substring(line.indexOf("java.util.Set<") + 14).split("> ") | |
methods.put(values[1], values[0]) | |
} | |
if(methods.size() == 0) | |
return | |
def sourceLines = sourceFile.text.split("\n") | |
def index = sourceLines.length | |
while(index > 0) { | |
index-- | |
if(sourceLines[index].contains("}")) { | |
break; | |
} | |
} | |
def output = new StringBuffer() | |
for(i = 0; i < sourceLines.length; i++) { | |
output.append(sourceLines[i] +"\n") | |
if(i == (index - 1)) { | |
addStuff(output, methods) | |
} | |
} | |
sourceFile.text = output.toString() | |
} | |
void addStuff(output, methods) { | |
methods.each { name, type -> | |
output.append(" @Deprecated\n") | |
output.append(" public java.util.Set<" + type + "> " + name + "() {\n") | |
output.append(" return " + name + "Set();\n") | |
output.append(" }\n\n") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment