Minor, rename and invert meaning of ClassId.isTopLevelClass
Also use a simpler constructor and simplify ClassDeserializer.ClassKey
This commit is contained in:
+1
-2
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.name.ClassId;
|
import org.jetbrains.kotlin.name.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
||||||
|
|
||||||
@@ -47,7 +46,7 @@ public final class JvmAnnotationNames {
|
|||||||
public static class KotlinSyntheticClass {
|
public static class KotlinSyntheticClass {
|
||||||
public static final JvmClassName CLASS_NAME = JvmClassName.byInternalName("kotlin/jvm/internal/KotlinSyntheticClass");
|
public static final JvmClassName CLASS_NAME = JvmClassName.byInternalName("kotlin/jvm/internal/KotlinSyntheticClass");
|
||||||
public static final ClassId KIND_CLASS_ID =
|
public static final ClassId KIND_CLASS_ID =
|
||||||
new ClassId(new FqName("kotlin.jvm.internal"), new FqNameUnsafe("KotlinSyntheticClass.Kind"));
|
ClassId.topLevel(CLASS_NAME.getFqNameForClassNameWithoutDollars()).createNestedClassId(Name.identifier("Kind"));
|
||||||
public static final String KIND_INTERNAL_NAME = JvmClassName.byClassId(KIND_CLASS_ID).getInternalName();
|
public static final String KIND_INTERNAL_NAME = JvmClassName.byClassId(KIND_CLASS_ID).getInternalName();
|
||||||
|
|
||||||
public static final Name KIND_FIELD_NAME = Name.identifier("kind");
|
public static final Name KIND_FIELD_NAME = Name.identifier("kind");
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ public final class ClassId {
|
|||||||
return new ClassId(getPackageFqName(), relativeClassName.parent());
|
return new ClassId(getPackageFqName(), relativeClassName.parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTopLevelClass() {
|
public boolean isNestedClass() {
|
||||||
return relativeClassName.parent().isRoot();
|
return !relativeClassName.parent().isRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import org.jetbrains.kotlin.types.Approximation.DataFlowExtras
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import kotlin.platform.platformStatic
|
import kotlin.platform.platformStatic
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
public trait FlexibleTypeCapabilities {
|
public trait FlexibleTypeCapabilities {
|
||||||
fun <T: TypeCapability> getCapability(capabilityClass: Class<T>, jetType: JetType, flexibility: Flexibility): T?
|
fun <T: TypeCapability> getCapability(capabilityClass: Class<T>, jetType: JetType, flexibility: Flexibility): T?
|
||||||
@@ -40,7 +38,7 @@ public trait Flexibility : TypeCapability, SubtypingRepresentatives {
|
|||||||
// it creates a flexible type, e.g. (Foo..Foo?).
|
// it creates a flexible type, e.g. (Foo..Foo?).
|
||||||
// This is used in tests and Evaluate Expression to have flexible types in the code,
|
// This is used in tests and Evaluate Expression to have flexible types in the code,
|
||||||
// but normal users should not be referencing this classifier
|
// but normal users should not be referencing this classifier
|
||||||
public val FLEXIBLE_TYPE_CLASSIFIER: ClassId = ClassId(FqName("kotlin.internal.flexible"), FqNameUnsafe.topLevel(Name.identifier("ft")))
|
public val FLEXIBLE_TYPE_CLASSIFIER: ClassId = ClassId.topLevel(FqName("kotlin.internal.flexible.ft"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// lowerBound is a subtype of upperBound
|
// lowerBound is a subtype of upperBound
|
||||||
|
|||||||
+7
-8
@@ -31,21 +31,20 @@ public class ClassDeserializer(private val components: DeserializationComponents
|
|||||||
private fun createClass(key: ClassKey): DeserializedClassDescriptor? {
|
private fun createClass(key: ClassKey): DeserializedClassDescriptor? {
|
||||||
val classId = key.classId
|
val classId = key.classId
|
||||||
val classData = key.classData ?: components.classDataFinder.findClassData(classId) ?: return null
|
val classData = key.classData ?: components.classDataFinder.findClassData(classId) ?: return null
|
||||||
val outerContext = if (classId.isTopLevelClass()) {
|
val outerContext = if (classId.isNestedClass()) {
|
||||||
|
deserializeClass(classId.getOuterClassId())?.c ?: return null
|
||||||
|
}
|
||||||
|
else {
|
||||||
val fragments = components.packageFragmentProvider.getPackageFragments(classId.getPackageFqName())
|
val fragments = components.packageFragmentProvider.getPackageFragments(classId.getPackageFqName())
|
||||||
assert(fragments.size() == 1) { "There should be exactly one package: $fragments, class id is $classId" }
|
assert(fragments.size() == 1) { "There should be exactly one package: $fragments, class id is $classId" }
|
||||||
components.createContext(fragments.single(), classData.getNameResolver())
|
components.createContext(fragments.single(), classData.getNameResolver())
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
deserializeClass(classId.getOuterClassId())?.c ?: return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return DeserializedClassDescriptor(outerContext, classData.getClassProto(), classData.getNameResolver())
|
return DeserializedClassDescriptor(outerContext, classData.getClassProto(), classData.getNameResolver())
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class ClassKey(val classId: ClassId, val classData: ClassData?) {
|
private data class ClassKey(val classId: ClassId, classData: ClassData?) {
|
||||||
override fun equals(other: Any?): Boolean = other is ClassKey && classId == other.classId
|
// This property is not declared in the constructor because it shouldn't participate in equals/hashCode
|
||||||
override fun hashCode(): Int = classId.hashCode()
|
val classData: ClassData? = classData
|
||||||
override fun toString(): String = classId.toString()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -111,7 +111,7 @@ private class ClassClsStubBuilder(
|
|||||||
ProtoBuf.Class.Kind.OBJECT, ProtoBuf.Class.Kind.CLASS_OBJECT -> {
|
ProtoBuf.Class.Kind.OBJECT, ProtoBuf.Class.Kind.CLASS_OBJECT -> {
|
||||||
KotlinObjectStubImpl(
|
KotlinObjectStubImpl(
|
||||||
parentStub, shortName, fqName, superTypeRefs,
|
parentStub, shortName, fqName, superTypeRefs,
|
||||||
isTopLevel = classId.isTopLevelClass(),
|
isTopLevel = !classId.isNestedClass(),
|
||||||
isClassObject = isClassObject,
|
isClassObject = isClassObject,
|
||||||
isLocal = false,
|
isLocal = false,
|
||||||
isObjectLiteral = false
|
isObjectLiteral = false
|
||||||
@@ -127,7 +127,7 @@ private class ClassClsStubBuilder(
|
|||||||
isTrait = classKind == ProtoBuf.Class.Kind.TRAIT,
|
isTrait = classKind == ProtoBuf.Class.Kind.TRAIT,
|
||||||
isEnumEntry = classKind == ProtoBuf.Class.Kind.ENUM_ENTRY,
|
isEnumEntry = classKind == ProtoBuf.Class.Kind.ENUM_ENTRY,
|
||||||
isLocal = false,
|
isLocal = false,
|
||||||
isTopLevel = classId.isTopLevelClass()
|
isTopLevel = !classId.isNestedClass()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user