public static IMethod getMethodThatInvokesThisMethod(MethodInvocation node) { ASTNode parentNode = node.getParent(); while (parentNode.getNodeType() != ASTNode.METHOD_DECLARATION) { parentNode = parentNode.getParent(); } MethodDeclaration md = (MethodDeclaration) parentNode; IBinding binding = md.resolveBinding(); return (IMethod)binding.getJavaElement(); }
@Override public boolean visit(MethodInvocation mi) { if (mi.getParent() instanceof ExpressionStatement && mi.getName().getIdentifier().equals("error") && mi.arguments().size() == 1 && mi.getExpression() instanceof SimpleName && mi.getExpression().toString().contains("log")) { if (isOnCaught(mi, type)) { addHit(mi); correctMI(mi); } } return true; } };
@Override public boolean visit(SimpleName node) { IBinding nodeBinding= node.resolveBinding(); if (fElementVariable != null && fElementVariable.equals(nodeBinding)) { fMakeFinal= false; } if (nodeBinding == fIteratorVariable) { if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) { MethodInvocation invocation= (MethodInvocation) node.getParent(); String name= invocation.getName().getIdentifier(); if (name.equals("next") || name.equals("nextElement")) { //$NON-NLS-1$ //$NON-NLS-2$ nextInvocationCount[0]++; Expression left= null; if (invocation.getLocationInParent() == Assignment.RIGHT_HAND_SIDE_PROPERTY) { left= ((Assignment) invocation.getParent()).getLeftHandSide(); } else if (invocation.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) { left= ((VariableDeclarationFragment) invocation.getParent()).getName(); } return visitElementVariable(left); } } otherInvocationThenNext[0]= true; } return true; }
@Override public boolean visit(SimpleName node) { IBinding nodeBinding= node.resolveBinding(); if (fElementVariable != null && fElementVariable.equals(nodeBinding)) { fMakeFinal= false; } if (nodeBinding == fIteratorVariable) { if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) { MethodInvocation invocation= (MethodInvocation) node.getParent(); String name= invocation.getName().getIdentifier(); if (name.equals("next") || name.equals("nextElement")) { //$NON-NLS-1$ //$NON-NLS-2$ nextInvocationCount[0]++; Expression left= null; if (invocation.getLocationInParent() == Assignment.RIGHT_HAND_SIDE_PROPERTY) { left= ((Assignment) invocation.getParent()).getLeftHandSide(); } else if (invocation.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) { left= ((VariableDeclarationFragment) invocation.getParent()).getName(); } return visitElementVariable(left); } } otherInvocationThenNext[0]= true; } return true; }
if (methodInvocation.getParent() instanceof Statement) {
if (methodInvocation.getParent() instanceof Statement) {
@Override public boolean visit(MethodInvocation node) { handleArguments(node.arguments(), this.options.alignment_for_arguments_in_method_invocation); handleTypeArguments(node.typeArguments()); boolean isInvocationChainRoot = !(node.getParent() instanceof MethodInvocation) || node.getLocationInParent() != MethodInvocation.EXPRESSION_PROPERTY; if (isInvocationChainRoot) { Expression expression = node; MethodInvocation invocation = node; while (expression instanceof MethodInvocation) { invocation = (MethodInvocation) expression; expression = invocation.getExpression(); if (expression != null) { this.wrapIndexes.add(this.tm.firstIndexBefore(invocation.getName(), TokenNameDOT)); this.secondaryWrapIndexes.add(this.tm.firstIndexIn(invocation.getName(), TokenNameIdentifier)); } } Collections.reverse(this.wrapIndexes); this.wrapParentIndex = (expression != null) ? this.tm.lastIndexIn(expression, -1) : this.tm.lastIndexIn(invocation, -1); this.wrapGroupEnd = this.tm.lastIndexIn(node, -1); handleWrap(this.options.alignment_for_selector_in_method_invocation); } return true; }
@Override public boolean visit(MethodInvocation node) { handleArguments(node.arguments(), this.options.alignment_for_arguments_in_method_invocation); handleTypeArguments(node.typeArguments()); boolean isInvocationChainRoot = !(node.getParent() instanceof MethodInvocation) || node.getLocationInParent() != MethodInvocation.EXPRESSION_PROPERTY; if (isInvocationChainRoot) { Expression expression = node; MethodInvocation invocation = node; while (expression instanceof MethodInvocation) { invocation = (MethodInvocation) expression; expression = invocation.getExpression(); if (expression != null) { this.wrapIndexes.add(this.tm.firstIndexBefore(invocation.getName(), TokenNameDOT)); this.secondaryWrapIndexes.add(this.tm.firstIndexIn(invocation.getName(), TokenNameIdentifier)); } } Collections.reverse(this.wrapIndexes); this.wrapParentIndex = (expression != null) ? this.tm.lastIndexIn(expression, -1) : this.tm.lastIndexIn(invocation, -1); this.wrapGroupEnd = this.tm.lastIndexIn(node, -1); handleWrap(this.options.alignment_for_selector_in_method_invocation); } return true; }
@Override public boolean visit(MethodInvocation node) { handleArguments(node.arguments(), this.options.alignment_for_arguments_in_method_invocation); handleTypeArguments(node.typeArguments()); boolean isInvocationChainRoot = !(node.getParent() instanceof MethodInvocation) || node.getLocationInParent() != MethodInvocation.EXPRESSION_PROPERTY; if (isInvocationChainRoot) { Expression expression = node; MethodInvocation invocation = node; while (expression instanceof MethodInvocation) { invocation = (MethodInvocation) expression; expression = invocation.getExpression(); if (expression != null) { this.wrapIndexes.add(this.tm.firstIndexBefore(invocation.getName(), TokenNameDOT)); this.secondaryWrapIndexes.add(this.tm.firstIndexIn(invocation.getName(), TokenNameIdentifier)); } } Collections.reverse(this.wrapIndexes); this.wrapParentIndex = (expression != null) ? this.tm.lastIndexIn(expression, -1) : this.tm.lastIndexIn(invocation, -1); this.wrapGroupEnd = this.tm.firstIndexIn(node.getName(), -1); handleWrap(this.options.alignment_for_selector_in_method_invocation); } return true; }
@Override public boolean visit(MethodInvocation node) { handleArguments(node.arguments(), this.options.alignment_for_arguments_in_method_invocation); handleTypeArguments(node.typeArguments()); boolean isInvocationChainRoot = !(node.getParent() instanceof MethodInvocation) || node.getLocationInParent() != MethodInvocation.EXPRESSION_PROPERTY; if (isInvocationChainRoot) { Expression expression = node; MethodInvocation invocation = node; while (expression instanceof MethodInvocation) { invocation = (MethodInvocation) expression; expression = invocation.getExpression(); if (expression != null) { this.wrapIndexes.add(this.tm.firstIndexBefore(invocation.getName(), TokenNameDOT)); this.secondaryWrapIndexes.add(this.tm.firstIndexIn(invocation.getName(), TokenNameIdentifier)); } } Collections.reverse(this.wrapIndexes); this.wrapParentIndex = (expression != null) ? this.tm.lastIndexIn(expression, -1) : this.tm.lastIndexIn(invocation, -1); this.wrapGroupEnd = this.tm.firstIndexIn(node.getName(), -1); handleWrap(this.options.alignment_for_selector_in_method_invocation); } return true; }
if (!(debugMI.getParent() instanceof ExpressionStatement)) { continue;
private boolean maybeReplaceEquals(final boolean isPositive, final Expression node, final MethodInvocation mi) { if (isMethod(mi, "java.math.BigDecimal", "equals", "java.lang.Object") || isMethod(mi, "java.math.BigInteger", "equals", "java.lang.Object")) { final Expression arg0 = arg0(mi); if (hasType(arg0, "java.math.BigDecimal", "java.math.BigInteger")) { if (isInStringAppend(mi.getParent())) { this.ctx.getRefactorings().replace(node, parenthesize(getCompareToNode(isPositive, mi))); } else { this.ctx.getRefactorings().replace(node, getCompareToNode(isPositive, mi)); } return DO_NOT_VISIT_SUBTREE; } } return VISIT_SUBTREE; }
TypeDeclaration typeDeclaration = getAncestor(enclosingMethod, TypeDeclaration.class); MethodDeclaration onPauseMethod = findMethod(typeDeclaration, "onPause"); if (onPauseMethod != null && node.getParent().getNodeType() == ASTNode.EXPRESSION_STATEMENT) { r.remove(node.getParent()); r.insertLast( onPauseMethod.getBody(), if (!releasePresenceChecker.findOrDefault(typeDeclaration, false)) { MethodDeclaration onPauseMethod = findMethod(typeDeclaration, "onPause"); if (onPauseMethod != null && node.getParent().getNodeType() == ASTNode.EXPRESSION_STATEMENT) { r.insertLast( onPauseMethod.getBody(),
@Override public boolean visit(MethodInvocation mi) { Expression miExpr = mi.getExpression(); if (isKeySetMethod(miExpr)) { final MethodInvocation mapKeySetMi = (MethodInvocation) miExpr; if (isMethod(mi, "java.util.Set", "clear")) { return removeInvocationOfMapKeySet(mapKeySetMi, mi, "clear"); } if (isMethod(mi, "java.util.Set", "size")) { return removeInvocationOfMapKeySet(mapKeySetMi, mi, "size"); } if (isMethod(mi, "java.util.Set", "isEmpty")) { return removeInvocationOfMapKeySet(mapKeySetMi, mi, "isEmpty"); } if (isMethod(mi, "java.util.Set", "remove", "java.lang.Object") // If parent is not an expression statement, the MethodInvocation must return a boolean. // In that case, we cannot replace because `Map.removeKey(key) != null` // is not strictly equivalent to `Map.keySet().remove(key)` && mi.getParent().getNodeType() == EXPRESSION_STATEMENT) { return removeInvocationOfMapKeySet(mapKeySetMi, mi, "remove"); } if (isMethod(mi, "java.util.Set", "contains", "java.lang.Object")) { return removeInvocationOfMapKeySet(mapKeySetMi, mi, "containsKey"); } } return VISIT_SUBTREE; }
ASTNode parent= invocationNode.getParent(); while (parent instanceof Expression && parent.getNodeType() != ASTNode.CAST_EXPRESSION) { parent= parent.getParent();
ASTNode parent= invocationNode.getParent(); while (parent instanceof Expression && parent.getNodeType() != ASTNode.CAST_EXPRESSION) { parent= parent.getParent();
ASTNode parent= invocationNode.getParent(); while (parent instanceof Expression && parent.getNodeType() != ASTNode.CAST_EXPRESSION) { parent= parent.getParent();
ASTNode parent= invocationNode.getParent(); while (parent instanceof Expression && parent.getNodeType() != ASTNode.CAST_EXPRESSION) { parent= parent.getParent();
private void processOrdinaryMethodInvocation(MethodInvocation node) { IMethodBinding method = node.resolveMethodBinding(); CSExpression targetExpression = mapMethodTargetExpression(node); if ((method.getModifiers() & Modifier.STATIC) != 0 && !(targetExpression instanceof CSTypeReferenceExpression) && node.getExpression() != null) targetExpression = mappedTypeReference(node.getExpression().resolveTypeBinding()); String name = resolveTargetMethodName(targetExpression, node); CSExpression target = null == targetExpression ? new CSReferenceExpression(name) : new CSMemberReferenceExpression(targetExpression, name); CSMethodInvocationExpression mie = new CSMethodInvocationExpression(target); mapMethodInvocationArguments(mie, node); mapTypeArguments(mie, node); IMethodBinding base = getOverridedMethod(method); if (base != null && base.getReturnType() != method.getReturnType() && !(node.getParent() instanceof ExpressionStatement)) pushExpression (new CSParenthesizedExpression (new CSCastExpression (mappedTypeReference(method.getReturnType()), mie))); else pushExpression(mie); }