Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] AST rewrite on other AST.

Hi Kenneth,

First, you can refer to the excellent tutorial page from Lars, especially the section at:

To answer your query on text edits, yes, you should use text edits to have the change - this is not a big thing, since you need to create a rewriter, get the edits from edits = rewriter.rewrite(doc) and then apply the edits by edits.apply(doc);

If you have the JDT.Core sources, then you can also have a look at the testcase org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingStatementsTest.testSwitchStatement13() for the usage.

Despite trying the above, if you are stuck with the issue, please attach a shortened, self-contained version of the program that demonstrates the issue.


-----jdt-dev-bounces@xxxxxxxxxxx wrote: -----
To: "Eclipse JDT general developers list." <jdt-dev@xxxxxxxxxxx>
From: Kenneth Styrberg
Sent by: jdt-dev-bounces@xxxxxxxxxxx
Date: 07/07/2020 07:51PM
Subject: [EXTERNAL] [jdt-dev] AST rewrite on other AST.

Hi, I'm trying to fix a bug where a modification needs to be done on a
Node (oldNode), that is in another CompilationUnit currently not in
scope for the ChangeProposal.

Currently I tried with:

     ASTNode newOldNode= ASTNode.copySubtree(newNode.getAST(), oldNode);

to create the newOldNode and connect it to the AST, but if I add changes
to newOldNode it doesn't update the CompilationUnit.

I've also tried with:

     CompilationUnit oldNodeCompilationUnit=
     ASTRewrite oldNodeRewrite=

and work with oldNodeRewrite, but that doesn't work either.

I've read the article "Abstract Syntax Tree", and it states to use a
TextEdit and manipulate files using ITextFileBufferManager, But I hope
there a a shorter path to do what I want.

All help appreciated.



jdt-dev mailing list
To unsubscribe from this list, visit

Back to the top