public enum class AnnotationTarget { /** Class, interface or object, annotation class is also included */ CLASS, /** Annotation class only */ ANNOTATION_CLASS, /** Generic type parameter (unsupported yet) */ TYPE_PARAMETER, /** Property */ PROPERTY, /** Field, including property's backing field */ FIELD, /** Local variable */ LOCAL_VARIABLE, /** Value parameter of a function or a constructor */ VALUE_PARAMETER, /** Constructor only (primary or secondary) */ CONSTRUCTOR, /** Function (constructors are not included) */ FUNCTION, /** Property getter only */ PROPERTY_GETTER, /** Property setter only */ PROPERTY_SETTER, /** Type usage */ TYPE, /** Any expression */ EXPRESSION, /** File */ FILE, /** Type alias */ @SinceKotlin("1.1") TYPEALIAS }
public enum class AnnotationRetention { /** Annotation isn't stored in binary output */ SOURCE, /** Annotation is stored in binary output, but invisible for reflection */ BINARY, /** Annotation is stored in binary output and visible for reflection (default retention) */ RUNTIME }
overridefunprocess(annotations: MutableSet<outTypeElement>, roundEnv: RoundEnvironment): Boolean { mLogger.info("processor start") //获取所有用@MyClass注解的类 val elements = roundEnv.getElementsAnnotatedWith(MyClass::class.java) elements.forEach { val typeElement = it as TypeElement val members = elementUtils!!.getAllMembers(typeElement)
//创建一个bingdView的方法,参数为activity,并使用JvmStatic注解 val bindFunBuilder = FunSpec.builder("bindView").addParameter("activity", typeElement.asClassName()).addAnnotation(JvmStatic::class.java)
members.forEach { //获取所有@findview注解的属性 val find: findView? = it.getAnnotation(findView::class.java) if (find != null) { mLogger.info("find annotation " + it.simpleName) //方法中添加findviewById bindFunBuilder.addStatement("activity.${it.simpleName} = activity.findViewById(${find.value})") } } val bindFun = bindFunBuilder.build()