diff --git a/python/psi-api/src/com/jetbrains/python/psi/PyImportElement.java b/python/psi-api/src/com/jetbrains/python/psi/PyImportElement.java index d53f5f2f93a9..b0ba10eced94 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/PyImportElement.java +++ b/python/psi-api/src/com/jetbrains/python/psi/PyImportElement.java @@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable; /** * @author yole */ -public interface PyImportElement extends PyElement, NameDefiner, StubBasedPsiElement { +public interface PyImportElement extends PyElement, PyImportedNameDefiner, StubBasedPsiElement { @Nullable PyReferenceExpression getImportReferenceExpression(); diff --git a/python/psi-api/src/com/jetbrains/python/psi/PyImportedNameDefiner.java b/python/psi-api/src/com/jetbrains/python/psi/PyImportedNameDefiner.java new file mode 100644 index 000000000000..8081d0fd38d9 --- /dev/null +++ b/python/psi-api/src/com/jetbrains/python/psi/PyImportedNameDefiner.java @@ -0,0 +1,9 @@ +package com.jetbrains.python.psi; + +/** + * Name definer that defines names imported somehow from other modules. + * + * @author vlan + */ +public interface PyImportedNameDefiner extends NameDefiner { +} diff --git a/python/psi-api/src/com/jetbrains/python/psi/PyStarImportElement.java b/python/psi-api/src/com/jetbrains/python/psi/PyStarImportElement.java index 1f91048da631..1a00a21c17d9 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/PyStarImportElement.java +++ b/python/psi-api/src/com/jetbrains/python/psi/PyStarImportElement.java @@ -5,5 +5,5 @@ package com.jetbrains.python.psi; * User: dcheryasov * Date: Jul 28, 2008 */ -public interface PyStarImportElement extends PyElement, NameDefiner { +public interface PyStarImportElement extends PyElement, PyImportedNameDefiner { } diff --git a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/Scope.java b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/Scope.java index d4aeb3f752c8..4882c509e157 100644 --- a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/Scope.java +++ b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/Scope.java @@ -3,7 +3,7 @@ package com.jetbrains.python.codeInsight.dataflow.scope; import com.intellij.codeInsight.dataflow.DFALimitExceededException; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNamedElement; -import com.jetbrains.python.psi.NameDefiner; +import com.jetbrains.python.psi.PyImportedNameDefiner; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +27,7 @@ public interface Scope { boolean containsDeclaration(String name); @NotNull - List getNameDefiners(); + List getImportedNameDefiners(); @Nullable PsiNamedElement getNamedElement(String name); diff --git a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java index 68ce31d527be..ab86fac9b9bb 100644 --- a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java +++ b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java @@ -6,7 +6,6 @@ import com.intellij.codeInsight.dataflow.map.DFAMap; import com.intellij.codeInsight.dataflow.map.DFAMapEngine; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNamedElement; -import com.jetbrains.cython.psi.CythonIncludeStatement; import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.codeInsight.dataflow.PyReachingDefsDfaInstance; @@ -31,7 +30,7 @@ public class ScopeImpl implements Scope { private volatile List myNestedScopes; private final ScopeOwner myFlowOwner; private volatile Map myNamedElements; - private volatile List myNameDefiners; // declarations which declare unknown set of names, such as 'from ... import *' + private volatile List myImportedNameDefiners; // Declarations which declare unknown set of imported names private volatile Set myAugAssignments; public ScopeImpl(final ScopeOwner flowOwner) { @@ -97,7 +96,7 @@ public class ScopeImpl implements Scope { } public boolean containsDeclaration(final String name) { - if (myNamedElements == null || myNameDefiners == null) { + if (myNamedElements == null || myImportedNameDefiners == null) { collectDeclarations(); } if (isNonlocal(name)) { @@ -109,7 +108,7 @@ public class ScopeImpl implements Scope { if (isAugAssignment(name)) { return true; } - for (NameDefiner definer : getNameDefiners()) { + for (NameDefiner definer : getImportedNameDefiners()) { if (definer.getElementNamed(name) != null) { return true; } @@ -119,11 +118,11 @@ public class ScopeImpl implements Scope { @NotNull @Override - public List getNameDefiners() { - if (myNameDefiners == null) { + public List getImportedNameDefiners() { + if (myImportedNameDefiners == null) { collectDeclarations(); } - return myNameDefiners; + return myImportedNameDefiners; } @Nullable @@ -158,7 +157,7 @@ public class ScopeImpl implements Scope { private void collectDeclarations() { final Map namedElements = new HashMap(); - final List nameDefiners = new ArrayList(); + final List importedNameDefiners = new ArrayList(); final List nestedScopes = new ArrayList(); final Set globals = new HashSet(); final Set nonlocals = new HashSet(); @@ -214,9 +213,8 @@ public class ScopeImpl implements Scope { if (node instanceof PsiNamedElement && !(node instanceof PyKeywordArgument)) { namedElements.put(node.getName(), (PsiNamedElement)node); } - // TODO: Cython-specific code - if (node instanceof PyStarImportElement || node instanceof PyImportElement || node instanceof CythonIncludeStatement) { - nameDefiners.add((NameDefiner)node); + if (node instanceof PyImportedNameDefiner) { + importedNameDefiners.add((PyImportedNameDefiner)node); } if (node instanceof ScopeOwner) { final Scope scope = ControlFlowCache.getScope((ScopeOwner)node); @@ -228,7 +226,7 @@ public class ScopeImpl implements Scope { } }); - Collections.sort(nameDefiners, new Comparator() { + Collections.sort(importedNameDefiners, new Comparator() { @Override public int compare(NameDefiner d1, NameDefiner d2) { return getPriority(d2) - getPriority(d1); @@ -243,7 +241,7 @@ public class ScopeImpl implements Scope { }); myNamedElements = namedElements; - myNameDefiners = nameDefiners; + myImportedNameDefiners = importedNameDefiners; myNestedScopes = nestedScopes; myGlobals = globals; myNonlocals = nonlocals; diff --git a/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java b/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java index c39173f7a531..3d490f57d71f 100644 --- a/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java +++ b/python/src/com/jetbrains/python/psi/resolve/PyResolveUtil.java @@ -125,7 +125,7 @@ public class PyResolveUtil { } } } - for (NameDefiner definer : scope.getNameDefiners()) { + for (NameDefiner definer : scope.getImportedNameDefiners()) { if (!processor.execute(definer, ResolveState.initial())) { found = true; break;