Skip to content

Instantly share code, notes, and snippets.

@tarek360
Last active June 8, 2017 12:25
Show Gist options
  • Save tarek360/0145a95b7b32eeb46255704861e5ab1e to your computer and use it in GitHub Desktop.
Save tarek360/0145a95b7b32eeb46255704861e5ab1e to your computer and use it in GitHub Desktop.
import com.google.auto.service.AutoService
import com.tarek30.annotation.EasyJSON
import javax.annotation.processing.AbstractProcessor
import javax.annotation.processing.ProcessingEnvironment
import javax.annotation.processing.Processor
import javax.annotation.processing.RoundEnvironment
import javax.lang.model.SourceVersion
import javax.lang.model.element.TypeElement
@AutoService(Processor::class)
class EasyJSONProcessor : AbstractProcessor() {
@Synchronized override fun init(processingEnv: ProcessingEnvironment) {
super.init(processingEnv)
}
override fun getSupportedAnnotationTypes(): Set<String> {
return setOf(EasyJSON::class.java.canonicalName)
}
override fun getSupportedSourceVersion(): SourceVersion {
return SourceVersion.latestSupported()
}
override fun process(annotations: Set<TypeElement>, roundEnv: RoundEnvironment): Boolean {
// Your annotated classes
val annotatedClasses =
roundEnv.getElementsAnnotatedWith(EasyJSON::class.java)
// Filter annotated classes which is defined
// with @Target(AnnotationTarget.CLASS)
.filterIsInstance<TypeElement>()
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment