Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Eclipse CDT: Modify and save AST

I'm exploring ways to alter the AST of a C/C++ code (e.g., rename a node, add
a new variable) and apply these changes to the source file.

I did a lot of reading here in SO and in Eclipse forums. However I didn't
find a minimal working example.

It seems that the correct way to make changes in an AST is by using the
ASTRewrite class.

A similar question was asked in SO a few months ago, but it is still

Here is where I'm stuck at the moment:

//get the factory
INodeFactory nodeFactory = myAST.getASTNodeFactory();

//create a new function declarator
IASTNode n =

//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());
When I run this code snippet, I get a

java.lang.NoClassDefFoundError: org/eclipse/ltk/core/refactoring/Change
Any hints are appreciated.

View this message in context:
Sent from the Eclipse CDT - Development mailing list archive at

Back to the top