/** * An excellent method! Feel free to use it! * * @param old the old node * @param neo the new node */ public static void replaceNode(ASTNode old, ASTNode neo) { StructuralPropertyDescriptor p = old.getLocationInParent(); if (p == null) { // node is unparented return; } if (p.isChildProperty()) { old.getParent().setStructuralProperty(p, neo); return; } if (p.isChildListProperty()) { List l = (List) old.getParent().getStructuralProperty(p); l.set(l.indexOf(old), neo); } }
private void replaceInParent(ASTNode nodeToReplace, ASTNode replacementNode) { if (nodeToReplace.getParent() == null) { throw new IllegalArgumentException(nodeToReplace, "The node to replace does not have a parent"); } final StructuralPropertyDescriptor locationInParent = nodeToReplace.getLocationInParent(); if (locationInParent instanceof ChildPropertyDescriptor) { final ChildPropertyDescriptor cpd = (ChildPropertyDescriptor) locationInParent; nodeToReplace.getParent().setStructuralProperty(cpd, replacementNode); } else if (locationInParent instanceof ChildListPropertyDescriptor) { final ChildListPropertyDescriptor clpd = (ChildListPropertyDescriptor) locationInParent; @SuppressWarnings("unchecked") final List<ASTNode> property = (List<ASTNode>) nodeToReplace.getParent().getStructuralProperty(clpd); property.set(property.indexOf(nodeToReplace), replacementNode); } else { throw new NotImplementedException(nodeToReplace, locationInParent); } } }
/** * Removes this node from its parent. Has no effect if this node * is unparented. If this node appears as an element of a child list * property of its parent, then this node is removed from the * list using <code>List.remove</code>. * If this node appears as the value of a child property of its * parent, then this node is detached from its parent * by passing <code>null</code> to the appropriate setter method; * this operation fails if this node is in a mandatory property. * * @since 3.0 */ public final void delete() { StructuralPropertyDescriptor p = getLocationInParent(); if (p == null) { // node is unparented return; } if (p.isChildProperty()) { getParent().setStructuralProperty(this.location, null); return; } if (p.isChildListProperty()) { List l = (List) getParent().getStructuralProperty(this.location); l.remove(this); } }
/** * Removes this node from its parent. Has no effect if this node * is unparented. If this node appears as an element of a child list * property of its parent, then this node is removed from the * list using <code>List.remove</code>. * If this node appears as the value of a child property of its * parent, then this node is detached from its parent * by passing <code>null</code> to the appropriate setter method; * this operation fails if this node is in a mandatory property. * * @since 3.0 */ public final void delete() { StructuralPropertyDescriptor p = getLocationInParent(); if (p == null) { // node is unparented return; } if (p.isChildProperty()) { getParent().setStructuralProperty(this.location, null); return; } if (p.isChildListProperty()) { List l = (List) getParent().getStructuralProperty(this.location); l.remove(this); } }
/** * Removes this node from its parent. Has no effect if this node * is unparented. If this node appears as an element of a child list * property of its parent, then this node is removed from the * list using <code>List.remove</code>. * If this node appears as the value of a child property of its * parent, then this node is detached from its parent * by passing <code>null</code> to the appropriate setter method; * this operation fails if this node is in a mandatory property. * * @since 3.0 */ public final void delete() { StructuralPropertyDescriptor p = getLocationInParent(); if (p == null) { // node is unparented return; } if (p.isChildProperty()) { getParent().setStructuralProperty(this.location, null); return; } if (p.isChildListProperty()) { List l = (List) getParent().getStructuralProperty(this.location); l.remove(this); } }
/** * Removes this node from its parent. Has no effect if this node * is unparented. If this node appears as an element of a child list * property of its parent, then this node is removed from the * list using <code>List.remove</code>. * If this node appears as the value of a child property of its * parent, then this node is detached from its parent * by passing <code>null</code> to the appropriate setter method; * this operation fails if this node is in a mandatory property. * * @since 3.0 */ public final void delete() { StructuralPropertyDescriptor p = getLocationInParent(); if (p == null) { // node is unparented return; } if (p.isChildProperty()) { getParent().setStructuralProperty(this.location, null); return; } if (p.isChildListProperty()) { List l = (List) getParent().getStructuralProperty(this.location); l.remove(this); } }
/** * Removes this node from its parent. Has no effect if this node * is unparented. If this node appears as an element of a child list * property of its parent, then this node is removed from the * list using <code>List.remove</code>. * If this node appears as the value of a child property of its * parent, then this node is detached from its parent * by passing <code>null</code> to the appropriate setter method; * this operation fails if this node is in a mandatory property. * * @since 3.0 */ public final void delete() { StructuralPropertyDescriptor p = getLocationInParent(); if (p == null) { // node is unparented return; } if (p.isChildProperty()) { getParent().setStructuralProperty(this.location, null); return; } if (p.isChildListProperty()) { List l = (List) getParent().getStructuralProperty(this.location); l.remove(this); } }
/** * Removes this node from its parent. Has no effect if this node * is unparented. If this node appears as an element of a child list * property of its parent, then this node is removed from the * list using <code>List.remove</code>. * If this node appears as the value of a child property of its * parent, then this node is detached from its parent * by passing <code>null</code> to the appropriate setter method; * this operation fails if this node is in a mandatory property. * * @since 3.0 */ public final void delete() { StructuralPropertyDescriptor p = getLocationInParent(); if (p == null) { // node is unparented return; } if (p.isChildProperty()) { getParent().setStructuralProperty(this.location, null); return; } if (p.isChildListProperty()) { List l = (List) getParent().getStructuralProperty(this.location); l.remove(this); } }
if (statements.size() == 1 && statements.get(0) instanceof Block) { Block innerBlock= (Block) statements.remove(0); block.getParent().setStructuralProperty(block.getLocationInParent(), innerBlock);
private static Expression getAssignedValue(ProposalParameter context) { ASTNode parent = context.accessNode.getParent(); ASTRewrite astRewrite = context.astRewrite; IJavaProject javaProject = context.compilationUnit.getJavaProject(); IMethodBinding getter = findGetter(context); Expression getterExpression = null; if (getter != null) { getterExpression = astRewrite.getAST().newSimpleName("placeholder"); //$NON-NLS-1$ } ITypeBinding type = context.variableBinding.getType(); boolean is50OrHigher = JavaModelUtil.is50OrHigher(javaProject); Expression result = GetterSetterUtil.getAssignedValue(parent, astRewrite, getterExpression, type, is50OrHigher); if (result != null && getterExpression != null && getterExpression.getParent() != null) { getterExpression.getParent().setStructuralProperty(getterExpression.getLocationInParent(), createMethodInvocation(context, getter, null)); } return result; }
private static Expression getAssignedValue(ProposalParameter context) { ASTNode parent= context.accessNode.getParent(); ASTRewrite astRewrite= context.astRewrite; IJavaProject javaProject= context.compilationUnit.getJavaProject(); IMethodBinding getter= findGetter(context); Expression getterExpression= null; if (getter != null) { getterExpression= astRewrite.getAST().newSimpleName("placeholder"); //$NON-NLS-1$ } ITypeBinding type= context.variableBinding.getType(); boolean is50OrHigher= JavaModelUtil.is50OrHigher(javaProject); Expression result= GetterSetterUtil.getAssignedValue(parent, astRewrite, getterExpression, type, is50OrHigher); if (result != null && getterExpression != null && getterExpression.getParent() != null) { getterExpression.getParent().setStructuralProperty(getterExpression.getLocationInParent(), createMethodInvocation(context, getter, null)); } return result; }
private static Expression getAssignedValue(ProposalParameter context) { ASTNode parent= context.accessNode.getParent(); ASTRewrite astRewrite= context.astRewrite; IJavaProject javaProject= context.compilationUnit.getJavaProject(); IMethodBinding getter= findGetter(context); Expression getterExpression= null; if (getter != null) { getterExpression= astRewrite.getAST().newSimpleName("placeholder"); //$NON-NLS-1$ } ITypeBinding type= context.variableBinding.getType(); boolean is50OrHigher= JavaModelUtil.is50OrHigher(javaProject); Expression result= GetterSetterUtil.getAssignedValue(parent, astRewrite, getterExpression, type, is50OrHigher); if (result != null && getterExpression != null && getterExpression.getParent() != null) { getterExpression.getParent().setStructuralProperty(getterExpression.getLocationInParent(), createMethodInvocation(context, getter, null)); } return result; }
if (statements.size() == 1 && statements.get(0) instanceof Block) { Block innerBlock= (Block) statements.remove(0); block.getParent().setStructuralProperty(block.getLocationInParent(), innerBlock);
if (statements.size() == 1 && statements.get(0) instanceof Block) { Block innerBlock= (Block) statements.remove(0); block.getParent().setStructuralProperty(block.getLocationInParent(), innerBlock);