use of com.jetbrains.python.toolbox.Maybe in project intellij-community by JetBrains.
the class PyCallExpressionHelper method getSuperCallType.
@NotNull
private static Maybe<PyType> getSuperCallType(@NotNull PyCallExpression call, TypeEvalContext context) {
final PyExpression callee = call.getCallee();
if (callee instanceof PyReferenceExpression) {
PsiElement must_be_super_init = ((PyReferenceExpression) callee).getReference().resolve();
if (must_be_super_init instanceof PyFunction) {
PyClass must_be_super = ((PyFunction) must_be_super_init).getContainingClass();
if (must_be_super == PyBuiltinCache.getInstance(call).getClass(PyNames.SUPER)) {
final PyArgumentList argumentList = call.getArgumentList();
if (argumentList != null) {
final PyClass containingClass = PsiTreeUtil.getParentOfType(call, PyClass.class);
PyExpression[] args = argumentList.getArguments();
if (args.length > 1) {
PyExpression first_arg = args[0];
if (first_arg instanceof PyReferenceExpression) {
final PyReferenceExpression firstArgRef = (PyReferenceExpression) first_arg;
final PyExpression qualifier = firstArgRef.getQualifier();
if (qualifier != null && PyNames.__CLASS__.equals(firstArgRef.getReferencedName())) {
final PsiReference qRef = qualifier.getReference();
final PsiElement element = qRef == null ? null : qRef.resolve();
if (element instanceof PyParameter) {
final PyParameterList parameterList = PsiTreeUtil.getParentOfType(element, PyParameterList.class);
if (parameterList != null && element == parameterList.getParameters()[0]) {
return new Maybe<>(getSuperCallTypeForArguments(context, containingClass, args[1]));
}
}
}
PsiElement possible_class = firstArgRef.getReference().resolve();
if (possible_class instanceof PyClass && ((PyClass) possible_class).isNewStyleClass(context)) {
final PyClass first_class = (PyClass) possible_class;
return new Maybe<>(getSuperCallTypeForArguments(context, first_class, args[1]));
}
}
} else if ((call.getContainingFile() instanceof PyFile) && ((PyFile) call.getContainingFile()).getLanguageLevel().isPy3K() && (containingClass != null)) {
return new Maybe<>(getSuperClassUnionType(containingClass, context));
}
}
}
}
}
return new Maybe<>();
}
Aggregations