List<PsiMethod> (@NotNull PsiMethod nearest) { List<PsiMethod> enclosingMethods = new ArrayList<>(); enclosingMethods.add(nearest); PsiMethod method = nearest; while(true) { method = PsiTreeUtil.getParentOfType(method, PsiMethod.class, true); if (method == null) break; enclosingMethods.add(method); } if (enclosingMethods.size() > 1) { List<PsiMethod> methodsNotImplementingLibraryInterfaces = new ArrayList<>(); for(PsiMethod enclosing: enclosingMethods) { PsiMethod[] superMethods = enclosing.findDeepestSuperMethods(); boolean libraryInterfaceMethod = false; for(PsiMethod superMethod: superMethods) { libraryInterfaceMethod |= isLibraryInterfaceMethod(superMethod); } if (!libraryInterfaceMethod) { methodsNotImplementingLibraryInterfaces.add(enclosing); } } if (!methodsNotImplementingLibraryInterfaces.isEmpty()) { return methodsNotImplementingLibraryInterfaces; } } return enclosingMethods; }