PsiClass (Editor editor, final PsiFile file) { if (file == null) return null; int offset = editor.getCaretModel().getOffset(); PsiElement context = file.findElementAt(offset); if (context == null) return null; PsiClass clazz = PsiTreeUtil.getParentOfType(context, PsiClass.class, false); if (clazz == null) { return null; } //exclude interfaces, non-java classes etc for (GenerateToStringClassFilter filter : GenerateToStringClassFilter.EP_NAME.getExtensionList()) { if (!filter.canGenerateToString(clazz)) return null; } return clazz; }