Search in sources :

Example 1 with BlockTreeImpl

use of org.sonar.java.model.statement.BlockTreeImpl 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

InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)1 ArrayTypeTreeImpl (org.sonar.java.model.JavaTree.ArrayTypeTreeImpl)1 MethodTreeImpl (org.sonar.java.model.declaration.MethodTreeImpl)1 IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)1 BlockTreeImpl (org.sonar.java.model.statement.BlockTreeImpl)1 ParameterizedTypeTree (org.sonar.plugins.java.api.tree.ParameterizedTypeTree)1 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)1