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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user