Search in sources :

Example 16 with InternalSyntaxToken

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

the class TreeFactory method newArrayCreatorWithDimension.

public NewArrayTreeImpl newArrayCreatorWithDimension(InternalSyntaxToken openBracketToken, ExpressionTree expression, InternalSyntaxToken closeBracketToken, Optional<List<ArrayAccessExpressionTreeImpl>> arrayAccesses, Optional<List<Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>>>> dims) {
    ImmutableList.Builder<ArrayDimensionTree> dimensions = ImmutableList.builder();
    dimensions.add(new ArrayDimensionTreeImpl(openBracketToken, expression, closeBracketToken));
    if (arrayAccesses.isPresent()) {
        for (ArrayAccessExpressionTreeImpl arrayAccess : arrayAccesses.get()) {
            dimensions.add(arrayAccess.dimension());
        }
    }
    if (dims.isPresent()) {
        for (Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>> dim : dims.get()) {
            Tuple<InternalSyntaxToken, InternalSyntaxToken> brackets = dim.second();
            List<AnnotationTreeImpl> annotations = dim.first().or(ImmutableList.<AnnotationTreeImpl>of());
            dimensions.add(new ArrayDimensionTreeImpl(annotations, brackets.first(), null, brackets.second()));
        }
    }
    return new NewArrayTreeImpl(dimensions.build(), InitializerListTreeImpl.emptyList());
}
Also used : NewArrayTreeImpl(org.sonar.java.model.expression.NewArrayTreeImpl) Optional(com.sonar.sslr.api.typed.Optional) ImmutableList(com.google.common.collect.ImmutableList) ArrayDimensionTreeImpl(org.sonar.java.model.ArrayDimensionTreeImpl) AnnotationTreeImpl(org.sonar.java.model.declaration.AnnotationTreeImpl) ArrayDimensionTree(org.sonar.plugins.java.api.tree.ArrayDimensionTree) ArrayAccessExpressionTreeImpl(org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 17 with InternalSyntaxToken

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

the class TreeFactory method newModuleName.

public ModuleNameTree newModuleName(InternalSyntaxToken firstIdentifier, Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> rest) {
    List<IdentifierTree> identifiers = new ArrayList<>();
    List<SyntaxToken> separators = new ArrayList<>();
    identifiers.add(new IdentifierTreeImpl(firstIdentifier));
    if (rest.isPresent()) {
        for (Tuple<InternalSyntaxToken, InternalSyntaxToken> modulePart : rest.get()) {
            separators.add(modulePart.first());
            identifiers.add(new IdentifierTreeImpl(modulePart.second()));
        }
    }
    return new ModuleNameTreeImpl(Collections.unmodifiableList(identifiers), Collections.unmodifiableList(separators));
}
Also used : SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ArrayList(java.util.ArrayList) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 18 with InternalSyntaxToken

use of org.sonar.java.model.InternalSyntaxToken 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 19 with InternalSyntaxToken

use of org.sonar.java.model.InternalSyntaxToken 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 20 with InternalSyntaxToken

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

Aggregations

InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)26 IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)9 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)8 ImmutableList (com.google.common.collect.ImmutableList)7 Optional (com.sonar.sslr.api.typed.Optional)5 AnnotationTreeImpl (org.sonar.java.model.declaration.AnnotationTreeImpl)4 ArrayList (java.util.ArrayList)3 ArrayTypeTreeImpl (org.sonar.java.model.JavaTree.ArrayTypeTreeImpl)3 MemberSelectExpressionTreeImpl (org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)3 TypeArgumentListTreeImpl (org.sonar.java.model.expression.TypeArgumentListTreeImpl)3 ArrayDimensionTree (org.sonar.plugins.java.api.tree.ArrayDimensionTree)3 SyntaxToken (org.sonar.plugins.java.api.tree.SyntaxToken)3 ArrayDimensionTreeImpl (org.sonar.java.model.ArrayDimensionTreeImpl)2 JavaTree (org.sonar.java.model.JavaTree)2 MethodTreeImpl (org.sonar.java.model.declaration.MethodTreeImpl)2 ModuleNameListTreeImpl (org.sonar.java.model.declaration.ModuleNameListTreeImpl)2 VariableTreeImpl (org.sonar.java.model.declaration.VariableTreeImpl)2 ArrayAccessExpressionTreeImpl (org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl)2 NewArrayTreeImpl (org.sonar.java.model.expression.NewArrayTreeImpl)2 NewClassTreeImpl (org.sonar.java.model.expression.NewClassTreeImpl)2