f9d5c299bba27c182ebff8486d73a481545bf01c
[JavaForFun] /
1 package de.example.custom.java.checks;
2
3 import java.util.List;
4
5 import javax.annotation.Nullable;
6
7 import org.sonar.api.utils.log.Logger;
8 import org.sonar.api.utils.log.Loggers;
9 import org.sonar.check.Rule;
10 import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
11 import org.sonar.plugins.java.api.JavaFileScannerContext;
12 import org.sonar.plugins.java.api.semantic.Symbol;
13 import org.sonar.plugins.java.api.tree.AnnotationTree;
14 import org.sonar.plugins.java.api.tree.ClassTree;
15 import org.sonar.plugins.java.api.tree.Tree;
16 import org.sonar.plugins.java.api.tree.Tree.Kind;
17 import org.sonar.plugins.java.api.tree.VariableTree;
18
19 import com.google.common.collect.ImmutableList;
20
21 @Rule(key = "GUJ0002")
22 public class SpringServiceInstanceFieldCheck extends IssuableSubscriptionVisitor {
23         private static final Logger LOG = Loggers.get(SpringServiceInstanceFieldCheck.class);
24         
25          private JavaFileScannerContext context;
26
27
28         @Override
29         public List<Kind> nodesToVisit() {
30                 return ImmutableList.of(Kind.CLASS, Kind.VARIABLE);
31         }
32
33         @Override
34         public void visitNode(Tree tree) {
35                 
36                 if (tree.is(Kind.CLASS) && isSpringService((ClassTree) tree)) {
37                         
38                 }
39                 
40         }
41         
42         
43           public void visitAnnotation(AnnotationTree annotationTree) {
44                     scan(annotationTree.annotationType());
45                     scan(annotationTree.arguments());
46                   }
47          
48         
49           private static boolean isOwnedByASpringService(VariableTree variable) {
50                     Symbol owner = variable.symbol().owner();
51                     return owner.isTypeSymbol() && (owner.type().isSubtypeOf("javax.servlet.http.HttpServlet") || owner.type().isSubtypeOf("org.apache.struts.action.Action"));
52                   }
53           
54           private static boolean isSpringService(ClassTree tree) {
55                   tree.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
56                   tree.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
57                   return true;
58                   
59          }
60
61           protected void scan(@Nullable Tree tree) {
62                     if (tree != null) {
63                     }
64                   }
65
66 }