Search in sources :

Example 1 with Modifier

use of org.sonar.plugins.java.api.tree.Modifier in project sonar-java by SonarSource.

the class ModifiersOrderCheck method getFirstBadlyOrdered.

private static ModifierTree getFirstBadlyOrdered(ModifiersTree modifiersTree) {
    ListIterator<ModifierTree> modifiersIterator = modifiersTree.listIterator();
    skipAnnotations(modifiersIterator);
    Modifier[] modifiers = Modifier.values();
    int modifierIndex = 0;
    while (modifiersIterator.hasNext()) {
        ModifierTree modifier = modifiersIterator.next();
        if (modifier.is(Kind.ANNOTATION)) {
            break;
        }
        ModifierKeywordTree mkt = (ModifierKeywordTree) modifier;
        for (; modifierIndex < modifiers.length && !mkt.modifier().equals(modifiers[modifierIndex]); modifierIndex++) {
        // We're just interested in the final value of modifierIndex
        }
        if (modifierIndex == modifiers.length) {
            return modifier;
        }
    }
    return testOnlyAnnotationsAreLeft(modifiersIterator);
}
Also used : ModifierTree(org.sonar.plugins.java.api.tree.ModifierTree) ModifierKeywordTree(org.sonar.plugins.java.api.tree.ModifierKeywordTree) Modifier(org.sonar.plugins.java.api.tree.Modifier)

Example 2 with Modifier

use of org.sonar.plugins.java.api.tree.Modifier in project sonar-java by SonarSource.

the class PublicStaticFieldShouldBeFinalCheck method isPublicStaticNotFinal.

private static boolean isPublicStaticNotFinal(VariableTree tree) {
    boolean isPublic = false;
    boolean isStatic = false;
    boolean isFinal = false;
    for (ModifierKeywordTree modifierKeywordTree : tree.modifiers().modifiers()) {
        Modifier modifier = modifierKeywordTree.modifier();
        if (modifier == Modifier.PUBLIC) {
            isPublic = true;
        } else if (modifier == Modifier.STATIC) {
            isStatic = true;
        } else if (modifier == Modifier.FINAL) {
            isFinal = true;
        }
    }
    return isPublic && isStatic && !isFinal;
}
Also used : ModifierKeywordTree(org.sonar.plugins.java.api.tree.ModifierKeywordTree) Modifier(org.sonar.plugins.java.api.tree.Modifier)

Example 3 with Modifier

use of org.sonar.plugins.java.api.tree.Modifier in project sonar-java by SonarSource.

the class BadConstantNameCheck method isStaticFinal.

private static boolean isStaticFinal(VariableTree variableTree) {
    boolean isStatic = false;
    boolean isFinal = false;
    for (ModifierKeywordTree modifierKeywordTree : variableTree.modifiers().modifiers()) {
        Modifier modifier = modifierKeywordTree.modifier();
        if (modifier == Modifier.STATIC) {
            isStatic = true;
        }
        if (modifier == Modifier.FINAL) {
            isFinal = true;
        }
    }
    return isStatic && isFinal;
}
Also used : ModifierKeywordTree(org.sonar.plugins.java.api.tree.ModifierKeywordTree) Modifier(org.sonar.plugins.java.api.tree.Modifier)

Aggregations

Modifier (org.sonar.plugins.java.api.tree.Modifier)3 ModifierKeywordTree (org.sonar.plugins.java.api.tree.ModifierKeywordTree)3 ModifierTree (org.sonar.plugins.java.api.tree.ModifierTree)1