Search in sources :

Example 1 with ListTree

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

the class TryStatementTreeImpl method filterVariableTreeResources.

private static ListTree filterVariableTreeResources(ResourceListTreeImpl resources) {
    ImmutableList.Builder<Tree> filteredResources = ImmutableList.builder();
    ImmutableList.Builder<SyntaxToken> filteredSeparators = ImmutableList.builder();
    Iterator<SyntaxToken> separators = resources.separators().iterator();
    for (Tree resource : resources) {
        SyntaxToken separator = null;
        if (separators.hasNext()) {
            separator = separators.next();
        }
        if (resource.is(Kind.VARIABLE)) {
            filteredResources.add(resource);
            if (separator != null) {
                filteredSeparators.add(separator);
            }
        }
    }
    return new ResourceListTreeImpl(filteredResources.build(), filteredSeparators.build());
}
Also used : InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) ImmutableList(com.google.common.collect.ImmutableList) ListTree(org.sonar.plugins.java.api.tree.ListTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree) JavaTree(org.sonar.java.model.JavaTree) Tree(org.sonar.plugins.java.api.tree.Tree) TryStatementTree(org.sonar.plugins.java.api.tree.TryStatementTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) CatchTree(org.sonar.plugins.java.api.tree.CatchTree) ResourceListTreeImpl(org.sonar.java.ast.parser.ResourceListTreeImpl)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ResourceListTreeImpl (org.sonar.java.ast.parser.ResourceListTreeImpl)1 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)1 JavaTree (org.sonar.java.model.JavaTree)1 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)1 CatchTree (org.sonar.plugins.java.api.tree.CatchTree)1 ListTree (org.sonar.plugins.java.api.tree.ListTree)1 SyntaxToken (org.sonar.plugins.java.api.tree.SyntaxToken)1 Tree (org.sonar.plugins.java.api.tree.Tree)1 TryStatementTree (org.sonar.plugins.java.api.tree.TryStatementTree)1 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)1