Eclipse JDT
Release 3.0

org.eclipse.jdt.core.dom.rewrite
Class ListRewrite

java.lang.Object
  extended byorg.eclipse.jdt.core.dom.rewrite.ListRewrite

public final class ListRewrite
extends Object

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:
ASTRewrite.getListRewrite(ASTNode, ChildListPropertyDescriptor)

Method Summary
 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.
 List getOriginalList()
          Returns the original nodes in the list property managed by this rewriter.
 List getRewrittenList()
          Returns the nodes in the revised list property managed by this rewriter.
 void insertAfter(ASTNode node, ASTNode element, 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 element, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

remove

public void remove(ASTNode node,
                   TextEditGroup editGroup)
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
editGroup - the edit group in which to collect the corresponding text edits, or null 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)

replace

public void replace(ASTNode node,
                    ASTNode replacement,
                    TextEditGroup editGroup)
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 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 replaced in this list.

Parameters:
node - the node being replaced
replacement - the replacement node, or null if no replacement
editGroup - the edit group in which to collect the corresponding text edits, or null 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

public void insertAfter(ASTNode node,
                        ASTNode element,
                        TextEditGroup editGroup)
Inserts the given node into the list after the given element. The existing node 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.

Parameters:
node - the node to insert
element - the element after which the given node is to be inserted
editGroup - the edit group in which to collect the corresponding text edits, or null 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 if element is not a member of the list (original or new), or if the described modification is otherwise invalid

insertBefore

public void insertBefore(ASTNode node,
                         ASTNode element,
                         TextEditGroup editGroup)
Inserts the given node into the list before the given element. The existing node 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.

Parameters:
node - the node to insert
element - the element before which the given node is to be inserted
editGroup - the edit group in which to collect the corresponding text edits, or null 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 if element is not a member of the list (original or new), or if the described modification is otherwise invalid

insertFirst

public void insertFirst(ASTNode node,
                        TextEditGroup editGroup)
Inserts the given node into the list at the start of the list. Equivalent to insertAt(node, 0, editGroup).

Parameters:
node - the node to insert
editGroup - the edit group in which to collect the corresponding text edits, or null 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(ASTNode, int, TextEditGroup)

insertLast

public void insertLast(ASTNode node,
                       TextEditGroup editGroup)
Inserts the given node into the list at the end of the list. Equivalent to insertAt(node, -1, editGroup).

Parameters:
node - the node to insert
editGroup - the edit group in which to collect the corresponding text edits, or null 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(ASTNode, int, TextEditGroup)

insertAt

public void insertAt(ASTNode node,
                     int index,
                     TextEditGroup editGroup)
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 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.

Parameters:
node - the node to insert
index - insertion index in the combined list of original and inserted nodes; -1 indicates insertion as the last element
editGroup - the edit group in which to collect the corresponding text edits, or null 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

public final 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. 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 range
last - the node that ends the range
Returns:
the new placeholder node
Throws:
IllegalArgumentException - if the node is null, or if the node is not part of this rewriter's AST

getOriginalList

public List 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

public 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

Eclipse JDT
Release 3.0

Copyright (c) IBM Corp. and others 2000, 2004. All Rights Reserved.