use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class IncorrectOrderOfMembersCheck method visitClass.
@Override
public void visitClass(ClassTree tree) {
int prev = 0;
for (int i = 0; i < tree.members().size(); i++) {
final Tree member = tree.members().get(i);
final int priority;
IdentifierTree identifier;
if (member.is(Tree.Kind.VARIABLE)) {
priority = 0;
identifier = ((VariableTree) member).simpleName();
} else if (member.is(Tree.Kind.CONSTRUCTOR)) {
priority = 1;
identifier = ((MethodTree) member).simpleName();
} else if (member.is(Tree.Kind.METHOD)) {
priority = 2;
identifier = ((MethodTree) member).simpleName();
} else {
continue;
}
if (priority < prev) {
context.reportIssue(this, identifier, "Move this " + NAMES[priority] + " to comply with Java Code Conventions.");
} else {
prev = priority;
}
}
super.visitClass(tree);
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class ForLoopCounterChangedCheck method visitForStatement.
@Override
public void visitForStatement(ForStatementTree tree) {
Set<String> pendingLoopCounters = Sets.newHashSet();
for (StatementTree statementTree : tree.initializer()) {
if (statementTree.is(Tree.Kind.VARIABLE)) {
pendingLoopCounters.add(((VariableTree) statementTree).simpleName().name());
}
}
scan(tree.initializer());
scan(tree.condition());
scan(tree.update());
loopCounters.addAll(pendingLoopCounters);
scan(tree.statement());
loopCounters.removeAll(pendingLoopCounters);
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class FieldModifierCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
classTree.members().stream().filter(FieldModifierCheck::isConsentWithCheck).forEach(member -> {
IdentifierTree simpleName = ((VariableTree) member).simpleName();
reportIssue(simpleName, "Explicitly declare the visibility for \"" + simpleName.name() + "\".");
});
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class EqualsParametersMarkedNonNullCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
List<VariableTree> params = methodTree.parameters();
if ("equals".equals(methodTree.symbol().name()) && params.size() == 1) {
VariableTree variable = params.get(0);
if (variable.type().symbolType().is("java.lang.Object") && NullableAnnotationUtils.isAnnotatedNonNull(variable.symbol())) {
reportIssue(variable, "\"equals\" method parameters should not be marked \"@Nonnull\".");
}
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class UnusedTestRuleCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree classTree = (ClassTree) tree;
for (Tree member : classTree.members()) {
if (member.is(Tree.Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) member;
Symbol symbol = variableTree.symbol();
if (isTestNameOrTemporaryFolderRule(symbol) && symbol.usages().isEmpty()) {
reportIssue(variableTree.simpleName(), "Remove this unused \"" + symbol.type() + "\".");
}
}
}
}
Aggregations