8e0df34b5d3cce57746252972edbdadab07700c8
[JavaForFun] /
1 package de.example.custom.checks;
2
3 import java.util.List;
4
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.JavaFileScannerContext;
10 import org.sonar.plugins.java.api.semantic.Symbol;
11 import org.sonar.plugins.java.api.tree.ClassTree;
12 import org.sonar.plugins.java.api.tree.Tree;
13 import org.sonar.plugins.java.api.tree.Tree.Kind;
14 import org.sonar.plugins.java.api.tree.VariableTree;
15
16 import com.google.common.collect.ImmutableList;
17
18 @Rule(key = "GU0002")
19 public class SpringServiceInstanceFieldCheck extends IssuableSubscriptionVisitor {
20         private static final Logger LOG = Loggers.get(SpringServiceInstanceFieldCheck.class);
21         
22          private JavaFileScannerContext context;
23
24
25         @Override
26         public List<Kind> nodesToVisit() {
27                 return ImmutableList.of(Kind.CLASS, Kind.VARIABLE);
28         }
29
30         @Override
31         public void visitNode(Tree tree) {
32                 if (tree.is(Kind.CLASS) && isSpringService((ClassTree) tree)) {
33                         
34                 }
35                 
36         }
37          
38         
39           private static boolean isOwnedByASpringService(VariableTree variable) {
40                     Symbol owner = variable.symbol().owner();
41                     return owner.isTypeSymbol() && (owner.type().isSubtypeOf("javax.servlet.http.HttpServlet") || owner.type().isSubtypeOf("org.apache.struts.action.Action"));
42                   }
43           
44           private static boolean isSpringService(ClassTree tree) {
45                   tree.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
46                   return true;
47                   
48          }
49
50
51 }