Example usage for org.eclipse.jdt.core.dom MethodInvocation equals

List of usage examples for org.eclipse.jdt.core.dom MethodInvocation equals

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom MethodInvocation equals.

Prototype

@Override
public final boolean equals(Object obj) 

Source Link

Document

The ASTNode implementation of this Object method uses object identity (==).

Usage

From source file:org.autorefactor.refactoring.rules.StringRefactoring.java

License:Open Source License

@Override
public boolean visit(MethodInvocation node) {
    final Expression expression = node.getExpression();
    final ASTNode parent = node.getParent();
    final ASTBuilder b = this.ctx.getASTBuilder();
    final boolean isStringValueOf = isStringValueOf(node);
    if (isMethod(node, "java.lang.Object", "toString")) {
        if (hasType(expression, "java.lang.String")) {
            // if node is already a String, no need to call toString()
            this.ctx.getRefactorings().replace(node, b.move(expression));
            return DO_NOT_VISIT_SUBTREE;
        } else if (parent.getNodeType() == INFIX_EXPRESSION) {
            // if node is in a String context, no need to call toString()
            final InfixExpression ie = (InfixExpression) node.getParent();
            final Expression leftOp = ie.getLeftOperand();
            final Expression rightOp = ie.getRightOperand();
            final boolean leftOpIsString = hasType(leftOp, "java.lang.String");
            final boolean rightOpIsString = hasType(rightOp, "java.lang.String");
            final MethodInvocation lmi = as(leftOp, MethodInvocation.class);
            final MethodInvocation rmi = as(rightOp, MethodInvocation.class);
            if (!node.equals(lmi) && !node.equals(rmi) && (leftOpIsString || rightOpIsString)) {
                // node is in the extended operands
                ctx.getRefactorings().replace(node, replaceToString(node.getExpression()));
                return DO_NOT_VISIT_SUBTREE;
            } else if (leftOpIsString && isMethod(rmi, "java.lang.Object", "toString")) {
                ctx.getRefactorings().replace(rmi, replaceToString(rmi.getExpression()));
                return DO_NOT_VISIT_SUBTREE;
            } else if (rightOpIsString && node.equals(lmi)) {
                ctx.getRefactorings().replace(lmi, replaceToString(lmi.getExpression()));
                return DO_NOT_VISIT_SUBTREE;
            }/*ww w  . j ava  2s . com*/
        }
    } else if (isStringValueOf && hasType(arg0(node), "java.lang.String")) {
        this.ctx.getRefactorings().replace(node, b.move(arg0(node)));
        return DO_NOT_VISIT_SUBTREE;
    } else if ((isToStringForPrimitive(node) || isStringValueOf) && parent.getNodeType() == INFIX_EXPRESSION) {
        // if node is in a String context, no need to call toString()
        final InfixExpression ie = (InfixExpression) node.getParent();
        final Expression lo = ie.getLeftOperand();
        final Expression ro = ie.getRightOperand();
        if (node.equals(lo)) {
            if (hasType(ro, "java.lang.String")) {
                replaceStringValueOfByArg0(lo, node);
                return DO_NOT_VISIT_SUBTREE;
            }
        } else if (node.equals(ro)) {
            if (hasType(lo, "java.lang.String")
                    // Do not refactor left and right operand at the same time
                    // to avoid compilation errors post refactoring
                    && !ctx.getRefactorings().hasBeenRefactored(lo)) {
                replaceStringValueOfByArg0(ro, node);
                return DO_NOT_VISIT_SUBTREE;
            }
        } else {
            // left or right operation is necessarily a string, so just replace
            replaceStringValueOfByArg0(node, node);
            return DO_NOT_VISIT_SUBTREE;
        }
    }
    return VISIT_SUBTREE;
}

From source file:org.eclipse.wb.internal.core.model.nonvisual.EllipsisObjectInfo.java

License:Open Source License

@Override
protected Expression getMoveItemExpression(JavaInfo item, JavaInfo nextItem,
        AbstractArrayObjectInfo oldAbstractArrayInfo, int oldIndex, int newIndex) throws Exception {
    Expression element;//from   w w  w.j a v a 2  s . c  o m
    if (oldAbstractArrayInfo instanceof EllipsisObjectInfo) {
        EllipsisObjectInfo oldEllipsisInfo = (EllipsisObjectInfo) oldAbstractArrayInfo;
        MethodInvocation oldInvocation = oldEllipsisInfo.getInvocation();
        if (oldInvocation.equals(m_invocation)) {
            // move in same array
            getParent().moveChild(item, nextItem);
            m_items.remove(item);
            m_items.add(newIndex, item);
            // exchange elements
            element = getEditor().moveInvocationArgument(oldInvocation,
                    oldEllipsisInfo.getParameterIndex() + oldIndex, getParameterIndex() + newIndex);
        } else {
            element = moveFromEllipsis(item, nextItem, oldInvocation, oldEllipsisInfo, oldIndex, newIndex);
        }
        /*} else if (oldAbstractArrayInfo instanceof ArrayObjectInfo) {
           // moving item from array to this ellipsis-array
           ArrayObjectInfo oldArrayInfo = (ArrayObjectInfo) oldAbstractArrayInfo;
           // TODO
           Assert.fail("Not implemented");
           element = null;*/
    } else {
        // moving item from outside
        element = moveOther(item, nextItem, newIndex);
    }
    return element;
}