mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Transitive resolution (when an imported name is re-exported).
This commit is contained in:
@@ -87,6 +87,11 @@ public class PyFileImpl extends PsiFileBase implements PyFile {
|
||||
if (!processor.execute(e, substitutor)) return false;
|
||||
}
|
||||
|
||||
for(PyFromImportStatement e: getFromImports()) {
|
||||
if (e == lastParent) continue;
|
||||
if (!e.processDeclarations(processor, substitutor, null, this)) return false;
|
||||
}
|
||||
|
||||
// if we're in a stmt (not place itself), try buitins:
|
||||
if (lastParent != null) {
|
||||
final String fileName = getName();
|
||||
@@ -147,6 +152,20 @@ public class PyFileImpl extends PsiFileBase implements PyFile {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<PyFromImportStatement> getFromImports() {
|
||||
final List<PyFromImportStatement> result = new ArrayList<PyFromImportStatement>();
|
||||
accept(new PyRecursiveElementVisitor() {
|
||||
public void visitPyElement(final PyElement node) {
|
||||
super.visitPyElement(node);
|
||||
if (PyFromImportStatement.class.isInstance(node)) {
|
||||
//noinspection unchecked
|
||||
result.add((PyFromImportStatement)node);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> List<T> getTopLevelItems(final IElementType elementType, final Class itemClass) {
|
||||
final List<T> result = new ArrayList<T>();
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from channel import * # token must pass through
|
||||
print(token)
|
||||
# <ref>
|
||||
@@ -0,0 +1 @@
|
||||
from source import token # this re-exports token
|
||||
@@ -0,0 +1 @@
|
||||
token = 'Yes' # an exported name
|
||||
@@ -8,6 +8,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.PyTargetExpression;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -78,6 +79,11 @@ public class PyMultiFileResolveTest extends CodeInsightTestCase {
|
||||
assertTrue(element instanceof PyFunction);
|
||||
}
|
||||
|
||||
public void testTransitiveImport() throws Exception {
|
||||
PsiElement element = doResolve();
|
||||
assertTrue(element instanceof PyTargetExpression);
|
||||
}
|
||||
|
||||
private PsiElement doResolve() throws Exception {
|
||||
String testName = getTestName(true);
|
||||
String fileName = getTestName(false) + ".py";
|
||||
|
||||
Reference in New Issue
Block a user