private static IdentifierTree getIdentifier(MethodInvocationTree mit) { IdentifierTree id; if (mit.methodSelect().is(Tree.Kind.IDENTIFIER)) { id = (IdentifierTree) mit.methodSelect(); } else { id = ((MemberSelectExpressionTree) mit.methodSelect()).identifier(); } return id; }
@CheckForNull private static MemberSelectExpressionTree getMemberSelect(MethodInvocationTree mit) { ExpressionTree methodSelect = mit.methodSelect(); if (!methodSelect.is(Tree.Kind.MEMBER_SELECT)) { return null; } return (MemberSelectExpressionTree) methodSelect; }
private void logState(MethodInvocationTree mit) { if (mit.methodSelect().is(Tree.Kind.IDENTIFIER) && "printState".equals(((IdentifierTree) mit.methodSelect()).name())) { debugPrint(((JavaTree) mit).getLine(), node); } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (METHOD_MATCHERS.anyMatch(tree)) { useClassGetName = true; } scan(tree.methodSelect()); } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (isCallToExitMethod(tree)) { reportIssue(tree.methodSelect(), "Remove this call to \"" + idName + "\" or ensure it is really required."); } }
private static Optional<MethodInvocationTree> previousMITInChain(MethodInvocationTree mit) { ExpressionTree methodSelect = mit.methodSelect(); if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) { ExpressionTree expression = ((MemberSelectExpressionTree) methodSelect).expression(); if (expression.is(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree previousInvocation = (MethodInvocationTree) expression; return Optional.of(previousInvocation); } } return Optional.empty(); }
private static boolean isCallToSuper(MethodTree methodTree, Tree callToSuper) { if (callToSuper.is(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree methodInvocationTree = (MethodInvocationTree) callToSuper; if (methodInvocationTree.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mset = (MemberSelectExpressionTree) methodInvocationTree.methodSelect(); if (callSuperMethodWithSameName(mset, methodTree) && callsWithSameParameters(methodInvocationTree.arguments(), methodTree.parameters())) { return true; } } } return false; }
private void checkMethodInvocation(MethodInvocationTree methodInvocationTree) { if (unboxingInvocationMatcher.matches(methodInvocationTree)) { MemberSelectExpressionTree methodSelect = (MemberSelectExpressionTree) methodInvocationTree.methodSelect(); checkInstantiation(methodSelect.expression()); } }
@Override protected void onMethodInvocationFound(MethodInvocationTree mit) { if (mit.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree selectExpression = (MemberSelectExpressionTree) mit.methodSelect(); if (selectExpression.expression().symbolType().is(CSRF_CONFIGURER_CLASS)) { reportIssue(selectExpression.identifier(), MESSAGE); } } }
private static Type getMethodOwnerType(MethodInvocationTree methodSelectTree) { if (methodSelectTree.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { return ((MemberSelectExpressionTree) methodSelectTree.methodSelect()).expression().symbolType(); } else { return methodSelectTree.symbol().owner().type(); } }
@CheckForNull private static Symbol invocationTarget(MethodInvocationTree mit) { ExpressionTree methodSelect = mit.methodSelect(); if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) { ExpressionTree methodSelectExpression = ((MemberSelectExpressionTree) methodSelect).expression(); if (methodSelectExpression.is(Tree.Kind.IDENTIFIER)) { return ((IdentifierTree) methodSelectExpression).symbol(); } } return null; }
@CheckForNull private static ExpressionTree getPreparedStatementReference(MethodInvocationTree mit) { ExpressionTree methodSelect = mit.methodSelect(); if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) { ExpressionTree expression = ((MemberSelectExpressionTree) methodSelect).expression(); if (expression.is(Tree.Kind.IDENTIFIER)) { Symbol referenceSymbol = ((IdentifierTree) expression).symbol(); return ReassignmentFinder.getClosestReassignmentOrDeclarationExpression(mit, referenceSymbol); } } return null; }
@Override protected void onMethodInvocationFound(MethodInvocationTree mit) { if (hasSemantic() && mit.methodSelect().is(Kind.MEMBER_SELECT)) { ExpressionTree expressionTree = ((MemberSelectExpressionTree) mit.methodSelect()).expression(); if (expressionTree.is(Kind.NEW_CLASS)) { reportIssue(expressionTree); } else if (expressionTree.is(Kind.IDENTIFIER) && variableUsedOnlyToGetClass((IdentifierTree) expressionTree)) { reportIssue(getInitializer((IdentifierTree) expressionTree)); } } }
private void handleMethodInvocation(MethodInvocationTree mit) { ExpressionTree methodSelect = mit.methodSelect(); if (EQUALS_MATCHER.matches(mit) && methodSelect.is(Kind.MEMBER_SELECT)) { handleEqualsMethod(mit, (MemberSelectExpressionTree) methodSelect); } else if (GET_CONNECTION_MATCHER.matches(mit)) { handleGetConnectionMethod(mit); } else { isSettingPassword(mit).ifPresent(settingPassword -> report(methodSelect, settingPassword)); } }
@Override protected void onMethodInvocationFound(MethodInvocationTree method) { if (isArgumentAppended(method) && typeIsByte(method.arguments().get(0))) { reportIssue(method.methodSelect(), "Use String.format( \"%02X\", ...) instead."); } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (TO_STRING_MATCHERS.anyMatch(tree)) { ExpressionTree abstractTypedTree = ((MemberSelectExpressionTree) tree.methodSelect()).expression(); if (abstractTypedTree.is(Kind.NEW_CLASS) || isValueOfInvocation(abstractTypedTree)) { String typeName = abstractTypedTree.symbolType().toString(); createIssue(tree, typeName); } } super.visitMethodInvocation(tree); }
private void handleConstructor(NewClassTree tree) { if (!PASSWORD_AUTHENTICATION_CONSTRUCTOR.matches(tree)) { return; } ExpressionTree secondArg = tree.arguments().get(1); if (secondArg.is(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree mit = (MethodInvocationTree) secondArg; if (STRING_TO_CHAR_ARRAY.matches(mit) && isCallOnStringLiteral(mit.methodSelect())) { reportIssue(tree, "Remove this hard-coded password."); } } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if(tree.symbol().isMethodSymbol()) { String className = tree.symbol().owner().type().fullyQualifiedName(); checkIfDisallowed(className, tree.methodSelect()); } super.visitMethodInvocation(tree); }
private static String getNewlyCreatedClassName(MethodInvocationTree mit) { MemberSelectExpressionTree mset = (MemberSelectExpressionTree) mit.methodSelect(); if (mset.expression().is(Tree.Kind.NEW_CLASS)) { Tree classId = ((NewClassTree) mset.expression()).identifier(); if (classId.is(Tree.Kind.IDENTIFIER)) { return ((IdentifierTree) classId).name(); } else if (classId.is(Tree.Kind.MEMBER_SELECT)) { return ((MemberSelectExpressionTree) classId).identifier().name(); } } return ""; }
private void check(MethodInvocationTree tree) { if (isEquals(tree.methodSelect()) && tree.arguments().size() == 1 && tree.arguments().get(0).is(Kind.STRING_LITERAL)) { LiteralTree stringLiteral = (LiteralTree) tree.arguments().get(0); reportIssue(stringLiteral, "Move the " + stringLiteral.value() + " string literal on the left side of this string comparison."); } }