diff --git a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt index a0ed37783e7..38b51e7362b 100644 --- a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt +++ b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt @@ -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 { diff --git a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt index d4fa5856855..55b787afa1d 100644 --- a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt +++ b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt @@ -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 ("" == name) + AnnotatedConstructorDescriptor(classFqName) + else + AnnotatedMethodDescriptor(classFqName, name) + } else -> throw AssertionError("Unknown type: $type") }) diff --git a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt index 0e7daec152c..c6571d1dc52 100644 --- a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt +++ b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt @@ -37,6 +37,10 @@ private class RoundEnvironmentWrapper( return getEnclosedElements().filter { it.getKind() == kind && it.getSimpleName().toString() == name } } + private fun TypeElement.filterEnclosedElements(kind: ElementKind): List { + 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) })