public final class ASTRewrite
extends java.lang.Object
IASTComment
can be
removed from or added to a node.
The initial implementation does not support nodes that implement
IASTPreprocessorStatement
or IASTProblem
.
EXPERIMENTAL. This class or interface has been added as part of a work in progress. There is no guarantee that this API will work or that it will remain the same. Please do not use this API without consulting with the CDT team.
Modifier and Type | Class and Description |
---|---|
static class |
ASTRewrite.CommentPosition
Defines the positions of the comment.
|
Modifier and Type | Method and Description |
---|---|
void |
addComment(IASTNode node,
IASTComment comment,
ASTRewrite.CommentPosition pos)
Assigns the comment to the node.
|
static ASTRewrite |
create(IASTTranslationUnit node)
Creates a rewriter for a translation unit.
|
IASTNode |
createLiteralNode(java.lang.String code)
Creates and returns a node for a source string that is to be inserted into
the output document.
|
java.util.List<IASTComment> |
getComments(IASTNode node,
ASTRewrite.CommentPosition pos)
Returns comments for the given node.
|
ASTRewrite |
insertBefore(IASTNode parent,
IASTNode insertionPoint,
IASTNode newNode,
TextEditGroup editGroup)
Inserts the given node in this rewriter.
|
void |
remove(IASTNode node,
TextEditGroup editGroup)
Removes the given node in this rewriter.
|
ASTRewrite |
replace(IASTNode node,
IASTNode replacement,
TextEditGroup editGroup)
Replaces the given node in this rewriter.
|
Change |
rewriteAST()
Converts all modifications recorded by this rewriter into the change object required by
the refactoring framework.
|
public static ASTRewrite create(IASTTranslationUnit node)
public final IASTNode createLiteralNode(java.lang.String code)
code
- the string to be inserted; lines should not have extra indentationjava.lang.IllegalArgumentException
- if the code is null.public final void remove(IASTNode node, TextEditGroup editGroup)
node
- the node being removededitGroup
- the edit group in which to collect the corresponding
text edits, or null
java.lang.IllegalArgumentException
- if the node is null, the node is not
part of this rewriter's AST.public final ASTRewrite replace(IASTNode node, IASTNode replacement, TextEditGroup editGroup)
node
- the node being replacedreplacement
- the node replacing the given oneeditGroup
- the edit group in which to collect the corresponding text edits,
or null
java.lang.IllegalArgumentException
- if the node or the replacement is null, or if the node is
not part of this rewriter's ASTpublic final ASTRewrite insertBefore(IASTNode parent, IASTNode insertionPoint, IASTNode newNode, TextEditGroup editGroup)
parent
- the parent the new node is added to.insertionPoint
- the node before which the insertion shall be done, or null
for inserting after the last child.newNode
- the node being insertededitGroup
- the edit group in which to collect the corresponding
text edits, or null
java.lang.IllegalArgumentException
- if the parent or the newNode is null, or if the parent is
not part of this rewriter's AST, or the insertionPoint is not a child of the parent.public Change rewriteAST()
Calling this methods does not discard the modifications on record. Subsequence modifications are added to the ones already on record. If this method is called again later, the resulting text edit object will accurately reflect the net cumulative affect of all those changes.
public void addComment(IASTNode node, IASTComment comment, ASTRewrite.CommentPosition pos)
node
- the node.comment
- the comment to be attached to the node at the given position.pos
- the position of the comment.public java.util.List<IASTComment> getComments(IASTNode node, ASTRewrite.CommentPosition pos)
node
- the nodepos
- the position of the comments