Fix FIR Java enhancement of java.util.Map & similar supertypes
This commit is contained in:
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall
|
|||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.*
|
import org.jetbrains.kotlin.fir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaValueParameter
|
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.java.types.FirJavaTypeRef
|
||||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
|
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
|
||||||
@@ -144,7 +145,8 @@ internal fun JavaClassifierType.toConeKotlinTypeWithNullability(
|
|||||||
return when (val classifier = classifier) {
|
return when (val classifier = classifier) {
|
||||||
is JavaClass -> {
|
is JavaClass -> {
|
||||||
//val classId = classifier.classId!!
|
//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)
|
val lookupTag = ConeClassLikeLookupTagImpl(classId)
|
||||||
lookupTag.constructClassType(
|
lookupTag.constructClassType(
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ private val KOTLIN_COLLECTIONS = FqName("kotlin.collections")
|
|||||||
|
|
||||||
private val KOTLIN_COLLECTIONS_PREFIX_LENGTH = KOTLIN_COLLECTIONS.asString().length + 1
|
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())
|
val mutableFqName = JavaToKotlinClassMap.readOnlyToMutable(asSingleFqName().toUnsafe())
|
||||||
return mutableFqName?.let {
|
return mutableFqName?.let {
|
||||||
ClassId(KOTLIN_COLLECTIONS, FqName(it.asString().substring(KOTLIN_COLLECTIONS_PREFIX_LENGTH)), false)
|
ClassId(KOTLIN_COLLECTIONS, FqName(it.asString().substring(KOTLIN_COLLECTIONS_PREFIX_LENGTH)), false)
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
public abstract class AbstractMap : R|kotlin/Any|, R|kotlin/collections/MutableMap<kotlin/String, kotlin/String>| {
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
public abstract class AbstractMap implements java.util.Map<String, String> {
|
||||||
|
|
||||||
|
}
|
||||||
Generated
+18
@@ -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")
|
@TestMetadata("compiler/fir/resolve/testData/enhancement/signatureAnnotations")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
public abstract class ClassWithTypePExtendsIterableP<P> : R|kotlin/Any|, R|kotlin/collections/Iterable<P>| {
|
public abstract class ClassWithTypePExtendsIterableP<P> : R|kotlin/Any|, R|kotlin/collections/MutableIterable<P>| {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
public open class ClassWithTypePRefNext<R : R|kotlin/collections/Iterable<P>|, P> : R|kotlin/Any| {
|
public open class ClassWithTypePRefNext<R : R|kotlin/collections/MutableIterable<P>|, P> : R|kotlin/Any| {
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
public open class MethodWithTypeParameters : R|kotlin/Any| {
|
public open class MethodWithTypeParameters : R|kotlin/Any| {
|
||||||
public open operator fun <A, B : R|java/lang/Runnable|, R|kotlin/collections/List<kotlin/Cloneable>|> foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!, list: R|ft<kotlin/collections/MutableList<in kotlin/String>, kotlin/collections/List<in kotlin/String>?>|!): R|kotlin/Unit|
|
public open operator fun <A, B : R|java/lang/Runnable|, R|kotlin/collections/MutableList<kotlin/Cloneable>|> foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!, list: R|ft<kotlin/collections/MutableList<in kotlin/String>, kotlin/collections/List<in kotlin/String>?>|!): R|kotlin/Unit|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
public open class WrongTypeParameterBoundStructure1 : R|kotlin/Any| {
|
public open class WrongTypeParameterBoundStructure1 : R|kotlin/Any| {
|
||||||
public open operator fun <A, B : R|java/lang/Runnable|, R|kotlin/collections/List<kotlin/Cloneable>|> foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!): R|kotlin/Unit|
|
public open operator fun <A, B : R|java/lang/Runnable|, R|kotlin/collections/MutableList<kotlin/Cloneable>|> foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!): R|kotlin/Unit|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
public abstract interface SubclassOfCollection<E> : R|kotlin/collections/Collection<E>| {
|
public abstract interface SubclassOfCollection<E> : R|kotlin/collections/MutableCollection<E>| {
|
||||||
public abstract operator fun iterator(): R|kotlin/collections/Iterator<ft<E, E?>>|
|
public abstract operator fun iterator(): R|kotlin/collections/MutableIterator<ft<E, E?>>|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
public abstract interface SubclassOfMapEntry<K, V> : R|kotlin/collections/Map.Entry<K, V>| {
|
public abstract interface SubclassOfMapEntry<K, V> : R|kotlin/collections/MutableMap.MutableEntry<K, V>| {
|
||||||
public abstract operator fun setValue(value: R|ft<V, V?>|!): R|ft<V, V?>|!
|
public abstract operator fun setValue(value: R|V|): R|V|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
public abstract interface GenericInterfaceParametersWithBounds<A : R|kotlin/Comparable<A>|, R|kotlin/Cloneable|, B : R|kotlin/collections/List<A>|> : R|kotlin/Any| {
|
public abstract interface GenericInterfaceParametersWithBounds<A : R|kotlin/Comparable<A>|, R|kotlin/Cloneable|, B : R|kotlin/collections/MutableList<A>|> : R|kotlin/Any| {
|
||||||
public abstract operator fun method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit|
|
public abstract operator fun method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
public abstract interface GenericMethodParameters : R|kotlin/Any| {
|
public abstract interface GenericMethodParameters : R|kotlin/Any| {
|
||||||
public abstract operator fun <A : R|kotlin/CharSequence|, B : R|kotlin/collections/List<A>|> method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit|
|
public abstract operator fun <A : R|kotlin/CharSequence|, B : R|kotlin/collections/MutableList<A>|> method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@ public open class TypeParameterOfMethod : R|kotlin/Any| {
|
|||||||
|
|
||||||
public open static operator fun <T : R|kotlin/CharSequence|> max2(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|!
|
public open static operator fun <T : R|kotlin/CharSequence|> max2(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|!
|
||||||
|
|
||||||
public open static operator fun <A : R|kotlin/CharSequence|, B : R|kotlin/collections/List<A>|> method(a: R|ft<java/util/Comparator<ft<A, A?>>, java/util/Comparator<ft<A, A?>>?>|!, b: R|ft<B, B?>|!): R|kotlin/Unit|
|
public open static operator fun <A : R|kotlin/CharSequence|, B : R|kotlin/collections/MutableList<A>|> method(a: R|ft<java/util/Comparator<ft<A, A?>>, java/util/Comparator<ft<A, A?>>?>|!, b: R|ft<B, B?>|!): R|kotlin/Unit|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user