Use module to resolve annotation classes in AnnotationDescriptorLoader
This commit is contained in:
@@ -27,7 +27,6 @@ import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils
|
||||
@@ -56,6 +55,9 @@ public fun DeserializerForDecompiler(classFile: VirtualFile): DeserializerForDec
|
||||
|
||||
public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val directoryPackageFqName: FqName) : ResolverForDecompiler {
|
||||
|
||||
private val moduleDescriptor =
|
||||
ModuleDescriptorImpl(Name.special("<module for building decompiled sources>"), listOf(), PlatformToKotlinClassMap.EMPTY)
|
||||
|
||||
override fun resolveTopLevelClass(classFqName: FqName) = classes(classFqName.toClassId())
|
||||
|
||||
override fun resolveDeclarationsInPackage(packageFqName: FqName): Collection<DeclarationDescriptor> {
|
||||
@@ -100,19 +102,13 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
|
||||
private val deserializerStorage = DescriptorDeserializersStorage(storageManager);
|
||||
{
|
||||
deserializerStorage.setClassResolver {
|
||||
fqName ->
|
||||
classes(fqName.toClassId())
|
||||
}
|
||||
deserializerStorage.setModule(moduleDescriptor)
|
||||
deserializerStorage.setErrorReporter(LOGGING_REPORTER)
|
||||
}
|
||||
|
||||
private val annotationLoader = AnnotationDescriptorLoader();
|
||||
{
|
||||
annotationLoader.setClassResolver {
|
||||
fqName ->
|
||||
classes(fqName.toClassId())
|
||||
}
|
||||
annotationLoader.setModule(moduleDescriptor)
|
||||
annotationLoader.setKotlinClassFinder(localClassFinder)
|
||||
annotationLoader.setErrorReporter(LOGGING_REPORTER)
|
||||
annotationLoader.setStorage(deserializerStorage)
|
||||
@@ -120,10 +116,6 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
|
||||
private val constantLoader = ConstantDescriptorLoader();
|
||||
{
|
||||
constantLoader.setClassResolver {
|
||||
fqName ->
|
||||
classes(fqName.toClassId())
|
||||
}
|
||||
constantLoader.setKotlinClassFinder(localClassFinder)
|
||||
constantLoader.setErrorReporter(LOGGING_REPORTER)
|
||||
constantLoader.setStorage(deserializerStorage)
|
||||
@@ -149,9 +141,6 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
}
|
||||
}
|
||||
|
||||
private val moduleDescriptor =
|
||||
ModuleDescriptorImpl(Name.special("<module for building decompiled sources>"), listOf(), PlatformToKotlinClassMap.EMPTY);
|
||||
|
||||
{
|
||||
moduleDescriptor.addFragmentProvider(DependencyKind.BUILT_INS,
|
||||
KotlinBuiltIns.getInstance().getBuiltInsModule().getPackageFragmentProvider())
|
||||
@@ -166,13 +155,8 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
}
|
||||
|
||||
private fun resolveClassByClassId(classId: ClassId): ClassDescriptor? {
|
||||
val binaryClass = localClassFinder.findKotlinClass(classId)
|
||||
if (binaryClass != null) {
|
||||
return deserializeBinaryClass(binaryClass)
|
||||
}
|
||||
val fullFqName = classId.asSingleFqName()
|
||||
assert(fullFqName.isSafe(), "Safe fq name expected here, got $fullFqName instead")
|
||||
return MissingDependencyErrorClassDescriptor(ErrorUtils.getErrorModule(), fullFqName.toSafe())
|
||||
val binaryClass = localClassFinder.findKotlinClass(classId) ?: return null
|
||||
return deserializeBinaryClass(binaryClass)
|
||||
}
|
||||
|
||||
private fun deserializeBinaryClass(kotlinClass: KotlinJvmBinaryClass): ClassDescriptor {
|
||||
|
||||
@@ -95,6 +95,11 @@ public class LazyResolveByStubTestGenerated extends AbstractLazyResolveByStubTes
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/loadJava/compiledKotlin/annotations/classes"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationInClassObject.kt")
|
||||
public void testAnnotationInClassObject() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/AnnotationInClassObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassInClassObject.kt")
|
||||
public void testClassInClassObject() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassInClassObject.kt");
|
||||
@@ -115,6 +120,11 @@ public class LazyResolveByStubTestGenerated extends AbstractLazyResolveByStubTes
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DollarsInAnnotationName.kt")
|
||||
public void testDollarsInAnnotationName() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/DollarsInAnnotationName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("EnumArgument.kt")
|
||||
public void testEnumArgument() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/EnumArgument.kt");
|
||||
@@ -125,6 +135,11 @@ public class LazyResolveByStubTestGenerated extends AbstractLazyResolveByStubTes
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/MultipleAnnotations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NestedAnnotation.kt")
|
||||
public void testNestedAnnotation() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/NestedAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NestedClass.kt")
|
||||
public void testNestedClass() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/NestedClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user