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:https://www.vogella.com/tutorials/EclipseJDT/article.html#using-jdt-to-modify-existing-source-code

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.

Regards,
Manoj

-----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=
ASTResolving.findParentCompilationUnit(oldNode);
     ASTRewrite oldNodeRewrite=
ASTRewrite.create(oldNodeCompilationUnit.getAST());

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.

Regards,

Kenneth


_______________________________________________
jdt-dev mailing list
jdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev




Back to the top