Make ClassDescriptor#classId nullable
Local classes or anonymous objects do not have a class id. Use "!!" almost everywhere to make assertion explicit
This commit is contained in:
@@ -242,7 +242,7 @@ public class KotlinTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static ContainingClassesInfo forClassMemberOrNull(@NotNull ClassId classId) {
|
private static ContainingClassesInfo forClassMember(@NotNull ClassId classId) {
|
||||||
return new ContainingClassesInfo(classId, classId);
|
return new ContainingClassesInfo(classId, classId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,7 +258,7 @@ public class KotlinTypeMapper {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClassId classId = getContainerClassIdForClassDescriptor((ClassDescriptor) parentDeclaration);
|
ClassId classId = getContainerClassIdForClassDescriptor((ClassDescriptor) parentDeclaration);
|
||||||
containingClassesInfo = ContainingClassesInfo.forClassMemberOrNull(classId);
|
containingClassesInfo = ContainingClassesInfo.forClassMember(classId);
|
||||||
}
|
}
|
||||||
if (containingClassesInfo == null) {
|
if (containingClassesInfo == null) {
|
||||||
throw new IllegalStateException("Couldn't find container for " + deserializedDescriptor.getName());
|
throw new IllegalStateException("Couldn't find container for " + deserializedDescriptor.getName());
|
||||||
@@ -269,11 +269,14 @@ public class KotlinTypeMapper {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static ClassId getContainerClassIdForClassDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
private static ClassId getContainerClassIdForClassDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
||||||
ClassId classId = DescriptorUtilsKt.getClassId(classDescriptor);
|
ClassId classId = DescriptorUtilsKt.getClassId(classDescriptor);
|
||||||
|
assert classId != null : "Deserialized class should have a ClassId: " + classDescriptor;
|
||||||
|
|
||||||
if (isInterface(classDescriptor)) {
|
if (isInterface(classDescriptor)) {
|
||||||
FqName relativeClassName = classId.getRelativeClassName();
|
FqName relativeClassName = classId.getRelativeClassName();
|
||||||
//TODO test nested trait fun inlining
|
//TODO test nested trait fun inlining
|
||||||
classId = new ClassId(classId.getPackageFqName(), Name.identifier(relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
return new ClassId(classId.getPackageFqName(), Name.identifier(relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
||||||
}
|
}
|
||||||
|
|
||||||
return classId;
|
return classId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ class MissingDependencyClassChecker : CallChecker {
|
|||||||
|
|
||||||
fun consider(classDescriptor: ClassDescriptor) {
|
fun consider(classDescriptor: ClassDescriptor) {
|
||||||
if (classDescriptor is NotFoundClasses.MockClassDescriptor) {
|
if (classDescriptor is NotFoundClasses.MockClassDescriptor) {
|
||||||
result.add(classDescriptor.classId)
|
result.add(classDescriptor.classId!!)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
(classDescriptor.containingDeclaration as? ClassDescriptor)?.let(::consider)
|
(classDescriptor.containingDeclaration as? ClassDescriptor)?.let(::consider)
|
||||||
|
|||||||
+3
-3
@@ -73,11 +73,11 @@ object FileClassAnnotationsChecker: AdditionalAnnotationChecker {
|
|||||||
fileAnnotationsToCheck.add(Pair(entry, classDescriptor))
|
fileAnnotationsToCheck.add(Pair(entry, classDescriptor))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileAnnotationsToCheck.any { it.second.classId.asSingleFqName() == JvmFileClassUtil.JVM_MULTIFILE_CLASS }) return
|
if (!fileAnnotationsToCheck.any { it.second.classId?.asSingleFqName() == JvmFileClassUtil.JVM_MULTIFILE_CLASS }) return
|
||||||
|
|
||||||
for ((entry, classDescriptor) in fileAnnotationsToCheck) {
|
for ((entry, classDescriptor) in fileAnnotationsToCheck) {
|
||||||
val classFqName = classDescriptor.classId.asSingleFqName()
|
val classFqName = classDescriptor.classId!!.asSingleFqName()
|
||||||
if (ALWAYS_APPLICABLE.contains(classFqName)) continue
|
if (classFqName in ALWAYS_APPLICABLE) continue
|
||||||
if (classDescriptor.getAnnotationRetention() != KotlinRetention.SOURCE) {
|
if (classDescriptor.getAnnotationRetention() != KotlinRetention.SOURCE) {
|
||||||
trace.report(ErrorsJvm.ANNOTATION_IS_NOT_APPLICABLE_TO_MULTIFILE_CLASSES.on(entry, classFqName))
|
trace.report(ErrorsJvm.ANNOTATION_IS_NOT_APPLICABLE_TO_MULTIFILE_CLASSES.on(entry, classFqName))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,16 +74,13 @@ val ClassifierDescriptorWithTypeParameters.denotedClassDescriptor: ClassDescript
|
|||||||
else -> throw UnsupportedOperationException("Unexpected descriptor kind: $this")
|
else -> throw UnsupportedOperationException("Unexpected descriptor kind: $this")
|
||||||
}
|
}
|
||||||
|
|
||||||
val ClassDescriptor.classId: ClassId
|
val ClassDescriptor.classId: ClassId?
|
||||||
get() {
|
get() = containingDeclaration.let { owner ->
|
||||||
val owner = containingDeclaration
|
when (owner) {
|
||||||
if (owner is PackageFragmentDescriptor) {
|
is PackageFragmentDescriptor -> ClassId(owner.fqName, name)
|
||||||
return ClassId(owner.fqName, name)
|
is ClassDescriptor -> owner.classId?.createNestedClassId(name)
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
else if (owner is ClassDescriptor) {
|
|
||||||
return owner.classId.createNestedClassId(name)
|
|
||||||
}
|
|
||||||
throw IllegalStateException("Illegal container: $owner")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val ClassifierDescriptorWithTypeParameters.hasCompanionObject: Boolean
|
val ClassifierDescriptorWithTypeParameters.hasCompanionObject: Boolean
|
||||||
|
|||||||
+1
-1
@@ -161,7 +161,7 @@ class DeserializedClassDescriptor(
|
|||||||
if (unresolved.isNotEmpty()) {
|
if (unresolved.isNotEmpty()) {
|
||||||
c.components.errorReporter.reportIncompleteHierarchy(
|
c.components.errorReporter.reportIncompleteHierarchy(
|
||||||
this@DeserializedClassDescriptor,
|
this@DeserializedClassDescriptor,
|
||||||
unresolved.map { it.classId.asSingleFqName().asString() }
|
unresolved.map { it.classId?.asSingleFqName()?.asString() ?: it.name.asString() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ internal object RuntimeTypeMapper {
|
|||||||
|
|
||||||
val classId = klass.classId
|
val classId = klass.classId
|
||||||
if (!classId.isLocal) {
|
if (!classId.isLocal) {
|
||||||
JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(classId.asSingleFqName(), DefaultBuiltIns.Instance)?.let { return it.classId }
|
JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(classId.asSingleFqName(), DefaultBuiltIns.Instance)?.let { return it.classId!! }
|
||||||
}
|
}
|
||||||
|
|
||||||
return classId
|
return classId
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ internal fun ClassDescriptor.toJavaClass(): Class<*>? {
|
|||||||
else -> {
|
else -> {
|
||||||
// If this is neither a Kotlin class nor a Java class, it is either a built-in or some fake class descriptor like the one
|
// If this is neither a Kotlin class nor a Java class, it is either a built-in or some fake class descriptor like the one
|
||||||
// that's created for java.io.Serializable in JvmBuiltInsSettings
|
// that's created for java.io.Serializable in JvmBuiltInsSettings
|
||||||
val classId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(DescriptorUtils.getFqName(this)) ?: classId
|
val classId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(DescriptorUtils.getFqName(this)) ?: classId!!
|
||||||
val packageName = classId.packageFqName.asString()
|
val packageName = classId.packageFqName.asString()
|
||||||
val className = classId.relativeClassName.asString()
|
val className = classId.relativeClassName.asString()
|
||||||
// All pseudo-classes like kotlin.String.Companion must be accessible from the current class loader
|
// All pseudo-classes like kotlin.String.Companion must be accessible from the current class loader
|
||||||
|
|||||||
+2
-2
@@ -81,10 +81,10 @@ private fun PsiMember.relativeClassName(): List<Name> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun ClassDescriptor.relativeClassName(): List<Name> {
|
private fun ClassDescriptor.relativeClassName(): List<Name> {
|
||||||
return classId.relativeClassName.pathSegments().drop(1).orEmpty()
|
return classId!!.relativeClassName.pathSegments().drop(1).orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ClassDescriptor.desc(): String = "L" + JvmClassName.byClassId(classId).internalName + ";"
|
private fun ClassDescriptor.desc(): String = "L" + JvmClassName.byClassId(classId!!).internalName + ";"
|
||||||
|
|
||||||
private object ByJvmSignatureIndexer : DecompiledTextIndexer<ClassNameAndSignature> {
|
private object ByJvmSignatureIndexer : DecompiledTextIndexer<ClassNameAndSignature> {
|
||||||
override fun indexDescriptor(descriptor: DeclarationDescriptor): Collection<ClassNameAndSignature> {
|
override fun indexDescriptor(descriptor: DeclarationDescriptor): Collection<ClassNameAndSignature> {
|
||||||
|
|||||||
+1
-1
@@ -187,7 +187,7 @@ object KotlinJavascriptSerializationUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getFileName(classDescriptor: ClassDescriptor): String {
|
private fun getFileName(classDescriptor: ClassDescriptor): String {
|
||||||
return KotlinJavascriptSerializedResourcePaths.getClassMetadataPath(classDescriptor.classId)
|
return KotlinJavascriptSerializedResourcePaths.getClassMetadataPath(classDescriptor.classId!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toContentMap(module: ModuleDescriptor): Map<String, ByteArray> {
|
fun toContentMap(module: ModuleDescriptor): Map<String, ByteArray> {
|
||||||
|
|||||||
Reference in New Issue
Block a user