我通过ASTRewrite在AST中做了一些更改,并通过Change.perform应用了这些更改,C文件已经正确地更新了新的更改(插入新节点),但在调试模式下,AST对象感觉不到这些更改
ast.getRawSignature(); // C file code as text
ASTRewrite rewriter = ASTRewrite.create(ast);
addNewNode(node, ast, rewriter); //Inserting some node
Change c = rewriter.rewriteAST();
try {
c.perform(new NullProgressMonitor());
} catch (CoreException e) {
e.printStackTrace();
}
/**WHAT I WANT TO FLUSH THE AST HERE TO FEEL THE CHANGES**/
ast.getRawSignature(); //it still the same C old code and the C file already updated我需要刷新AST才能感受到AST对象本身的变化,我如何才能做到这一点?
发布于 2018-10-15 00:28:22
在一个AST被初始构造之后,它不再是可变的(在它上调用IASTTranslationUnit.freeze(),并且任何进一步尝试调用该AST中的节点上的setter都将失败)。
这意味着Change.perform()不能在AST上执行更改,只能在文件上执行更改。要获得反映这些更改的AST,您需要构建一个新的AST。
https://stackoverflow.com/questions/52802032
复制相似问题