@Nullable
 private static VirtualFile findFileToPatchByComponents(
     ApplyPatchContext context, final String[] pathNameComponents, final int lastComponentToFind) {
   VirtualFile patchedDir = context.getBaseDir();
   for (int i = context.getSkipTopDirs(); i < lastComponentToFind; i++) {
     VirtualFile nextChild;
     if (pathNameComponents[i].equals("..")) {
       nextChild = patchedDir.getParent();
     } else {
       nextChild = patchedDir.findChild(pathNameComponents[i]);
     }
     if (nextChild == null) {
       if (context.isCreateDirectories()) {
         try {
           nextChild = patchedDir.createChildDirectory(null, pathNameComponents[i]);
         } catch (IOException e) {
           return null;
         }
       } else {
         context.registerMissingDirectory(patchedDir, pathNameComponents, i);
         return null;
       }
     }
     patchedDir = nextChild;
   }
   return patchedDir;
 }
 private static boolean checkPackageRename(
     final ApplyPatchContext context,
     final String[] beforeNameComponents,
     final String[] afterNameComponents) {
   int changedIndex = -1;
   for (int i = context.getSkipTopDirs(); i < afterNameComponents.length - 1; i++) {
     if (!beforeNameComponents[i].equals(afterNameComponents[i])) {
       if (changedIndex != -1) {
         return true;
       }
       changedIndex = i;
     }
   }
   if (changedIndex == -1) return false;
   VirtualFile oldDir =
       findFileToPatchByComponents(context, beforeNameComponents, changedIndex + 1);
   VirtualFile newDir =
       findFileToPatchByComponents(
           context.getPrepareContext(), afterNameComponents, changedIndex + 1);
   if (oldDir != null && newDir == null) {
     context.addPendingRename(oldDir, afterNameComponents[changedIndex]);
     return false;
   }
   return true;
 }