private static @Nullable PsiClass getSubjectClass(Editor editor, final PsiFile file) {
        if (file == null) return null;

        int offset = editor.getCaretModel().getOffset();
        PsiElement context = file.findElementAt(offset);

        PsiClass clazz = PsiTreeUtil.getParentOfType(context, PsiClass.class, false);
        if (clazz == null) {
          if (file instanceof PsiJavaFile javaFile && javaFile.getClasses().length == 1 &&
              javaFile.getClasses()[0] instanceof PsiImplicitClass implicitClass &&
              implicitClass.getFirstChild() != null && PsiMethodUtil.hasMainMethod(implicitClass)) {
            clazz = implicitClass;
          }
          else {
            return null;
          }
        }

        //exclude interfaces, non-java classes etc
        for (GenerateToStringClassFilter filter : GenerateToStringClassFilter.EP_NAME.getExtensionList()) {
            if (!filter.canGenerateToString(clazz)) return null;
        }
        return clazz;
    }
private static @Nullable PsiClass getSubjectClass(Editor editor, final PsiFile file)