Search in sources :

Example 6 with ArrayTypeTreeImpl

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

Example 7 with ArrayTypeTreeImpl

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

the class TreeFactory method newArrayTypeTree.

@CheckForNull
private static ArrayTypeTreeImpl newArrayTypeTree(Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> dims) {
    ArrayTypeTreeImpl result = null;
    if (dims.isPresent()) {
        for (Tuple<InternalSyntaxToken, InternalSyntaxToken> dim : dims.get()) {
            InternalSyntaxToken openBracketToken = dim.first();
            InternalSyntaxToken closeBracketToken = dim.second();
            result = new ArrayTypeTreeImpl(result, ImmutableList.<AnnotationTreeImpl>of(), openBracketToken, closeBracketToken);
        }
    }
    return result;
}
Also used : AnnotationTreeImpl(org.sonar.java.model.declaration.AnnotationTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) CheckForNull(javax.annotation.CheckForNull)

Aggregations

ArrayTypeTreeImpl (org.sonar.java.model.JavaTree.ArrayTypeTreeImpl)7 IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)5 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)3 AnnotationTreeImpl (org.sonar.java.model.declaration.AnnotationTreeImpl)2 VariableTreeImpl (org.sonar.java.model.declaration.VariableTreeImpl)2 MemberSelectExpressionTreeImpl (org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)2 ParameterizedTypeTree (org.sonar.plugins.java.api.tree.ParameterizedTypeTree)2 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)2 CheckForNull (javax.annotation.CheckForNull)1 MethodTreeImpl (org.sonar.java.model.declaration.MethodTreeImpl)1 BlockTreeImpl (org.sonar.java.model.statement.BlockTreeImpl)1