Use ClassId instead of JvmClassName in KotlinJvmBinaryClass
ClassId contains exact information about origin of the class (e.g. if '$' in the class name denotes nested classes separator or just a character in the name)
This commit is contained in:
@@ -37,15 +37,15 @@ public fun buildDecompiledText(
|
||||
): DecompiledText {
|
||||
val kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(classFile)
|
||||
assert(kotlinClass != null) { "Decompiled data factory shouldn't be called on an unsupported file: " + classFile }
|
||||
val classFqName = kotlinClass!!.getClassName().getFqNameForClassNameWithoutDollars()
|
||||
val classId = kotlinClass!!.getClassId()
|
||||
val kind = kotlinClass.getClassHeader().kind
|
||||
val packageFqName = classFqName.parent()
|
||||
val packageFqName = classId.getPackageFqName()
|
||||
|
||||
return if (kind == KotlinClassHeader.Kind.PACKAGE_FACADE) {
|
||||
buildDecompiledText(packageFqName, ArrayList(resolver.resolveDeclarationsInPackage(packageFqName)))
|
||||
}
|
||||
else if (kind == KotlinClassHeader.Kind.CLASS) {
|
||||
buildDecompiledText(packageFqName, listOf(resolver.resolveTopLevelClass(classFqName)).filterNotNull())
|
||||
buildDecompiledText(packageFqName, listOf(resolver.resolveTopLevelClass(classId)).filterNotNull())
|
||||
}
|
||||
else {
|
||||
throw UnsupportedOperationException("Unknown header kind: " + kind)
|
||||
|
||||
+5
-6
@@ -48,8 +48,7 @@ import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl
|
||||
public fun DeserializerForDecompiler(classFile: VirtualFile): DeserializerForDecompiler {
|
||||
val kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(classFile)
|
||||
assert(kotlinClass != null) { "Decompiled data factory shouldn't be called on an unsupported file: " + classFile }
|
||||
val classFqName = kotlinClass!!.getClassName().getFqNameForClassNameWithoutDollars()
|
||||
val packageFqName = classFqName.parent()
|
||||
val packageFqName = kotlinClass!!.getClassId().getPackageFqName()
|
||||
return DeserializerForDecompiler(classFile.getParent()!!, packageFqName)
|
||||
}
|
||||
|
||||
@@ -60,14 +59,14 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
|
||||
private fun createDummyModule(name: String) = ModuleDescriptorImpl(Name.special("<$name>"), listOf(), PlatformToKotlinClassMap.EMPTY)
|
||||
|
||||
override fun resolveTopLevelClass(classFqName: FqName) = deserializationContext.classDeserializer.deserializeClass(classFqName.toClassId())
|
||||
override fun resolveTopLevelClass(classId: ClassId) = deserializationContext.classDeserializer.deserializeClass(classId)
|
||||
|
||||
override fun resolveDeclarationsInPackage(packageFqName: FqName): Collection<DeclarationDescriptor> {
|
||||
assert(packageFqName == directoryPackageFqName, "Was called for $packageFqName but only $directoryPackageFqName is expected.")
|
||||
val binaryClassForPackageClass = localClassFinder.findKotlinClass(PackageClassUtils.getPackageClassId(packageFqName))
|
||||
val annotationData = binaryClassForPackageClass?.getClassHeader()?.annotationData
|
||||
if (annotationData == null) {
|
||||
LOG.error("Could not read annotation data for $packageFqName from ${binaryClassForPackageClass?.getClassName()}")
|
||||
LOG.error("Could not read annotation data for $packageFqName from ${binaryClassForPackageClass?.getClassId()}")
|
||||
return Collections.emptyList()
|
||||
}
|
||||
val membersScope = DeserializedPackageMemberScope(
|
||||
@@ -122,7 +121,7 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
val binaryClass = localClassFinder.findKotlinClass(classId) ?: return null
|
||||
val data = binaryClass.getClassHeader().annotationData
|
||||
if (data == null) {
|
||||
LOG.error("Annotation data missing for ${binaryClass.getClassName()}")
|
||||
LOG.error("Annotation data missing for ${binaryClass.getClassId()}")
|
||||
return null
|
||||
}
|
||||
return JavaProtoBufUtil.readClassDataFrom(data)
|
||||
@@ -186,7 +185,7 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
LOG.error("Could not infer visibility for $descriptor")
|
||||
}
|
||||
override fun reportIncompatibleAbiVersion(kotlinClass: KotlinJvmBinaryClass, actualVersion: Int) {
|
||||
LOG.error("Incompatible ABI version for class ${kotlinClass.getClassName()}, actual version: $actualVersion")
|
||||
LOG.error("Incompatible ABI version for class ${kotlinClass.getClassId()}, actual version: $actualVersion")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ package org.jetbrains.jet.plugin.libraries
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.descriptors.serialization.ClassId
|
||||
|
||||
public trait ResolverForDecompiler {
|
||||
public fun resolveTopLevelClass(classFqName: FqName): ClassDescriptor?
|
||||
public fun resolveTopLevelClass(classId: ClassId): ClassDescriptor?
|
||||
|
||||
public fun resolveDeclarationsInPackage(packageFqName: FqName): Collection<DeclarationDescriptor>
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public final class KotlinClassFileIndex extends ScalarIndexExtension<FqName> {
|
||||
try {
|
||||
KotlinJvmBinaryClass kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(inputData.getFile());
|
||||
if (kotlinClass != null && kotlinClass.getClassHeader().getKind() != KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION) {
|
||||
return Collections.singletonMap(kotlinClass.getClassName().getFqNameForClassNameWithoutDollars(), null);
|
||||
return Collections.singletonMap(kotlinClass.getClassId().asSingleFqName().toSafe(), null);
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext
|
||||
import org.jetbrains.jet.descriptors.serialization.ClassId
|
||||
|
||||
public class DecompiledTextConsistencyTest : JetLightCodeInsightFixtureTestCase() {
|
||||
|
||||
@@ -66,8 +67,9 @@ class ProjectBasedResolverForDecompiler(project: Project) : ResolverForDecompile
|
||||
module, null, null
|
||||
).getModuleDescriptor()
|
||||
}
|
||||
override fun resolveTopLevelClass(classFqName: FqName): ClassDescriptor? {
|
||||
return module.resolveTopLevelClass(classFqName)
|
||||
|
||||
override fun resolveTopLevelClass(classId: ClassId): ClassDescriptor? {
|
||||
return module.resolveTopLevelClass(classId.asSingleFqName().toSafe())
|
||||
}
|
||||
|
||||
override fun resolveDeclarationsInPackage(packageFqName: FqName): Collection<DeclarationDescriptor> {
|
||||
|
||||
Reference in New Issue
Block a user