Make ClassId's relative class name FqName instead of FqNameUnsafe
It was FqNameUnsafe in times when there were classes without identifier names, specifically class objects with names like '<class-object-for-...>'
This commit is contained in:
+15
-16
@@ -16,25 +16,26 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.resolve.constants.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.*
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.isSpecialAnnotation
|
||||
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
|
||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.constants.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.resolve.jvm.PLATFORM_TYPES
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
|
||||
private object DEPRECATED_IN_JAVA : JavaLiteralAnnotationArgument {
|
||||
override val name: Name? = null
|
||||
@@ -49,13 +50,11 @@ fun LazyJavaResolverContext.resolveAnnotation(annotation: JavaAnnotation): LazyJ
|
||||
|
||||
class LazyJavaAnnotationDescriptor(
|
||||
private val c: LazyJavaResolverContext,
|
||||
val javaAnnotation : JavaAnnotation
|
||||
val javaAnnotation: JavaAnnotation
|
||||
) : AnnotationDescriptor {
|
||||
|
||||
private val fqName = c.storageManager.createNullableLazyValue {
|
||||
javaAnnotation.getClassId().asSingleFqName().let {
|
||||
if (it.isSafe()) it.toSafe() else null
|
||||
}
|
||||
javaAnnotation.getClassId()?.asSingleFqName()
|
||||
}
|
||||
|
||||
private val type = c.storageManager.createLazyValue {(): JetType ->
|
||||
|
||||
+2
-3
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import java.lang.reflect.Array
|
||||
import java.lang.reflect.Modifier
|
||||
@@ -43,7 +42,7 @@ public fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
|
||||
javaClass<Enum<*>>().isAssignableFrom(this)
|
||||
|
||||
public val Class<*>.fqName: FqName
|
||||
get() = classId.asSingleFqName().toSafe()
|
||||
get() = classId.asSingleFqName()
|
||||
|
||||
public val Class<*>.classId: ClassId
|
||||
get() = when {
|
||||
@@ -51,7 +50,7 @@ public val Class<*>.classId: ClassId
|
||||
isArray() -> throw IllegalArgumentException("Can't compute ClassId for array type: $this")
|
||||
getEnclosingMethod() != null, getEnclosingConstructor() != null, getSimpleName().isEmpty() -> {
|
||||
val fqName = FqName(getName())
|
||||
ClassId(fqName.parent(), FqNameUnsafe.topLevel(fqName.shortName()), /* local = */ true)
|
||||
ClassId(fqName.parent(), FqName.topLevel(fqName.shortName()), /* local = */ true)
|
||||
}
|
||||
else -> getDeclaringClass()?.classId?.createNestedClassId(Name.identifier(getSimpleName())) ?: ClassId.topLevel(FqName(getName()))
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ public final class ClassId {
|
||||
}
|
||||
|
||||
private final FqName packageFqName;
|
||||
private final FqNameUnsafe relativeClassName;
|
||||
private final FqName relativeClassName;
|
||||
private final boolean local;
|
||||
|
||||
public ClassId(@NotNull FqName packageFqName, @NotNull FqNameUnsafe relativeClassName, boolean local) {
|
||||
public ClassId(@NotNull FqName packageFqName, @NotNull FqName relativeClassName, boolean local) {
|
||||
this.packageFqName = packageFqName;
|
||||
assert !relativeClassName.isRoot() :
|
||||
"Class name must not be root: " + packageFqName + (local ? " (local)" : "");
|
||||
@@ -46,7 +46,7 @@ public final class ClassId {
|
||||
}
|
||||
|
||||
public ClassId(@NotNull FqName packageFqName, @NotNull Name topLevelName) {
|
||||
this(packageFqName, FqNameUnsafe.topLevel(topLevelName), false);
|
||||
this(packageFqName, FqName.topLevel(topLevelName), false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -55,7 +55,7 @@ public final class ClassId {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FqNameUnsafe getRelativeClassName() {
|
||||
public FqName getRelativeClassName() {
|
||||
return relativeClassName;
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@ public final class ClassId {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FqNameUnsafe asSingleFqName() {
|
||||
public FqName asSingleFqName() {
|
||||
if (packageFqName.isRoot()) return relativeClassName;
|
||||
return new FqNameUnsafe(packageFqName.asString() + "." + relativeClassName.asString());
|
||||
return new FqName(packageFqName.asString() + "." + relativeClassName.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,7 +120,7 @@ public final class ClassId {
|
||||
if (lastSlash == -1) {
|
||||
throw new IllegalArgumentException("Class id should contain slash: " + string);
|
||||
}
|
||||
FqNameUnsafe relativeClassName = new FqNameUnsafe(string.substring(lastSlash + 1));
|
||||
FqName relativeClassName = new FqName(string.substring(lastSlash + 1));
|
||||
FqName packageFqName = new FqName(string.substring(0, lastSlash).replace('/', '.'));
|
||||
return new ClassId(packageFqName, relativeClassName, false);
|
||||
}
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.serialization.deserialization;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
|
||||
@@ -85,7 +84,7 @@ public class NameResolver {
|
||||
index = proto.getParentQualifiedName();
|
||||
}
|
||||
|
||||
return new ClassId(FqName.fromSegments(packageFqName), FqNameUnsafe.fromSegments(relativeClassName), local);
|
||||
return new ClassId(FqName.fromSegments(packageFqName), FqName.fromSegments(relativeClassName), local);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+5
-8
@@ -16,19 +16,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
|
||||
public data class ProtoContainer(val classProto: ProtoBuf.Class?, val packageFqName: FqName?) {
|
||||
{
|
||||
assert(classProto != null || packageFqName != null)
|
||||
assert(classProto == null || packageFqName == null)
|
||||
init {
|
||||
assert((classProto != null) xor (packageFqName != null))
|
||||
}
|
||||
|
||||
fun getFqName(nameResolver: NameResolver): FqNameUnsafe {
|
||||
if (packageFqName != null) return packageFqName.toUnsafe()
|
||||
fun getFqName(nameResolver: NameResolver): FqName {
|
||||
if (packageFqName != null) return packageFqName
|
||||
|
||||
return nameResolver.getClassId(classProto!!.getFqName()).asSingleFqName()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user