Search in sources :

Example 21 with InternalSyntaxToken

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

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

the class TreeFactory method newPostfixExpression.

public ExpressionTree newPostfixExpression(ExpressionTree expression, Optional<InternalSyntaxToken> postfixOperator) {
    ExpressionTree result = expression;
    if (postfixOperator.isPresent()) {
        InternalSyntaxToken postfixOperatorToken = postfixOperator.get();
        result = new InternalPostfixUnaryExpression(kindMaps.getPostfixOperator((JavaPunctuator) postfixOperator.get().getGrammarRuleKey()), result, postfixOperatorToken);
    }
    return result;
}
Also used : InternalPostfixUnaryExpression(org.sonar.java.model.expression.InternalPostfixUnaryExpression) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 23 with InternalSyntaxToken

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

the class TreeFactory method newOpensModuleDirective.

public ModuleDirectiveTree newOpensModuleDirective(InternalSyntaxToken opensKeyword, ExpressionTree packageName, Optional<Tuple<InternalSyntaxToken, ListTreeImpl<ModuleNameTree>>> moduleNames, InternalSyntaxToken semicolonToken) {
    InternalSyntaxToken toKeyword = null;
    ListTreeImpl<ModuleNameTree> otherModuleNames = ModuleNameListTreeImpl.emptyList();
    if (moduleNames.isPresent()) {
        Tuple<InternalSyntaxToken, ListTreeImpl<ModuleNameTree>> toModuleNames = moduleNames.get();
        toKeyword = toModuleNames.first();
        otherModuleNames = toModuleNames.second();
    }
    return new OpensDirectiveTreeImpl(opensKeyword, packageName, toKeyword, otherModuleNames, semicolonToken);
}
Also used : ModuleNameListTreeImpl(org.sonar.java.model.declaration.ModuleNameListTreeImpl) TypeArgumentListTreeImpl(org.sonar.java.model.expression.TypeArgumentListTreeImpl) OpensDirectiveTreeImpl(org.sonar.java.model.declaration.OpensDirectiveTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree)

Example 24 with InternalSyntaxToken

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

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

the class TreeFactory method newExportsModuleDirective.

public ModuleDirectiveTree newExportsModuleDirective(InternalSyntaxToken exportsKeyword, ExpressionTree packageName, Optional<Tuple<InternalSyntaxToken, ListTreeImpl<ModuleNameTree>>> moduleNames, InternalSyntaxToken semicolonToken) {
    InternalSyntaxToken toKeyword = null;
    ListTreeImpl<ModuleNameTree> otherModuleNames = ModuleNameListTreeImpl.emptyList();
    if (moduleNames.isPresent()) {
        Tuple<InternalSyntaxToken, ListTreeImpl<ModuleNameTree>> toModuleNames = moduleNames.get();
        toKeyword = toModuleNames.first();
        otherModuleNames = toModuleNames.second();
    }
    return new ExportsDirectiveTreeImpl(exportsKeyword, packageName, toKeyword, otherModuleNames, semicolonToken);
}
Also used : ExportsDirectiveTreeImpl(org.sonar.java.model.declaration.ExportsDirectiveTreeImpl) ModuleNameListTreeImpl(org.sonar.java.model.declaration.ModuleNameListTreeImpl) TypeArgumentListTreeImpl(org.sonar.java.model.expression.TypeArgumentListTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree)

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