The capabilities of the ASTRewrite basically work as follows: You can remove, replace and insert nodes. The methods for replacing and inserting nodes return a new ASTRewrite
object specifically for the subtree that has been inserted (or that is the replacement for another node respectively). This API is required as the arguments of those methods can either be new AST nodes or nodes that already
exist in the same AST. In order to avoid modifications of an inserted subtree in two locations you get an ASTRewrite for every occurrence of the subtree.
An example to make it more clear:
- You have a function definition, known by its AST node...
ICPPASTFunctionDefinition fun = ...;
- ...and you want to create a clone of this function with a different name, ...
ASTRewrite rewrite = ...;
ASTRewrite insertionRewrite = rewrite.insertBefore(fun.getParent(), fun, fun);
- ... the insertBefore method call duplicates the function definition (inserts it again before the already existing definition). Now if you would like to make a change to that newly inserted function definition (and only to that definition) you need to use
the insertionRewrite object to make these changes. Othwerwise, if there was only one rewrite object it would either affect both definitions of the function or only the original definition.
However, the infrastructure provided by CDT does not support working on a modification, description represented by an ASTRewrite, in the same way as if it was parsed from a source file. It lacks information about name bindings.
I hope this helps.
Regards
Thomas
Von: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> im Auftrag von Krishna Narasimhan <krishna.nm86@xxxxxxxxx>
Gesendet: Dienstag, 7. Juni 2016 00:02
An: CDT General developers list.
Betreff: Re: [cdt-dev] Using ASTRewriter to reflect intermediate changes to the AST and perform further rewrites
Would be really nice if you could send an example if u bump into it.
Not obligatory. But thanks a lot anyway
On Jun 6, 2016 11:55 PM, "Sergey Prigogin" < eclipse.sprigogin@xxxxxxxxx> wrote:
This is done by creating hew rewriters based on the previously created rewriters. Don't remember examples from the top of my head, but should be able to find a few in the refactoring code.
-sergey
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev
|