diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt index 6147bcce080..5d7aa812184 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.impl.* import org.jetbrains.kotlin.fir.java.declarations.FirJavaValueParameter +import org.jetbrains.kotlin.fir.java.enhancement.readOnlyToMutable import org.jetbrains.kotlin.fir.java.types.FirJavaTypeRef import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl @@ -144,7 +145,8 @@ internal fun JavaClassifierType.toConeKotlinTypeWithNullability( return when (val classifier = classifier) { is JavaClass -> { //val classId = classifier.classId!! - val classId = JavaToKotlinClassMap.mapJavaToKotlin(classifier.fqName!!) ?: classifier.classId!! + var classId = JavaToKotlinClassMap.mapJavaToKotlin(classifier.fqName!!) ?: classifier.classId!! + classId = classId.readOnlyToMutable() ?: classId val lookupTag = ConeClassLikeLookupTagImpl(classId) lookupTag.constructClassType( diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt index 93c3bd6c863..838eb4c0cbd 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt @@ -114,7 +114,7 @@ private val KOTLIN_COLLECTIONS = FqName("kotlin.collections") private val KOTLIN_COLLECTIONS_PREFIX_LENGTH = KOTLIN_COLLECTIONS.asString().length + 1 -private fun ClassId.readOnlyToMutable(): ClassId? { +internal fun ClassId.readOnlyToMutable(): ClassId? { val mutableFqName = JavaToKotlinClassMap.readOnlyToMutable(asSingleFqName().toUnsafe()) return mutableFqName?.let { ClassId(KOTLIN_COLLECTIONS, FqName(it.asString().substring(KOTLIN_COLLECTIONS_PREFIX_LENGTH)), false) diff --git a/compiler/fir/resolve/testData/enhancement/mapping/AbstractMap.fir.txt b/compiler/fir/resolve/testData/enhancement/mapping/AbstractMap.fir.txt new file mode 100644 index 00000000000..a049f0507fc --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/mapping/AbstractMap.fir.txt @@ -0,0 +1,2 @@ +public abstract class AbstractMap : R|kotlin/Any|, R|kotlin/collections/MutableMap| { +} diff --git a/compiler/fir/resolve/testData/enhancement/mapping/AbstractMap.java b/compiler/fir/resolve/testData/enhancement/mapping/AbstractMap.java new file mode 100644 index 00000000000..def17938b07 --- /dev/null +++ b/compiler/fir/resolve/testData/enhancement/mapping/AbstractMap.java @@ -0,0 +1,3 @@ +public abstract class AbstractMap implements java.util.Map { + +} \ No newline at end of file diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/OwnFirTypeEnhancementTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/OwnFirTypeEnhancementTestGenerated.java index f05be14a941..1d7fd28c927 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/OwnFirTypeEnhancementTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/java/OwnFirTypeEnhancementTestGenerated.java @@ -115,6 +115,24 @@ public class OwnFirTypeEnhancementTestGenerated extends AbstractOwnFirTypeEnhanc } } + @TestMetadata("compiler/fir/resolve/testData/enhancement/mapping") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Mapping extends AbstractOwnFirTypeEnhancementTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + @TestMetadata("AbstractMap.java") + public void testAbstractMap() throws Exception { + runTest("compiler/fir/resolve/testData/enhancement/mapping/AbstractMap.java"); + } + + public void testAllFilesPresentInMapping() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/enhancement/mapping"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true); + } + } + @TestMetadata("compiler/fir/resolve/testData/enhancement/signatureAnnotations") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/testData/loadJava/compiledJava/ClassWithTypePExtendsIterableP.fir.txt b/compiler/testData/loadJava/compiledJava/ClassWithTypePExtendsIterableP.fir.txt index f89481ec031..6816e45886b 100644 --- a/compiler/testData/loadJava/compiledJava/ClassWithTypePExtendsIterableP.fir.txt +++ b/compiler/testData/loadJava/compiledJava/ClassWithTypePExtendsIterableP.fir.txt @@ -1,2 +1,2 @@ -public abstract class ClassWithTypePExtendsIterableP

: R|kotlin/Any|, R|kotlin/collections/Iterable

| { +public abstract class ClassWithTypePExtendsIterableP

: R|kotlin/Any|, R|kotlin/collections/MutableIterable

| { } diff --git a/compiler/testData/loadJava/compiledJava/ClassWithTypePRefNext.fir.txt b/compiler/testData/loadJava/compiledJava/ClassWithTypePRefNext.fir.txt index 04f13bacdc8..ac8bd69effb 100644 --- a/compiler/testData/loadJava/compiledJava/ClassWithTypePRefNext.fir.txt +++ b/compiler/testData/loadJava/compiledJava/ClassWithTypePRefNext.fir.txt @@ -1,2 +1,2 @@ -public open class ClassWithTypePRefNext|, P> : R|kotlin/Any| { +public open class ClassWithTypePRefNext|, P> : R|kotlin/Any| { } diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/MethodWithTypeParameters.fir.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/MethodWithTypeParameters.fir.txt index febeb879eff..a3c14aed3b5 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/MethodWithTypeParameters.fir.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/MethodWithTypeParameters.fir.txt @@ -1,4 +1,4 @@ public open class MethodWithTypeParameters : R|kotlin/Any| { - public open operator fun |> foo(a: R|ft|!, b: R|ft, kotlin/collections/List?>|!, list: R|ft, kotlin/collections/List?>|!): R|kotlin/Unit| + public open operator fun |> foo(a: R|ft|!, b: R|ft, kotlin/collections/List?>|!, list: R|ft, kotlin/collections/List?>|!): R|kotlin/Unit| } diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.fir.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.fir.txt index ac6464ce5bc..b4ab2dcdeee 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.fir.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.fir.txt @@ -1,4 +1,4 @@ public open class WrongTypeParameterBoundStructure1 : R|kotlin/Any| { - public open operator fun |> foo(a: R|ft|!, b: R|ft, kotlin/collections/List?>|!): R|kotlin/Unit| + public open operator fun |> foo(a: R|ft|!, b: R|ft, kotlin/collections/List?>|!): R|kotlin/Unit| } diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfCollection.fir.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfCollection.fir.txt index bcfcf4f8368..f6602c058e3 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfCollection.fir.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfCollection.fir.txt @@ -1,4 +1,4 @@ -public abstract interface SubclassOfCollection : R|kotlin/collections/Collection| { - public abstract operator fun iterator(): R|kotlin/collections/Iterator>| +public abstract interface SubclassOfCollection : R|kotlin/collections/MutableCollection| { + public abstract operator fun iterator(): R|kotlin/collections/MutableIterator>| } diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt index 25ec1b86587..99af87fa9e7 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt @@ -1,4 +1,4 @@ -public abstract interface SubclassOfMapEntry : R|kotlin/collections/Map.Entry| { - public abstract operator fun setValue(value: R|ft|!): R|ft|! +public abstract interface SubclassOfMapEntry : R|kotlin/collections/MutableMap.MutableEntry| { + public abstract operator fun setValue(value: R|V|): R|V| } diff --git a/compiler/testData/loadJava/compiledJava/sam/GenericInterfaceParametersWithBounds.fir.txt b/compiler/testData/loadJava/compiledJava/sam/GenericInterfaceParametersWithBounds.fir.txt index 30463ac53cd..0a557b2ebfe 100644 --- a/compiler/testData/loadJava/compiledJava/sam/GenericInterfaceParametersWithBounds.fir.txt +++ b/compiler/testData/loadJava/compiledJava/sam/GenericInterfaceParametersWithBounds.fir.txt @@ -1,4 +1,4 @@ -public abstract interface GenericInterfaceParametersWithBounds|, R|kotlin/Cloneable|, B : R|kotlin/collections/List|> : R|kotlin/Any| { +public abstract interface GenericInterfaceParametersWithBounds|, R|kotlin/Cloneable|, B : R|kotlin/collections/MutableList|> : R|kotlin/Any| { public abstract operator fun method(a: R|kotlin/Array>|, b: R|ft|!): R|kotlin/Unit| } diff --git a/compiler/testData/loadJava/compiledJava/sam/GenericMethodParameters.fir.txt b/compiler/testData/loadJava/compiledJava/sam/GenericMethodParameters.fir.txt index a12537b7965..51e16490dbb 100644 --- a/compiler/testData/loadJava/compiledJava/sam/GenericMethodParameters.fir.txt +++ b/compiler/testData/loadJava/compiledJava/sam/GenericMethodParameters.fir.txt @@ -1,4 +1,4 @@ public abstract interface GenericMethodParameters : R|kotlin/Any| { - public abstract operator fun |> method(a: R|kotlin/Array>|, b: R|ft|!): R|kotlin/Unit| + public abstract operator fun |> method(a: R|kotlin/Array>|, b: R|ft|!): R|kotlin/Unit| } diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/TypeParameterOfMethod.fir.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/TypeParameterOfMethod.fir.txt index 37dfeb2a8e2..76f2d42d00a 100644 --- a/compiler/testData/loadJava/compiledJava/sam/adapters/TypeParameterOfMethod.fir.txt +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/TypeParameterOfMethod.fir.txt @@ -3,6 +3,6 @@ public open class TypeParameterOfMethod : R|kotlin/Any| { public open static operator fun max2(comparator: R|ft>, java/util/Comparator>?>|!, value1: R|ft|!, value2: R|ft|!): R|ft|! - public open static operator fun |> method(a: R|ft>, java/util/Comparator>?>|!, b: R|ft|!): R|kotlin/Unit| + public open static operator fun |> method(a: R|ft>, java/util/Comparator>?>|!, b: R|ft|!): R|kotlin/Unit| }