我正在探索改变C / C ++代码的AST的方法(例如,重命名节点,添加新变量)并将这些更改应用于源文件。
我在SO和Eclipse论坛上做过很多阅读。但是,我没有找到最小的工作示例。
似乎在AST中进行更改的正确方法是使用ASTRewrite类。
几个月前在SO中询问了similar question,但它仍然悬而未决。
这就是我现在陷入困境的地方:
//get the factory
INodeFactory nodeFactory = myAST.getASTNodeFactory();
//create a new function declarator
IASTNode n = nodeFactory.newFunctionDeclarator(nodeFactory.newName("testMe"));
//get the rewriter
ASTRewrite rewriter = ASTRewrite.create(mainAST);
//replace node with n, node is not null
rewriter.replace(node, n, null);
//make the changes
Change c = rewriter.rewriteAST();
c.perform(new NullProgressMonitor());
当我运行此代码段时,我得到了一个
java.lang.NoClassDefFoundError: org/eclipse/ltk/core/refactoring/Change
任何提示都表示赞赏。