Transitive resolution (when an imported name is re-exported).

This commit is contained in:
Dmitry Cheryasov
2008-05-23 17:07:37 +04:00
parent efbc5c7b4e
commit 4acc786242
5 changed files with 30 additions and 0 deletions
@@ -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";