FIR: Fix loading Java annotations with Class[]-typed methods
This commit is contained in:
+6
@@ -34513,6 +34513,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/reflection"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("classArrayInAnnotation.kt")
|
||||
public void testClassArrayInAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/reflection/classArrayInAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noReflectionInClassPath.kt")
|
||||
public void testNoReflectionInClassPath() throws Exception {
|
||||
|
||||
@@ -125,7 +125,7 @@ internal fun JavaClassifierType.toFirResolvedTypeRef(
|
||||
internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
session: FirSession,
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
forAnnotationValueParameter: Boolean = false,
|
||||
forAnnotationMember: Boolean = false,
|
||||
isForSupertypes: Boolean = false,
|
||||
attributes: ConeAttributes = ConeAttributes.Empty
|
||||
): ConeKotlinType {
|
||||
@@ -134,7 +134,7 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
toConeKotlinTypeWithoutEnhancement(
|
||||
session,
|
||||
javaTypeParameterStack,
|
||||
forAnnotationValueParameter = forAnnotationValueParameter,
|
||||
forAnnotationMember = forAnnotationMember,
|
||||
attributes = attributes
|
||||
)
|
||||
}
|
||||
@@ -152,7 +152,7 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
toConeKotlinTypeWithoutEnhancement(
|
||||
session,
|
||||
javaTypeParameterStack,
|
||||
forAnnotationValueParameter,
|
||||
forAnnotationMember,
|
||||
isForSupertypes,
|
||||
attributes = attributes
|
||||
)
|
||||
@@ -225,7 +225,7 @@ private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
forTypeParameterBounds: Boolean = false,
|
||||
isForSupertypes: Boolean = false,
|
||||
forAnnotationValueParameter: Boolean = false,
|
||||
forAnnotationMember: Boolean = false,
|
||||
attributes: ConeAttributes = ConeAttributes.Empty
|
||||
): ConeKotlinType {
|
||||
val lowerBound = toConeKotlinTypeForFlexibleBound(
|
||||
@@ -234,10 +234,10 @@ private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
||||
isLowerBound = true,
|
||||
forTypeParameterBounds,
|
||||
isForSupertypes,
|
||||
forAnnotationValueParameter = forAnnotationValueParameter,
|
||||
forAnnotationMember = forAnnotationMember,
|
||||
attributes = attributes
|
||||
)
|
||||
if (forAnnotationValueParameter) {
|
||||
if (forAnnotationMember) {
|
||||
return lowerBound
|
||||
}
|
||||
val upperBound =
|
||||
@@ -248,7 +248,7 @@ private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
||||
forTypeParameterBounds,
|
||||
isForSupertypes,
|
||||
lowerBound,
|
||||
forAnnotationValueParameter = forAnnotationValueParameter,
|
||||
forAnnotationMember = forAnnotationMember,
|
||||
attributes = attributes
|
||||
)
|
||||
|
||||
@@ -362,13 +362,13 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
||||
forTypeParameterBounds: Boolean,
|
||||
isForSupertypes: Boolean,
|
||||
lowerBound: ConeLookupTagBasedType? = null,
|
||||
forAnnotationValueParameter: Boolean = false,
|
||||
forAnnotationMember: Boolean = false,
|
||||
attributes: ConeAttributes = ConeAttributes.Empty
|
||||
): ConeLookupTagBasedType {
|
||||
return when (val classifier = classifier) {
|
||||
is JavaClass -> {
|
||||
//val classId = classifier.classId!!
|
||||
var classId = if (forAnnotationValueParameter) {
|
||||
var classId = if (forAnnotationMember) {
|
||||
JavaToKotlinClassMap.mapJavaToKotlinIncludingClassMapping(classifier.fqName!!)
|
||||
} else {
|
||||
JavaToKotlinClassMap.mapJavaToKotlin(classifier.fqName!!)
|
||||
|
||||
+2
-2
@@ -51,7 +51,7 @@ internal class EnhancementSignatureParts(
|
||||
session: FirSession,
|
||||
javaTypeEnhancementState: JavaTypeEnhancementState,
|
||||
predefined: TypeEnhancementInfo? = null,
|
||||
forAnnotationValueParameter: Boolean = false
|
||||
forAnnotationMember: Boolean = false
|
||||
): PartEnhancementResult {
|
||||
val qualifiers = computeIndexedQualifiersForOverride(session, javaTypeEnhancementState)
|
||||
|
||||
@@ -64,7 +64,7 @@ internal class EnhancementSignatureParts(
|
||||
val typeWithoutEnhancement = current.type.toConeKotlinTypeWithoutEnhancement(
|
||||
session,
|
||||
javaTypeParameterStack,
|
||||
forAnnotationValueParameter,
|
||||
forAnnotationMember,
|
||||
attributes = attributesCache.getValue(current)
|
||||
)
|
||||
val containsFunctionN = typeWithoutEnhancement.contains {
|
||||
|
||||
+5
-2
@@ -319,7 +319,7 @@ class FirSignatureEnhancement(
|
||||
session,
|
||||
jsr305State,
|
||||
predefinedEnhancementInfo?.parametersInfo?.getOrNull(index),
|
||||
forAnnotationValueParameter = owner.classKind == ClassKind.ANNOTATION_CLASS
|
||||
forAnnotationMember = owner.classKind == ClassKind.ANNOTATION_CLASS
|
||||
)
|
||||
val firResolvedTypeRef = signatureParts.type
|
||||
val defaultValueExpression = when (val defaultValue = ownerParameter.getDefaultValueFromAnnotation()) {
|
||||
@@ -345,7 +345,10 @@ class FirSignatureEnhancement(
|
||||
if (owner is FirJavaField) AnnotationQualifierApplicabilityType.FIELD
|
||||
else AnnotationQualifierApplicabilityType.METHOD_RETURN_TYPE,
|
||||
typeInSignature = TypeInSignature.Return
|
||||
).enhance(session, jsr305State, predefinedEnhancementInfo?.returnTypeInfo)
|
||||
).enhance(
|
||||
session, jsr305State, predefinedEnhancementInfo?.returnTypeInfo,
|
||||
forAnnotationMember = this.owner.classKind == ClassKind.ANNOTATION_CLASS
|
||||
)
|
||||
return signatureParts.type
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// FILE: JavaAnn.java
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// FILE: JavaAnn.java
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// FILE: JavaAnn.java
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// FILE: JavaAnn.java
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// FILE: JavaAnn.java
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// MODULE: lib
|
||||
// FILE: JavaAnn.java
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// FILE: MyAnn.java
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface MyAnn {
|
||||
/**
|
||||
* @return the classes to be run
|
||||
*/
|
||||
public Class<?>[] value();
|
||||
}
|
||||
// FILE: main.kt
|
||||
|
||||
fun foo(y: MyAnn?): List<Class<*>>? {
|
||||
return y?.value?.map { it.java }
|
||||
}
|
||||
Generated
+6
@@ -34609,6 +34609,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/reflection"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("classArrayInAnnotation.kt")
|
||||
public void testClassArrayInAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/reflection/classArrayInAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noReflectionInClassPath.kt")
|
||||
public void testNoReflectionInClassPath() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user