use of org.sonar.plugins.java.api.tree.MethodTree 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.MethodTree 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.MethodTree in project sonar-java by SonarSource.
the class TransactionalMethodVisibilityCheck method visitNode.
@Override
public void visitNode(Tree tree) {
MethodTree method = (MethodTree) tree;
boolean isPublic = method.modifiers().contains(Modifier.PUBLIC);
if (hasSemantic()) {
isPublic = method.symbol().isPublic();
}
if (!isPublic && hasTransactionalAnnotation(method)) {
reportIssue(method.simpleName(), "Make this method \"public\" or remove the \"@Transactional\" annotation");
}
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class SerializableContract method hasSpecialHandlingSerializationMethods.
public static boolean hasSpecialHandlingSerializationMethods(ClassTree classTree) {
boolean hasWriteObject = false;
boolean hasReadObject = false;
String classFullyQualifiedName = classTree.symbol().type().fullyQualifiedName();
for (Tree member : classTree.members()) {
MethodMatcher writeObjectMatcher = writeObjectMatcher(classFullyQualifiedName);
MethodMatcher readObjectMatcher = readObjectMatcher(classFullyQualifiedName);
if (member.is(Tree.Kind.METHOD)) {
MethodTree methodTree = (MethodTree) member;
if (ModifiersUtils.hasModifier(methodTree.modifiers(), Modifier.PRIVATE)) {
hasWriteObject |= writeObjectMatcher.matches(methodTree) && methodThrows(methodTree, "java.io.IOException");
hasReadObject |= readObjectMatcher.matches(methodTree) && methodThrows(methodTree, "java.io.IOException", "java.lang.ClassNotFoundException");
}
}
}
return hasReadObject && hasWriteObject;
}
use of org.sonar.plugins.java.api.tree.MethodTree in project sonar-java by SonarSource.
the class BooleanMethodNameCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
IdentifierTree simpleName = methodTree.simpleName();
if (returnsBoolean(methodTree) && isBooleanGetter(simpleName) && isNotOverriding(methodTree)) {
reportIssue(simpleName, "Rename this method to start with \"is\" or \"has\".");
}
}
Aggregations