Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2004, 2013 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.core.dom.rewrite;
 
 import java.util.List;
 
 import  org.eclipse.text.edits.TextEditGroup;

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)
 
 public final class ListRewrite {
 
 	private ASTNode parent;
 	private ASTRewrite rewriter;
 
 
 	/* package*/ ListRewrite(ASTRewrite rewriterASTNode parentChildListPropertyDescriptor childProperty) {
 		this.rewriter;
 		this.parent;
 		this.childProperty;
 	}
 
 		return this..getRewriteEventStore();
 	}
 
 	private ListRewriteEvent getEvent() {
 		return getRewriteStore().getListEvent(this.this.true);
 	}

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()
 
 	public ASTNode getParent() {
 		return this.;
 	}

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:
getParent()
 
 		return this.;
 	}

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, 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)
 
 	public void remove(ASTNode node, TextEditGroup editGroup) {
 		if (node == null) {
 			throw new IllegalArgumentException();
 		}
 		RewriteEvent eventgetEvent().removeEntry(node);
 		if (editGroup != null) {
			getRewriteStore().setEventEditGroup(eventeditGroup);
		}
	}

Returns the ASTRewrite instance from which this ListRewriter has been created from.

Returns:
the parent AST Rewriter instance.
Since:
3.1
		return this.;
	}


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 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 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)
	public void replace(ASTNode nodeASTNode replacement, TextEditGroup editGroup) {
		if (node == null) {
		}
		RewriteEvent eventgetEvent().replaceEntry(nodereplacement);
		if (editGroup != null) {
			getRewriteStore().setEventEditGroup(eventeditGroup);
		}
	}

Inserts the given node into the list after the given element. The existing node 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.

Parameters:
node the node to insert
previousElement 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 previousElement is not a member of the list (original or new), or if the described modification is otherwise invalid
	public void insertAfter(ASTNode nodeASTNode previousElement, TextEditGroup editGroup) {
		if (node == null || previousElement == null) {
		}
		int indexgetEvent().getIndex(previousElement.);
		if (index == -1) {
			throw new IllegalArgumentException("Node does not exist"); //$NON-NLS-1$
		}
		internalInsertAt(nodeindex + 1, trueeditGroup);
	}

Inserts the given node into the list before the given element. The existing node 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.

Parameters:
node the node to insert
nextElement 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 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 invalid
	public void insertBefore(ASTNode nodeASTNode nextElement, TextEditGroup editGroup) {
		if (node == null || nextElement == null) {
		}
		int indexgetEvent().getIndex(nextElement.);
		if (index == -1) {
			throw new IllegalArgumentException("Node does not exist"); //$NON-NLS-1$
		}
		internalInsertAt(nodeindexfalseeditGroup);
	}

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)
	public void insertFirst(ASTNode node, TextEditGroup editGroup) {
		if (node == null) {
		}
		internalInsertAt(node, 0, falseeditGroup);
	}

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)
	public void insertLast(ASTNode node, TextEditGroup editGroup) {
		if (node == null) {
		}
		internalInsertAt(node, -1, trueeditGroup);
	}

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
	public void insertAt(ASTNode nodeint index, TextEditGroup editGroup) {
		if (node == null) {
		}
		internalInsertAt(nodeindexisInsertBoundToPreviousByDefault(node), editGroup);
	}
	private void internalInsertAt(ASTNode nodeint indexboolean boundToPrevious, TextEditGroup editGroup) {
		RewriteEvent eventgetEvent().insert(nodeindex);
		if (boundToPrevious) {
		}
		if (editGroup != null) {
			getRewriteStore().setEventEditGroup(eventeditGroup);
		}
	}
	private void validatePropertyType(ASTNode node) {
			return;
		}
			String message = node.getClass().getName() + " is not a valid type for " + this..getNodeClass().getName() //$NON-NLS-1$
" property '" + this..getId() + "'. Must be " + this..getElementType().getName(); //$NON-NLS-1$ //$NON-NLS-2$
			throw new IllegalArgumentException(message);
		}
	}
	private ASTNode createTargetNode(ASTNode firstASTNode lastboolean isMoveASTNode replacingNode, TextEditGroup editGroup) {
		if (first == null || last == null) {
		}
		NodeInfoStore nodeStorethis..getNodeStore();
		ASTNode placeholdernodeStore.newPlaceholderNode(first.getNodeType()); // revisit: could use list type
		if (placeholder == null) {
			throw new IllegalArgumentException("Creating a target node is not supported for nodes of type" + first.getClass().getName()); //$NON-NLS-1$
		}
		Block internalPlaceHoldernodeStore.createCollapsePlaceholder();
		CopySourceInfo infogetRewriteStore().createRangeCopy(this.this.firstlastisMoveinternalPlaceHolderreplacingNodeeditGroup);
		nodeStore.markAsCopyTarget(placeholderinfo);
		return placeholder;
	}

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 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 createCopyTarget(ASTNode firstASTNode last) {
		if (first == last) {
			return this..createCopyTarget(first);
else {
			return createTargetNode(firstlastfalsenullnull);
		}
	}

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 range
last the node that ends the range
Returns:
the new placeholder node
Throws:
IllegalArgumentException 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.
Since:
3.1
	public final ASTNode createMoveTarget(ASTNode firstASTNode last) {
		return createMoveTarget(firstlastnullnull);
	}

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 range
last the node that ends the range
replacingNode a node that is set at the location of the moved nodes or null to remove all nodes
editGroup the edit group in which to collect the corresponding text edits fro a replace, or null if ungrouped
Returns:
the new placeholder node
Throws:
IllegalArgumentException 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.
Since:
3.1
	public final ASTNode createMoveTarget(ASTNode firstASTNode lastASTNode replacingNode, TextEditGroup editGroup) {
		if (first == last) {
			replace(firstreplacingNodeeditGroup);
			return this..createMoveTarget(first);
else {
			return createTargetNode(firstlasttruereplacingNodeeditGroup);
		}
	}
	/*
	 * Heuristic to decide if a inserted node is bound to previous or the next sibling.
	 */
	private boolean isInsertBoundToPreviousByDefault(ASTNode node) {
		return (node instanceof Statement || node instanceof FieldDeclaration);
	}

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
	public List getOriginalList() {
		return Collections.unmodifiableList(list);
	}

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
	public List getRewrittenList() {
		List list= (ListgetEvent().getNewValue();
		return Collections.unmodifiableList(list);
	}
New to GrepCode? Check out our FAQ X