Search in sources :

Example 6 with SyntaxTrivia

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

the class SubscriptionVisitor method visit.

private void visit(Tree tree) {
    boolean isSubscribed = isSubscribed(tree);
    boolean shouldVisitSyntaxToken = (visitToken || visitTrivia) && tree.is(Tree.Kind.TOKEN);
    if (shouldVisitSyntaxToken) {
        SyntaxToken syntaxToken = (SyntaxToken) tree;
        if (visitToken) {
            visitToken(syntaxToken);
        }
        if (visitTrivia) {
            for (SyntaxTrivia syntaxTrivia : syntaxToken.trivias()) {
                visitTrivia(syntaxTrivia);
            }
        }
    } else if (isSubscribed) {
        visitNode(tree);
    }
    visitChildren(tree);
    if (!shouldVisitSyntaxToken && isSubscribed) {
        leaveNode(tree);
    }
}
Also used : SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) SyntaxTrivia(org.sonar.plugins.java.api.tree.SyntaxTrivia)

Example 7 with SyntaxTrivia

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

the class JavaNodeBuilder method createTrivias.

private static List<SyntaxTrivia> createTrivias(List<Trivia> trivias) {
    List<SyntaxTrivia> result = Lists.newArrayList();
    for (Trivia trivia : trivias) {
        Token trivialToken = trivia.getToken();
        result.add(InternalSyntaxTrivia.create(trivialToken.getValue(), trivialToken.getLine(), trivialToken.getColumn()));
    }
    return result;
}
Also used : SyntaxTrivia(org.sonar.plugins.java.api.tree.SyntaxTrivia) InternalSyntaxTrivia(org.sonar.java.model.InternalSyntaxTrivia) Token(com.sonar.sslr.api.Token) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) SyntaxTrivia(org.sonar.plugins.java.api.tree.SyntaxTrivia) Trivia(com.sonar.sslr.api.Trivia) InternalSyntaxTrivia(org.sonar.java.model.InternalSyntaxTrivia)

Aggregations

SyntaxTrivia (org.sonar.plugins.java.api.tree.SyntaxTrivia)7 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)2 SyntaxToken (org.sonar.plugins.java.api.tree.SyntaxToken)2 Token (com.sonar.sslr.api.Token)1 Trivia (com.sonar.sslr.api.Trivia)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 InternalSyntaxTrivia (org.sonar.java.model.InternalSyntaxTrivia)1 IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)1 ConstraintManager (org.sonar.java.se.constraint.ConstraintManager)1 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)1 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)1