use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyImportReference method getVariants.
@NotNull
@Override
public Object[] getVariants() {
// no completion in invalid import statements
PyImportElement importElement = PsiTreeUtil.getParentOfType(myElement, PyImportElement.class);
if (importElement != null) {
PsiErrorElement prevError = PsiTreeUtil.getPrevSiblingOfType(importElement, PsiErrorElement.class);
if (prevError != null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
}
PyExpression qualifier = myElement.getQualifier();
final TypeEvalContext context = TypeEvalContext.codeCompletion(myElement.getProject(), CompletionUtil.getOriginalOrSelf(myElement).getContainingFile());
if (qualifier != null) {
// qualifier's type must be module, it should know how to complete
PyType type = context.getType(qualifier);
if (type != null) {
Object[] variants = getTypeCompletionVariants(myElement, type);
if (!alreadyHasImportKeyword()) {
replaceInsertHandler(variants, ImportKeywordHandler.INSTANCE);
}
return variants;
} else {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
} else {
// complete to possible modules
return new ImportVariantCollector(context).execute();
}
}
use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyOperatorReference method resolveLeftAndRightOperators.
private void resolveLeftAndRightOperators(List<RatedResolveResult> res, PyBinaryExpression expr, String name) {
final TypeEvalContext typeEvalContext = myContext.getTypeEvalContext();
typeEvalContext.trace("Trying to resolve left operator");
typeEvalContext.traceIndent();
try {
res.addAll(resolveMember(expr.getLeftExpression(), name));
} finally {
typeEvalContext.traceUnindent();
}
typeEvalContext.trace("Trying to resolve right operator");
typeEvalContext.traceIndent();
try {
res.addAll(resolveMember(expr.getRightExpression(), leftToRightOperatorName(name)));
} finally {
typeEvalContext.traceUnindent();
}
}
use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyResolveCalleeTest method resolveCallee.
@NotNull
private PyCallExpression.PyMarkedCallee resolveCallee() {
final PsiReference ref = myFixture.getReferenceAtCaretPosition("/resolve/callee/" + getTestName(false) + ".py");
final PyCallExpression call = PsiTreeUtil.getParentOfType(ref.getElement(), PyCallExpression.class);
final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile());
final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
final List<PyCallExpression.PyMarkedCallee> callees = call.multiResolveCallee(resolveContext);
assertEquals(1, callees.size());
return callees.get(0);
}
use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyPackageUtil method resolveRequiresValue.
@Nullable
private static PyListLiteralExpression resolveRequiresValue(@NotNull Module module, @Nullable PyExpression requires) {
if (requires instanceof PyListLiteralExpression) {
return (PyListLiteralExpression) requires;
}
if (requires instanceof PyReferenceExpression) {
final TypeEvalContext context = TypeEvalContext.deepCodeInsight(module.getProject());
final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
final QualifiedResolveResult result = ((PyReferenceExpression) requires).followAssignmentsChain(resolveContext);
final PsiElement element = result.getElement();
if (element instanceof PyListLiteralExpression) {
return (PyListLiteralExpression) element;
}
}
return null;
}
use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyMoveSymbolDelegate method isSuitableInstanceMethod.
private static boolean isSuitableInstanceMethod(@Nullable PsiElement element) {
final PyFunction function = as(element, PyFunction.class);
if (function == null || function.getContainingClass() == null) {
return false;
}
final String funcName = function.getName();
if (funcName == null || PyUtil.isSpecialName(funcName)) {
return false;
}
final TypeEvalContext typeEvalContext = TypeEvalContext.userInitiated(function.getProject(), function.getContainingFile());
if (PySuperMethodsSearch.search(function, typeEvalContext).findFirst() != null)
return false;
if (PyOverridingMethodsSearch.search(function, true).findFirst() != null)
return false;
if (function.getDecoratorList() != null || function.getModifier() != null)
return false;
if (function.getContainingClass().findPropertyByCallable(function) != null)
return false;
return true;
}
Aggregations