AA: null check containing file for PsiElement
This commit is contained in:
committed by
Ilya Kirillov
parent
814920b344
commit
8c3df04c8e
+8
-2
@@ -15,9 +15,15 @@ internal class KtModuleProviderImpl(
|
|||||||
internal val mainModules: List<KtModule>,
|
internal val mainModules: List<KtModule>,
|
||||||
) : ProjectStructureProvider() {
|
) : ProjectStructureProvider() {
|
||||||
override fun getKtModuleForKtElement(element: PsiElement): KtModule {
|
override fun getKtModuleForKtElement(element: PsiElement): KtModule {
|
||||||
val containingFile = element.containingFile.virtualFile
|
val containingFileAsPsiFile = element.containingFile
|
||||||
|
?: error("Can't get containing PsiFile for ${element.text}")
|
||||||
|
// If an [element] is created on the fly, e.g., via [KtPsiFactory],
|
||||||
|
// its containing [PsiFile] may not have [VirtualFile].
|
||||||
|
// That also means the [element] is not bound to any [KtModule] either.
|
||||||
|
val containingFileAsVirtualFile = containingFileAsPsiFile.virtualFile
|
||||||
|
?: error("Can't get containing VirtualFile for ${element.text} in $containingFileAsPsiFile")
|
||||||
return mainModules.first { module ->
|
return mainModules.first { module ->
|
||||||
containingFile in module.contentScope
|
containingFileAsVirtualFile in module.contentScope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user