title: How to get the type of an instance of javax.lang.model.element.Element
body: <p>I'm following <a href="https://medium.com/@Miqubel/hello-world-of-annotation-processing-in-kotlin-3ec0290c1fdd" rel="nofollow noreferrer">Hello World of Annotation Processing in Kotlin</a> and <a href="https://github.com/square/kotlinpoet" rel="nofollow noreferrer">KotlinPoet's documentation</a> and am trying to implement a generic builder for Kotlin. I'd like to generically create a method for every field in an annotated data class and give it's argument the same name and type of the field. The problem is that I cannot find which type the field has, given the instance of <code>javax.lang.model.element.Element</code> that I have. Here's what I managed that far:</p>
  
  <pre><code>fieldsIn(klass.enclosedElements)
              .forEach {
                  classBuilder
                          .addProperty(PropertySpec
                                  .builder(it.toString(), String::class, KModifier.INTERNAL)
                                  .mutable(true)
                                  .initializer("\"\"")
                                  .build())
  
                  classBuilder
                          .addFunction(FunSpec
                                  .builder(it.toString())
                                  .addParameter(ParameterSpec
                                          .builder(
                                                  it.toString(), 
                                                  it.?) // what to use here?
                                          .build())
                                  .build())
              }
  </code></pre>
  
  <p>How can I find the type of the field? I read in the <a href="https://docs.oracle.com/javase/7/docs/api/javax/lang/model/element/Element.html#asType()" rel="nofollow noreferrer">documentation</a> that you should use method <code>asType()</code> but this return an instance of <code>TypeMirror</code>. I can't really see how to continue from here. Any suggestions are welcome.</p>