use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class UnusedLocalVariableCheck method checkVariableUsages.
private void checkVariableUsages() {
for (VariableTree variableTree : variables) {
Symbol symbol = variableTree.symbol();
if (symbol.usages().size() == assignments.get(symbol).size()) {
IdentifierTree simpleName = variableTree.simpleName();
reportIssue(simpleName, "Remove this unused \"" + simpleName + "\" local variable.");
}
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class UnusedMethodParameterCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
if (methodTree.block() == null || isExcluded(methodTree)) {
return;
}
Set<String> documentedParameters = documentedParameters(methodTree);
boolean overridableMethod = overridableMethod(methodTree.symbol());
List<IdentifierTree> unused = Lists.newArrayList();
for (VariableTree var : methodTree.parameters()) {
Symbol symbol = var.symbol();
if (symbol.usages().isEmpty() && !symbol.metadata().isAnnotatedWith(AUTHORIZED_ANNOTATION) && !isStrutsActionParameter(var) && (!overridableMethod || !documentedParameters.contains(symbol.name()))) {
unused.add(var.simpleName());
}
}
Set<String> unresolvedIdentifierNames = unresolvedIdentifierNames(methodTree.block());
// kill the noise regarding unresolved identifiers, and remove the one with matching names from the list of unused
unused = unused.stream().filter(id -> !unresolvedIdentifierNames.contains(id.name())).collect(Collectors.toList());
if (!unused.isEmpty()) {
reportUnusedParameters(unused);
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class UnusedPrivateMethodCheck method reportUnusedPrivateMethods.
private void reportUnusedPrivateMethods() {
unusedPrivateMethods.stream().filter(methodTree -> !unresolvedMethodNames.contains(methodTree.simpleName().name())).forEach(methodTree -> {
IdentifierTree simpleName = methodTree.simpleName();
reportIssue(simpleName, String.format("Remove this unused private \"%s\" %s.", simpleName.name(), methodTree.is(Tree.Kind.CONSTRUCTOR) ? "constructor" : "method"));
});
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class BadAbstractClassNameCheck method visitClass.
@Override
public void visitClass(ClassTree tree) {
IdentifierTree simpleName = tree.simpleName();
if (tree.is(Tree.Kind.CLASS) && simpleName != null) {
if (pattern.matcher(simpleName.name()).matches()) {
if (!isAbstract(tree)) {
context.reportIssue(this, simpleName, "Make this class abstract or rename it, since it matches the regular expression '" + format + "'.");
}
} else {
if (isAbstract(tree)) {
context.reportIssue(this, simpleName, "Rename this abstract class name to match the regular expression '" + format + "'.");
}
}
}
super.visitClass(tree);
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class BadTestClassNameCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
IdentifierTree simpleName = classTree.simpleName();
if (hasInvalidName(simpleName) && hasTestMethod(classTree.members())) {
reportIssue(simpleName, "Rename class \"" + simpleName + "\" to match the regular expression: '" + format + "'");
}
}
Aggregations