PsiElement (@NotNull AnActionEvent e) { PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT); if (element != null) { return element; } RefEntity[] entities = getSelectedRefElements(e); RefEntity refEntity = ContainerUtil.find(entities, entity -> entity instanceof RefElement); return refEntity != null ? ((RefElement)refEntity).getPsiElement() : null; }