From 4eb534e39beaa8c38674446d09695d16e1a223c2 Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Wed, 21 Jul 2021 16:56:34 +0200 Subject: [PATCH] [FIR IDE] Remove withFirWithPossibleResolve inside function --- .../KtFirCompletionCandidateChecker.kt | 2 +- .../api/fir/components/KtFirScopeProvider.kt | 4 ++-- .../fir/symbols/KtFirOverrideInfoProvider.kt | 8 ++++---- .../api/fir/symbols/KtFirTypeAndAnnotations.kt | 2 +- .../symbols/annotations/KtFirAnnotationCall.kt | 2 +- .../api/fir/utils/FirRefWithValidityCheck.kt | 18 ------------------ 6 files changed, 9 insertions(+), 27 deletions(-) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirCompletionCandidateChecker.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirCompletionCandidateChecker.kt index b90ce15ccf7..8caee26f99f 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirCompletionCandidateChecker.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirCompletionCandidateChecker.kt @@ -45,7 +45,7 @@ internal class KtFirCompletionCandidateChecker( possibleExplicitReceiver: KtExpression?, ): KtExtensionApplicabilityResult = withValidityAssertion { require(firSymbolForCandidate is KtFirSymbol<*>) - return firSymbolForCandidate.firRef.withFirWithPossibleResolveInside( + return firSymbolForCandidate.firRef.withFir( phase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE ) { declaration -> check(declaration is FirCallableDeclaration) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirScopeProvider.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirScopeProvider.kt index 7659af77574..e5b82bd7ddc 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirScopeProvider.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirScopeProvider.kt @@ -59,8 +59,8 @@ internal class KtFirScopeProvider( private val packageMemberScopeCache = IdentityHashMap() private inline fun KtSymbolWithMembers.withFirForScope(crossinline body: (FirClass) -> T): T? = when (this) { - is KtFirNamedClassOrObjectSymbol -> firRef.withFirWithPossibleResolveInside(FirResolvePhase.TYPES, body) - is KtFirAnonymousObjectSymbol -> firRef.withFirWithPossibleResolveInside(FirResolvePhase.TYPES, body) + is KtFirNamedClassOrObjectSymbol -> firRef.withFir(FirResolvePhase.TYPES, body) + is KtFirAnonymousObjectSymbol -> firRef.withFir(FirResolvePhase.TYPES, body) is KtFirEnumEntrySymbol -> firRef.withFir(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) { val initializer = it.initializer check(initializer is FirAnonymousObject) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirOverrideInfoProvider.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirOverrideInfoProvider.kt index a5278c73f42..da3f8e40ac2 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirOverrideInfoProvider.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirOverrideInfoProvider.kt @@ -37,10 +37,10 @@ class KtFirOverrideInfoProvider( require(classSymbol is KtFirSymbol<*>) // Inspecting visibility requires resolving to status - return memberSymbol.firRef.withFirWithPossibleResolveInside(FirResolvePhase.STATUS) outer@{ memberFir -> + return memberSymbol.firRef.withFir(FirResolvePhase.STATUS) outer@{ memberFir -> if (memberFir !is FirCallableDeclaration) return@outer false - classSymbol.firRef.withFirWithPossibleResolveInside inner@{ parentClassFir -> + classSymbol.firRef.withFir inner@{ parentClassFir -> if (parentClassFir !is FirClass) return@inner false memberFir.isVisibleInClass(parentClassFir) @@ -53,10 +53,10 @@ class KtFirOverrideInfoProvider( require(parentClassSymbol is KtFirSymbol<*>) // Inspecting implementation status requires resolving to status - return memberSymbol.firRef.withFirWithPossibleResolveInside(FirResolvePhase.STATUS) outer@{ memberFir -> + return memberSymbol.firRef.withFir(FirResolvePhase.STATUS) outer@{ memberFir -> if (memberFir !is FirCallableDeclaration) return@outer null - parentClassSymbol.firRef.withFirWithPossibleResolveInside inner@{ parentClassFir -> + parentClassSymbol.firRef.withFir inner@{ parentClassFir -> if (parentClassFir !is FirClass) return@inner null memberFir.symbol.getImplementationStatus( diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirTypeAndAnnotations.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirTypeAndAnnotations.kt index 9decd38c570..b5868240126 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirTypeAndAnnotations.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/KtFirTypeAndAnnotations.kt @@ -69,7 +69,7 @@ internal fun FirRefWithValidityCheck.superTypesAndAnnotationsLi if(fir.resolvePhase >= FirResolvePhase.SUPER_TYPES) { fir.superTypeRefs.mapToTypeAndAnnotations(this, builder) } else null - } ?: withFirByTypeWithPossibleResolveInside(ResolveType.NoResolve) { fir -> + } ?: withFirByType(ResolveType.NoResolve) { fir -> fir.resolveSupertypesInTheAir(builder.rootSession).mapToTypeAndAnnotations(this, builder) } } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/annotations/KtFirAnnotationCall.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/annotations/KtFirAnnotationCall.kt index e77715a5fc1..180a7eb8b50 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/annotations/KtFirAnnotationCall.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/symbols/annotations/KtFirAnnotationCall.kt @@ -31,7 +31,7 @@ internal class KtFirAnnotationCall( } override val classId: ClassId? by cached { - containingDeclaration.withFirByTypeWithPossibleResolveInside(ResolveType.AnnotationType) { fir -> + containingDeclaration.withFirByType(ResolveType.AnnotationType) { fir -> annotationCallRef.getClassId(fir.moduleData.session) } } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt index b6c73da663a..f713a0bfab6 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt @@ -45,24 +45,6 @@ internal class FirRefWithValidityCheck(fir: D, resolveSt return action(fir) } - /** - * Runs [action] with fir element with write action hold - * Consider using this then [action] may call some resolve - */ - inline fun withFirWithPossibleResolveInside( - phase: FirResolvePhase = FirResolvePhase.RAW_FIR, - crossinline action: (fir: D) -> R - ): R = withFir(phase, action) - - /** - * Runs [action] with fir element with write action hold - * Consider using this then [action] may call some resolve - */ - inline fun withFirByTypeWithPossibleResolveInside( - resolveType: ResolveType = ResolveType.NoResolve, - crossinline action: (fir: D) -> R - ): R = withFirByType(resolveType, action) - val resolveState get() = resolveStateWeakRef.get() ?: throw EntityWasGarbageCollectedException("FirModuleResolveState")