[Analysis API] Simplify 'getNotUnderContentRootModule()'
In the resulting implementation of dangling file modules, 'getNotUnderContentRootModule()' is never called with a not-null file.
This commit is contained in:
+2
-18
@@ -7,16 +7,13 @@ package org.jetbrains.kotlin.analysis.project.structure.impl
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
|
||||||
import com.intellij.psi.PsiFileSystemItem
|
import com.intellij.psi.PsiFileSystemItem
|
||||||
import com.intellij.psi.PsiJavaFile
|
import com.intellij.psi.PsiJavaFile
|
||||||
import com.intellij.util.containers.ContainerUtil
|
|
||||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtStaticProjectStructureProvider
|
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtStaticProjectStructureProvider
|
||||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory.findJvmRootsForJavaFiles
|
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory.findJvmRootsForJavaFiles
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.LLFirBuiltinsSessionFactory
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.LLFirBuiltinsSessionFactory
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.*
|
import org.jetbrains.kotlin.analysis.project.structure.*
|
||||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||||
|
|
||||||
@@ -33,25 +30,12 @@ internal class KtStandaloneProjectStructureProvider(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val notUnderContentRootModuleCache = ContainerUtil.createConcurrentWeakMap<PsiFile, KtNotUnderContentRootModule>()
|
|
||||||
|
|
||||||
private val builtinsModule: KtBuiltinsModule by lazy {
|
private val builtinsModule: KtBuiltinsModule by lazy {
|
||||||
LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(platform).ktModule as KtBuiltinsModule
|
LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(platform).ktModule as KtBuiltinsModule
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNotUnderContentRootModule(project: Project, file: PsiFile?): KtNotUnderContentRootModule {
|
override fun getNotUnderContentRootModule(project: Project): KtNotUnderContentRootModule {
|
||||||
if (file == null) {
|
return ktNotUnderContentRootModuleWithoutPsiFile
|
||||||
return ktNotUnderContentRootModuleWithoutPsiFile
|
|
||||||
}
|
|
||||||
|
|
||||||
return notUnderContentRootModuleCache.getOrPut(file) {
|
|
||||||
KtNotUnderContentRootModuleImpl(
|
|
||||||
name = file.name,
|
|
||||||
moduleDescription = "Standalone-not-under-content-root-module-for-$file",
|
|
||||||
file = file,
|
|
||||||
project = project,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(KtModuleStructureInternals::class)
|
@OptIn(KtModuleStructureInternals::class)
|
||||||
|
|||||||
+1
-2
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.analysis.test.framework.services
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
|
||||||
import com.intellij.psi.PsiFileSystemItem
|
import com.intellij.psi.PsiFileSystemItem
|
||||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleProjectStructure
|
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleProjectStructure
|
||||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtStaticProjectStructureProvider
|
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtStaticProjectStructureProvider
|
||||||
@@ -22,7 +21,7 @@ class KtTestProjectStructureProvider(
|
|||||||
private val builtinsModule: KtBuiltinsModule,
|
private val builtinsModule: KtBuiltinsModule,
|
||||||
private val projectStructure: KtModuleProjectStructure,
|
private val projectStructure: KtModuleProjectStructure,
|
||||||
) : KtStaticProjectStructureProvider() {
|
) : KtStaticProjectStructureProvider() {
|
||||||
override fun getNotUnderContentRootModule(project: Project, file: PsiFile?): KtNotUnderContentRootModule {
|
override fun getNotUnderContentRootModule(project: Project): KtNotUnderContentRootModule {
|
||||||
error("Not-under content root modules most be initialized explicitly in tests")
|
error("Not-under content root modules most be initialized explicitly in tests")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -42,7 +42,7 @@ public abstract class ProjectStructureProvider {
|
|||||||
*/
|
*/
|
||||||
public abstract fun getModule(element: PsiElement, contextualModule: KtModule?): KtModule
|
public abstract fun getModule(element: PsiElement, contextualModule: KtModule?): KtModule
|
||||||
|
|
||||||
protected abstract fun getNotUnderContentRootModule(project: Project, file: PsiFile?): KtNotUnderContentRootModule
|
protected abstract fun getNotUnderContentRootModule(project: Project): KtNotUnderContentRootModule
|
||||||
|
|
||||||
@OptIn(KtModuleStructureInternals::class)
|
@OptIn(KtModuleStructureInternals::class)
|
||||||
protected fun computeSpecialModule(file: PsiFile): KtModule? {
|
protected fun computeSpecialModule(file: PsiFile): KtModule? {
|
||||||
@@ -81,7 +81,7 @@ public abstract class ProjectStructureProvider {
|
|||||||
return getModule(contextElement, contextualModule = null)
|
return getModule(contextElement, contextualModule = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
return getNotUnderContentRootModule(file.project, file = null)
|
return getNotUnderContentRootModule(file.project)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user