如何更新对读取文件完成的转换?
How update a transformation done on a read file?
如何更新文件的内容,"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>;`
}
visit
returns 新树。您可以使用 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
如何更新文件的内容,"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>;`
}
visit
returns 新树。您可以使用 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