Search in sources :

Example 31 with UastNode

use of org.sonar.uast.UastNode in project sonar-go by SonarSource.

the class HighlightingVisitor method scanRecursively.

public void scanRecursively(UastNode node, boolean parentIsATypeDefinition) {
    UastNode.Token token = node.token;
    boolean isATypeDefinition = parentIsATypeDefinition || node.kinds.contains(Kind.TYPE);
    if (token != null) {
        if (node.kinds.contains(Kind.COMMENT)) {
            highlight(token, node.kinds.contains(Kind.STRUCTURED_COMMENT) ? TypeOfText.STRUCTURED_COMMENT : TypeOfText.COMMENT);
        } else if (node.kinds.contains(Kind.KEYWORD)) {
            highlight(token, TypeOfText.KEYWORD);
        } else if (node.kinds.contains(Kind.LITERAL)) {
            highlight(token, node.kinds.contains(Kind.STRING_LITERAL) ? TypeOfText.STRING : TypeOfText.CONSTANT);
        } else if (isATypeDefinition) {
            highlight(token, TypeOfText.KEYWORD_LIGHT);
        }
    }
    for (UastNode child : node.children) {
        scanRecursively(child, isATypeDefinition);
    }
}
Also used : UastNode(org.sonar.uast.UastNode)

Aggregations

UastNode (org.sonar.uast.UastNode)31 Test (org.junit.jupiter.api.Test)16 StringReader (java.io.StringReader)10 InputFile (org.sonar.api.batch.fs.InputFile)5 ArrayList (java.util.ArrayList)4 List (java.util.List)2 Set (java.util.Set)2 BinaryExpressionLike (org.sonar.uast.helpers.BinaryExpressionLike)2 CaseLike (org.sonar.uast.helpers.CaseLike)2 IfLike (org.sonar.uast.helpers.IfLike)2 SwitchLike (org.sonar.uast.helpers.SwitchLike)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1