@Nullable
  public static PsiClass getMainClass(PsiElement element) {
    while (element != null) {
      if (element instanceof PsiClass aClass) {
        if (PsiMethodUtil.hasMainInClass(aClass)) {
          return aClass;
        }
      }
      else if (element instanceof PsiJavaFile javaFile) {
        final PsiClass[] classes = javaFile.getClasses();
        for (PsiClass aClass : classes) {
          if (PsiMethodUtil.hasMainInClass(aClass)) {
            return aClass;
          }
        }
      }
      element = element.getParent();
    }
    return null;
  }
@Nullable
  public static PsiClass getMainClass(PsiElement element)