Search in sources :

Example 6 with ForEachStatement

use of org.sonar.plugins.java.api.tree.ForEachStatement in project sonar-java by SonarSource.

the class UnusedLocalVariableCheck method leaveNode.

@Override
public void leaveNode(Tree tree) {
    if (hasSemantic()) {
        if (tree.is(Tree.Kind.BLOCK, Tree.Kind.STATIC_INITIALIZER)) {
            BlockTree blockTree = (BlockTree) tree;
            addVariables(blockTree.body());
        } else if (tree.is(Tree.Kind.FOR_STATEMENT)) {
            ForStatementTree forStatementTree = (ForStatementTree) tree;
            addVariables(forStatementTree.initializer());
        } else if (tree.is(Tree.Kind.FOR_EACH_STATEMENT)) {
            ForEachStatement forEachStatement = (ForEachStatement) tree;
            addVariable(forEachStatement.variable());
        } else if (tree.is(Tree.Kind.EXPRESSION_STATEMENT)) {
            leaveExpressionStatement((ExpressionStatementTree) tree);
        } else {
            checkVariableUsages();
            variables.clear();
            assignments.clear();
        }
    }
}
Also used : ForStatementTree(org.sonar.plugins.java.api.tree.ForStatementTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree) ExpressionStatementTree(org.sonar.plugins.java.api.tree.ExpressionStatementTree) ForEachStatement(org.sonar.plugins.java.api.tree.ForEachStatement)

Aggregations

ForEachStatement (org.sonar.plugins.java.api.tree.ForEachStatement)6 Test (org.junit.Test)2 Symbol (org.sonar.plugins.java.api.semantic.Symbol)2 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)2 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)2 ForStatementTree (org.sonar.plugins.java.api.tree.ForStatementTree)2 HashMap (java.util.HashMap)1 JavaTree (org.sonar.java.model.JavaTree)1 DoWhileStatementTree (org.sonar.plugins.java.api.tree.DoWhileStatementTree)1 ExpressionStatementTree (org.sonar.plugins.java.api.tree.ExpressionStatementTree)1 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)1 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)1 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)1 Tree (org.sonar.plugins.java.api.tree.Tree)1 WhileStatementTree (org.sonar.plugins.java.api.tree.WhileStatementTree)1