summaryrefslogtreecommitdiff
path: root/python/src/com/jetbrains/python/psi/impl/PyStarImportElementImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/com/jetbrains/python/psi/impl/PyStarImportElementImpl.java')
-rw-r--r--python/src/com/jetbrains/python/psi/impl/PyStarImportElementImpl.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/python/src/com/jetbrains/python/psi/impl/PyStarImportElementImpl.java b/python/src/com/jetbrains/python/psi/impl/PyStarImportElementImpl.java
index 307ac8e22841..4011c233e38d 100644
--- a/python/src/com/jetbrains/python/psi/impl/PyStarImportElementImpl.java
+++ b/python/src/com/jetbrains/python/psi/impl/PyStarImportElementImpl.java
@@ -15,6 +15,8 @@
*/
package com.jetbrains.python.psi.impl;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import com.intellij.lang.ASTNode;
import com.intellij.navigation.ItemPresentation;
import com.intellij.psi.PsiElement;
@@ -50,7 +52,11 @@ public class PyStarImportElementImpl extends PyElementImpl implements PyStarImpo
for (PsiElement importedFile : new HashSet<PsiElement>(importedFiles)) { // resolver gives lots of duplicates
final PsiElement source = PyUtil.turnDirIntoInit(importedFile);
if (source instanceof PyFile) {
- chain.add(((PyFile) source).iterateNames());
+ Iterable<PyElement> declaredNames = ((PyFile)source).iterateNames();
+ if (((PyFile)source).getDunderAll() == null) {
+ declaredNames = excludeUnderscoredNames(declaredNames);
+ }
+ chain.add(declaredNames);
}
}
return chain;
@@ -58,6 +64,19 @@ public class PyStarImportElementImpl extends PyElementImpl implements PyStarImpo
return Collections.emptyList();
}
+ private static Iterable<PyElement> excludeUnderscoredNames(Iterable<PyElement> declaredNames) {
+ return Iterables.filter(declaredNames, new Predicate<PyElement>() {
+ @Override
+ public boolean apply(@Nullable PyElement input) {
+ final String name = input != null ? input.getName() : null;
+ if (name != null && name.startsWith("_")) {
+ return false;
+ }
+ return true;
+ }
+ });
+ }
+
@Nullable
public PsiElement getElementNamed(final String name) {
if (PyUtil.isClassPrivateName(name)) {
@@ -76,7 +95,7 @@ public class PyStarImportElementImpl extends PyElementImpl implements PyStarImpo
final PsiElement result = results != null && !results.isEmpty() ? results.get(0).getElement() : null;
if (result != null) {
final List<String> all = sourceFile.getDunderAll();
- if (all != null && !all.contains(name)) {
+ if (all != null ? !all.contains(name) : name.startsWith("_")) {
continue;
}
return result;