Search in sources :

Example 1 with ModifiersTreeImpl

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

the class TreeFactory method newAnnotationType.

public ClassTreeImpl newAnnotationType(InternalSyntaxToken openBraceToken, Optional<List<JavaTree>> annotationTypeElementDeclarations, InternalSyntaxToken closeBraceToken) {
    // TODO
    ModifiersTreeImpl emptyModifiers = ModifiersTreeImpl.emptyModifiers();
    ImmutableList.Builder<Tree> members = ImmutableList.builder();
    if (annotationTypeElementDeclarations.isPresent()) {
        for (JavaTree annotationTypeElementDeclaration : annotationTypeElementDeclarations.get()) {
            if (annotationTypeElementDeclaration.getGrammarRuleKey().equals(JavaLexer.VARIABLE_DECLARATORS)) {
                for (VariableTreeImpl variable : (VariableDeclaratorListTreeImpl) annotationTypeElementDeclaration) {
                    members.add(variable);
                }
            } else if (!annotationTypeElementDeclaration.is(Kind.TOKEN)) {
                members.add(annotationTypeElementDeclaration);
            }
        }
    }
    return new ClassTreeImpl(emptyModifiers, openBraceToken, members.build(), closeBraceToken);
}
Also used : ClassTreeImpl(org.sonar.java.model.declaration.ClassTreeImpl) NewClassTreeImpl(org.sonar.java.model.expression.NewClassTreeImpl) ImmutableList(com.google.common.collect.ImmutableList) ImportClauseTree(org.sonar.plugins.java.api.tree.ImportClauseTree) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree) ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ArrayDimensionTree(org.sonar.plugins.java.api.tree.ArrayDimensionTree) Tree(org.sonar.plugins.java.api.tree.Tree) ListTree(org.sonar.plugins.java.api.tree.ListTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) JavaTree(org.sonar.java.model.JavaTree) StatementTree(org.sonar.plugins.java.api.tree.StatementTree) ModifierTree(org.sonar.plugins.java.api.tree.ModifierTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) PackageDeclarationTree(org.sonar.plugins.java.api.tree.PackageDeclarationTree) AnnotationTree(org.sonar.plugins.java.api.tree.AnnotationTree) TypeParameterTree(org.sonar.plugins.java.api.tree.TypeParameterTree) ModuleDirectiveTree(org.sonar.plugins.java.api.tree.ModuleDirectiveTree) ModuleDeclarationTree(org.sonar.plugins.java.api.tree.ModuleDeclarationTree) VariableTreeImpl(org.sonar.java.model.declaration.VariableTreeImpl) ModifiersTreeImpl(org.sonar.java.model.declaration.ModifiersTreeImpl) JavaTree(org.sonar.java.model.JavaTree)

Example 2 with ModifiersTreeImpl

use of org.sonar.java.model.declaration.ModifiersTreeImpl 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 3 with ModifiersTreeImpl

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

the class TreeFactory method newRequiresModuleDirective.

public ModuleDirectiveTree newRequiresModuleDirective(InternalSyntaxToken requiresToken, InternalSyntaxToken staticModifier, InternalSyntaxToken transitiveTokenAsModuleName, InternalSyntaxToken semicolonToken) {
    ModifierKeywordTreeImpl staticModifierTree = new ModifierKeywordTreeImpl(Modifier.STATIC, staticModifier);
    ModifiersTreeImpl modifiers = new ModifiersTreeImpl(Collections.singletonList(staticModifierTree));
    return new RequiresDirectiveTreeImpl(requiresToken, modifiers, transitiveModuleName(transitiveTokenAsModuleName), semicolonToken);
}
Also used : ModifierKeywordTreeImpl(org.sonar.java.model.declaration.ModifierKeywordTreeImpl) RequiresDirectiveTreeImpl(org.sonar.java.model.declaration.RequiresDirectiveTreeImpl) ModifiersTreeImpl(org.sonar.java.model.declaration.ModifiersTreeImpl)

Aggregations

ModifiersTreeImpl (org.sonar.java.model.declaration.ModifiersTreeImpl)3 ModifierKeywordTreeImpl (org.sonar.java.model.declaration.ModifierKeywordTreeImpl)2 RequiresDirectiveTreeImpl (org.sonar.java.model.declaration.RequiresDirectiveTreeImpl)2 ModifierTree (org.sonar.plugins.java.api.tree.ModifierTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)1 JavaTree (org.sonar.java.model.JavaTree)1 ClassTreeImpl (org.sonar.java.model.declaration.ClassTreeImpl)1 VariableTreeImpl (org.sonar.java.model.declaration.VariableTreeImpl)1 NewClassTreeImpl (org.sonar.java.model.expression.NewClassTreeImpl)1 AnnotationTree (org.sonar.plugins.java.api.tree.AnnotationTree)1 ArrayDimensionTree (org.sonar.plugins.java.api.tree.ArrayDimensionTree)1 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)1 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)1 ImportClauseTree (org.sonar.plugins.java.api.tree.ImportClauseTree)1 ListTree (org.sonar.plugins.java.api.tree.ListTree)1 ModuleDeclarationTree (org.sonar.plugins.java.api.tree.ModuleDeclarationTree)1 ModuleDirectiveTree (org.sonar.plugins.java.api.tree.ModuleDirectiveTree)1 ModuleNameTree (org.sonar.plugins.java.api.tree.ModuleNameTree)1