Search in sources :

Example 11 with ClassTreeImpl

use of org.sonar.java.model.declaration.ClassTreeImpl in project sonar-java by SonarSource.

the class SyntaxHighlighterVisitor method visitToken.

@Override
public void visitToken(SyntaxToken syntaxToken) {
    String text = syntaxToken.text();
    if (keywords.contains(text)) {
        if (isInterfaceOfAnnotationType(syntaxToken)) {
            ClassTreeImpl annotationType = (ClassTreeImpl) syntaxToken.parent();
            highlight(annotationType.atToken(), annotationType.declarationKeyword(), TypeOfText.KEYWORD);
        } else {
            highlight(syntaxToken, TypeOfText.KEYWORD);
        }
    } else if (isRestrictedKeyword(syntaxToken)) {
        highlight(syntaxToken, TypeOfText.KEYWORD);
    }
}
Also used : ClassTreeImpl(org.sonar.java.model.declaration.ClassTreeImpl)

Example 12 with ClassTreeImpl

use of org.sonar.java.model.declaration.ClassTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newEnumDeclaration.

public ClassTreeImpl newEnumDeclaration(InternalSyntaxToken enumToken, InternalSyntaxToken identifierToken, Optional<Tuple<InternalSyntaxToken, QualifiedIdentifierListTreeImpl>> implementsClause, InternalSyntaxToken openBraceToken, Optional<List<EnumConstantTreeImpl>> enumConstants, Optional<InternalSyntaxToken> semicolonToken, Optional<List<JavaTree>> enumDeclarations, InternalSyntaxToken closeBraceToken) {
    List<JavaTree> members = Lists.newLinkedList();
    EnumConstantTreeImpl lastEnumConstant = null;
    if (enumConstants.isPresent()) {
        for (EnumConstantTreeImpl enumConstant : enumConstants.get()) {
            members.add(enumConstant);
            lastEnumConstant = enumConstant;
        }
    }
    if (semicolonToken.isPresent()) {
        InternalSyntaxToken semicolon = semicolonToken.get();
        // add the semicolon as endToken of the last enumConstant, or as empty statement in the enum members
        if (lastEnumConstant != null) {
            lastEnumConstant.setEndToken(semicolon);
        } else {
            members.add(newEmptyMember(semicolon));
        }
    }
    if (enumDeclarations.isPresent()) {
        for (JavaTree enumDeclaration : enumDeclarations.get()) {
            members.add(enumDeclaration);
        }
    }
    ClassTreeImpl result = newClassBody(Kind.ENUM, openBraceToken, Optional.of((List<JavaTree>) ImmutableList.<JavaTree>builder().addAll(members).build()), closeBraceToken);
    result.completeDeclarationKeyword(enumToken);
    IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
    result.completeIdentifier(identifier);
    if (implementsClause.isPresent()) {
        InternalSyntaxToken implementsKeyword = implementsClause.get().first();
        QualifiedIdentifierListTreeImpl interfaces = implementsClause.get().second();
        result.completeInterfaces(implementsKeyword, interfaces);
    }
    return result;
}
Also used : ClassTreeImpl(org.sonar.java.model.declaration.ClassTreeImpl) NewClassTreeImpl(org.sonar.java.model.expression.NewClassTreeImpl) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) EnumConstantTreeImpl(org.sonar.java.model.declaration.EnumConstantTreeImpl) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) JavaTree(org.sonar.java.model.JavaTree)

Aggregations

ClassTreeImpl (org.sonar.java.model.declaration.ClassTreeImpl)12 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)8 Test (org.junit.Test)6 AnnotationInstance (org.sonar.plugins.java.api.semantic.SymbolMetadata.AnnotationInstance)4 VariableTreeImpl (org.sonar.java.model.declaration.VariableTreeImpl)3 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)3 ImmutableList (com.google.common.collect.ImmutableList)2 JavaTree (org.sonar.java.model.JavaTree)2 MethodTreeImpl (org.sonar.java.model.declaration.MethodTreeImpl)2 NewClassTreeImpl (org.sonar.java.model.expression.NewClassTreeImpl)2 Type (org.sonar.plugins.java.api.semantic.Type)2 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)2 TypeParameterTree (org.sonar.plugins.java.api.tree.TypeParameterTree)2 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)1 EnumConstantTreeImpl (org.sonar.java.model.declaration.EnumConstantTreeImpl)1 ModifiersTreeImpl (org.sonar.java.model.declaration.ModifiersTreeImpl)1 IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)1