[java] Use navigationElement instead of originalFile to retrieve the file for JPMS module resolution

The problem arises with Kotlin light classes created by `DecompiledLightClassesFactory`. The resulting class isn't physical, and its `originalFile` doesn't point to the physical file as well. Thus, module info isn't found which, e.g., leads to some symbols not being recommended in the "Add dependency" family of quick fixes.

`navigationElement`, however, is set properly in such classes so it can be used to find a PSI element which resides next to the potential module-info. As `TargetModuleInfo.module` can resolve JPMS module both via sources and via class files, it seems alright to provide any of such.

GitOrigin-RevId: cec0309959a56e1976b4da5ca1f69b4041278e2a
This commit is contained in:
Stanislav Utikeev
2025-06-24 03:48:15 +00:00
committed by intellij-monorepo-bot
parent 91183afb04
commit 7acb1c3ced
@@ -70,7 +70,7 @@ sealed interface JpmsModuleInfo {
*/
@JvmStatic
fun findTargetModuleInfos(targetPackageName: String, targetFile: PsiFile?, place: PsiFile): List<TargetModuleInfo>? {
val originalTargetFile = targetFile?.originalFile
val originalTargetFile = targetFile?.navigationElement
if (!PsiUtil.isAvailable(JavaFeature.MODULES, place)) return null
val useVFile = place.virtualFile