mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'python-fixes'
This commit is contained in:
@@ -15,16 +15,17 @@
|
||||
*/
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.AccessDirection;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyImportedModule;
|
||||
import com.jetbrains.python.psi.resolve.PointInImport;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
@@ -36,6 +37,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -57,6 +59,20 @@ public class PyImportedModuleType implements PyType {
|
||||
if (resolved != null) {
|
||||
final PsiFile containingFile = location != null ? location.getContainingFile() : null;
|
||||
List<PsiElement> elements = Collections.singletonList(ResolveImportUtil.resolveChild(resolved, name, containingFile, false, true));
|
||||
final PyImportElement importElement = myImportedModule.getImportElement();
|
||||
if (location != null && importElement != null && PyUtil.inSameFile(location, importElement) &&
|
||||
ResolveImportUtil.getPointInImport(location) == PointInImport.NONE && resolved instanceof PsiFileSystemItem) {
|
||||
final List<PsiElement> importedSubmodules = PyModuleType.collectImportedSubmodules((PsiFileSystemItem)resolved, location);
|
||||
if (importedSubmodules != null) {
|
||||
final Set<PsiElement> imported = Sets.newHashSet(importedSubmodules);
|
||||
elements = ContainerUtil.filter(elements, new Condition<PsiElement>() {
|
||||
@Override
|
||||
public boolean value(PsiElement element) {
|
||||
return imported.contains(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return ResolveImportUtil.rateResults(elements);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -388,7 +388,8 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
|
||||
@NotNull PsiElement location,
|
||||
@Nullable final Set<String> existingNames) {
|
||||
|
||||
return ContainerUtil.mapNotNull(collectImportedSubmodules(pyPackage, location),
|
||||
final List<PsiElement> elements = collectImportedSubmodules(pyPackage, location);
|
||||
return elements != null ? ContainerUtil.mapNotNull(elements,
|
||||
new Function<PsiElement, LookupElement>() {
|
||||
@Override
|
||||
public LookupElement fun(PsiElement element) {
|
||||
@@ -400,10 +401,10 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}) : Collections.<LookupElement>emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public static List<PsiElement> collectImportedSubmodules(@NotNull PsiFileSystemItem pyPackage, @NotNull PsiElement location) {
|
||||
final PsiElement parentAnchor;
|
||||
if (pyPackage instanceof PyFile && PyUtil.isPackage(((PyFile)pyPackage))) {
|
||||
@@ -413,7 +414,7 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
|
||||
parentAnchor = pyPackage;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Package argument should be either standard Python package or namespace package");
|
||||
return null;
|
||||
}
|
||||
|
||||
final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(location);
|
||||
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
import pkg1.m1
|
||||
|
||||
print(pkg1.m2)
|
||||
print(pkg1.<warning descr="Cannot find reference 'nonexistent' in 'imported module pkg1'">nonexistent</warning>)
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
import pkg1.m2
|
||||
-1
@@ -1 +0,0 @@
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import nspkg1.m2
|
||||
|
||||
print(nspkg1.m2)
|
||||
print(nspkg1.<warning descr="Cannot find reference 'm3' in 'imported module nspkg1'">m3</warning>)
|
||||
print(nspkg1.<warning descr="Cannot find reference 'nssubpkg1' in 'imported module nspkg1'">nssubpkg1</warning>)
|
||||
@@ -0,0 +1 @@
|
||||
a1 = 42
|
||||
@@ -0,0 +1 @@
|
||||
a2 = -1
|
||||
@@ -0,0 +1,3 @@
|
||||
import p1.m1
|
||||
|
||||
print(p1.<warning descr="Cannot find reference 'm2' in 'imported module p1'">m2</warning>.a2)
|
||||
+5
@@ -112,6 +112,11 @@ public class Py3UnresolvedReferencesInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-14385
|
||||
public void testNotImportedSubmodulesOfNamespacePackage() {
|
||||
doMultiFileTest("main.py");
|
||||
}
|
||||
|
||||
// PY-15017
|
||||
public void testClassLevelReferenceInMethodAnnotation() {
|
||||
doTest();
|
||||
|
||||
+1
-4
@@ -510,10 +510,7 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-14615
|
||||
public void testImplicitlyImportedSubModule() {
|
||||
doMultiFileTest();
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -38,6 +38,11 @@ public class PyUnusedImportTest extends PyTestCase {
|
||||
doTest("test1.py");
|
||||
}
|
||||
|
||||
// PY-5621
|
||||
public void testUnusedSubmodule() {
|
||||
doTest("test1.py");
|
||||
}
|
||||
|
||||
// PY-6380
|
||||
public void testUnusedAfterStarImport() {
|
||||
doTest("test1.py");
|
||||
|
||||
Reference in New Issue
Block a user