boolean (PsiDirectory directory) { PsiDirectory targetDirectory = myNestedDirsToMove.get(directory).getTargetDirectory(); //don't delete super directory if move was performed inside subpackage if (targetDirectory != null && PsiTreeUtil.isAncestor(directory, targetDirectory, false)) { return true; } //don't delete subdirectory: something could be moved in there if (PsiTreeUtil.isAncestor(targetDirectory, directory, false)) { return true; } return false; }