mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed references to qualified classes in docstring type annotations (PY-6022)
This commit is contained in:
@@ -78,7 +78,7 @@ public class DocStringTypeReference extends PsiReferenceBase<PsiElement> {
|
||||
}
|
||||
if (myType instanceof PyImportedModuleType) {
|
||||
final PyImportedModule module = ((PyImportedModuleType)myType).getImportedModule();
|
||||
return PyUtil.turnDirIntoInit(ResolveImportUtil.resolveModuleInRoots(module.getImportedPrefix(), module.getContainingFile()));
|
||||
return module.resolve();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -110,11 +110,16 @@ public class PyImportedModule extends LightElement implements NameDefiner {
|
||||
|
||||
@Nullable
|
||||
public PyFile resolve() {
|
||||
final PsiElement element;
|
||||
if (myImportElement != null) {
|
||||
final PsiElement result = PyUtil.turnDirIntoInit(ResolveImportUtil.resolveImportElement(myImportElement, myImportedPrefix));
|
||||
if (result instanceof PyFile) {
|
||||
return (PyFile)result;
|
||||
}
|
||||
element = ResolveImportUtil.resolveImportElement(myImportElement, myImportedPrefix);
|
||||
}
|
||||
else {
|
||||
element = ResolveImportUtil.resolveModuleInRoots(getImportedPrefix(), getContainingFile());
|
||||
}
|
||||
final PsiElement result = PyUtil.turnDirIntoInit(element);
|
||||
if (result instanceof PyFile) {
|
||||
return (PyFile)result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
import com.jetbrains.python.psi.impl.PyImportedModule;
|
||||
import com.jetbrains.python.psi.impl.PyQualifiedName;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.resolve.RatedResolveResult;
|
||||
import com.jetbrains.python.psi.stubs.PyClassNameIndex;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -184,15 +186,30 @@ public class PyTypeParser {
|
||||
if (CharMatcher.JAVA_LETTER_OR_DIGIT.or(CharMatcher.is('.')).or(CharMatcher.is('_')).matchesAllOf(type)) {
|
||||
final List<TextRange> ranges = splitRanges(type, ".");
|
||||
final TextRange classRange = !ranges.isEmpty() ? ranges.remove(ranges.size() - 1) : new TextRange(0, type.length());
|
||||
PyType moduleType = null;
|
||||
if (!ranges.isEmpty()) {
|
||||
final TextRange first = ranges.get(0);
|
||||
for (TextRange range : ranges) {
|
||||
final PyQualifiedName moduleName = PyQualifiedName.fromDottedString(first.union(range).substring(type));
|
||||
final PyType t = new PyImportedModuleType(new PyImportedModule(null, anchor.getContainingFile(), moduleName));
|
||||
types.put(range.shiftRight(offset), t);
|
||||
moduleType = new PyImportedModuleType(new PyImportedModule(null, anchor.getContainingFile(), moduleName));
|
||||
types.put(range.shiftRight(offset), moduleType);
|
||||
}
|
||||
}
|
||||
final String shortName = classRange.substring(type);
|
||||
if (moduleType != null) {
|
||||
final PyResolveContext context = PyResolveContext.defaultContext();
|
||||
final List<? extends RatedResolveResult> results = moduleType.resolveMember(shortName, null, AccessDirection.READ, context);
|
||||
if (results != null && !results.isEmpty()) {
|
||||
final RatedResolveResult result = results.get(0);
|
||||
final PsiElement resolved = result.getElement();
|
||||
if (resolved instanceof PyTypedElement) {
|
||||
final PyType t = ((PyTypedElement)resolved).getType(context.getTypeEvalContext());
|
||||
types.put(classRange.shiftRight(offset), t);
|
||||
fullRanges.put(t, whole);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
final Collection<PyClass> classes = PyClassNameIndex.find(shortName, anchor.getProject(), true);
|
||||
for (PyClass aClass : classes) {
|
||||
if (type.equals(aClass.getQualifiedName())) {
|
||||
|
||||
Reference in New Issue
Block a user