Search in sources :

Example 1 with RequiresDirectiveTreeImpl

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

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

ModifierKeywordTreeImpl (org.sonar.java.model.declaration.ModifierKeywordTreeImpl)2 ModifiersTreeImpl (org.sonar.java.model.declaration.ModifiersTreeImpl)2 RequiresDirectiveTreeImpl (org.sonar.java.model.declaration.RequiresDirectiveTreeImpl)2 ArrayList (java.util.ArrayList)1 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)1 ModifierTree (org.sonar.plugins.java.api.tree.ModifierTree)1