Search in sources :

Example 11 with IdentifierTreeImpl

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

the class TreeFactory method completeInterfaceDeclaration.

public ClassTreeImpl completeInterfaceDeclaration(InternalSyntaxToken interfaceToken, InternalSyntaxToken identifierToken, Optional<TypeParameterListTreeImpl> typeParameters, Optional<Tuple<InternalSyntaxToken, QualifiedIdentifierListTreeImpl>> extendsClause, ClassTreeImpl partial) {
    IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
    partial.completeDeclarationKeyword(interfaceToken);
    partial.completeIdentifier(identifier);
    if (typeParameters.isPresent()) {
        partial.completeTypeParameters(typeParameters.get());
    }
    if (extendsClause.isPresent()) {
        InternalSyntaxToken extendsKeyword = extendsClause.get().first();
        QualifiedIdentifierListTreeImpl interfaces = extendsClause.get().second();
        partial.completeInterfaces(extendsKeyword, interfaces);
    }
    return partial;
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 12 with IdentifierTreeImpl

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

the class TreeFactory method newImportDeclaration.

public ImportTreeImpl newImportDeclaration(InternalSyntaxToken importToken, Optional<InternalSyntaxToken> staticToken, ExpressionTree qualifiedIdentifier, Optional<Tuple<InternalSyntaxToken, InternalSyntaxToken>> dotStar, InternalSyntaxToken semicolonToken) {
    ExpressionTree target = qualifiedIdentifier;
    if (dotStar.isPresent()) {
        IdentifierTreeImpl identifier = new IdentifierTreeImpl(dotStar.get().second());
        InternalSyntaxToken dotToken = dotStar.get().first();
        target = new MemberSelectExpressionTreeImpl(qualifiedIdentifier, dotToken, identifier);
    }
    InternalSyntaxToken staticKeyword = staticToken.orNull();
    return new ImportTreeImpl(importToken, staticKeyword, target, semicolonToken);
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ImportTreeImpl(org.sonar.java.model.JavaTree.ImportTreeImpl) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)

Example 13 with IdentifierTreeImpl

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

the class TreeFactory method basicClassExpression.

public ExpressionTree basicClassExpression(PrimitiveTypeTreeImpl basicType, Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> dimensions, InternalSyntaxToken dotToken, InternalSyntaxToken classToken) {
    // 15.8.2. Class Literals
    // int.class
    // int[].class
    IdentifierTreeImpl classIdentifier = new IdentifierTreeImpl(classToken);
    ArrayTypeTreeImpl nestedDimensions = newArrayTypeTree(dimensions);
    TypeTree typeTree = applyDim(basicType, nestedDimensions);
    return new MemberSelectExpressionTreeImpl((ExpressionTree) typeTree, dotToken, classIdentifier);
}
Also used : ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)

Example 14 with IdentifierTreeImpl

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

the class TreeFactory method completeClassDeclaration.

// End of types
// Classes, enums and interfaces
public ClassTreeImpl completeClassDeclaration(InternalSyntaxToken classSyntaxToken, InternalSyntaxToken identifierToken, Optional<TypeParameterListTreeImpl> typeParameters, Optional<Tuple<InternalSyntaxToken, TypeTree>> extendsClause, Optional<Tuple<InternalSyntaxToken, QualifiedIdentifierListTreeImpl>> implementsClause, ClassTreeImpl partial) {
    IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
    partial.completeDeclarationKeyword(classSyntaxToken);
    partial.completeIdentifier(identifier);
    if (typeParameters.isPresent()) {
        partial.completeTypeParameters(typeParameters.get());
    }
    if (extendsClause.isPresent()) {
        partial.completeSuperclass(extendsClause.get().first(), extendsClause.get().second());
    }
    if (implementsClause.isPresent()) {
        InternalSyntaxToken implementsKeyword = implementsClause.get().first();
        QualifiedIdentifierListTreeImpl interfaces = implementsClause.get().second();
        partial.completeInterfaces(implementsKeyword, interfaces);
    }
    return partial;
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 15 with IdentifierTreeImpl

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

the class TreeFactory method newMethodOrConstructor.

private static MethodTreeImpl newMethodOrConstructor(Optional<TypeTree> type, InternalSyntaxToken identifierToken, FormalParametersListTreeImpl parameters, Optional<List<Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>>>> annotatedDimensions, Optional<Tuple<InternalSyntaxToken, QualifiedIdentifierListTreeImpl>> throwsClause, JavaTree blockOrSemicolon) {
    IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
    ArrayTypeTreeImpl nestedDimensions = newArrayTypeTreeWithAnnotations(annotatedDimensions);
    TypeTree actualType;
    if (type.isPresent()) {
        actualType = applyDim(type.get(), nestedDimensions);
    } else {
        actualType = null;
    }
    BlockTreeImpl block = null;
    InternalSyntaxToken semicolonToken = null;
    if (blockOrSemicolon.is(Tree.Kind.BLOCK)) {
        block = (BlockTreeImpl) blockOrSemicolon;
    } else {
        semicolonToken = (InternalSyntaxToken) blockOrSemicolon;
    }
    InternalSyntaxToken throwsToken = null;
    ListTree<TypeTree> throwsClauses = QualifiedIdentifierListTreeImpl.emptyList();
    if (throwsClause.isPresent()) {
        throwsToken = throwsClause.get().first();
        throwsClauses = throwsClause.get().second();
    }
    return new MethodTreeImpl(actualType, identifier, parameters, throwsToken, throwsClauses, block, semicolonToken);
}
Also used : ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) BlockTreeImpl(org.sonar.java.model.statement.BlockTreeImpl) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) MethodTreeImpl(org.sonar.java.model.declaration.MethodTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

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