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
|
||||
private static ContainingClassesInfo forClassMemberOrNull(@NotNull ClassId classId) {
|
||||
private static ContainingClassesInfo forClassMember(@NotNull ClassId classId) {
|
||||
return new ContainingClassesInfo(classId, classId);
|
||||
}
|
||||
}
|
||||
@@ -258,7 +258,7 @@ public class KotlinTypeMapper {
|
||||
}
|
||||
else {
|
||||
ClassId classId = getContainerClassIdForClassDescriptor((ClassDescriptor) parentDeclaration);
|
||||
containingClassesInfo = ContainingClassesInfo.forClassMemberOrNull(classId);
|
||||
containingClassesInfo = ContainingClassesInfo.forClassMember(classId);
|
||||
}
|
||||
if (containingClassesInfo == null) {
|
||||
throw new IllegalStateException("Couldn't find container for " + deserializedDescriptor.getName());
|
||||
@@ -269,11 +269,14 @@ public class KotlinTypeMapper {
|
||||
@NotNull
|
||||
private static ClassId getContainerClassIdForClassDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
||||
ClassId classId = DescriptorUtilsKt.getClassId(classDescriptor);
|
||||
assert classId != null : "Deserialized class should have a ClassId: " + classDescriptor;
|
||||
|
||||
if (isInterface(classDescriptor)) {
|
||||
FqName relativeClassName = classId.getRelativeClassName();
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class MissingDependencyClassChecker : CallChecker {
|
||||
|
||||
fun consider(classDescriptor: ClassDescriptor) {
|
||||
if (classDescriptor is NotFoundClasses.MockClassDescriptor) {
|
||||
result.add(classDescriptor.classId)
|
||||
result.add(classDescriptor.classId!!)
|
||||
return
|
||||
}
|
||||
(classDescriptor.containingDeclaration as? ClassDescriptor)?.let(::consider)
|
||||
|
||||
+3
-3
@@ -73,11 +73,11 @@ object FileClassAnnotationsChecker: AdditionalAnnotationChecker {
|
||||
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) {
|
||||
val classFqName = classDescriptor.classId.asSingleFqName()
|
||||
if (ALWAYS_APPLICABLE.contains(classFqName)) continue
|
||||
val classFqName = classDescriptor.classId!!.asSingleFqName()
|
||||
if (classFqName in ALWAYS_APPLICABLE) continue
|
||||
if (classDescriptor.getAnnotationRetention() != KotlinRetention.SOURCE) {
|
||||
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")
|
||||
}
|
||||
|
||||
val ClassDescriptor.classId: ClassId
|
||||
get() {
|
||||
val owner = containingDeclaration
|
||||
if (owner is PackageFragmentDescriptor) {
|
||||
return ClassId(owner.fqName, name)
|
||||
val ClassDescriptor.classId: ClassId?
|
||||
get() = containingDeclaration.let { owner ->
|
||||
when (owner) {
|
||||
is PackageFragmentDescriptor -> 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
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ class DeserializedClassDescriptor(
|
||||
if (unresolved.isNotEmpty()) {
|
||||
c.components.errorReporter.reportIncompleteHierarchy(
|
||||
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
|
||||
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
|
||||
|
||||
@@ -51,7 +51,7 @@ internal fun ClassDescriptor.toJavaClass(): Class<*>? {
|
||||
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
|
||||
// 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 className = classId.relativeClassName.asString()
|
||||
// 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> {
|
||||
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> {
|
||||
override fun indexDescriptor(descriptor: DeclarationDescriptor): Collection<ClassNameAndSignature> {
|
||||
|
||||
+1
-1
@@ -187,7 +187,7 @@ object KotlinJavascriptSerializationUtil {
|
||||
}
|
||||
|
||||
private fun getFileName(classDescriptor: ClassDescriptor): String {
|
||||
return KotlinJavascriptSerializedResourcePaths.getClassMetadataPath(classDescriptor.classId)
|
||||
return KotlinJavascriptSerializedResourcePaths.getClassMetadataPath(classDescriptor.classId!!)
|
||||
}
|
||||
|
||||
fun toContentMap(module: ModuleDescriptor): Map<String, ByteArray> {
|
||||
|
||||
Reference in New Issue
Block a user