title: Proper way for getting annotations of Java-Methods in custom Sonar rules
body: <p>I try to write a custom Sonar-rule (Java) and struggle with the proper way for getting annotation of invoked Java methods. 
  This rule should detect illegal access to methods and fields marked as <code>@VisibleForTesting</code>. Accesing such elements from production code is illegal, but access from the same class is legal. 
  My first approach is to implement <code>BaseTreeVisitor.visitMethodInvocation(MethodInvocationTree)</code> and use the metadata of the belonging symbol:</p>
  
  <ul>
  <li>get annotations: <code>methodInvocationSymbol.metadata().annotations()</code></li>
  <li>analyse the names of the symbols of each <code>AnnotationInstance</code> (annotations class) and its owner (annotations package)</li>
  </ul>
  
  <p>This works great as long other classes invoke the method. When the call is made <em>inside the same class</em> - the annotations name and package are set to <code>!unknownSymbol!</code>.</p>
  
  <p>I also tried an alternative approach: to analyse the <code>IdentifierTree</code> of the <code>AnnotationTree</code> (inside of <code>BaseTreeVisitor.visitMethodInvocation(MethodInvocationTree))</code>, but I could not find the way how to get the package name of the annotation. </p>
  
  <p>I use sonar-java-plugin 3.7.1 and sonar-plugin-api 5.1.</p>
  
  <p>The code is commited in this <a href="https://github.com/arxes-tolina/sonar-plugins" rel="nofollow noreferrer">mvn / Eclipse project</a>.
  The <code>UnexpectedAccessCheckTest</code> contains 2 use-cases. The "InvokedFromOtherClass" works well. The <code>InvokedFromSameClass</code> passes the test, but it happens only by accident - the annotation is not correctly detected.
  It produces this output:</p>
  
  <pre><code>[main] DEBUG d.t.s.p.vft.checks.IsAnAnnotation - Checking Annotation. 
      Expected [com.google.common.annotations.VisibleForTesting] 
      got [.!unknownSymbol!]
  </code></pre>
  
  <p>The correct running use-case produces this:</p>
  
  <pre><code>[main] DEBUG d.t.s.p.vft.checks.IsAnAnnotation - Checking Annotation. 
      Expected [com.google.common.annotations.VisibleForTesting] 
      got [com.google.common.annotations.VisibleForTesting]
  </code></pre>
  
  <p>Do you have any hint for me?</p>