package com.intellij.ide.impl.dataRules;

import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.psi.PsiElement;

public class PsiElementFromSelectionRule implements GetDataRule {
  public Object getData(DataProvider dataProvider) {
    final Object element = dataProvider.getData(DataConstants.SELECTED_ITEM);
    if (element instanceof PsiElement) {
      return element;
    }

    return null;
  }
}
@@ -417,24 +417,111 @@
 iElement) %7B%0A
+      PsiElement psiElement = (PsiElement)element;%0A      if (psiElement.isValid()) %7B%0A  
       return
@@ -526,24 +526,32 @@
 rn element;%0A
+      %7D%0A
     %7D%0A%0A    r

validate PSI element from selection (IDEADEV-33792)