@Nullable
 public static VirtualFile findPatchTarget(
     final ApplyPatchContext context,
     final String beforeName,
     final String afterName,
     final boolean isNewFile)
     throws IOException {
   VirtualFile file = null;
   if (beforeName != null) {
     file = findFileToPatchByName(context, beforeName, isNewFile);
   }
   if (file == null) {
     file = findFileToPatchByName(context, afterName, isNewFile);
   } else if (context.isAllowRename() && afterName != null && !beforeName.equals(afterName)) {
     String[] beforeNameComponents = beforeName.split("/");
     String[] afterNameComponents = afterName.split("/");
     if (!beforeNameComponents[beforeNameComponents.length - 1].equals(
         afterNameComponents[afterNameComponents.length - 1])) {
       context.registerBeforeRename(file);
       file.rename(FilePatch.class, afterNameComponents[afterNameComponents.length - 1]);
       context.addAffectedFile(file);
     }
     boolean needMove = (beforeNameComponents.length != afterNameComponents.length);
     if (!needMove) {
       needMove = checkPackageRename(context, beforeNameComponents, afterNameComponents);
     }
     if (needMove) {
       VirtualFile moveTarget =
           findFileToPatchByComponents(
               context, afterNameComponents, afterNameComponents.length - 1);
       if (moveTarget == null) {
         return null;
       }
       context.registerBeforeRename(file);
       file.move(FilePatch.class, moveTarget);
       context.addAffectedFile(file);
     }
   }
   return file;
 }
 public Result apply(
     final VirtualFile fileToPatch,
     final ApplyPatchContext context,
     final Project project,
     FilePath pathBeforeRename,
     Getter<CharSequence> baseContents,
     CommitContext commitContext)
     throws IOException {
   if (LOG.isDebugEnabled()) {
     LOG.debug("apply patch called for : " + fileToPatch.getPath());
   }
   context.addAffectedFile(getTarget(fileToPatch));
   if (myPatch.isNewFile()) {
     applyCreate(fileToPatch, commitContext);
   } else if (myPatch.isDeletedFile()) {
     FileEditorManagerImpl.getInstance(project).closeFile(fileToPatch);
     fileToPatch.delete(this);
   } else {
     return applyChange(project, fileToPatch, pathBeforeRename, baseContents);
   }
   return SUCCESS;
 }