Search in sources :

Example 6 with InternalSyntaxToken

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

the class TreeFactory method newClassCastExpression.

public TypeCastExpressionTreeImpl newClassCastExpression(TypeTree type, Optional<Tuple<InternalSyntaxToken, BoundListTreeImpl>> classTypes, InternalSyntaxToken closeParenToken, ExpressionTree expression) {
    BoundListTreeImpl bounds = BoundListTreeImpl.emptyList();
    InternalSyntaxToken andToken = null;
    if (classTypes.isPresent()) {
        andToken = classTypes.get().first();
        bounds = classTypes.get().second();
    }
    return new TypeCastExpressionTreeImpl(type, andToken, bounds, closeParenToken, expression);
}
Also used : InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) TypeCastExpressionTreeImpl(org.sonar.java.model.expression.TypeCastExpressionTreeImpl)

Example 7 with InternalSyntaxToken

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

the class TreeFactory method newArrayInitializer.

public NewArrayTreeImpl newArrayInitializer(InternalSyntaxToken openBraceToken, Optional<InternalSyntaxToken> optionalComma, Optional<List<Tuple<ExpressionTree, Optional<InternalSyntaxToken>>>> rests, InternalSyntaxToken closeBraceToken) {
    ImmutableList.Builder<ExpressionTree> initializers = ImmutableList.builder();
    ImmutableList.Builder<SyntaxToken> separators = ImmutableList.builder();
    if (optionalComma.isPresent()) {
        separators.add(optionalComma.get());
    }
    if (rests.isPresent()) {
        for (Tuple<ExpressionTree, Optional<InternalSyntaxToken>> rest : rests.get()) {
            initializers.add(rest.first());
            if (rest.second().isPresent()) {
                separators.add(rest.second().get());
            }
        }
    }
    return new NewArrayTreeImpl(ImmutableList.<ArrayDimensionTree>of(), new InitializerListTreeImpl(initializers.build(), separators.build())).completeWithCurlyBraces(openBraceToken, closeBraceToken);
}
Also used : NewArrayTreeImpl(org.sonar.java.model.expression.NewArrayTreeImpl) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) Optional(com.sonar.sslr.api.typed.Optional) ImmutableList(com.google.common.collect.ImmutableList) ArrayDimensionTree(org.sonar.plugins.java.api.tree.ArrayDimensionTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree)

Example 8 with InternalSyntaxToken

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

the class TreeFactory method newAnnotationTypeMethod.

public MethodTreeImpl newAnnotationTypeMethod(InternalSyntaxToken openParenToken, InternalSyntaxToken closeParenToken, Optional<Tuple<InternalSyntaxToken, ExpressionTree>> defaultValue) {
    FormalParametersListTreeImpl parameters = new FormalParametersListTreeImpl(openParenToken, closeParenToken);
    InternalSyntaxToken defaultToken = null;
    ExpressionTree defaultExpression = null;
    if (defaultValue.isPresent()) {
        defaultToken = defaultValue.get().first();
        defaultExpression = defaultValue.get().second();
    }
    return new MethodTreeImpl(parameters, defaultToken, defaultExpression);
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MethodTreeImpl(org.sonar.java.model.declaration.MethodTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 9 with InternalSyntaxToken

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

the class TreeFactory method newRequiresModuleDirective.

public ModuleDirectiveTree newRequiresModuleDirective(InternalSyntaxToken requiresToken, Optional<List<InternalSyntaxToken>> modifiers, ModuleNameTree moduleName, InternalSyntaxToken semicolonToken) {
    ModifiersTreeImpl newModifiers = ModifiersTreeImpl.emptyModifiers();
    if (modifiers.isPresent()) {
        List<ModifierTree> modifierKeywords = new ArrayList<>();
        // JLS9 - ยง7.7.1 'requires' only 'static' and 'transitive' modifiers are allowed
        for (InternalSyntaxToken modifierAsSyntaxToken : modifiers.get()) {
            if (JavaRestrictedKeyword.TRANSITIVE.getValue().equals(modifierAsSyntaxToken.text())) {
                modifierKeywords.add(new ModifierKeywordTreeImpl(Modifier.TRANSITIVE, modifierAsSyntaxToken));
            } else {
                modifierKeywords.add(new ModifierKeywordTreeImpl(Modifier.STATIC, modifierAsSyntaxToken));
            }
        }
        newModifiers = new ModifiersTreeImpl(modifierKeywords);
    }
    return new RequiresDirectiveTreeImpl(requiresToken, newModifiers, moduleName, semicolonToken);
}
Also used : ModifierTree(org.sonar.plugins.java.api.tree.ModifierTree) ModifierKeywordTreeImpl(org.sonar.java.model.declaration.ModifierKeywordTreeImpl) ArrayList(java.util.ArrayList) RequiresDirectiveTreeImpl(org.sonar.java.model.declaration.RequiresDirectiveTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) ModifiersTreeImpl(org.sonar.java.model.declaration.ModifiersTreeImpl)

Example 10 with InternalSyntaxToken

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

the class JavaNodeBuilder method createNonTerminal.

@Override
public Object createNonTerminal(GrammarRuleKey ruleKey, Rule rule, List<Object> children, int startIndex, int endIndex) {
    for (Object child : children) {
        if (child instanceof InternalSyntaxToken) {
            InternalSyntaxToken syntaxToken = (InternalSyntaxToken) child;
            syntaxToken.setGrammarRuleKey(ruleKey);
            return child;
        }
    }
    return new InternalSyntaxSpacing(startIndex, endIndex);
}
Also used : InternalSyntaxSpacing(org.sonar.java.model.InternalSyntaxSpacing) 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