public static PsiElement findTargetContainer(PsiClass anonOrLocalClass) {
    PsiElement parent = anonOrLocalClass.getParent();
    while (true) {
      if (parent instanceof PsiClass && !(parent instanceof PsiAnonymousClass)) {
        return parent;
      }
      if (parent instanceof PsiFile) {
        return parent;
      }
      parent = parent.getParent();
    }
  }
public static PsiElement findTargetContainer(PsiClass anonOrLocalClass)