@Override public void visitIdentifier(IdentifierTree tree) { if (methodSymbol.equals(tree.symbol().owner())) { used.add(tree.symbol()); } super.visitIdentifier(tree); }
@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); } }
private SymbolicValue createIdentifierSymbolicValue(IdentifierTree identifier) { final Type type = identifier.symbol().type(); if (type != null && type.is("java.lang.Boolean")) { if ("TRUE".equals(identifier.name())) { return SymbolicValue.TRUE_LITERAL; } else if ("FALSE".equals(identifier.name())) { return SymbolicValue.FALSE_LITERAL; } } return createDefaultSymbolicValue(); }
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; }
@CheckForNull private static Tree getAssignedVariable(ExpressionTree expression) { if (expression.is(Tree.Kind.ARRAY_ACCESS_EXPRESSION)) { return getAssignedVariable(((ArrayAccessExpressionTree) expression).expression()); } IdentifierTree identifier; if (expression.is(Tree.Kind.IDENTIFIER)) { identifier = (IdentifierTree) expression; } else { identifier = ((MemberSelectExpressionTree) expression).identifier(); } return identifier.symbol().declaration(); }
@Override public void visitReturnStatement(ReturnStatementTree syntaxNode) { SymbolicValue currentVal = programState.peekValue(); if (currentVal != null) { final ExpressionTree expression = syntaxNode.expression(); if (expression != null) { if (expression.is(Tree.Kind.IDENTIFIER)) { final IdentifierTree identifier = (IdentifierTree) expression; currentVal = programState.getValue(identifier.symbol()); } else { currentVal = programState.peekValue(); } programState = closeResource(programState, currentVal); } } }
private void addAssignment(IdentifierTree identifier) { Symbol reference = identifier.symbol(); if (!reference.isUnknown()) { assignments.put(reference, identifier); } }
@Override public void visitIdentifier(IdentifierTree tree) { super.visitIdentifier(tree); checkSymbol(tree.symbol()); }