PsiElement () { final AbstractProjectViewPane viewPane = getCurrentProjectViewPane(); if (viewPane == null) { return null; } TreePath path = viewPane.getSelectedPath(); if (path == null) { return null; } path = path.getParentPath(); if (path == null) { return null; } ProjectViewNode<?> descriptor = TreeUtil.getLastUserObject(ProjectViewNode.class, path); if (descriptor != null) { Object element = descriptor.getValue(); if (element instanceof PsiElement psiElement) { if (!psiElement.isValid()) return null; return psiElement; } else { return null; } } return null; }