Search in sources :

Example 11 with SyntaxToken

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

the class NestedIfStatementsCheck method visitForStatement.

@Override
public void visitForStatement(ForStatementTree tree) {
    SyntaxToken forKeyword = tree.forKeyword();
    checkNesting(forKeyword);
    nestingLevel.push(forKeyword);
    super.visitForStatement(tree);
    nestingLevel.pop();
}
Also used : SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken)

Example 12 with SyntaxToken

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

the class NestedIfStatementsCheck method visitForEachStatement.

@Override
public void visitForEachStatement(ForEachStatement tree) {
    SyntaxToken forKeyword = tree.forKeyword();
    checkNesting(forKeyword);
    nestingLevel.push(forKeyword);
    super.visitForEachStatement(tree);
    nestingLevel.pop();
}
Also used : SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken)

Example 13 with SyntaxToken

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

the class NestedIfStatementsCheck method visitIfStatement.

@Override
public void visitIfStatement(IfStatementTree tree) {
    SyntaxToken ifKeyword = tree.ifKeyword();
    checkNesting(ifKeyword);
    nestingLevel.push(ifKeyword);
    visit(tree);
    nestingLevel.pop();
}
Also used : SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken)

Example 14 with SyntaxToken

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

the class ListTreeImplTest method emptySeparators.

@Test
public void emptySeparators() throws Exception {
    Tree tree1 = new EmptyStatementTreeImpl(null);
    List<Tree> trees = Lists.newArrayList(tree1);
    List<SyntaxToken> separators = Lists.newArrayList();
    ListTreeImpl<Tree> listTree = new MyList(trees, separators);
    Iterable<Tree> result = listTree.children();
    assertThat(Lists.newArrayList(result)).containsExactly(tree1);
}
Also used : InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) EmptyStatementTreeImpl(org.sonar.java.model.statement.EmptyStatementTreeImpl) Tree(org.sonar.plugins.java.api.tree.Tree) Test(org.junit.Test)

Example 15 with SyntaxToken

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

the class TreeFactory method newStatementExpressions.

public StatementExpressionListTreeImpl newStatementExpressions(ExpressionTree expression, Optional<List<Tuple<InternalSyntaxToken, ExpressionTree>>> rests) {
    ImmutableList.Builder<StatementTree> statements = ImmutableList.builder();
    statements.add(new ExpressionStatementTreeImpl(expression, null));
    ImmutableList.Builder<SyntaxToken> separators = ImmutableList.builder();
    if (rests.isPresent()) {
        for (Tuple<InternalSyntaxToken, ExpressionTree> rest : rests.get()) {
            separators.add(rest.first());
            statements.add(new ExpressionStatementTreeImpl(rest.second(), null));
        }
    }
    return new StatementExpressionListTreeImpl(statements.build(), separators.build());
}
Also used : StatementTree(org.sonar.plugins.java.api.tree.StatementTree) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) ImmutableList(com.google.common.collect.ImmutableList) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) ExpressionStatementTreeImpl(org.sonar.java.model.statement.ExpressionStatementTreeImpl)

Aggregations

SyntaxToken (org.sonar.plugins.java.api.tree.SyntaxToken)47 Tree (org.sonar.plugins.java.api.tree.Tree)9 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)7 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)7 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)7 Test (org.junit.Test)6 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)6 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)5 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)5 ImmutableList (com.google.common.collect.ImmutableList)4 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)4 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)4 IfStatementTree (org.sonar.plugins.java.api.tree.IfStatementTree)3 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)3 StatementTree (org.sonar.plugins.java.api.tree.StatementTree)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 CheckForNull (javax.annotation.CheckForNull)2