Package org.eclipse.jdt.core.dom.rewrite
Class ListRewrite
java.lang.Object
org.eclipse.jdt.core.dom.rewrite.ListRewrite
For describing manipulations to a child list property of an AST node.
This class is not intended to be subclassed.
- Since:
- 3.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfinal ASTNode
createCopyTarget
(ASTNode first, ASTNode last) Creates and returns a placeholder node for a true copy of a range of nodes of the current list.final ASTNode
createMoveTarget
(ASTNode first, ASTNode last) Creates and returns a placeholder node for a move of a range of nodes of the current list.final ASTNode
createMoveTarget
(ASTNode first, ASTNode last, ASTNode replacingNode, TextEditGroup editGroup) Creates and returns a placeholder node for a move of a range of nodes of the current list.Returns the ASTRewrite instance from which this ListRewriter has been created from.Returns the property of the parent node for which this list rewriter was created.Returns the original nodes in the list property managed by this rewriter.Returns the parent of the list for which this list rewriter was created.Returns the nodes in the revised list property managed by this rewriter.void
insertAfter
(ASTNode node, ASTNode previousElement, TextEditGroup editGroup) Inserts the given node into the list after the given element.void
insertAt
(ASTNode node, int index, TextEditGroup editGroup) Inserts the given node into the list at the given index.void
insertBefore
(ASTNode node, ASTNode nextElement, TextEditGroup editGroup) Inserts the given node into the list before the given element.void
insertFirst
(ASTNode node, TextEditGroup editGroup) Inserts the given node into the list at the start of the list.void
insertLast
(ASTNode node, TextEditGroup editGroup) Inserts the given node into the list at the end of the list.void
remove
(ASTNode node, TextEditGroup editGroup) Removes the given node from its parent's list property in the rewriter.void
replace
(ASTNode node, ASTNode replacement, TextEditGroup editGroup) Replaces the given node from its parent's list property in the rewriter.
-
Method Details
-
getParent
Returns the parent of the list for which this list rewriter was created.- Returns:
- the node that contains the list for which this list rewriter was created
- Since:
- 3.1
- See Also:
-
getLocationInParent
Returns the property of the parent node for which this list rewriter was created.- Returns:
- the property of the parent node for which this list rewriter was created
- Since:
- 3.1
- See Also:
-
remove
Removes the given node from its parent's list property in the rewriter. The node must be contained in the list. The AST itself is not actually modified in any way; rather, the rewriter just records a note that this node has been removed from this list.- Parameters:
node
- the node being removed. The node can either be an original node in this list or (since 3.4) a new node already inserted or used as replacement in this AST rewriter.editGroup
- the edit group in which to collect the corresponding text edits, ornull
if ungrouped- Throws:
IllegalArgumentException
- if the node is null, or if the node is not part of this rewriter's AST, or if the described modification is invalid (not a member of this node's original list)
-
getASTRewrite
Returns the ASTRewrite instance from which this ListRewriter has been created from.- Returns:
- the parent AST Rewriter instance.
- Since:
- 3.1
-
replace
Replaces the given node from its parent's list property in the rewriter. The node must be contained in the list. The replacement node must either be brand new (not part of the original AST) or a placeholder node (for example, one created byASTRewrite.createCopyTarget(ASTNode)
,ASTRewrite.createMoveTarget(ASTNode)
, orASTRewrite.createStringPlaceholder(String, int)
). The AST itself is not actually modified in any way; rather, the rewriter just records a note that this node has been replaced in this list.- Parameters:
node
- the node being removed. The node can either be an original node in this list or (since 3.4) a new node already inserted or used as replacement in this AST rewriter.replacement
- the replacement node, ornull
if no replacementeditGroup
- the edit group in which to collect the corresponding text edits, ornull
if ungrouped- Throws:
IllegalArgumentException
- if the node is null, or if the node is not part of this rewriter's AST, or if the replacement node is not a new node (or placeholder), or if the described modification is otherwise invalid (not a member of this node's original list)
-
insertAfter
Inserts the given node into the list after the given element. The existing nodepreviousElement
must be in the list, either as an original or as a new node that has been inserted. The inserted node must either be brand new (not part of the original AST) or a placeholder node (for example, one created byASTRewrite.createCopyTarget(ASTNode)
,ASTRewrite.createMoveTarget(ASTNode)
, orASTRewrite.createStringPlaceholder(String, int)
). The AST itself is not actually modified in any way; rather, the rewriter just records a note that this node has been inserted into the list.- Parameters:
node
- the node to insertpreviousElement
- the element after which the given node is to be insertededitGroup
- the edit group in which to collect the corresponding text edits, ornull
if ungrouped- Throws:
IllegalArgumentException
- if the node or element is null, or if the node is not part of this rewriter's AST, or if the inserted node is not a new node (or placeholder), or ifpreviousElement
is not a member of the list (original or new), or if the described modification is otherwise invalid
-
insertBefore
Inserts the given node into the list before the given element. The existing nodenextElement
must be in the list, either as an original or as a new node that has been inserted. The inserted node must either be brand new (not part of the original AST) or a placeholder node (for example, one created byASTRewrite.createCopyTarget(ASTNode)
,ASTRewrite.createMoveTarget(ASTNode)
, orASTRewrite.createStringPlaceholder(String, int)
). The AST itself is not actually modified in any way; rather, the rewriter just records a note that this node has been inserted into the list.- Parameters:
node
- the node to insertnextElement
- the element before which the given node is to be insertededitGroup
- the edit group in which to collect the corresponding text edits, ornull
if ungrouped- Throws:
IllegalArgumentException
- if the node or next element is null, or if the node is not part of this rewriter's AST, or if the inserted node is not a new node (or placeholder), or ifnextElement
is not a member of the list (original or new), or if the described modification is otherwise invalid
-
insertFirst
Inserts the given node into the list at the start of the list. Equivalent toinsertAt(node, 0, editGroup)
.- Parameters:
node
- the node to inserteditGroup
- the edit group in which to collect the corresponding text edits, ornull
if ungrouped- Throws:
IllegalArgumentException
- if the node is null, or if the node is not part of this rewriter's AST, or if the inserted node is not a new node (or placeholder), or if the described modification is otherwise invalid (not a member of this node's original list)- See Also:
-
insertLast
Inserts the given node into the list at the end of the list. Equivalent toinsertAt(node, -1, editGroup)
.- Parameters:
node
- the node to inserteditGroup
- the edit group in which to collect the corresponding text edits, ornull
if ungrouped- Throws:
IllegalArgumentException
- if the node is null, or if the node is not part of this rewriter's AST, or if the inserted node is not a new node (or placeholder), or if the described modification is otherwise invalid (not a member of this node's original list)- See Also:
-
insertAt
Inserts the given node into the list at the given index. The index corresponds to a combined list of original and new nodes; removed or replaced nodes are still in the combined list. The inserted node must either be brand new (not part of the original AST) or a placeholder node (for example, one created byASTRewrite.createCopyTarget(ASTNode)
,ASTRewrite.createMoveTarget(ASTNode)
, orASTRewrite.createStringPlaceholder(String, int)
). The AST itself is not actually modified in any way; rather, the rewriter just records a note that this node has been inserted into the list.- Parameters:
node
- the node to insertindex
- insertion index in the combined list of original and inserted nodes;-1
indicates insertion as the last elementeditGroup
- the edit group in which to collect the corresponding text edits, ornull
if ungrouped- Throws:
IllegalArgumentException
- if the node is null, or if the node is not part of this rewriter's AST, or if the inserted node is not a new node (or placeholder), or if the described modification is otherwise invalid (not a member of this node's original list)IndexOutOfBoundsException
- if the index is negative and not -1, or if it is larger than the size of the combined list
-
createCopyTarget
Creates and returns a placeholder node for a true copy of a range of nodes of the current list. The placeholder node can either be inserted as new or used to replace an existing node. When the document is rewritten, a copy of the source code for the given node range is inserted into the output document at the position corresponding to the placeholder (indentation is adjusted).- Parameters:
first
- the node that starts the rangelast
- the node that ends the range- Returns:
- the new placeholder node
- Throws:
IllegalArgumentException
- An exception is thrown if the first or last node arenull
, if a node is not a child of the current list or if the first node is not before the last node. AnIllegalArgumentException
is also thrown if the copied range is overlapping with an other moved or copied range.
-
createMoveTarget
Creates and returns a placeholder node for a move of a range of nodes of the current list. The placeholder node can either be inserted as new or used to replace an existing node. When the document is rewritten, a copy of the source code for the given node range is inserted into the output document at the position corresponding to the placeholder (indentation is adjusted).- Parameters:
first
- the node that starts the rangelast
- the node that ends the range- Returns:
- the new placeholder node
- Throws:
IllegalArgumentException
- An exception is thrown if the first or last node arenull
, if a node is not a child of the current list or if the first node is not before the last node. AnIllegalArgumentException
is also thrown if the moved range is overlapping with an other moved or copied range.- Since:
- 3.1
-
createMoveTarget
public final ASTNode createMoveTarget(ASTNode first, ASTNode last, ASTNode replacingNode, TextEditGroup editGroup) Creates and returns a placeholder node for a move of a range of nodes of the current list. The moved nodes can optionally be replaced by a specified node. The placeholder node can either be inserted as new or used to replace an existing node. When the document is rewritten, a copy of the source code for the given node range is inserted into the output document at the position corresponding to the placeholder (indentation is adjusted).- Parameters:
first
- the node that starts the rangelast
- the node that ends the rangereplacingNode
- a node that is set at the location of the moved nodes ornull
to remove all nodeseditGroup
- the edit group in which to collect the corresponding text edits fro a replace, ornull
if ungrouped- Returns:
- the new placeholder node
- Throws:
IllegalArgumentException
- An exception is thrown if the first or last node arenull
, if a node is not a child of the current list or if the first node is not before the last node. AnIllegalArgumentException
is also thrown if the moved range is overlapping with an other moved or copied range.- Since:
- 3.1
-
getOriginalList
Returns the original nodes in the list property managed by this rewriter. The returned list is unmodifiable.- Returns:
- a list of all original nodes in the list
-
getRewrittenList
Returns the nodes in the revised list property managed by this rewriter. The returned list is unmodifiable.- Returns:
- a list of all nodes in the list taking into account all the described changes
-