PyFunction (PsiElement element, HashSet<PsiElement> visited) { if (visited.contains(element)) { return null; } visited.add(element); if (element instanceof PyFunction) { return (PyFunction)element; } if (element instanceof PyTargetExpression) { final PyExpression assignedValue = ((PyTargetExpression)element).findAssignedValue(); return resolveToFunction(assignedValue, visited); } if (element instanceof PyReferenceExpression) { final PsiElement resolveResult = ((PyReferenceExpression)element).getReference().resolve(); return resolveToFunction(resolveResult, visited); } return null; }