public final class ListRewrite extends Object
This class is not intended to be subclassed.
ASTRewrite.getListRewrite(ASTNode, ChildListPropertyDescriptor)
Modifier and Type | Method and Description |
---|---|
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.
|
ASTNode |
createMoveTarget(ASTNode first,
ASTNode last)
Creates and returns a placeholder node for a move of a range of nodes of the
current list.
|
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.
|
ASTRewrite |
getASTRewrite()
Returns the ASTRewrite instance from which this ListRewriter has been created from.
|
StructuralPropertyDescriptor |
getLocationInParent()
Returns the property of the parent node for which this list rewriter was created.
|
List |
getOriginalList()
Returns the original nodes in the list property managed by this
rewriter.
|
ASTNode |
getParent()
Returns the parent of the list for which this list rewriter was created.
|
List |
getRewrittenList()
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.
|
public ASTNode getParent()
getLocationInParent()
public StructuralPropertyDescriptor getLocationInParent()
getParent()
public void remove(ASTNode node, TextEditGroup editGroup)
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, or null
if ungroupedIllegalArgumentException
- 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)public ASTRewrite getASTRewrite()
public void replace(ASTNode node, ASTNode replacement, TextEditGroup editGroup)
ASTRewrite.createCopyTarget(ASTNode)
,
ASTRewrite.createMoveTarget(ASTNode)
,
or ASTRewrite.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.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, or null
if no
replacementeditGroup
- the edit group in which to collect the corresponding
text edits, or null
if ungroupedIllegalArgumentException
- 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)public void insertAfter(ASTNode node, ASTNode previousElement, TextEditGroup editGroup)
previousElement
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 by
ASTRewrite.createCopyTarget(ASTNode)
,
ASTRewrite.createMoveTarget(ASTNode)
,
or ASTRewrite.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.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, or null
if ungroupedIllegalArgumentException
- 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 if previousElement
is not a member
of the list (original or new), or if the described modification is
otherwise invalidpublic void insertBefore(ASTNode node, ASTNode nextElement, TextEditGroup editGroup)
nextElement
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 by
ASTRewrite.createCopyTarget(ASTNode)
,
ASTRewrite.createMoveTarget(ASTNode)
,
or ASTRewrite.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.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, or null
if ungroupedIllegalArgumentException
- 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 if nextElement
is not a member
of the list (original or new), or if the described modification is
otherwise invalidpublic void insertFirst(ASTNode node, TextEditGroup editGroup)
insertAt(node, 0, editGroup)
.node
- the node to inserteditGroup
- the edit group in which to collect the corresponding
text edits, or null
if ungroupedIllegalArgumentException
- 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)insertAt(ASTNode, int, TextEditGroup)
public void insertLast(ASTNode node, TextEditGroup editGroup)
insertAt(node, -1, editGroup)
.node
- the node to inserteditGroup
- the edit group in which to collect the corresponding
text edits, or null
if ungroupedIllegalArgumentException
- 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)insertAt(ASTNode, int, TextEditGroup)
public void insertAt(ASTNode node, int index, TextEditGroup editGroup)
ASTRewrite.createCopyTarget(ASTNode)
,
ASTRewrite.createMoveTarget(ASTNode)
,
or ASTRewrite.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.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, or null
if ungroupedIllegalArgumentException
- 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 listpublic final ASTNode createCopyTarget(ASTNode first, ASTNode last)
first
- the node that starts the rangelast
- the node that ends the rangeIllegalArgumentException
- An exception is thrown if the first or last node
are null
, if a node is not a child of the current list or if the first node
is not before the last node. An IllegalArgumentException
is
also thrown if the copied range is overlapping with an other moved or copied range.public final ASTNode createMoveTarget(ASTNode first, ASTNode last)
first
- the node that starts the rangelast
- the node that ends the rangeIllegalArgumentException
- An exception is thrown if the first or last node
are null
, if a node is not a child of the current list or if the first node
is not before the last node. An IllegalArgumentException
is
also thrown if the moved range is overlapping with an other moved or copied range.public final ASTNode createMoveTarget(ASTNode first, ASTNode last, ASTNode replacingNode, TextEditGroup editGroup)
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
or null
to remove all nodeseditGroup
- the edit group in which to collect the corresponding
text edits fro a replace, or null
if ungroupedIllegalArgumentException
- An exception is thrown if the first or
last node are null
, if a node is not a child of the current list or
if the first node is not before the last node. An IllegalArgumentException
is also thrown if the moved range is overlapping with an other moved
or copied range.public List getOriginalList()
public List getRewrittenList()
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.