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);
}
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;
}
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;
}
Aggregations