Search in sources :

Example 16 with IdentifierTreeImpl

use of org.sonar.java.model.expression.IdentifierTreeImpl 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)

Example 17 with IdentifierTreeImpl

use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newIdentifierOrMethodInvocation.

public ExpressionTree newIdentifierOrMethodInvocation(Optional<TypeArgumentListTreeImpl> typeArguments, InternalSyntaxToken identifierToken, Optional<ArgumentListTreeImpl> arguments) {
    IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
    ExpressionTree result = identifier;
    if (arguments.isPresent()) {
        result = new MethodInvocationTreeImpl(identifier, typeArguments.orNull(), arguments.get());
    }
    return result;
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MethodInvocationTreeImpl(org.sonar.java.model.expression.MethodInvocationTreeImpl)

Example 18 with IdentifierTreeImpl

use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method completeTypeParameter.

public TypeParameterTreeImpl completeTypeParameter(Optional<List<AnnotationTreeImpl>> annotations, InternalSyntaxToken identifierToken, Optional<TypeParameterTreeImpl> partial) {
    IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
    completeTypeTreeWithAnnotations(identifier, annotations);
    return partial.isPresent() ? partial.get().complete(identifier) : new TypeParameterTreeImpl(identifier);
}
Also used : TypeParameterTreeImpl(org.sonar.java.model.TypeParameterTreeImpl) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl)

Aggregations

IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)18 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)9 ArrayTypeTreeImpl (org.sonar.java.model.JavaTree.ArrayTypeTreeImpl)5 MemberSelectExpressionTreeImpl (org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)5 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)5 NewClassTreeImpl (org.sonar.java.model.expression.NewClassTreeImpl)3 ParameterizedTypeTree (org.sonar.plugins.java.api.tree.ParameterizedTypeTree)3 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)3 Optional (com.sonar.sslr.api.typed.Optional)2 ArrayList (java.util.ArrayList)2 JavaTree (org.sonar.java.model.JavaTree)2 EnumConstantTreeImpl (org.sonar.java.model.declaration.EnumConstantTreeImpl)2 VariableTreeImpl (org.sonar.java.model.declaration.VariableTreeImpl)2 MethodInvocationTreeImpl (org.sonar.java.model.expression.MethodInvocationTreeImpl)2 TypeArgumentListTreeImpl (org.sonar.java.model.expression.TypeArgumentListTreeImpl)2 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Test (org.junit.Test)1 ImportTreeImpl (org.sonar.java.model.JavaTree.ImportTreeImpl)1