private void checkInstantiation(ExpressionTree expression) { if (isBadlyInstantiated(expression)) { reportIssue(expression, message); } }
@Override public void visitAssignmentExpression(AssignmentExpressionTree tree) { if (isFieldAssignment(tree) && isNullAssignment(tree)) { addIssue(tree, "Remove this nullification of \"" + getFieldName(tree) + "\"."); } }
private void visitStatement(StatementTree tree) { executionState = new ExecutionState(executionState); scan(tree); executionState = executionState.restoreParent(); }
@Override public void visitForEachStatement(ForEachStatement tree) { scan(tree.expression()); currentState.invalidateVariables(new AssignmentVisitor().findAssignedVariables(tree.statement())); currentState = new State(currentState); scan(tree.statement()); restorePreviousState(); }
@Override public void visitWhileStatement(WhileStatementTree tree) { ConditionalState conditionalState = visitCondition(tree.condition()); Set<VariableSymbol> assignedVariables = new AssignmentVisitor().findAssignedVariables(tree.statement()); currentState = conditionalState.trueState; currentState.invalidateVariables(assignedVariables); scan(tree.statement()); restorePreviousState(); currentState.invalidateVariables(assignedVariables); }
private static boolean isArgumentCompatible(Type argumentType, Type collectionParameterType) { return isSubtypeOf(argumentType, collectionParameterType) || isSubtypeOf(collectionParameterType, argumentType) || autoboxing(argumentType, collectionParameterType); }
@Override public void visitNode(Tree tree) { if (isCloneMethod(tree)) { foundSuperClone = false; } else if (isSuperCloneCall(tree)) { foundSuperClone = true; } }
private void visitRelationalEqualTo(BinaryExpressionTree tree) { VariableSymbol symbol = extractRelationalSymbol(tree); if (symbol != null && currentConditionalState != null) { currentConditionalState.trueState.setVariableValue(symbol, AbstractValue.NULL); currentConditionalState.falseState.setVariableValue(symbol, AbstractValue.NOTNULL); } }
private ConditionalState visitCondition(ExpressionTree tree) { ConditionalState oldConditionalState = currentConditionalState; ConditionalState conditionalState = new ConditionalState(currentState); currentConditionalState = conditionalState; scan(tree); currentConditionalState = oldConditionalState; return conditionalState; }
private void checkInstanciation(ExpressionTree expression) { if (isBadlyInstanciated(expression)) { addIssue(expression, message); } }
@Override public void visitMethodInvocation(MethodInvocationTree tree) { if (!isGetter(tree) && !isAnnotationMethod(tree)) { shouldReport = true; hasMethodInvocation = true; } }
@Override public void visitNode(Tree tree) { if(!hasSemantic()) { return; } checkClassTree((ClassTree) tree); }
private static boolean neitherIsPublicStaticFinal(ExpressionTree leftOperand, ExpressionTree rightOperand) { if (compatibleTypes(leftOperand, rightOperand)) { return !isFinal(leftOperand) && !isFinal(rightOperand); } return true; }
@Override public void visitConditionalExpression(ConditionalExpressionTree tree) { // cut the exploration to report only 1 level reportIssue(tree, "Extract this nested ternary operation into an independent statement."); }
private static String getToStringMessage(ExpressionTree arg) { if (isInStringArrayInitializer(arg)) { return "No need to call \"toString()\" method since an array of Objects can be used here."; } return "No need to call \"toString()\" method as formatting and string conversion is done by the Formatter."; }
private boolean checkArgumentNumber(MethodInvocationTree mit, int nbReadParams, int nbArgs) { if (nbReadParams > nbArgs) { reportIssue(mit, "Not enough arguments."); return true; } return false; }
@Override public void visitDoWhileStatement(DoWhileStatementTree tree) { currentState.invalidateVariables(new AssignmentVisitor().findAssignedVariables(tree.statement())); currentState = new State(currentState); scan(tree.statement()); scan(tree.condition()); restorePreviousState(); }
private void checkInstantiation(ExpressionTree expression) { if (isBadlyInstantiated(expression)) { reportIssue(expression, message); } }
private void visitRelationalNotEqualTo(BinaryExpressionTree tree) { VariableSymbol symbol = extractRelationalSymbol(tree); if (symbol != null && currentConditionalState != null) { currentConditionalState.trueState.setVariableValue(symbol, AbstractValue.NOTNULL); currentConditionalState.falseState.setVariableValue(symbol, AbstractValue.NULL); } }
@Override public void visitSwitchStatement(SwitchStatementTree tree) { checkForIssue(tree.expression(), MESSAGE_NULLABLE_EXPRESSION, MESSAGE_NULL_LITERAL); scan(tree.expression()); Set<VariableSymbol> variables = new AssignmentVisitor().findAssignedVariables(tree.cases()); currentState.invalidateVariables(variables); for (CaseGroupTree caseTree : tree.cases()) { currentState = new State(currentState); scan(caseTree); restorePreviousState(); } }