[Analysis API] Add IGNORE_SELF dangling file resolution mode
In the 'IGNORE_SELF' mode, dangling files don't have their own declarations in providers. As a result, all references there resolve to declarations of the original file. It is conceptually similar to that we had in on-air resolve, however, now it's possible to work with the whole content of the in-memory 'FirFile'. As it can be seen in 'ProjectStructureProvider.kt' (KtFile.danglingFileResolutionMode), the 'IGNORE_SELF' mode is automatically applied for non-physical files with an original file being set. For other scenarios, now there is a new 'analyzeCopy()' function that allows to pass the analysis mode explicitly.
This commit is contained in:
+6
-7
@@ -11,7 +11,8 @@ import com.intellij.testFramework.TestDataFile
|
||||
import junit.framework.ComparisonFailure
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.analyzeInDependedAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.analyzeCopy
|
||||
import org.jetbrains.kotlin.analysis.project.structure.DanglingFileResolutionMode
|
||||
import org.jetbrains.kotlin.analysis.test.framework.AnalysisApiTestDirectives
|
||||
import org.jetbrains.kotlin.analysis.test.framework.TestWithDisposable
|
||||
import org.jetbrains.kotlin.analysis.test.framework.project.structure.ktModuleProvider
|
||||
@@ -205,12 +206,10 @@ abstract class AbstractAnalysisApiBasedTest : TestWithDisposable() {
|
||||
return if (configurator.analyseInDependentSession) {
|
||||
val originalContainingFile = contextElement.containingKtFile
|
||||
val fileCopy = originalContainingFile.copy() as KtFile
|
||||
val sameElementInCopy = PsiTreeUtil.findSameElementInCopy(contextElement, fileCopy)
|
||||
analyzeInDependedAnalysisSession(
|
||||
originalContainingFile,
|
||||
sameElementInCopy,
|
||||
action = { action(sameElementInCopy) }
|
||||
)
|
||||
|
||||
analyzeCopy(fileCopy, DanglingFileResolutionMode.IGNORE_SELF) {
|
||||
action(PsiTreeUtil.findSameElementInCopy<KtElement>(contextElement, fileCopy))
|
||||
}
|
||||
} else {
|
||||
analyze(contextElement, action = { action(contextElement) })
|
||||
}
|
||||
|
||||
+1
-4
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtMod
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtStaticProjectStructureProvider
|
||||
import org.jetbrains.kotlin.analysis.project.structure.*
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.contains
|
||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
@@ -29,9 +28,7 @@ class KtTestProjectStructureProvider(
|
||||
|
||||
@OptIn(KtModuleStructureInternals::class)
|
||||
override fun getModule(element: PsiElement, contextualModule: KtModule?): KtModule {
|
||||
// Unwrap context-dependent file copies coming from dependent sessions
|
||||
val containingFile = element.containingFile.originalFile
|
||||
|
||||
val containingFile = element.containingFile
|
||||
val virtualFile = containingFile.virtualFile
|
||||
|
||||
if (virtualFile != null) {
|
||||
|
||||
Reference in New Issue
Block a user