@Override
 public void visitMethodInvocation(MethodInvocationTree syntaxNode) {
   final ExpressionTree methodSelect = syntaxNode.methodSelect();
   if (isClosingResource(syntaxNode.symbol())) {
     if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
       final ExpressionTree targetExpression =
           ((MemberSelectExpressionTree) methodSelect).expression();
       if (targetExpression.is(Tree.Kind.IDENTIFIER)) {
         final IdentifierTree identifier = (IdentifierTree) targetExpression;
         programState = closeResource(programState, programState.getValue(identifier.symbol()));
       } else {
         programState = closeResource(programState, programState.peekValue());
       }
     }
   } else if (syntaxNode.methodSelect().is(Tree.Kind.MEMBER_SELECT)
       && isOpeningResultSet(syntaxNode.symbol())) {
     final SymbolicValue value = getTargetValue(syntaxNode);
     constraintManager.setValueFactory(new WrappedValueFactory(value));
   } else if (isClosingResultSets(syntaxNode.symbol())) {
     if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
       final SymbolicValue value = getTargetValue(syntaxNode);
       closeResultSetsRelatedTo(value);
     }
   } else {
     closeArguments(syntaxNode.arguments(), 1);
   }
 }
 public static IdentifierTree methodName(MethodInvocationTree mit) {
   IdentifierTree id;
   if (mit.methodSelect().is(Tree.Kind.IDENTIFIER)) {
     id = (IdentifierTree) mit.methodSelect();
   } else {
     id = ((MemberSelectExpressionTree) mit.methodSelect()).identifier();
   }
   return id;
 }
 @Override
 public void visitMethodInvocation(MethodInvocationTree syntaxNode) {
   if (syntaxNode.methodSelect().is(Tree.Kind.MEMBER_SELECT)
       && needsClosing(syntaxNode.symbolType())) {
     final ExpressionTree targetExpression =
         ((MemberSelectExpressionTree) syntaxNode.methodSelect()).expression();
     if (targetExpression.is(Tree.Kind.IDENTIFIER)
         && !isWithinTryHeader(syntaxNode)
         && (syntaxNode.symbol().isStatic() || isJdbcResourceCreation(targetExpression))) {
       programState =
           programState.addConstraint(
               programState.peekValue(),
               new ObjectConstraint(false, false, syntaxNode, Status.OPENED));
     }
   }
 }
Beispiel #4
0
 private void buildMethodInvocation(MethodInvocationTree tree) {
   MethodInvocationTree mit = tree;
   currentBlock.elements.add(mit);
   build(mit.methodSelect());
   for (ExpressionTree arg : Lists.reverse(mit.arguments())) {
     build(arg);
   }
 }
 @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 SymbolicValue getTargetValue(MethodInvocationTree syntaxNode) {
   final ExpressionTree targetExpression =
       ((MemberSelectExpressionTree) syntaxNode.methodSelect()).expression();
   final SymbolicValue value;
   if (targetExpression.is(Tree.Kind.IDENTIFIER)) {
     final IdentifierTree identifier = (IdentifierTree) targetExpression;
     value = programState.getValue(identifier.symbol());
   } else {
     value = programState.peekValue();
   }
   return value;
 }
 private static boolean isEqualsMethod(MethodInvocationTree syntaxNode) {
   if (syntaxNode.arguments().size() == 1) {
     ExpressionTree methodSelect = syntaxNode.methodSelect();
     if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
       MemberSelectExpressionTree expression = (MemberSelectExpressionTree) methodSelect;
       if ("equals".equals(expression.identifier().name())
           && syntaxNode.symbol().isMethodSymbol()) {
         Symbol.MethodSymbol symbol = (Symbol.MethodSymbol) syntaxNode.symbol();
         return symbol.parameterTypes().get(0).is("java.lang.Object");
       }
     }
   }
   return false;
 }
 private void visitMethodInvocationTree(MethodInvocationTree methodInvocationTree) {
   if (isValueOfInvocation(methodInvocationTree)) {
     checkForUnboxing(methodInvocationTree.arguments().get(0));
   } else if (isUnboxingMethodInvocation(methodInvocationTree)) {
     ExpressionTree methodSelect = methodInvocationTree.methodSelect();
     if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
       MemberSelectExpressionTree memberSelectExpressionTree =
           (MemberSelectExpressionTree) methodSelect;
       checkForBoxing(memberSelectExpressionTree.expression());
     }
   } else {
     Symbol symbol = methodInvocationTree.symbol();
     if (symbol.isMethodSymbol()) {
       List<Type> parametersTypes = ((Symbol.MethodSymbol) symbol).parameterTypes();
       checkMethodInvocationArguments(methodInvocationTree, parametersTypes);
     }
   }
 }
 @Nullable
 private State checkAndAdvanceState(
     MethodInvocationTree mit, State requiredState, State nextState) {
   ExpressionTree methodSelect = mit.methodSelect();
   if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
     ExpressionTree expressionTree = ((MemberSelectExpressionTree) methodSelect).expression();
     if (expressionTree.is(Tree.Kind.IDENTIFIER)) {
       Symbol symbol = ((IdentifierTree) expressionTree).symbol();
       Map<Symbol, State> symbolStateMap = symbolStack.peek();
       if (symbolStateMap != null
           && symbolStateMap.containsKey(symbol)
           && requiredState.equals(symbolStateMap.get(symbol))) {
         symbolStateMap.put(symbol, nextState);
         return nextState;
       }
     }
   }
   return null;
 }
 private void checkForUnboxing(ExpressionTree expressionTree) {
   if (!expressionTree.is(Tree.Kind.METHOD_INVOCATION)) {
     return;
   }
   MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree;
   if (isUnboxingMethodInvocation(methodInvocationTree)) {
     ExpressionTree methodSelect = methodInvocationTree.methodSelect();
     if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
       MemberSelectExpressionTree memberSelectExpressionTree =
           (MemberSelectExpressionTree) methodSelect;
       ExpressionTree unboxedExpression = memberSelectExpressionTree.expression();
       String unboxingResultTypeName = methodInvocationTree.symbolType().fullyQualifiedName();
       if (unboxingResultTypeName.equals(
           PRIMITIVE_TYPES_BY_WRAPPER.get(unboxedExpression.symbolType().fullyQualifiedName()))) {
         addUnboxingIssue(expressionTree, unboxedExpression);
       }
     }
   }
 }
 private static Type getMethodOwner(MethodInvocationTree mit) {
   if (mit.methodSelect().is(Kind.MEMBER_SELECT)) {
     return ((MemberSelectExpressionTree) mit.methodSelect()).expression().symbolType();
   }
   return mit.symbol().owner().type();
 }