mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix SOE in new-style resolve (PY-6305) (oh god the contract of findExportedName() is so confusing)
This commit is contained in:
@@ -183,9 +183,11 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiElement resolveDeclaration(String name, PsiElement result) {
|
||||
if (result instanceof PyImportElement) {
|
||||
return findNameInImportElement(name, (PyImportElement)result);
|
||||
final PyImportElement importElement = (PyImportElement)result;
|
||||
return findNameInImportElement(name, importElement, importElement.getContainingImportStatement() instanceof PyFromImportStatement);
|
||||
}
|
||||
else if (result instanceof PyFromImportStatement) {
|
||||
return ((PyFromImportStatement) result).resolveImportSource();
|
||||
@@ -557,7 +559,7 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression {
|
||||
@Nullable
|
||||
private PsiElement findNameInImportStatement(String name, PyImportStatement child) {
|
||||
for (PyImportElement importElement: child.getImportElements()) {
|
||||
final PsiElement result = findNameInImportElement(name, importElement);
|
||||
final PsiElement result = findNameInImportElement(name, importElement, false);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
@@ -566,8 +568,8 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiElement findNameInImportElement(String name, PyImportElement importElement) {
|
||||
final PsiElement result = importElement.getElementNamed(name, false);
|
||||
private PsiElement findNameInImportElement(String name, PyImportElement importElement, final boolean resolveImportElement) {
|
||||
final PsiElement result = importElement.getElementNamed(name, resolveImportElement);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
from pack import mod
|
||||
# <ref>
|
||||
@@ -96,6 +96,14 @@ public class PyMultiFileResolveTest extends PyResolveTestCase {
|
||||
assertTrue("is target?", elt instanceof PyTargetExpression);
|
||||
}
|
||||
|
||||
public void testFromPackageImportIntoInit() { // PY-6305
|
||||
myFixture.copyDirectoryToProject("fromPackageImportIntoInit/pack", "pack");
|
||||
final PsiFile psiFile = myFixture.configureByFile("pack/__init__.py");
|
||||
final PsiElement result = doResolve(psiFile);
|
||||
assertInstanceOf(result, PyFile.class);
|
||||
assertEquals("mod.py", ((PyFile) result).getName());
|
||||
}
|
||||
|
||||
public void testResolveInPkg() {
|
||||
ResolveResult[] results = doMultiResolve();
|
||||
assertTrue(results.length == 2); // func and import stmt
|
||||
|
||||
Reference in New Issue
Block a user