diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index e132568d380..e009e5041a7 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -973,6 +973,15 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati } fun tryParseTypeExpression(expression: KtExpression?): JCExpression? { + if (expression is KtReferenceExpression) { + val descriptor = kaptContext.bindingContext[BindingContext.REFERENCE_TARGET, expression] + if (descriptor is ClassDescriptor) { + return treeMaker.FqName(descriptor.fqNameSafe) + } else if (descriptor is TypeAliasDescriptor) { + descriptor.classDescriptor?.fqNameSafe?.let { return treeMaker.FqName(it) } + } + } + return when (expression) { is KtSimpleNameExpression -> treeMaker.SimpleName(expression.getReferencedName()) is KtDotQualifiedExpression -> { diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index a95f8e556bd..4697d4e4c19 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -44,6 +44,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/kapt3/kapt3-compiler/testData/converter"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("annotationWithFqNames.kt") + public void testAnnotationWithFqNames() throws Exception { + runTest("plugins/kapt3/kapt3-compiler/testData/converter/annotationWithFqNames.kt"); + } + @TestMetadata("annotations.kt") public void testAnnotations() throws Exception { runTest("plugins/kapt3/kapt3-compiler/testData/converter/annotations.kt"); diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/annotationWithFqNames.kt b/plugins/kapt3/kapt3-compiler/testData/converter/annotationWithFqNames.kt new file mode 100644 index 00000000000..175740491a6 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/annotationWithFqNames.kt @@ -0,0 +1,32 @@ +// CORRECT_ERROR_TYPES +// NO_VALIDATION + +//FILE: lib/Anno.java +package lib; + +public @interface Anno { + Class[] impls() default {}; +} + +//FILE: lib/impl/Impl.java +package lib.impl; + +public class Impl {} + +// FILE: test.kt +@file:Suppress("UNRESOLVED_REFERENCE", "ANNOTATION_ARGUMENT_MUST_BE_CONST", "NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION") +package test + +import lib.Anno +import lib.impl.Impl + +typealias Joo = Impl + +@Anno(impls = [Impl::class]) +class Foo + +@Anno(impls = [Impl::class, ABC::class]) +class Bar + +@Anno(impls = [Joo::class]) +class Boo \ No newline at end of file diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/annotationWithFqNames.txt b/plugins/kapt3/kapt3-compiler/testData/converter/annotationWithFqNames.txt new file mode 100644 index 00000000000..3dfb203c47f --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/annotationWithFqNames.txt @@ -0,0 +1,61 @@ +package lib; + +public @interface Anno { + + Class[] impls() default {}; +} + +//////////////////// + +package lib.impl; + +public class Impl { +} + +//////////////////// + +package test; + +import lib.Anno; +import lib.impl.Impl; + +@kotlin.Metadata() +@lib.Anno(impls = {lib.impl.Impl.class, ABC.class}) +public final class Bar { + + public Bar() { + super(); + } +} + +//////////////////// + +package test; + +import lib.Anno; +import lib.impl.Impl; + +@kotlin.Metadata() +@lib.Anno(impls = {lib.impl.Impl.class}) +public final class Boo { + + public Boo() { + super(); + } +} + +//////////////////// + +package test; + +import lib.Anno; +import lib.impl.Impl; + +@kotlin.Metadata() +@lib.Anno(impls = {lib.impl.Impl.class}) +public final class Foo { + + public Foo() { + super(); + } +}