mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-17 20:11:25 +07:00
Don't resolve to a directory considered as a java package if it is not located under jvm module (PY-49082)
Otherwise, some typeshed directory could be considered as a package and name would be resolved to it even if the corresponding python package is not installed (PyTypeShed.maySearchForStubInRoot is ignored in this case). GitOrigin-RevId: c453b28655b710f092c9ece3d868a0ee5141c0dd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4b3b2241d6
commit
94ae100455
@@ -2,6 +2,10 @@
|
||||
package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -19,7 +23,7 @@ public class PyJavaImportResolver implements PyImportResolver {
|
||||
String fqn = name.toString();
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(context.getProject());
|
||||
final PsiPackage aPackage = psiFacade.findPackage(fqn);
|
||||
if (aPackage != null) {
|
||||
if (aPackage != null && isUnderJvmModule(aPackage)) {
|
||||
return aPackage;
|
||||
}
|
||||
|
||||
@@ -30,4 +34,17 @@ public class PyJavaImportResolver implements PyImportResolver {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isUnderJvmModule(@NotNull PsiPackage psiPackage) {
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(psiPackage);
|
||||
|
||||
if (module != null) {
|
||||
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user