From b7b3caedcc0db1a8a588ffa8f94ad40c497f2763 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 24 Oct 2017 16:41:43 +0300 Subject: [PATCH] IDELightClassContexts: fix light member mismatch on InlineOnly members --- .../lightClasses/IDELightClassContexts.kt | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/IDELightClassContexts.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/IDELightClassContexts.kt index ca4348122ad..6c730570820 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/IDELightClassContexts.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/lightClasses/IDELightClassContexts.kt @@ -58,7 +58,6 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory import org.jetbrains.kotlin.resolve.calls.util.CallMaker import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator -import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil @@ -277,7 +276,7 @@ object IDELightClassContexts { val sm = LockBasedStorageManager.NO_LOCKS val moduleDescriptor = ModuleDescriptorImpl(realWorldModule.name, sm, realWorldModule.builtIns) - setupDependencies(moduleDescriptor, realWorldModule) + moduleDescriptor.setDependencies(moduleDescriptor, moduleDescriptor.builtIns.builtInsModule) val moduleInfo = files.first().getModuleInfo() val container = createContainer("LightClassStub", JvmPlatform) { @@ -293,6 +292,7 @@ object IDELightClassContexts { useInstance(IDELanguageSettingsProvider.getLanguageVersionSettings(moduleInfo, project)) useInstance(FileBasedDeclarationProviderFactory(sm, files)) + useInstance(CodegenAffectingAnnotations(realWorldModule)) useImpl() useInstance(object : WrappedTypeFactory(sm) { @@ -314,26 +314,23 @@ object IDELightClassContexts { return resolveSession } - private fun setupDependencies(moduleDescriptor: ModuleDescriptorImpl, realWorldModule: ModuleDescriptor) { - val jvmFieldClass = realWorldModule.getPackage(FqName("kotlin.jvm")).memberScope - .getContributedClassifier(Name.identifier("JvmField"), NoLookupLocation.FROM_IDE) + class CodegenAffectingAnnotations(private val realModule: ModuleDescriptor) { + fun get(name: String): ClassDescriptor? { + val annotationFqName = annotationsThatAffectCodegen.firstOrNull { it.shortName().asString() == name } ?: return null + return realModule.getPackage(annotationFqName.parent()).memberScope + .getContributedClassifier(annotationFqName.shortName(), NoLookupLocation.FROM_IDE) as? ClassDescriptor + } + + // see JvmPlatformAnnotations.kt, JvmFlagAnnotations.kt, also PsiModifier.MODIFIERS + private val annotationsThatAffectCodegen = listOf( + "JvmField", "JvmOverloads", "JvmName", "JvmStatic", + "Synchronized", "Transient", "Volatile", "Strictfp" + ).map { FqName("kotlin.jvm").child(Name.identifier(it)) } + FqName("kotlin.PublishedApi") + FqName("kotlin.Deprecated") + FqName("kotlin.internal.InlineOnly") - if (jvmFieldClass != null) { - moduleDescriptor.setDependencies(moduleDescriptor, jvmFieldClass.module as ModuleDescriptorImpl, moduleDescriptor.builtIns.builtInsModule) - } - else { - moduleDescriptor.setDependencies(moduleDescriptor, moduleDescriptor.builtIns.builtInsModule) - } } - // see JvmPlatformAnnotations.kt, JvmFlagAnnotations.kt, also PsiModifier.MODIFIERS - private val annotationsThatAffectCodegen = listOf( - "JvmField", "JvmOverloads", "JvmName", "JvmStatic", - "Synchronized", "Transient", "Volatile", "Strictfp" - ).map { FqName("kotlin.jvm").child(Name.identifier(it)) } + FqName("kotlin.PublishedApi") + FqName("kotlin.Deprecated") - class AdHocAnnotationResolver( - private val moduleDescriptor: ModuleDescriptor, + private val codegenAffectingAnnotations: CodegenAffectingAnnotations, private val callResolver: CallResolver, private val languageVersionSettings: LanguageVersionSettings, constantExpressionEvaluator: ConstantExpressionEvaluator, @@ -347,14 +344,7 @@ object IDELightClassContexts { private fun annotationClassByEntry(entryElement: KtAnnotationEntry): ClassDescriptor? { val annotationTypeReferencePsi = entryElement.calleeExpression?.constructorReferenceExpression ?: return null val referencedName = annotationTypeReferencePsi.getReferencedName() - for (annotationFqName in annotationsThatAffectCodegen) { - if (referencedName == annotationFqName.shortName().asString()) { - moduleDescriptor.getPackage(annotationFqName.parent()).memberScope - .getContributedClassifier(annotationFqName.shortName(), NoLookupLocation.FROM_IDE)?.let { return it as? ClassDescriptor } - - } - } - return null + return codegenAffectingAnnotations.get(referencedName) } override fun resolveAnnotationCall(annotationEntry: KtAnnotationEntry, scope: LexicalScope, trace: BindingTrace): OverloadResolutionResults {