mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Added TypeEvalContext.codeInsightFallback() constructor
This commit is contained in:
@@ -56,7 +56,7 @@ public class PyResolveContext {
|
||||
}
|
||||
|
||||
public TypeEvalContext getTypeEvalContext() {
|
||||
return myTypeEvalContext != null ? myTypeEvalContext : TypeEvalContext.fastStubOnly(null);
|
||||
return myTypeEvalContext != null ? myTypeEvalContext : TypeEvalContext.codeInsightFallback();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,7 +54,7 @@ public class TypeEvalContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* The most detailed type evaluation context for user-initiated actions.
|
||||
* Create the most detailed type evaluation context for user-initiated actions.
|
||||
*
|
||||
* Should be used for code completion, go to definition, find usages, refactorings, documentation.
|
||||
*/
|
||||
@@ -62,20 +62,31 @@ public class TypeEvalContext {
|
||||
return new TypeEvalContext(true, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a type evaluation context for deeper and slower code analysis.
|
||||
*
|
||||
* Should be used only when normal analysis context is not enough for getting good results.
|
||||
*/
|
||||
public static TypeEvalContext fast() {
|
||||
return new TypeEvalContext(false, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TypeEvalContext for performing analysis operations on the specified file which is currently open in the editor,
|
||||
* Create a type evaluation context for performing analysis operations on the specified file which is currently open in the editor,
|
||||
* without accessing stubs. For such a file, additional slow operations are allowed.
|
||||
*
|
||||
* @param origin the file open in the editor
|
||||
* @return the type eval context for the file.
|
||||
*/
|
||||
public static TypeEvalContext fastStubOnly(@Nullable PsiFile origin) {
|
||||
return new TypeEvalContext(false, false, origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the most shallow type evaluation context for code insight purposes when other more detailed contexts are not available.
|
||||
*
|
||||
* It's use should be minimized.
|
||||
*/
|
||||
public static TypeEvalContext codeInsightFallback() {
|
||||
return new TypeEvalContext(false, false, null);
|
||||
}
|
||||
|
||||
public TypeEvalContext withTracing() {
|
||||
if (myTrace == null) {
|
||||
|
||||
@@ -618,7 +618,7 @@ public class PyUtil {
|
||||
}
|
||||
|
||||
public static boolean hasUnresolvedAncestors(@NotNull PyClass cls) {
|
||||
for (PyClassLikeType type : cls.getAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : cls.getAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type == null) {
|
||||
return true;
|
||||
}
|
||||
@@ -968,7 +968,7 @@ public class PyUtil {
|
||||
if (isBaseException(pyClass.getQualifiedName())) {
|
||||
return true;
|
||||
}
|
||||
for (PyClassLikeType type : pyClass.getAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : pyClass.getAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type != null && isBaseException(type.getClassQName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping {
|
||||
@Nullable TypeEvalContext type_context
|
||||
) {
|
||||
PyExpression[] arguments = myArgumentList.getArguments();
|
||||
if (type_context == null) type_context = TypeEvalContext.fastStubOnly(null);
|
||||
if (type_context == null) type_context = TypeEvalContext.codeInsightFallback();
|
||||
myMarkedCallee = resolved_callee;
|
||||
List<PyExpression> unmatched_args = new LinkedList<PyExpression>();
|
||||
Collections.addAll(unmatched_args, arguments);
|
||||
|
||||
@@ -329,7 +329,7 @@ public class PyBuiltinCache {
|
||||
|
||||
private static boolean isValid(@Nullable PyType type) {
|
||||
if (type instanceof PyCollectionType) {
|
||||
final PyType elementType = ((PyCollectionType)type).getElementType(TypeEvalContext.fastStubOnly(null));
|
||||
final PyType elementType = ((PyCollectionType)type).getElementType(TypeEvalContext.codeInsightFallback());
|
||||
if (!isValid(elementType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
@Nullable
|
||||
@Override
|
||||
public Result<List<PyClassLikeType>> compute() {
|
||||
final TypeEvalContext context = myCachedContext != null ? myCachedContext : TypeEvalContext.fastStubOnly(null);
|
||||
final TypeEvalContext context = myCachedContext != null ? myCachedContext : TypeEvalContext.codeInsightFallback();
|
||||
final List<PyClassLikeType> ancestorTypes = isNewStyleClass() ? getMROAncestorTypes(context) : getOldStyleAncestorTypes(context);
|
||||
return Result.create(ancestorTypes, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
@NotNull
|
||||
@Override
|
||||
public List<PyClass> getAncestorClasses() {
|
||||
return getAncestorClasses(TypeEvalContext.fastStubOnly(null));
|
||||
return getAncestorClasses(TypeEvalContext.codeInsightFallback());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -224,7 +224,7 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
if (superClassQName.equals(getQualifiedName())) {
|
||||
return true;
|
||||
}
|
||||
for (PyClassLikeType type : getAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : getAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type != null && superClassQName.equals(type.getClassQName())) {
|
||||
return true;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
|
||||
@NotNull
|
||||
public PyClass[] getSuperClasses() {
|
||||
final List<PyClassLikeType> superTypes = getSuperClassTypes(TypeEvalContext.fastStubOnly(null));
|
||||
final List<PyClassLikeType> superTypes = getSuperClassTypes(TypeEvalContext.codeInsightFallback());
|
||||
if (superTypes.isEmpty()) {
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
@@ -925,7 +925,7 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
final PyClass objClass = PyBuiltinCache.getInstance(this).getClass("object");
|
||||
if (this == objClass) return true; // a rare but possible case
|
||||
if (hasNewStyleMetaClass(this)) return true;
|
||||
for (PyClassLikeType type : getOldStyleAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : getOldStyleAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type == null) {
|
||||
// unknown, assume new-style class
|
||||
return true;
|
||||
|
||||
@@ -451,7 +451,7 @@ public class PyTargetExpressionImpl extends PyPresentableElementImpl<PyTargetExp
|
||||
return ((PyFile)parent).getElementNamed(name);
|
||||
}
|
||||
else if (parent instanceof PyClass) {
|
||||
final PyType type = TypeEvalContext.fastStubOnly(null).getType((PyClass)parent);
|
||||
final PyType type = TypeEvalContext.codeInsightFallback().getType((PyClass)parent);
|
||||
if (type != null) {
|
||||
final List<? extends RatedResolveResult> results = type.resolveMember(name, null, AccessDirection.READ,
|
||||
PyResolveContext.noImplicits());
|
||||
|
||||
@@ -271,7 +271,7 @@ public class ResolveImportUtil {
|
||||
dir = (PsiDirectory)parent;
|
||||
}
|
||||
else if (parent != null) {
|
||||
PyType refType = PyReferenceExpressionImpl.getReferenceTypeFromProviders(parent, TypeEvalContext.fastStubOnly(null), null);
|
||||
PyType refType = PyReferenceExpressionImpl.getReferenceTypeFromProviders(parent, TypeEvalContext.codeInsightFallback(), null);
|
||||
if (refType != null) {
|
||||
final List<? extends RatedResolveResult> result = refType.resolveMember(referencedName, null, AccessDirection.READ,
|
||||
PyResolveContext.defaultContext());
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PythonUnitTestUtil {
|
||||
}
|
||||
|
||||
private static boolean isUnitTestCaseClass(PyClass cls, HashSet<String> testQualifiedNames) {
|
||||
for (PyClassLikeType type : cls.getAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : cls.getAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type != null && testQualifiedNames.contains(type.getClassQName())) {
|
||||
return true;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class PythonUnitTestUtil {
|
||||
}
|
||||
|
||||
public static boolean isTestCaseClass(@NotNull PyClass cls, Set<String> testQualifiedNames) {
|
||||
for (PyClassLikeType type : cls.getAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : cls.getAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type != null) {
|
||||
if (testQualifiedNames.contains(type.getClassQName())) {
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class PythonAtTestConfigurationProducer extends
|
||||
|
||||
protected boolean isTestClass(PyClass pyClass) {
|
||||
if (pyClass == null) return false;
|
||||
for (PyClassLikeType type : pyClass.getAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : pyClass.getAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type != null && "TestBase".equals(type.getName()) && hasTestFunction(pyClass)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PyTestUtil {
|
||||
}
|
||||
|
||||
public static boolean isPyTestClass(PyClass pyClass) {
|
||||
for (PyClassLikeType type : pyClass.getAncestorTypes(TypeEvalContext.fastStubOnly(null))) {
|
||||
for (PyClassLikeType type : pyClass.getAncestorTypes(TypeEvalContext.codeInsightFallback())) {
|
||||
if (type != null && PYTHON_TEST_QUALIFIED_CLASSES.contains(type.getClassQName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PyClassMROTest extends PyTestCase {
|
||||
}
|
||||
|
||||
public void assertMRO(@NotNull PyClass cls, @NotNull String... mro) {
|
||||
final List<PyClassLikeType> types = cls.getAncestorTypes(TypeEvalContext.fastStubOnly(null));
|
||||
final List<PyClassLikeType> types = cls.getAncestorTypes(TypeEvalContext.codeInsightFallback());
|
||||
final List<String> classNames = new ArrayList<String>();
|
||||
for (PyClassLikeType type : types) {
|
||||
if (type != null) {
|
||||
|
||||
Reference in New Issue
Block a user