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);
|
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
|
@Test
|
||||||
@TestMetadata("noReflectionInClassPath.kt")
|
@TestMetadata("noReflectionInClassPath.kt")
|
||||||
public void testNoReflectionInClassPath() throws Exception {
|
public void testNoReflectionInClassPath() throws Exception {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ internal fun JavaClassifierType.toFirResolvedTypeRef(
|
|||||||
internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
javaTypeParameterStack: JavaTypeParameterStack,
|
javaTypeParameterStack: JavaTypeParameterStack,
|
||||||
forAnnotationValueParameter: Boolean = false,
|
forAnnotationMember: Boolean = false,
|
||||||
isForSupertypes: Boolean = false,
|
isForSupertypes: Boolean = false,
|
||||||
attributes: ConeAttributes = ConeAttributes.Empty
|
attributes: ConeAttributes = ConeAttributes.Empty
|
||||||
): ConeKotlinType {
|
): ConeKotlinType {
|
||||||
@@ -134,7 +134,7 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
|||||||
toConeKotlinTypeWithoutEnhancement(
|
toConeKotlinTypeWithoutEnhancement(
|
||||||
session,
|
session,
|
||||||
javaTypeParameterStack,
|
javaTypeParameterStack,
|
||||||
forAnnotationValueParameter = forAnnotationValueParameter,
|
forAnnotationMember = forAnnotationMember,
|
||||||
attributes = attributes
|
attributes = attributes
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
|||||||
toConeKotlinTypeWithoutEnhancement(
|
toConeKotlinTypeWithoutEnhancement(
|
||||||
session,
|
session,
|
||||||
javaTypeParameterStack,
|
javaTypeParameterStack,
|
||||||
forAnnotationValueParameter,
|
forAnnotationMember,
|
||||||
isForSupertypes,
|
isForSupertypes,
|
||||||
attributes = attributes
|
attributes = attributes
|
||||||
)
|
)
|
||||||
@@ -225,7 +225,7 @@ private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
|||||||
javaTypeParameterStack: JavaTypeParameterStack,
|
javaTypeParameterStack: JavaTypeParameterStack,
|
||||||
forTypeParameterBounds: Boolean = false,
|
forTypeParameterBounds: Boolean = false,
|
||||||
isForSupertypes: Boolean = false,
|
isForSupertypes: Boolean = false,
|
||||||
forAnnotationValueParameter: Boolean = false,
|
forAnnotationMember: Boolean = false,
|
||||||
attributes: ConeAttributes = ConeAttributes.Empty
|
attributes: ConeAttributes = ConeAttributes.Empty
|
||||||
): ConeKotlinType {
|
): ConeKotlinType {
|
||||||
val lowerBound = toConeKotlinTypeForFlexibleBound(
|
val lowerBound = toConeKotlinTypeForFlexibleBound(
|
||||||
@@ -234,10 +234,10 @@ private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
|||||||
isLowerBound = true,
|
isLowerBound = true,
|
||||||
forTypeParameterBounds,
|
forTypeParameterBounds,
|
||||||
isForSupertypes,
|
isForSupertypes,
|
||||||
forAnnotationValueParameter = forAnnotationValueParameter,
|
forAnnotationMember = forAnnotationMember,
|
||||||
attributes = attributes
|
attributes = attributes
|
||||||
)
|
)
|
||||||
if (forAnnotationValueParameter) {
|
if (forAnnotationMember) {
|
||||||
return lowerBound
|
return lowerBound
|
||||||
}
|
}
|
||||||
val upperBound =
|
val upperBound =
|
||||||
@@ -248,7 +248,7 @@ private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
|||||||
forTypeParameterBounds,
|
forTypeParameterBounds,
|
||||||
isForSupertypes,
|
isForSupertypes,
|
||||||
lowerBound,
|
lowerBound,
|
||||||
forAnnotationValueParameter = forAnnotationValueParameter,
|
forAnnotationMember = forAnnotationMember,
|
||||||
attributes = attributes
|
attributes = attributes
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -362,13 +362,13 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
|||||||
forTypeParameterBounds: Boolean,
|
forTypeParameterBounds: Boolean,
|
||||||
isForSupertypes: Boolean,
|
isForSupertypes: Boolean,
|
||||||
lowerBound: ConeLookupTagBasedType? = null,
|
lowerBound: ConeLookupTagBasedType? = null,
|
||||||
forAnnotationValueParameter: Boolean = false,
|
forAnnotationMember: Boolean = false,
|
||||||
attributes: ConeAttributes = ConeAttributes.Empty
|
attributes: ConeAttributes = ConeAttributes.Empty
|
||||||
): ConeLookupTagBasedType {
|
): ConeLookupTagBasedType {
|
||||||
return when (val classifier = classifier) {
|
return when (val classifier = classifier) {
|
||||||
is JavaClass -> {
|
is JavaClass -> {
|
||||||
//val classId = classifier.classId!!
|
//val classId = classifier.classId!!
|
||||||
var classId = if (forAnnotationValueParameter) {
|
var classId = if (forAnnotationMember) {
|
||||||
JavaToKotlinClassMap.mapJavaToKotlinIncludingClassMapping(classifier.fqName!!)
|
JavaToKotlinClassMap.mapJavaToKotlinIncludingClassMapping(classifier.fqName!!)
|
||||||
} else {
|
} else {
|
||||||
JavaToKotlinClassMap.mapJavaToKotlin(classifier.fqName!!)
|
JavaToKotlinClassMap.mapJavaToKotlin(classifier.fqName!!)
|
||||||
|
|||||||
+2
-2
@@ -51,7 +51,7 @@ internal class EnhancementSignatureParts(
|
|||||||
session: FirSession,
|
session: FirSession,
|
||||||
javaTypeEnhancementState: JavaTypeEnhancementState,
|
javaTypeEnhancementState: JavaTypeEnhancementState,
|
||||||
predefined: TypeEnhancementInfo? = null,
|
predefined: TypeEnhancementInfo? = null,
|
||||||
forAnnotationValueParameter: Boolean = false
|
forAnnotationMember: Boolean = false
|
||||||
): PartEnhancementResult {
|
): PartEnhancementResult {
|
||||||
val qualifiers = computeIndexedQualifiersForOverride(session, javaTypeEnhancementState)
|
val qualifiers = computeIndexedQualifiersForOverride(session, javaTypeEnhancementState)
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ internal class EnhancementSignatureParts(
|
|||||||
val typeWithoutEnhancement = current.type.toConeKotlinTypeWithoutEnhancement(
|
val typeWithoutEnhancement = current.type.toConeKotlinTypeWithoutEnhancement(
|
||||||
session,
|
session,
|
||||||
javaTypeParameterStack,
|
javaTypeParameterStack,
|
||||||
forAnnotationValueParameter,
|
forAnnotationMember,
|
||||||
attributes = attributesCache.getValue(current)
|
attributes = attributesCache.getValue(current)
|
||||||
)
|
)
|
||||||
val containsFunctionN = typeWithoutEnhancement.contains {
|
val containsFunctionN = typeWithoutEnhancement.contains {
|
||||||
|
|||||||
+5
-2
@@ -319,7 +319,7 @@ class FirSignatureEnhancement(
|
|||||||
session,
|
session,
|
||||||
jsr305State,
|
jsr305State,
|
||||||
predefinedEnhancementInfo?.parametersInfo?.getOrNull(index),
|
predefinedEnhancementInfo?.parametersInfo?.getOrNull(index),
|
||||||
forAnnotationValueParameter = owner.classKind == ClassKind.ANNOTATION_CLASS
|
forAnnotationMember = owner.classKind == ClassKind.ANNOTATION_CLASS
|
||||||
)
|
)
|
||||||
val firResolvedTypeRef = signatureParts.type
|
val firResolvedTypeRef = signatureParts.type
|
||||||
val defaultValueExpression = when (val defaultValue = ownerParameter.getDefaultValueFromAnnotation()) {
|
val defaultValueExpression = when (val defaultValue = ownerParameter.getDefaultValueFromAnnotation()) {
|
||||||
@@ -345,7 +345,10 @@ class FirSignatureEnhancement(
|
|||||||
if (owner is FirJavaField) AnnotationQualifierApplicabilityType.FIELD
|
if (owner is FirJavaField) AnnotationQualifierApplicabilityType.FIELD
|
||||||
else AnnotationQualifierApplicabilityType.METHOD_RETURN_TYPE,
|
else AnnotationQualifierApplicabilityType.METHOD_RETURN_TYPE,
|
||||||
typeInSignature = TypeInSignature.Return
|
typeInSignature = TypeInSignature.Return
|
||||||
).enhance(session, jsr305State, predefinedEnhancementInfo?.returnTypeInfo)
|
).enhance(
|
||||||
|
session, jsr305State, predefinedEnhancementInfo?.returnTypeInfo,
|
||||||
|
forAnnotationMember = this.owner.classKind == ClassKind.ANNOTATION_CLASS
|
||||||
|
)
|
||||||
return signatureParts.type
|
return signatureParts.type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// MODULE: lib
|
// MODULE: lib
|
||||||
// FILE: JavaAnn.java
|
// FILE: JavaAnn.java
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// MODULE: lib
|
// MODULE: lib
|
||||||
// FILE: JavaAnn.java
|
// FILE: JavaAnn.java
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// MODULE: lib
|
// MODULE: lib
|
||||||
// FILE: JavaAnn.java
|
// FILE: JavaAnn.java
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// MODULE: lib
|
// MODULE: lib
|
||||||
// FILE: JavaAnn.java
|
// FILE: JavaAnn.java
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// MODULE: lib
|
// MODULE: lib
|
||||||
// FILE: JavaAnn.java
|
// FILE: JavaAnn.java
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
// DONT_TARGET_EXACT_BACKEND: JS JS_IR JS_IR_ES6 WASM NATIVE
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// MODULE: lib
|
// MODULE: lib
|
||||||
// FILE: JavaAnn.java
|
// 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);
|
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
|
@Test
|
||||||
@TestMetadata("noReflectionInClassPath.kt")
|
@TestMetadata("noReflectionInClassPath.kt")
|
||||||
public void testNoReflectionInClassPath() throws Exception {
|
public void testNoReflectionInClassPath() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user