public class MouseClickAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent e) {
PsiClass psiClass=getPsiClassFromContext(e);
new ToStringGenerator(psiClass).execute();
}
private PsiClass getPsiClassFromContext(AnActionEvent e) {
PsiFile psiFile= e.getData(LangDataKeys.PSI_FILE);
Editor editor= e.getData(PlatformDataKeys.EDITOR);
if(psiFile==null||editor==null){
e.getPresentation().setEnabled(false);
return null;
}
int offset=editor.getCaretModel().getOffset();
PsiElement elementAt=psiFile.findElementAt(offset);
PsiClass psiClass= PsiTreeUtil.getParentOfType(elementAt,PsiClass.class);
return psiClass;
}
}