public static boolean isValidTarget(PsiElement psiElement) {
    if (psiElement == null) return true;
    if (!(psiElement instanceof PsiDirectory || psiElement instanceof PsiDirectoryContainer)) return false;
    if (psiElement.getManager().isInProject(psiElement)) return true;
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
    return ScratchUtil.isScratch(virtualFile) ||
           virtualFile != null && ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex().isExcluded(virtualFile);
  }
public static boolean isValidTarget(PsiElement psiElement)