コード例 #1
0
    private TextFilePatch readPatch(String curLine, ListIterator<String> iterator)
        throws PatchSyntaxException {
      final TextFilePatch curPatch =
          mySaveHunks ? new TextFilePatch(null) : new EmptyTextFilePatch();
      extractFileName(curLine, curPatch, true, myDiffCommandLike && myIndexLike);

      if (!iterator.hasNext())
        throw new PatchSyntaxException(iterator.previousIndex(), "Second file name expected");
      curLine = iterator.next();
      String secondNamePrefix = myDiffFormat == DiffFormat.UNIFIED ? "+++ " : "--- ";
      if (!curLine.startsWith(secondNamePrefix)) {
        throw new PatchSyntaxException(iterator.previousIndex(), "Second file name expected");
      }
      extractFileName(curLine, curPatch, false, myDiffCommandLike && myIndexLike);

      while (iterator.hasNext()) {
        PatchHunk hunk;
        if (myDiffFormat == DiffFormat.UNIFIED) {
          hunk = readNextHunkUnified(iterator);
        } else {
          hunk = readNextHunkContext(iterator);
        }
        if (hunk == null) break;
        curPatch.addHunk(hunk);
      }
      if (curPatch.getBeforeName() == null) {
        curPatch.setBeforeName(curPatch.getAfterName());
      }
      if (curPatch.getAfterName() == null) {
        curPatch.setAfterName(curPatch.getBeforeName());
      }
      return curPatch;
    }
コード例 #2
0
 @Nullable
 public String getLastName() {
   if (myPatches.isEmpty()) {
     return null;
   } else {
     final TextFilePatch patch = myPatches.get(myPatches.size() - 1);
     return patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName();
   }
 }