private static List<PsiElement> getClosures(@NotNull PsiClass nestedClass) {
    List<PsiElement> closures = new ArrayList<>();
    closures.add(nestedClass); // process fields and initializers
    for (PsiMethod method : nestedClass.getMethods()) {
      PsiCodeBlock body = method.getBody();
      if (body != null && (method.isPhysical() || !nestedClass.isPhysical())) {
        // Skip analysis of non-physical methods of physical class (possibly autogenerated by some plugin like Lombok)
        closures.add(body);
      }
    }
    return closures;
  }
private static List<PsiElement> getClosures(@NotNull PsiClass nestedClass)