diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt index 47b06bd90ec..2ee2de266a8 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt @@ -88,15 +88,32 @@ fun KtElement.analyzeAndGetResult(): AnalysisResult { fun KtElement.findModuleDescriptor(): ModuleDescriptor = getResolutionFacade().moduleDescriptor +// This function is used on declarations to make analysis not only declaration itself but also it content: +// body for declaration with body, initializer & accessors for properties +fun KtDeclaration.analyzeWithContent(): BindingContext = analyzeFullyAndGetResult().bindingContext + +// This function is used to make full analysis of declaration container. +// All its declarations, including their content (see above), are analyzed. +inline fun T.analyzeWithDeclarations(): BindingContext where T : KtDeclarationContainer, T : KtElement = + analyzeFullyAndGetResult().bindingContext + +// NB: for statements / expressions, usually should be replaced with analyze(), +// for declarations, analyzeWithContent() will do what you want. +@Deprecated( + "Use either analyzeWithContent() or analyzeWithDeclarations() instead, or use just analyze()", + ReplaceWith("analyze()") +) +fun KtElement.analyzeFully(): BindingContext = analyzeFullyAndGetResult().bindingContext + // This and next function are expected to produce the same result as compiler // for the given element and its children (including diagnostics, trace slices, descriptors, etc.) // Not recommended to call both of them without real need // See also KotlinResolveCache, KotlinResolveDataProvider -// In the future should be unified with 'analyze` -fun KtElement.analyzeFully(): BindingContext = analyzeFullyAndGetResult().bindingContext +fun KtFile.analyzeFullyAndGetResult(vararg extraFiles: KtFile): AnalysisResult = + KotlinCacheService.getInstance(project).getResolutionFacade(listOf(this) + extraFiles.toList()).analyzeFullyAndGetResult(listOf(this)) -fun KtElement.analyzeFullyAndGetResult(vararg extraFiles: KtFile): AnalysisResult = - KotlinCacheService.getInstance(project).getResolutionFacade(listOf(this) + extraFiles.toList()).analyzeFullyAndGetResult(listOf(this)) +fun KtElement.analyzeFullyAndGetResult(): AnalysisResult = + KotlinCacheService.getInstance(project).getResolutionFacade(listOf(this)).analyzeFullyAndGetResult(listOf(this)) // this method don't check visibility and collect all descriptors with given fqName fun ResolutionFacade.resolveImportReference( diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt index e4660cf954d..811dd959da4 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -24,7 +24,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.util.ExceptionUtil import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.* @@ -154,7 +154,7 @@ private fun KtFile.findContextElement(): KtElement? { private var PsiElement.DEBUG_SMART_CAST: PsiElement? by CopyablePsiUserDataProperty(Key.create("DEBUG_SMART_CAST")) private fun KtCodeFragment.markSmartCasts() { - val bindingContext = runInReadActionWithWriteActionPriorityWithPCE { analyzeFully() } + val bindingContext = runInReadActionWithWriteActionPriorityWithPCE { analyzeWithDeclarations() } val factory = KtPsiFactory(project) getContentElement()?.forEachDescendantOfType { expression -> diff --git a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/DirectiveBasedActionUtils.kt b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/DirectiveBasedActionUtils.kt index ec8c04dab88..2c6219bfb40 100644 --- a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/DirectiveBasedActionUtils.kt +++ b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/DirectiveBasedActionUtils.kt @@ -10,7 +10,7 @@ import com.intellij.psi.PsiFile import com.intellij.testFramework.UsefulTestCase import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils @@ -22,7 +22,7 @@ object DirectiveBasedActionUtils { val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.text, "// ERROR:").sorted() - val actualErrors = file.analyzeFully().getDiagnostics() + val actualErrors = file.analyzeWithDeclarations().diagnostics .filter { it.getSeverity() == Severity.ERROR } .map { DefaultErrorMessages.render(it).replace("\n", "
") } .sorted() diff --git a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/testUtils.kt b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/testUtils.kt index 438a4cac118..434508edca5 100644 --- a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/testUtils.kt +++ b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/testUtils.kt @@ -32,12 +32,11 @@ import com.intellij.util.Consumer import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.idea.caches.resolve.LibraryModificationTracker -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.psi.KtFile -import java.lang.IllegalArgumentException import java.util.* enum class ModuleKind { @@ -74,7 +73,7 @@ fun Module.configureAs(kind: ModuleKind) { } fun KtFile.dumpTextWithErrors(): String { - val diagnostics = analyzeFully().diagnostics + val diagnostics = analyzeWithDeclarations().diagnostics val errors = diagnostics.filter { it.severity == Severity.ERROR } if (errors.isEmpty()) return text val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n") diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateEqualsAndHashcodeAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateEqualsAndHashcodeAction.kt index 4fe68080adb..57af985e486 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateEqualsAndHashcodeAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateEqualsAndHashcodeAction.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.core.CollectingNameValidator import org.jetbrains.kotlin.idea.core.KotlinNameSuggester @@ -98,7 +98,7 @@ class KotlinGenerateEqualsAndHashcodeAction : KotlinGenerateMemberActionBase - val context = klass.analyzeFully() + val context = klass.analyzeWithDeclarations() for (typeParameter in klass.typeParameters) { if (typeParameter.variance != Variance.INVARIANT) continue val parameterDescriptor = diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantNotNullExtensionReceiverOfInlineInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantNotNullExtensionReceiverOfInlineInspection.kt index 920ca0eed6f..b01b70bc5e9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantNotNullExtensionReceiverOfInlineInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantNotNullExtensionReceiverOfInlineInspection.kt @@ -10,7 +10,7 @@ import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* @@ -50,7 +50,7 @@ class RedundantNotNullExtensionReceiverOfInlineInspection : AbstractKotlinInspec return } - val context = function.analyzeFully() + val context = function.analyzeWithContent() val functionDescriptor = context[BindingContext.FUNCTION, function] ?: return val receiverParameter = functionDescriptor.extensionReceiverParameter ?: return val receiverValue = receiverParameter.value diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSuspendModifierInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSuspendModifierInspection.kt index 86f8d84cab5..800d29f2e6a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSuspendModifierInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSuspendModifierInspection.kt @@ -12,7 +12,7 @@ import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.PsiElementVisitor import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.Modality -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.highlighter.hasSuspendCalls import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix @@ -31,7 +31,7 @@ class RedundantSuspendModifierInspection : AbstractKotlinInspection() { if (!function.hasBody()) return if (function.hasModifier(KtTokens.OVERRIDE_KEYWORD)) return - val context = function.analyzeFully() + val context = function.analyzeWithContent() val descriptor = context[BindingContext.FUNCTION, function] ?: return if (descriptor.modality == Modality.OPEN) return diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertSecondaryConstructorToPrimaryIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertSecondaryConstructorToPrimaryIntention.kt index 49e094a8a00..25a3d547458 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertSecondaryConstructorToPrimaryIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertSecondaryConstructorToPrimaryIntention.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection import org.jetbrains.kotlin.idea.util.CommentSaver import org.jetbrains.kotlin.lexer.KtTokens @@ -59,7 +59,7 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio val klass = element.containingClassOrObject ?: return null if (klass.hasPrimaryConstructor()) return null - val context = klass.analyzeFully() + val context = klass.analyzeWithDeclarations() val classDescriptor = context[BindingContext.CLASS, klass] ?: return null val elementDescriptor = context[BindingContext.CONSTRUCTOR, element] ?: return null @@ -154,7 +154,7 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio override fun applyTo(element: KtSecondaryConstructor, editor: Editor?) { val klass = element.containingClassOrObject as? KtClass ?: return - val context = klass.analyzeFully() + val context = klass.analyzeWithDeclarations() val factory = KtPsiFactory(klass) val constructorCommentSaver = CommentSaver(element) val constructorInClass = klass.createPrimaryConstructorIfAbsent() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/InlineTypeParameterFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/InlineTypeParameterFix.kt index 03cf823b5d9..e6763912f19 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/InlineTypeParameterFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/InlineTypeParameterFix.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType @@ -32,7 +33,7 @@ class InlineTypeParameterFix(val typeReference: KtTypeReference) : KotlinQuickFi val bound = parameter.extendsBound ?: return val parameterList = parameter.parent as? KtTypeParameterList ?: return val parameterListOwner = typeReference.getStrictParentOfType() ?: return - val context = parameterListOwner.analyzeFully() + val context = parameterListOwner.analyzeWithContent() val parameterDescriptor = context[BindingContext.TYPE_PARAMETER, parameter] ?: return parameterListOwner.forEachDescendantOfType { typeReference -> val typeElement = typeReference.typeElement diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/MapPlatformClassToKotlinFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/MapPlatformClassToKotlinFix.kt index 4857b2842d2..05e4c050a75 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/MapPlatformClassToKotlinFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/MapPlatformClassToKotlinFix.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.idea.caches.resolve.analyze -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType @@ -61,7 +61,7 @@ class MapPlatformClassToKotlinFix( override fun getFamilyName() = "Change to Kotlin class" public override fun invoke(project: Project, editor: Editor?, file: KtFile) { - val bindingContext = file.analyzeFully() + val bindingContext = file.analyzeWithDeclarations() val imports = ArrayList() val usages = ArrayList() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt index bd31eeeba42..4d74342069f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.util.approximateWithResolvableType @@ -51,7 +51,7 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() { override fun doCreateActions(diagnostic: Diagnostic): List { val actions = LinkedList() - val context = (diagnostic.psiFile as KtFile).analyzeFully() + val context = (diagnostic.psiFile as KtFile).analyzeWithDeclarations() val diagnosticElement = diagnostic.psiElement if (diagnosticElement !is KtExpression) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyOverrideExplicitlyFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyOverrideExplicitlyFix.kt index 5d096f75101..f225a5daf36 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyOverrideExplicitlyFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyOverrideExplicitlyFix.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.core.ShortenReferences import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMemberChooserObject import org.jetbrains.kotlin.idea.core.overrideImplement.generateMember @@ -44,7 +44,7 @@ class SpecifyOverrideExplicitlyFix( override fun invoke(project: Project, editor: Editor?, file: KtFile) { val element = element ?: return - val context = element.analyzeFully() + val context = element.analyzeWithDeclarations() val delegatedDescriptor = context.diagnostics.forElement(element).mapNotNull { if (it.factory == Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE) Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE.cast(it).a diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt index d0b5de5a87c..48deb2f5eb9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt @@ -712,7 +712,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor { callable: PsiElement, newReceiverInfo: KotlinParameterInfo?) { if (newReceiverInfo != null && (callable is KtNamedFunction) && callable.bodyExpression != null) { - val originalContext = callable.analyzeFully() + val originalContext = callable.analyzeWithContent() val noReceiverRefs = ArrayList() callable.forEachDescendantOfType { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineFunctionHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineFunctionHandler.kt index d0de98a6c4c..95f0fd92e9d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineFunctionHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineFunctionHandler.kt @@ -27,7 +27,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.idea.KotlinLanguage -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor import org.jetbrains.kotlin.idea.codeInliner.CallableUsageReplacementStrategy import org.jetbrains.kotlin.psi.KtExpression @@ -76,7 +76,7 @@ class KotlinInlineFunctionHandler: InlineActionHandler() { } private fun KtNamedFunction.isRecursive(): Boolean { - val context = analyzeFully() + val context = analyzeWithContent() return bodyExpression?.includesCallOf(context[BindingContext.FUNCTION, this] ?: return false, context) ?: false } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt index 08008c80150..217099adfd9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt @@ -39,7 +39,7 @@ import org.jetbrains.kotlin.cfg.pseudocodeTraverser.traverseFollowingInstruction import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde @@ -711,11 +711,11 @@ fun ExtractionData.performAnalysis(): AnalysisResult { emptyList() ) - val body = ExtractionGeneratorConfiguration( + val generatedDeclaration = ExtractionGeneratorConfiguration( descriptor, ExtractionGeneratorOptions(inTempFile = true, allowExpressionBody = false) - ).generateDeclaration().declaration.getGeneratedBody() - val virtualContext = body.analyzeFully() + ).generateDeclaration().declaration + val virtualContext = generatedDeclaration.analyzeWithContent() if (virtualContext.diagnostics.all().any { it.factory == Errors.ILLEGAL_SUSPEND_FUNCTION_CALL || it.factory == Errors.ILLEGAL_SUSPEND_PROPERTY_ACCESS }) { descriptor = descriptor.copy(modifiers = listOf(KtTokens.SUSPEND_KEYWORD)) } @@ -784,8 +784,8 @@ fun ExtractableCodeDescriptor.validate(target: ExtractionTarget = ExtractionTarg val valueParameterList = (result.declaration as? KtNamedFunction)?.valueParameterList val typeParameterList = (result.declaration as? KtNamedFunction)?.typeParameterList - val body = result.declaration.getGeneratedBody() - val bindingContext = body.analyzeFully() + val generatedDeclaration = result.declaration + val bindingContext = generatedDeclaration.analyzeWithContent() fun processReference(currentRefExpr: KtSimpleNameExpression) { val resolveResult = currentRefExpr.resolveResult ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt index a909aca0649..27d80cebcea 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveUtils.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.shorten.addDelayedImportRequest @@ -490,7 +491,7 @@ sealed class OuterInstanceReferenceUsageInfo(element: PsiElement, private val is fun traverseOuterInstanceReferences(member: KtNamedDeclaration, stopAtFirst: Boolean, body: (OuterInstanceReferenceUsageInfo) -> Unit = {}): Boolean { if (member is KtObjectDeclaration || member is KtClass && !member.isInner()) return false - val context = member.analyzeFully() + val context = member.analyzeWithContent() val containingClassOrObject = member.containingClassOrObject ?: return false val outerClassDescriptor = containingClassOrObject.unsafeResolveToDescriptor() as ClassDescriptor var found = false diff --git a/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt b/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt index a57f12b4a55..0e7d74b2f14 100644 --- a/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt @@ -47,6 +47,7 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor import org.jetbrains.kotlin.idea.core.isOverridable import org.jetbrains.kotlin.idea.findUsages.KotlinFunctionFindUsagesOptions @@ -140,7 +141,7 @@ abstract class Slicer( operator fun get(element: KtElement): Pseudocode? { val container = element.containingDeclarationForPseudocode ?: return null return computedPseudocodes.getOrPut(container) { - container.getContainingPseudocode(container.analyzeFully())?.apply { computedPseudocodes[container] = this } ?: return null + container.getContainingPseudocode(container.analyzeWithContent())?.apply { computedPseudocodes[container] = this } ?: return null } } } @@ -213,7 +214,7 @@ class InflowSlicer( } private fun KtProperty.processProperty() { - val bindingContext by lazy { analyzeFully() } + val bindingContext by lazy { analyzeWithContent() } if (hasDelegateExpression()) { val getter = (unsafeResolveToDescriptor() as VariableDescriptorWithAccessors).getter diff --git a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt index 59478bebe40..5812125b069 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt @@ -20,10 +20,7 @@ import com.intellij.psi.PsiDocumentManager import junit.framework.TestCase import org.intellij.lang.annotations.Language import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.idea.caches.resolve.analyze -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult -import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade -import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.* import org.jetbrains.kotlin.idea.imports.importableFqName import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor @@ -389,7 +386,9 @@ class C(param1: String = "", param2: Int = 0) { """) as KtFile val defaultValue = ((file.declarations[0]) as KtClass).getPrimaryConstructor()!!.valueParameters[0].defaultValue!! - defaultValue.analyzeFullyAndGetResult() + // Kept to preserve correct behaviour of analyzeFully() on class internal elements + // TODO: delete after removal of KtElement.analyzeFully() + defaultValue.analyzeFully() } fun testPrimaryConstructorAnnotationFullAnalysis() { @@ -398,7 +397,7 @@ class C(param1: String = "", param2: Int = 0) { """) as KtFile val annotationArguments = ((file.declarations[0]) as KtClass).getPrimaryConstructor()!!.annotationEntries[0].valueArgumentList!! - annotationArguments.analyzeFullyAndGetResult() + annotationArguments.analyzeFully() } fun testFunctionParameterAnnotation() { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt index bdf293c99c1..f663b3992aa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt @@ -23,7 +23,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiTreeUtil import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture import org.jetbrains.kotlin.checkers.AbstractPsiCheckerTest -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils @@ -127,7 +127,7 @@ private fun JavaCodeInsightTestFixture.configureByCodeFragment(filePath: String) if (typeStr != null) { file.putCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR, { val codeFragment = KtPsiFactory(project).createBlockCodeFragment("val xxx: $typeStr", PsiTreeUtil.getParentOfType(elementAt, KtElement::class.java)) - val context = codeFragment.analyzeFully() + val context = codeFragment.analyzeWithDeclarations() val typeReference: KtTypeReference = PsiTreeUtil.getChildOfType(codeFragment.getContentElement().firstChild, KtTypeReference::class.java)!! context[BindingContext.TYPE, typeReference] }) diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/NoErrorsInStdlibTest.kt b/idea/tests/org/jetbrains/kotlin/idea/highlighter/NoErrorsInStdlibTest.kt index a1d550f3459..c66ca81075c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/NoErrorsInStdlibTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/NoErrorsInStdlibTest.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector import org.jetbrains.kotlin.diagnostics.Severity -import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase @@ -45,7 +45,7 @@ class NoErrorsInStdlibTest : KotlinLightCodeInsightFixtureTestCase() { val psiFile = psiManager.findFile(file) if (psiFile is KtFile) { hasAtLeastOneFile = true - val bindingContext = psiFile.analyzeFully() + val bindingContext = psiFile.analyzeWithDeclarations() val errors = bindingContext.diagnostics.all().filter { it.severity == Severity.ERROR } if (errors.isNotEmpty()) {