1 package de.example.custom.java.checks;
5 import org.sonar.api.utils.log.Logger;
6 import org.sonar.api.utils.log.Loggers;
7 import org.sonar.check.Rule;
8 import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
9 import org.sonar.plugins.java.api.semantic.Symbol.MethodSymbol;
10 import org.sonar.plugins.java.api.semantic.Type;
11 import org.sonar.plugins.java.api.tree.MethodTree;
12 import org.sonar.plugins.java.api.tree.Tree;
13 import org.sonar.plugins.java.api.tree.Tree.Kind;
15 import com.google.common.collect.ImmutableList;
17 @Rule(key = "GUJ0001")
18 public class ParameterCheck extends IssuableSubscriptionVisitor {
19 private static final Logger LOG = Loggers.get(ParameterCheck.class);
23 public List<Kind> nodesToVisit() {
24 return ImmutableList.of(Kind.METHOD);
28 public void visitNode(Tree tree) {
29 LOG.info("Visiting Node");
31 MethodTree method = (MethodTree) tree;
33 if (method.parameters().size() == 1) {
34 MethodSymbol symbol = method.symbol();
35 Type firstParameterType = symbol.parameterTypes().get(0);
36 Type returnType = symbol.returnType().type();
37 if(returnType.is(firstParameterType.fullyQualifiedName())) {
38 reportIssue(method.simpleName(),
39 "Remove this method");