如何更新文件的内容," teste.java"作为转换结果的例子?
loc s = |project://java-sample/teste.java|;
content = readFile(s);
CompilationUnit cUnit = parse(#CompilationUnit, content);
visit(cUnit) {
case (Statement) `if (<Expression cond>) { return true; } else { return false; }` =>
(Statement) `return <Expression cond>;`
}
答案 0 :(得分:1)
visit
返回新树。您可以使用writeFile
将该树保存到文件中,该文件将对其进行解组并保存文件:
loc s = |project://java-sample/teste.java|;
content = readFile(s);
CompilationUnit cUnit = parse(#CompilationUnit, content);
cUnitNew = visit(cUnit) { // note the assignment!
case (Statement) `if (<Expression cond>) { return true; } else { return false; }` =>
(Statement) `return <Expression cond>;`
}
writeFile(s, cUnitNew); // write the new string to disk