title: Kotlin Annotation: Get interface inner annotated properties
body: <h3>Overview</h3>
  
  <p>I'm trying to build my first annotation processor and it's going pretty well. I am creating a code generating processor that basically generates <code>SharedPreferences</code> for a defined interface.  My current annotations are <code>SharedPrefs</code> and <code>Default</code>.  <code>@SharedPrefs</code> informs the processor that the file is an interface and needs a generated prefs file. <code>@Default</code> is what I annotated some properties in the interface as in order to let the processor know what to set the default value to. There can be multiple files defined as <code>@SharedPrefs</code>.</p>
  
  <h3>Implementation</h3>
  
  <p>I currently use the following code to get a list of files annotated with <code>@SharedPrefs</code> and the <code>@Default</code>s:</p>
  
  <pre class="lang-java prettyprint-override"><code>roundEnv.getElementsAnnotatedWith(SharedPrefs::class.java)?.forEach { element -&gt;
    ...
    roundEnv.getElementsAnnotatedWith(Default::class.java)?.forEach {
      ...
    }
  }
  </code></pre>
  
  <p><code>@SharedPrefs</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Retention(AnnotationRetention.SOURCE)
  @Target(AnnotationTarget.CLASS)
  annotation class SharedPrefs(val showTraces: Boolean = false)
  </code></pre>
  
  <p><code>@Default</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Retention(AnnotationRetention.SOURCE)
  @Target(AnnotationTarget.PROPERTY)
  annotation class Default(val defaultValue: String = "[null]")
  </code></pre>
  
  <p>In Use:</p>
  
  <pre class="lang-java prettyprint-override"><code>@SharedPrefs
  interface InstanceSettings {
      var wifiPassword: String
      @Default("20")
      var count: Int
  }
  </code></pre>
  
  <h3>Problem</h3>
  
  <p>As is, the inner <code>forEach</code> is returning <em>all</em> properties from <em>all</em> files annotated with <code>@Default</code>.  The code generation works fine, but this doesn't seem like the best way forward.  Is there a way to get just the properties w/in the current <code>@SharedPrefs</code> class that I'm processing?  For instance, something like:</p>
  
  <pre class="lang-java prettyprint-override"><code>roundEnv.getElementsAnnotatedWith(SharedPrefs::class.java)?.forEach { element -&gt;
    ...
    element.methodToGetAnnotatedProperties(Default::class.java)?.forEach {
      ...
    }
  }
  </code></pre>
  
  <h3><strong>* EDIT *</strong></h3>
  
  <p>I found that, for methods that I annotate</p>
  
  <pre class="lang-java prettyprint-override"><code>@SomeAnnotation
  fun someMethod()
  </code></pre>
  
  <p>I can loop through the <code>element.enclosingElements</code> and find if it has an annotation using <code>enclosingElement.getAnnotation(&lt;SomeAnnotation::class.java&gt;)</code>.  Unfortunately, and correct me if I'm wrong here, I can't annotate interface variables with an annotation with <code>AnnotationTarget.FIELD</code> since they don't have a backing field since it's an interface and they're not implemented.  Therefore, I'm using <code>AnnotationTarget.PROPERTY</code>.  When looping through the enclosing elements, all of the variables show up as getters and setters.  For the example above for <code>InstanceSettings</code>, I get <code>getWifiPassword</code>, <code>setWifiPassword</code>, <code>getCount</code> and <code>setCount</code>. I <em>do not</em> get an element for just <code>wifiPassword</code> or <code>count</code>.  Calling <code>getAnnotation(Default::class.java)</code> will always return null on these since they are generated.</p>
  
  <p>Also, any other resources on annotation processing that anyone knows of would be a great addition in the comments.  Thanks!</p>