Support constructors in kapt wrapper
This commit is contained in:
+1
@@ -34,6 +34,7 @@ abstract class AnnotatedElementDescriptor(public val classFqName: String)
|
||||
|
||||
data class AnnotatedClassDescriptor(classFqName: String) : AnnotatedElementDescriptor(classFqName)
|
||||
data class AnnotatedMethodDescriptor(classFqName: String, public val methodName: String) : AnnotatedElementDescriptor(classFqName)
|
||||
data class AnnotatedConstructorDescriptor(classFqName: String) : AnnotatedElementDescriptor(classFqName)
|
||||
data class AnnotatedFieldDescriptor(classFqName: String, public val fieldName: String) : AnnotatedElementDescriptor(classFqName)
|
||||
|
||||
public abstract class AnnotationProcessorWrapper(private val processorFqName: String) : Processor {
|
||||
|
||||
+12
-2
@@ -70,8 +70,18 @@ public abstract class KotlinAnnotationProvider {
|
||||
val set = annotatedKotlinElements.getOrPut(annotationName) { hashSetOf() }
|
||||
set.add(when (type) {
|
||||
ANNOTATED_CLASS -> AnnotatedClassDescriptor(classFqName)
|
||||
ANNOTATED_FIELD -> AnnotatedFieldDescriptor(classFqName, elementName!!)
|
||||
ANNOTATED_METHOD -> AnnotatedMethodDescriptor(classFqName, elementName!!)
|
||||
ANNOTATED_FIELD -> {
|
||||
val name = elementName ?: throw AssertionError("Name for field must be provided")
|
||||
AnnotatedFieldDescriptor(classFqName, name)
|
||||
}
|
||||
ANNOTATED_METHOD -> {
|
||||
val name = elementName ?: throw AssertionError("Name for method must be provided")
|
||||
|
||||
if ("<init>" == name)
|
||||
AnnotatedConstructorDescriptor(classFqName)
|
||||
else
|
||||
AnnotatedMethodDescriptor(classFqName, name)
|
||||
}
|
||||
else -> throw AssertionError("Unknown type: $type")
|
||||
})
|
||||
|
||||
|
||||
+8
@@ -37,6 +37,10 @@ private class RoundEnvironmentWrapper(
|
||||
return getEnclosedElements().filter { it.getKind() == kind && it.getSimpleName().toString() == name }
|
||||
}
|
||||
|
||||
private fun TypeElement.filterEnclosedElements(kind: ElementKind): List<Element> {
|
||||
return getEnclosedElements().filter { it.getKind() == kind }
|
||||
}
|
||||
|
||||
private fun Element.hasAnnotation(annotationFqName: String): Boolean {
|
||||
return getAnnotationMirrors().any { annotationFqName == it.getAnnotationType().asElement().toString() }
|
||||
}
|
||||
@@ -49,6 +53,10 @@ private class RoundEnvironmentWrapper(
|
||||
val clazz = processingEnv.getElementUtils().getTypeElement(descriptor.classFqName) ?: return@fold set
|
||||
when (descriptor) {
|
||||
is AnnotatedClassDescriptor -> set.add(clazz)
|
||||
is AnnotatedConstructorDescriptor -> {
|
||||
set.addAll(clazz.filterEnclosedElements(ElementKind.CONSTRUCTOR)
|
||||
.filter { it.hasAnnotation(annotationFqName) })
|
||||
}
|
||||
is AnnotatedFieldDescriptor -> {
|
||||
set.addAll(clazz.filterEnclosedElements(ElementKind.FIELD, descriptor.fieldName)
|
||||
.filter { it.hasAnnotation(annotationFqName) })
|
||||
|
||||
Reference in New Issue
Block a user