Java Code Examples for org.eclipse.jdt.core.dom.StructuralPropertyDescriptor#isChildListProperty()
The following examples show how to use
org.eclipse.jdt.core.dom.StructuralPropertyDescriptor#isChildListProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseQuickFix.java From vscode-checkstyle with GNU Lesser General Public License v3.0 | 6 votes |
/** * Replaces a node in an AST with another node. If the replacement is successful * the original node is deleted. * * @param node The node to replace. * @param replacement The replacement node. * @return <code>true</code> if the node was successfully replaced. */ protected boolean replace(final ASTNode node, final ASTNode replacement) { final ASTNode parent = node.getParent(); final StructuralPropertyDescriptor descriptor = node.getLocationInParent(); if (descriptor != null) { if (descriptor.isChildProperty()) { parent.setStructuralProperty(descriptor, replacement); node.delete(); return true; } else if (descriptor.isChildListProperty()) { @SuppressWarnings("unchecked") final List<ASTNode> children = (List<ASTNode>) parent.getStructuralProperty(descriptor); children.set(children.indexOf(node), replacement); node.delete(); return true; } } return false; }
Example 2
Source File: InternalASTRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
void postAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) { if(property.isChildListProperty()) { ListRewriteEvent event = getListEvent(node, property); List list = (List)node.getStructuralProperty(property); int i = list.indexOf(child); int s = list.size(); int index; if(i + 1 < s) { ASTNode nextNode = (ASTNode)list.get(i + 1); index = event.getIndex(nextNode, ListRewriteEvent.NEW); } else { index = -1; } event.insert(child, index); if(child != null) { markAsMoveOrCopyTarget(node, child); } } }
Example 3
Source File: NodeUtils.java From SimFix with GNU General Public License v2.0 | 6 votes |
public static List<ASTNode> getAllSiblingNodes(ASTNode node){ List<ASTNode> siblings = new ArrayList<>(); StructuralPropertyDescriptor structuralPropertyDescriptor = node.getLocationInParent(); if (structuralPropertyDescriptor == null) { return siblings; } else if(structuralPropertyDescriptor.isChildListProperty()){ List list = (List) node.getParent().getStructuralProperty(structuralPropertyDescriptor); for(Object object : list){ if(object instanceof ASTNode){ siblings.add((ASTNode) object); } } } // else if(structuralPropertyDescriptor.isChildProperty()){ // ASTNode child = (ASTNode) node.getParent().getStructuralProperty(structuralPropertyDescriptor); // siblings.add(child); // } return siblings; }
Example 4
Source File: AbstractASTResolution.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Replaces a node in an AST with another node. If the replacement is successful the original node * is deleted. * * @param node * The node to replace. * @param replacement * The replacement node. * @return <code>true</code> if the node was successfully replaced. */ protected boolean replace(final ASTNode node, final ASTNode replacement) { final ASTNode parent = node.getParent(); final StructuralPropertyDescriptor descriptor = node.getLocationInParent(); if (descriptor != null) { if (descriptor.isChildProperty()) { parent.setStructuralProperty(descriptor, replacement); node.delete(); return true; } else if (descriptor.isChildListProperty()) { @SuppressWarnings("unchecked") final List<ASTNode> children = (List<ASTNode>) parent.getStructuralProperty(descriptor); children.set(children.indexOf(node), replacement); node.delete(); return true; } } return false; }
Example 5
Source File: ExtractMethodRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private boolean matchesLocationInEnclosingBodyDecl(BodyDeclaration originalEnclosingBodyDeclaration, BodyDeclaration duplicateEnclosingBodyDeclaration, VariableDeclaration originalReturnNode, VariableDeclaration duplicateReturnNode) { boolean matches = true; ASTNode original = originalReturnNode; ASTNode dupliacte = duplicateReturnNode; // walk up the parent chains to check if the location of the return nodes in their respective parent chains is same do { ASTNode originalParent = original.getParent(); ASTNode duplicateParent = dupliacte.getParent(); StructuralPropertyDescriptor originalLoc = original.getLocationInParent(); StructuralPropertyDescriptor duplicateLoc = dupliacte.getLocationInParent(); if (originalParent != null && duplicateParent != null && originalLoc.getNodeClass().equals(duplicateLoc.getNodeClass()) && originalLoc.getId().equals(duplicateLoc.getId())) { if (originalLoc.isChildListProperty() && duplicateLoc.isChildListProperty()) { int indexOfOriginal = ((List<?>) originalParent.getStructuralProperty(originalLoc)).indexOf(original); int indexOfDuplicate = ((List<?>) duplicateParent.getStructuralProperty(duplicateLoc)).indexOf(dupliacte); if (indexOfOriginal != indexOfDuplicate) { matches = false; break; } } } else { matches = false; break; } original = originalParent; dupliacte = duplicateParent; if ((originalEnclosingBodyDeclaration.equals(original) && !duplicateEnclosingBodyDeclaration.equals(dupliacte)) || (!originalEnclosingBodyDeclaration.equals(original) && duplicateEnclosingBodyDeclaration.equals(dupliacte))) { matches = false; break; } } while (!originalEnclosingBodyDeclaration.equals(original) && !duplicateEnclosingBodyDeclaration.equals(dupliacte)); return matches; }
Example 6
Source File: AddArgumentCorrectionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private ChildListPropertyDescriptor getProperty() { List<StructuralPropertyDescriptor> list= fCallerNode.structuralPropertiesForType(); for (int i= 0; i < list.size(); i++) { StructuralPropertyDescriptor curr= list.get(i); if (curr.isChildListProperty() && "arguments".equals(curr.getId())) { //$NON-NLS-1$ return (ChildListPropertyDescriptor) curr; } } return null; }
Example 7
Source File: EquivalentNodeFinder.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") private int getIndex(ASTNode node) { StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); if (locationInParent != null && locationInParent.isChildListProperty()) { List<ASTNode> parentsChildren = (List<ASTNode>) node.getParent().getStructuralProperty( locationInParent); if (parentsChildren != null) { return parentsChildren.indexOf(node); } } // The node is not contained within a list-based property on the parent return NOT_FROM_LIST; }
Example 8
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the list that contains the given ASTNode. If the node * isn't part of any list, <code>null</code> is returned. * * @param node the node in question * @return the list that contains the node or <code>null</code> */ public static List<? extends ASTNode> getContainingList(ASTNode node) { StructuralPropertyDescriptor locationInParent= node.getLocationInParent(); if (locationInParent != null && locationInParent.isChildListProperty()) { return getChildListProperty(node.getParent(), (ChildListPropertyDescriptor) locationInParent); } return null; }
Example 9
Source File: StructureSelectionAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
static ASTNode[] getSiblingNodes(ASTNode node) { ASTNode parent= node.getParent(); StructuralPropertyDescriptor locationInParent= node.getLocationInParent(); if (locationInParent.isChildListProperty()) { List<? extends ASTNode> siblings= ASTNodes.getChildListProperty(parent, (ChildListPropertyDescriptor) locationInParent); return siblings.toArray(new ASTNode[siblings.size()]); } return null; }
Example 10
Source File: AddArgumentCorrectionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private ChildListPropertyDescriptor getProperty() { List<StructuralPropertyDescriptor> list= fCallerNode.structuralPropertiesForType(); for (int i= 0; i < list.size(); i++) { StructuralPropertyDescriptor curr= list.get(i); if (curr.isChildListProperty() && "arguments".equals(curr.getId())) { //$NON-NLS-1$ return (ChildListPropertyDescriptor) curr; } } return null; }
Example 11
Source File: ASTRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Removes the given node from its parent in this rewriter. The AST itself * is not actually modified in any way; rather, the rewriter just records * a note that this node should not be there. * * @param node the node being removed. The node can either be an original node in the AST * or (since 3.4) a new node already inserted or used as replacement in this AST rewriter. * @param editGroup the edit group in which to collect the corresponding * text edits, or <code>null</code> 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 * (such as removing a required node) */ public final void remove(ASTNode node, TextEditGroup editGroup) { if (node == null) { throw new IllegalArgumentException(); } StructuralPropertyDescriptor property; ASTNode parent; if (RewriteEventStore.isNewNode(node)) { // remove a new node, bug 164862 PropertyLocation location= this.eventStore.getPropertyLocation(node, RewriteEventStore.NEW); if (location != null) { property= location.getProperty(); parent= location.getParent(); } else { throw new IllegalArgumentException("Node is not part of the rewriter's AST"); //$NON-NLS-1$ } } else { property= node.getLocationInParent(); parent= node.getParent(); } if (property.isChildListProperty()) { getListRewrite(parent, (ChildListPropertyDescriptor) property).remove(node, editGroup); } else { set(parent, property, null, editGroup); } }
Example 12
Source File: ASTRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Replaces the given node in this rewriter. The replacement node * must either be brand new (not part of the original AST) or a placeholder * node (for example, one created by {@link #createCopyTarget(ASTNode)} * or {@link #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. * * @param node the node being replaced. The node can either be an original node in the AST * or (since 3.4) a new node already inserted or used as replacement in this AST rewriter. * @param replacement the replacement node, or <code>null</code> if no * replacement * @param editGroup the edit group in which to collect the corresponding * text edits, or <code>null</code> 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 */ public final void replace(ASTNode node, ASTNode replacement, TextEditGroup editGroup) { if (node == null) { throw new IllegalArgumentException(); } StructuralPropertyDescriptor property; ASTNode parent; if (RewriteEventStore.isNewNode(node)) { // replace a new node, bug 164862 PropertyLocation location= this.eventStore.getPropertyLocation(node, RewriteEventStore.NEW); if (location != null) { property= location.getProperty(); parent= location.getParent(); } else { throw new IllegalArgumentException("Node is not part of the rewriter's AST"); //$NON-NLS-1$ } } else { property= node.getLocationInParent(); parent= node.getParent(); } if (property.isChildListProperty()) { getListRewrite(parent, (ChildListPropertyDescriptor) property).replace(node, replacement, editGroup); } else { set(parent, property, replacement, editGroup); } }
Example 13
Source File: InternalASTRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
void preAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) { if(property.isChildProperty()) { NodeRewriteEvent event = getNodeEvent(node, property); event.setNewValue(child); if(child != null) { markAsMoveOrCopyTarget(node, child); } } else if(property.isChildListProperty()) { // force event creation getListEvent(node, property); } }
Example 14
Source File: RewriteEventStore.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void validateIsListProperty(StructuralPropertyDescriptor property) { if (!property.isChildListProperty()) { String message= property.getId() + " is not a list property"; //$NON-NLS-1$ throw new IllegalArgumentException(message); } }
Example 15
Source File: RewriteEventStore.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void validateIsNodeProperty(StructuralPropertyDescriptor property) { if (property.isChildListProperty()) { String message= property.getId() + " is not a node property"; //$NON-NLS-1$ throw new IllegalArgumentException(message); } }
Example 16
Source File: ASTRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void validateIsListProperty(StructuralPropertyDescriptor property) { if (!property.isChildListProperty()) { String message= property.getId() + " is not a list property"; //$NON-NLS-1$ throw new IllegalArgumentException(message); } }
Example 17
Source File: ASTRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Returns the value of the given property as managed by this rewriter. If the property * has been removed, <code>null</code> is returned. If it has been replaced, the replacing value * is returned. If the property has not been changed yet, the original value is returned. * <p> * For child list properties use {@link ListRewrite#getRewrittenList()} to get access to the * rewritten nodes in a list. </p> * * @param node the node * @param property the node's property * @return the value of the given property as managed by this rewriter * * @since 3.2 */ public Object get(ASTNode node, StructuralPropertyDescriptor property) { if (node == null || property == null) { throw new IllegalArgumentException(); } if (property.isChildListProperty()) { throw new IllegalArgumentException("Use the list rewriter to access nodes in a list"); //$NON-NLS-1$ } return this.eventStore.getNewValue(node, property); }