PsiElement (@NotNull PsiElement context, @NotNull PyResolveContext resolveContext) { final PsiElement parent = myParent.resolve(context, resolveContext); if (parent == null) { return null; } if (parent instanceof PyFile) { return ((PyFile) parent).findTopLevelFunction(myFunctionName); } if (parent instanceof PyClass) { return ((PyClass) parent).findMethodByName(myFunctionName, false, resolveContext.getTypeEvalContext()); } if (resolveContext.getTypeEvalContext().maySwitchToAST(parent)) { for (PsiElement element : parent.getChildren()) { if (element instanceof PyFunction && myFunctionName.equals(((PyFunction)element).getName())) { return element; } } } return parent; }