SLC: add marker interface for collection inheritor
This commit is contained in:
committed by
Ilya Kirillov
parent
e15d8fc56f
commit
8d8d0d9922
+23
@@ -10,6 +10,8 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiJavaCodeReferenceElement
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.PsiReferenceList
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtSuperTypeList
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
|
||||
@@ -54,4 +56,25 @@ class KotlinSuperTypeListBuilder(kotlinOrigin: KtSuperTypeList?, manager: PsiMan
|
||||
|
||||
return element
|
||||
}
|
||||
|
||||
fun addMarkerInterfaceIfNeeded(classId: ClassId) {
|
||||
tryResolveMarkerInterfaceFQName(classId)?.let { addReference(it) }
|
||||
}
|
||||
|
||||
/***
|
||||
* @see org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
|
||||
*/
|
||||
private fun tryResolveMarkerInterfaceFQName(classId: ClassId): String? {
|
||||
for (mapping in JavaToKotlinClassMap.mutabilityMappings) {
|
||||
if (mapping.kotlinReadOnly == classId) {
|
||||
return "kotlin.jvm.internal.markers.KMappedMarker"
|
||||
} else if (mapping.kotlinMutable == classId) {
|
||||
return "kotlin.jvm.internal.markers.K" + classId.relativeClassName.asString()
|
||||
.replace("MutableEntry", "Entry") // kotlin.jvm.internal.markers.KMutableMap.Entry for some reason
|
||||
.replace(".", "$")
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
+17
-5
@@ -416,14 +416,26 @@ internal fun SymbolLightClassBase.createInheritanceList(forExtendsList: Boolean,
|
||||
return forExtendsList == !isJvmInterface
|
||||
}
|
||||
|
||||
//TODO Add support for kotlin.collections.
|
||||
superTypes.asSequence()
|
||||
.filter { it.needToAddTypeIntoList() }
|
||||
.mapNotNull { type ->
|
||||
if (type !is KtNonErrorClassType) return@mapNotNull null
|
||||
mapType(type, this@createInheritanceList, KtTypeMappingMode.SUPER_TYPE)
|
||||
.forEach { superType ->
|
||||
if (superType !is KtNonErrorClassType) return@forEach
|
||||
val mappedType =
|
||||
mapType(superType, this@createInheritanceList, KtTypeMappingMode.SUPER_TYPE_KOTLIN_COLLECTIONS_AS_IS)
|
||||
?: return@forEach
|
||||
listBuilder.addReference(mappedType)
|
||||
if (mappedType.canonicalText.startsWith("kotlin.collections.")) {
|
||||
val mappedToNoCollectionAsIs = mapType(superType, this@createInheritanceList, KtTypeMappingMode.SUPER_TYPE)
|
||||
if (mappedToNoCollectionAsIs != null &&
|
||||
mappedType.canonicalText != mappedToNoCollectionAsIs.canonicalText
|
||||
) {
|
||||
// Add java supertype
|
||||
listBuilder.addReference(mappedToNoCollectionAsIs)
|
||||
// Add marker interface
|
||||
listBuilder.addMarkerInterfaceIfNeeded(superType.classId)
|
||||
}
|
||||
}
|
||||
}
|
||||
.forEach { listBuilder.addReference(it) }
|
||||
|
||||
return listBuilder
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.JVM_STATIC_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.annotations.argumentValue
|
||||
import org.jetbrains.kotlin.resolve.constants.EnumValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
|
||||
@@ -143,8 +144,8 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
||||
//Add java supertype
|
||||
listBuilder.addReference(mappedToNoCollectionAsIs)
|
||||
//Add marker interface
|
||||
superType.tryResolveMarkerInterfaceFQName()?.let { marker ->
|
||||
listBuilder.addReference(marker)
|
||||
superType.constructor.declarationDescriptor.classId?.let { classId ->
|
||||
listBuilder.addMarkerInterfaceIfNeeded(classId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
|
||||
import org.jetbrains.kotlin.asJava.elements.*
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.codegen.DescriptorAsmUtil
|
||||
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
@@ -48,7 +47,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.JVM_STATIC_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.annotations.argumentValue
|
||||
import org.jetbrains.kotlin.resolve.constants.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
@@ -516,27 +514,6 @@ private fun ConstantValue<*>.asStringForPsiLiteral(parent: PsiElement): String =
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* @see org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
|
||||
*/
|
||||
fun KotlinType.tryResolveMarkerInterfaceFQName(): String? {
|
||||
|
||||
val classId = constructor.declarationDescriptor.classId
|
||||
|
||||
for (mapping in JavaToKotlinClassMap.mutabilityMappings) {
|
||||
if (mapping.kotlinReadOnly == classId) {
|
||||
return "kotlin.jvm.internal.markers.KMappedMarker"
|
||||
} else if (mapping.kotlinMutable == classId) {
|
||||
return "kotlin.jvm.internal.markers.K" + classId.relativeClassName.asString()
|
||||
.replace("MutableEntry", "Entry") // kotlin.jvm.internal.markers.KMutableMap.Entry for some reason
|
||||
.replace(".", "$")
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
internal inline fun Project.applyCompilerPlugins(body: (UltraLightClassModifierExtension) -> Unit) {
|
||||
UltraLightClassModifierExtension.getInstances(this).forEach { body(it) }
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
public final class TwoOverrides /* TwoOverrides*/ implements java.lang.Iterable<java.lang.String> {
|
||||
public final class TwoOverrides /* TwoOverrides*/ implements java.lang.Iterable<java.lang.String>, kotlin.collections.Iterable<java.lang.String>, kotlin.jvm.internal.markers.KMappedMarker {
|
||||
@java.lang.Override()
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
public java.lang.Void iterator();// iterator()
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
public final class TypeHierarchyMap /* p1.TypeHierarchyMap*/<TValue> implements java.util.Map<java.lang.Class<?>, TValue> {
|
||||
public final class TypeHierarchyMap /* p1.TypeHierarchyMap*/<TValue> implements java.util.Map<java.lang.Class<?>, TValue>, kotlin.collections.Map<java.lang.Class<?>, TValue>, kotlin.jvm.internal.markers.KMappedMarker {
|
||||
@java.lang.Override()
|
||||
public boolean containsKey(@org.jetbrains.annotations.NotNull() java.lang.Class<?>);// containsKey(java.lang.Class<?>)
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
public final class SmartSet /* SmartSet*/<T> extends kotlin.collections.AbstractSet<T> implements java.util.Set<T> {
|
||||
public final class SmartSet /* SmartSet*/<T> extends kotlin.collections.AbstractSet<T> implements java.util.Set<T>, kotlin.collections.MutableSet<T>, kotlin.jvm.internal.markers.KMutableSet {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final SmartSet.Companion Companion;
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
public final class MyList /* MyList*/ implements java.util.List<java.lang.String> {
|
||||
public final class MyList /* MyList*/ implements java.util.List<java.lang.String>, kotlin.collections.List<java.lang.String>, kotlin.jvm.internal.markers.KMappedMarker {
|
||||
@java.lang.Override()
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public java.lang.String get(int);// get(int)
|
||||
@@ -7,7 +7,7 @@ public final class MyList /* MyList*/ implements java.util.List<java.lang.String
|
||||
|
||||
}
|
||||
|
||||
public abstract interface ASet /* ASet*/<T> extends java.util.Collection<T> {
|
||||
public abstract interface ASet /* ASet*/<T> extends java.util.Collection<T>, kotlin.collections.MutableCollection<T>, kotlin.jvm.internal.markers.KMutableCollection {
|
||||
}
|
||||
|
||||
public abstract class MySet /* MySet*/<T> implements ASet<T> {
|
||||
|
||||
Reference in New Issue
Block a user