Introduce analyzeWithContent() & analyzeWithDeclarations()

These functions have more clear names & receivers.
Old analyzeFully() applied on KtElement made deprecated
because for general KtElement it's unclear what is "full analysis"
This commit is contained in:
Mikhail Glukhikh
2018-02-13 19:09:37 +03:00
parent e78bd73ba3
commit 8986b8a1a2
24 changed files with 74 additions and 56 deletions
@@ -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 <reified T> 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(
@@ -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<KtExpression> { expression ->
@@ -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", "<br>") }
.sorted()
@@ -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")
@@ -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<Kot
override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? {
if (klass !is KtClass) throw AssertionError("Not a class: ${klass.getElementTextWithContext()}")
val context = klass.analyzeFully()
val context = klass.analyzeWithDeclarations()
val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null
val equalsDescriptor = classDescriptor.findDeclaredEquals(false)
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
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.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
@@ -104,7 +104,7 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase<
}
override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? {
val context = klass.analyzeFully()
val context = klass.analyzeWithDeclarations()
val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null
val superConstructors = chooseSuperConstructors(klass, classDescriptor).map { it.descriptor as ConstructorDescriptor }
val propertiesToInitialize = choosePropertiesToInitialize(klass, context).map { it.descriptor as PropertyDescriptor }
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
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.analyzeFully
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.insertMembersAfter
@@ -132,7 +132,7 @@ class KotlinGenerateToStringAction : KotlinGenerateMemberActionBase<KotlinGenera
override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? {
if (klass !is KtClass) throw AssertionError("Not a class: ${klass.getElementTextWithContext()}")
val context = klass.analyzeFully()
val context = klass.analyzeWithDeclarations()
val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null
classDescriptor.findDeclaredToString(false)?.let {
@@ -44,7 +44,7 @@ class PlainTextPasteImportResolver(val dataForConversion: DataForConversion, val
private val importList = file.importList!!
private val psiElementFactory = PsiElementFactory.SERVICE.getInstance(project)
private val bindingContext by lazy { targetFile.analyzeFully() }
private val bindingContext by lazy { targetFile.analyzeWithDeclarations() }
private val resolutionFacade = targetFile.getResolutionFacade()
private val shortNameCache = PsiShortNamesCache.getInstance(project)
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.addRemoveModifier.addModifier
@@ -50,7 +50,7 @@ class AddVarianceModifierInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
return classOrObjectVisitor { klass ->
val context = klass.analyzeFully()
val context = klass.analyzeWithDeclarations()
for (typeParameter in klass.typeParameters) {
if (typeParameter.variance != Variance.INVARIANT) continue
val parameterDescriptor =
@@ -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
@@ -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
@@ -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()
@@ -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<KtTypeParameterListOwner>() ?: return
val context = parameterListOwner.analyzeFully()
val context = parameterListOwner.analyzeWithContent()
val parameterDescriptor = context[BindingContext.TYPE_PARAMETER, parameter] ?: return
parameterListOwner.forEachDescendantOfType<KtTypeReference> { typeReference ->
val typeElement = typeReference.typeElement
@@ -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<KtImportDirective>()
val usages = ArrayList<KtUserType>()
@@ -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<IntentionAction> {
val actions = LinkedList<IntentionAction>()
val context = (diagnostic.psiFile as KtFile).analyzeFully()
val context = (diagnostic.psiFile as KtFile).analyzeWithDeclarations()
val diagnosticElement = diagnostic.psiElement
if (diagnosticElement !is KtExpression) {
@@ -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
@@ -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<KtSimpleNameExpression>()
callable.forEachDescendantOfType<KtSimpleNameExpression> {
@@ -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
}
@@ -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
@@ -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
@@ -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
@@ -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() {
@@ -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]
})
@@ -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()) {