@Override public boolean matches(MethodInvocationTree item, VisitorState state) { return methodSelectMatcher.matches(item.getMethodSelect(), state); } }
private Fix replaceMethodName(MethodInvocationTree tree, VisitorState state, String newName) { String source = state.getSourceForNode((JCTree) tree.getMethodSelect()); int idx = source.lastIndexOf("contains"); String replacement = source.substring(0, idx) + newName + source.substring(idx + "contains".length()); Fix fix = SuggestedFix.replace(tree.getMethodSelect(), replacement); return fix; } }
@Override public boolean matches(ExpressionTree expressionTree, VisitorState state) { if (!(expressionTree instanceof MethodInvocationTree)) { return false; } MethodInvocationTree tree = (MethodInvocationTree) expressionTree; return methodSelectMatcher.matches(tree.getMethodSelect(), state); } };
/** Gets the symbol for a method invocation. */ @Nullable public static MethodSymbol getSymbol(MethodInvocationTree tree) { Symbol sym = ASTHelpers.getSymbol(tree.getMethodSelect()); if (!(sym instanceof MethodSymbol)) { // Defensive. Would only occur if there are errors in the AST. return null; } return (MethodSymbol) sym; }
private void buildObservableCallChain(MethodInvocationTree tree) { ExpressionTree methodSelect = tree.getMethodSelect(); if (methodSelect instanceof MemberSelectTree) { ExpressionTree receiverExpression = ((MemberSelectTree) methodSelect).getExpression(); if (receiverExpression instanceof MethodInvocationTree) { observableOuterCallInChain.put((MethodInvocationTree) receiverExpression, tree); } } // ToDo: What else can be here? If there are other cases than MemberSelectTree, handle them. }
@Override public Boolean visitMethodInvocation(MethodInvocationTree callTree, Void unused) { if (methodSymbol.equals(getSymbol(callTree.getMethodSelect()))) { return true; } return super.visitMethodInvocation(callTree, unused); }
@Nullable static ClassAndMethod tryGetMethodSymbol(MethodInvocationTree tree, Types types) { Symbol symbol = tryGetSymbol(tree.getMethodSelect()); if (symbol instanceof MethodSymbol) { return ClassAndMethod.make((MethodSymbol) symbol, types); } return null; }
@Override public boolean matches(ExpressionTree expressionTree, VisitorState state) { if (!(expressionTree instanceof MethodInvocationTree)) { return false; } MethodInvocationTree tree = (MethodInvocationTree) expressionTree; return methodSelectMatcher.matches(tree.getMethodSelect(), state) && methodArgumentMatcher.matches(tree, state); }
private static String getMethodName(ExpressionTree tree) { MethodInvocationTree method = (MethodInvocationTree) tree; ExpressionTree expressionTree = method.getMethodSelect(); JCFieldAccess access = (JCFieldAccess) expressionTree; return access.sym.getQualifiedName().toString(); }
@Override Fixer match(ExpressionTree tree, VisitorState state) { if (tree.getKind() != Kind.METHOD_INVOCATION) { return null; } MethodInvocationTree method = (MethodInvocationTree) tree; if (!method.getArguments().isEmpty()) { return null; } if (!RETURNS_LIST.matches(method, state)) { return null; } ExpressionTree expressionTree = method.getMethodSelect(); return isGetter(expressionTree) ? (n, s) -> Optional.of(generateFix(n, method)) : null; }
@Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { MethodSymbol symbol = getSymbol(tree); // TODO(cpovirk): determine whether anyone might be calling Foo.this() if (!isIdentifierWithName(tree.getMethodSelect(), "this")) { return NO_MATCH; } callersToEvaluate.put(symbol, new Caller(tree, state)); return evaluateCallers(symbol); }
@Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { return checkInvocation( tree, ASTHelpers.getType(tree.getMethodSelect()), state, ASTHelpers.getSymbol(tree)); }
@Override public ExpressionTree get(VisitorState state) { MethodInvocationTree method = (MethodInvocationTree) state.getPath().getLeaf(); return ((JCFieldAccess) method.getMethodSelect()).getExpression(); } };
@Override public Type get(VisitorState state) { MethodInvocationTree methodInvocation = (MethodInvocationTree) state.getPath().getLeaf(); return ASTHelpers.getReceiverType(methodInvocation.getMethodSelect()); } };
@Override Fixer match(ExpressionTree tree, VisitorState state) { if (tree.getKind() != Kind.METHOD_INVOCATION) { return null; } MethodInvocationTree method = (MethodInvocationTree) tree; if (!method.getArguments().isEmpty()) { return null; } if (RETURNS_LIST.matches(method, state)) { return null; } ExpressionTree expressionTree = method.getMethodSelect(); return isGetter(expressionTree) ? (n, s) -> generateFix(method, n, s) : null; }
@Override @Nullable public Choice<Unifier> visitMethodInvocation( MethodInvocationTree methodInvocation, @Nullable Unifier unifier) { return getMethodSelect() .unify(methodInvocation.getMethodSelect(), unifier) .thenChoose( unifications( getArguments(), methodInvocation.getArguments(), /* allowVarargs= */ true)); }
@Override Fixer match(ExpressionTree tree, VisitorState state) { if (tree.getKind() != Kind.METHOD_INVOCATION) { return null; } MethodInvocationTree method = (MethodInvocationTree) tree; if (method.getArguments().size() != 1 || !isGetter(method.getMethodSelect())) { return null; } if (!isSameType( getType(getOnlyElement(method.getArguments())), state.getSymtab().intType, state)) { return null; } return (n, s) -> Optional.of(generateFix(method, n)); }
@Override public Boolean visitMethodInvocation(MethodInvocationTree tree, Void unused) { boolean result = false; MethodSymbol methodSym = ASTHelpers.getSymbol(tree); if (methodSym != null) { ExpressionTree methodSelect = tree.getMethodSelect(); if (methodSelect.getKind() == Kind.MEMBER_SELECT) { MemberSelectTree memberSelect = (MemberSelectTree) methodSelect; result = isSuper(memberSelect.getExpression()) && memberSelect.getIdentifier().contentEquals(overridingMethodName); } } return result || super.visitMethodInvocation(tree, unused); }
/** Returns true if this method invocation is of the form {@code super.foo()} */ private static boolean isSuperCall(Type type, MethodInvocationTree tree, VisitorState state) { if (tree.getMethodSelect().getKind() == Kind.MEMBER_SELECT) { MemberSelectTree select = (MemberSelectTree) tree.getMethodSelect(); if (select.getExpression().getKind() == Kind.IDENTIFIER) { IdentifierTree ident = (IdentifierTree) select.getExpression(); return ident.getName().contentEquals("super"); } else if (select.getExpression().getKind() == Kind.MEMBER_SELECT) { MemberSelectTree subSelect = (MemberSelectTree) select.getExpression(); return subSelect.getIdentifier().contentEquals("super") && ASTHelpers.isSameType(ASTHelpers.getType(subSelect.getExpression()), type, state); } } return false; }
@Override public Choice<State<JCMethodInvocation>> visitMethodInvocation( final MethodInvocationTree node, State<?> state) { return chooseSubtrees( state, s -> unifyExpression(node.getMethodSelect(), s), s -> unifyExpressions(node.getArguments(), s), (select, args) -> maker().Apply(null, select, args)); }