void visit(StatementTree node) { referenceSymbol = false; hasBreakingStatement = false; node.accept(this); }
void visit(StatementTree node) { referenceSymbol = false; hasBreakingStatement = false; node.accept(this); }
private static boolean thenStmtInitializeField(StatementTree statementTree, Symbol field) { AssignmentVisitor visitor = new AssignmentVisitor(field); statementTree.accept(visitor); return visitor.assignmentToField; }
private static boolean thenStmtInitializeField(StatementTree statementTree, Symbol field) { AssignmentVisitor visitor = new AssignmentVisitor(field); statementTree.accept(visitor); return visitor.assignmentToField; }
private static boolean forBodyUpdatesLoopIdentifier(ForStatementTree forStatement, IdentifierTree loopIdentifier) { LoopVariableAssignmentVisitor visitor = new LoopVariableAssignmentVisitor(loopIdentifier); forStatement.statement().accept(visitor); return visitor.foundAssignment; }
private static Map<Symbol, Tree> singleUpdatesInBody(StatementTree statement, Collection<Symbol> conditionsNotUpdated) { UpdatesInBodyVisitor updatedInBodyVisitor = new UpdatesInBodyVisitor(conditionsNotUpdated); statement.accept(updatedInBodyVisitor); // only report if there is symbols which are updated only once, as multiple update cannot easily be moved to updates return updatedOnlyOnceWithUnaryExpression(updatedInBodyVisitor.updates, statement); }
private boolean forBodyUpdatesLoopIdentifier(ForStatementTree forStatement, IdentifierTree loopIdentifier) { LoopVariableAssignmentVisitor visitor = new LoopVariableAssignmentVisitor(loopIdentifier); forStatement.statement().accept(visitor); return visitor.foundAssignment; }
private static boolean forBodyUpdatesLoopIdentifier(ForStatementTree forStatement, IdentifierTree loopIdentifier) { LoopVariableAssignmentVisitor visitor = new LoopVariableAssignmentVisitor(loopIdentifier); forStatement.statement().accept(visitor); return visitor.foundAssignment; }
private static Map<Symbol, Tree> singleUpdatesInBody(StatementTree statement, Collection<Symbol> conditionsNotUpdated) { UpdatesInBodyVisitor updatedInBodyVisitor = new UpdatesInBodyVisitor(conditionsNotUpdated); statement.accept(updatedInBodyVisitor); // only report if there is symbols which are updated only once, as multiple update cannot easily be moved to updates return updatedOnlyOnceWithUnaryExpression(updatedInBodyVisitor.updates, statement); }
@Override public void visitIfStatement(IfStatementTree tree) { ConditionalState conditionalState = visitCondition(tree.condition()); currentState = conditionalState.trueState; tree.thenStatement().accept(this); if (tree.elseStatement() != null) { currentState = conditionalState.falseState; tree.elseStatement().accept(this); } currentState = currentState.parentState.mergeValues(conditionalState.trueState, conditionalState.falseState); }
private void checkModelProviderCall(Tree tree, StatementTree statement) { MethodInvocationTreeVisitor methodInvocationTreeVisitor = new MethodInvocationTreeVisitor(); statement.accept(methodInvocationTreeVisitor); if (methodInvocationTreeVisitor.isModelProviderGetCalled()) { context.reportIssue(this, tree, RULE_MESSAGE); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ForEachStatement actualStatement = (ForEachStatement) tree; Type variableType = actualStatement.variable().type().symbolType(); Type collectionItemType = getCollectionItemType(actualStatement.expression()); if (collectionItemType != null && !isMostPreciseType(variableType, collectionItemType)) { // Second pass: check if the variable is down-cast in the statement block DownCastVisitor downCastVisitor = new DownCastVisitor(actualStatement.variable().symbol()); actualStatement.statement().accept(downCastVisitor); if (downCastVisitor.hasDownCastOfLoopVariable) { List<JavaFileScannerContext.Location> locations = Collections.singletonList( new JavaFileScannerContext.Location(String.format(SECONDARY_MESSAGE, collectionItemType.name()), actualStatement.expression())); reportIssue(actualStatement.variable().type(), String.format(PRIMARY_MESSAGE, variableType.name()), locations, 0); } } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ForEachStatement actualStatement = (ForEachStatement) tree; Type variableType = actualStatement.variable().type().symbolType(); Type collectionItemType = getCollectionItemType(actualStatement.expression()); if (collectionItemType != null && !isMostPreciseType(variableType, collectionItemType)) { // Second pass: check if the variable is down-cast in the statement block DownCastVisitor downCastVisitor = new DownCastVisitor(actualStatement.variable().symbol()); actualStatement.statement().accept(downCastVisitor); if (downCastVisitor.hasDownCastOfLoopVariable) { List<JavaFileScannerContext.Location> locations = Collections.singletonList( new JavaFileScannerContext.Location(String.format(SECONDARY_MESSAGE, collectionItemType.name()), actualStatement.expression())); reportIssue(actualStatement.variable().type(), String.format(PRIMARY_MESSAGE, variableType.name()), locations, 0); } } }