mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
test fix: PyTypeParser is used instead of index search
You should never use index search in you have FQN of class or skeleton may be found. Use PyTypeParser instead
This commit is contained in:
@@ -18,7 +18,6 @@ package com.jetbrains.python.codeInsight;
|
||||
import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPolyVariantReference;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.Function;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
@@ -170,8 +169,11 @@ public class PyCustomMember {
|
||||
if (myTarget != null) {
|
||||
return myTarget;
|
||||
}
|
||||
PyClass targetClass =
|
||||
myTypeName != null && myTypeName.indexOf('.') > 0 ? PyPsiFacade.getInstance(context.getProject()).findClass(myTypeName) : null;
|
||||
|
||||
PyClass targetClass = null;
|
||||
if (myTypeName != null && myTypeName.indexOf('.') > 0) {
|
||||
targetClass = PyPsiFacade.getInstance(context.getProject()).createClassByQName(myTypeName, context);
|
||||
}
|
||||
final PsiElement resolveTarget = findResolveTarget(context);
|
||||
if (resolveTarget instanceof PyFunction && !myAlwaysResolveToCustomElement) {
|
||||
return resolveTarget;
|
||||
|
||||
@@ -39,6 +39,10 @@ public abstract class PyPsiFacade {
|
||||
public abstract QualifiedNameResolver qualifiedNameResolver(String qNameString);
|
||||
public abstract QualifiedNameResolver qualifiedNameResolver(QualifiedName qualifiedName);
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #createClassByQName(String, PsiElement)} or skeleton may be found
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public abstract PyClass findClass(String qName);
|
||||
|
||||
@@ -54,6 +58,9 @@ public abstract class PyPsiFacade {
|
||||
@Nullable
|
||||
public abstract PyType parseTypeAnnotation(@NotNull String annotation, @NotNull PsiElement anchor);
|
||||
|
||||
@Nullable
|
||||
public abstract PyClass createClassByQName(@NotNull String qName, @NotNull PsiElement anchor);
|
||||
|
||||
@Nullable
|
||||
public abstract String findShortestImportableName(@NotNull VirtualFile targetFile, @NotNull PsiElement anchor);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyPsiFacade;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import com.jetbrains.python.psi.resolve.QualifiedNameFinder;
|
||||
import com.jetbrains.python.psi.resolve.QualifiedNameResolver;
|
||||
import com.jetbrains.python.psi.resolve.QualifiedNameResolverImpl;
|
||||
@@ -81,6 +82,13 @@ public class PyPsiFacadeImpl extends PyPsiFacade {
|
||||
return PyTypeParser.getTypeByName(anchor, annotation);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public final PyClass createClassByQName(@NotNull final String qName, @NotNull final PsiElement anchor) {
|
||||
final PyClassType classType = PyUtil.as(parseTypeAnnotation(qName, anchor), PyClassType.class);
|
||||
return (classType != null ? classType.getPyClass() : null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String findShortestImportableName(@NotNull VirtualFile targetFile, @NotNull PsiElement anchor) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.jetbrains.python.psi.stubs;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||
@@ -52,6 +53,10 @@ public class PyClassNameIndex extends StringStubIndexExtension<PyClass> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use {@link com.jetbrains.python.psi.PyPsiFacade#createClassByQName(String, PsiElement)} or skeleton may be found
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public static PyClass findClass(@NotNull String qName, Project project, GlobalSearchScope scope) {
|
||||
int pos = qName.lastIndexOf(".");
|
||||
@@ -64,6 +69,10 @@ public class PyClassNameIndex extends StringStubIndexExtension<PyClass> {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link com.jetbrains.python.psi.PyPsiFacade#createClassByQName(String, PsiElement)} or skeleton may be found
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public static PyClass findClass(@Nullable String qName, Project project) {
|
||||
if (qName == null) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.codeInsight.completion.CompletionUtil;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -41,7 +40,6 @@ import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
import com.jetbrains.python.psi.impl.PyResolveResultRater;
|
||||
import com.jetbrains.python.psi.impl.ResolveResultList;
|
||||
import com.jetbrains.python.psi.resolve.*;
|
||||
import com.jetbrains.python.psi.stubs.PyClassNameIndex;
|
||||
import com.jetbrains.python.toolbox.Maybe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -649,8 +647,10 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PyClassTypeImpl createTypeByQName(@NotNull Project project, String classQualifiedName, boolean isDefinition) {
|
||||
PyClass pyClass = PyClassNameIndex.findClass(classQualifiedName, project);
|
||||
public static PyClassTypeImpl createTypeByQName(@NotNull final PsiElement anchor,
|
||||
@NotNull final String classQualifiedName,
|
||||
final boolean isDefinition) {
|
||||
final PyClass pyClass = PyPsiFacade.getInstance(anchor.getProject()).createClassByQName(classQualifiedName, anchor);
|
||||
if (pyClass == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.stubs.PyClassNameIndex;
|
||||
import com.jetbrains.python.psi.PyPsiFacade;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -41,9 +41,11 @@ public class PyCollectionTypeImpl extends PyClassTypeImpl implements PyCollectio
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PyCollectionTypeImpl createTypeByQName(@NotNull Project project, String classQualifiedName, boolean isDefinition,
|
||||
@NotNull List<PyType> elementTypes) {
|
||||
final PyClass pyClass = PyClassNameIndex.findClass(classQualifiedName, project);
|
||||
public static PyCollectionTypeImpl createTypeByQName(@NotNull final PsiElement anchor,
|
||||
@NotNull final String classQualifiedName,
|
||||
final boolean isDefinition,
|
||||
@NotNull final List<PyType> elementTypes) {
|
||||
final PyClass pyClass = PyPsiFacade.getInstance(anchor.getProject()).createClassByQName(classQualifiedName, anchor);
|
||||
if (pyClass == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -109,11 +109,17 @@ public class PyTypeParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param anchor should never be null or null will be returned
|
||||
*/
|
||||
@Nullable
|
||||
public static PyType getTypeByName(@Nullable final PsiElement anchor, @NotNull String type) {
|
||||
return parse(anchor, type).getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param anchor should never be null or null will be returned
|
||||
*/
|
||||
@NotNull
|
||||
public static ParseResult parse(@Nullable final PsiElement anchor, @NotNull String type) {
|
||||
if (anchor == null || !anchor.isValid()) {
|
||||
|
||||
Reference in New Issue
Block a user