import java.util.List;
+import javax.annotation.Nullable;
+
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.JavaFileScannerContext;
import org.sonar.plugins.java.api.semantic.Symbol;
+import org.sonar.plugins.java.api.tree.AnnotationTree;
import org.sonar.plugins.java.api.tree.ClassTree;
import org.sonar.plugins.java.api.tree.Tree;
import org.sonar.plugins.java.api.tree.Tree.Kind;
import com.google.common.collect.ImmutableList;
-@Rule(key = "GU0002")
+@Rule(key = "GUJ0002")
public class SpringServiceInstanceFieldCheck extends IssuableSubscriptionVisitor {
private static final Logger LOG = Loggers.get(SpringServiceInstanceFieldCheck.class);
@Override
public void visitNode(Tree tree) {
+
if (tree.is(Kind.CLASS) && isSpringService((ClassTree) tree)) {
}
}
+
+
+ public void visitAnnotation(AnnotationTree annotationTree) {
+ scan(annotationTree.annotationType());
+ scan(annotationTree.arguments());
+ }
private static boolean isOwnedByASpringService(VariableTree variable) {
private static boolean isSpringService(ClassTree tree) {
tree.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
+ tree.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
return true;
}
+ protected void scan(@Nullable Tree tree) {
+ if (tree != null) {
+ }
+ }
}
+++ /dev/null
-<p>Custom rule description.</p>
-<h2>Noncompliant Code Example</h2>
-<pre>
-class MyClass {
-
- int foo1(int value) { return 0; }
-
- MyClass foo2(MyClass value) { return null; }
-
- ...
-
-}
-</pre>
-<h2>See</h2>
-<ul>
- <li> <a href="https://www.securecoding.cert.org/confluence/x/EYBUC">CERT, MSC11-J.</a> - You are doing wrong!!! </li>
-</ul>
-
--- /dev/null
+<p>Custom rule description.</p>
+<h2>Noncompliant Code Example</h2>
+<pre>
+class MyClass {
+
+ int foo1(int value) { return 0; }
+
+ MyClass foo2(MyClass value) { return null; }
+
+ ...
+
+}
+</pre>
+<h2>See</h2>
+<ul>
+ <li> <a href="https://www.securecoding.cert.org/confluence/x/EYBUC">CERT, MSC11-J.</a> - You are doing wrong!!! </li>
+</ul>
+