Skip to content

Instantly share code, notes, and snippets.

@jcarvalho
Last active December 15, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcarvalho/5312513 to your computer and use it in GitHub Desktop.
Save jcarvalho/5312513 to your computer and use it in GitHub Desktop.
Generate Deprecated getXpto getters for Fenix Framework 2
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