public static boolean validElement(@NotNull PsiElement element) {
    if (element instanceof PsiFile) return true;
    if (!element.isPhysical()) return false;
    RefactoringSupportProvider provider = LanguageRefactoringSupport.INSTANCE.forContext(element);
    return provider != null && provider.isSafeDeleteAvailable(element);
  }
public static boolean validElement(@NotNull PsiElement element)