From d7daf51b75d1b79fffd920a6c0c121037eef4e38 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Fri, 15 Jul 2016 13:40:17 +0300 Subject: [PATCH] patch: rearrange methods --- .../diff/impl/patch/TextPatchBuilder.java | 79 +++++++++---------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java b/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java index fbf79fdca29e..c666687e5018 100644 --- a/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java +++ b/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java @@ -56,12 +56,6 @@ public class TextPatchBuilder { myCancelChecker = cancelChecker; } - private void checkCanceled() { - if (myCancelChecker != null) { - myCancelChecker.run(); - } - } - @NotNull public static List buildPatch(@NotNull Collection> changes, @NotNull String basePath, @@ -75,20 +69,12 @@ public class TextPatchBuilder { @NotNull private List build(@NotNull Collection> changes) throws VcsException { - List result = new ArrayList(); + List result = new ArrayList<>(); for (BeforeAfter c : changes) { checkCanceled(); - AirContentRevision beforeRevision; - AirContentRevision afterRevision; - if (myIsReversePath) { - beforeRevision = c.getAfter(); - afterRevision = c.getBefore(); - } - else { - beforeRevision = c.getBefore(); - afterRevision = c.getAfter(); - } + AirContentRevision beforeRevision = myIsReversePath ? c.getAfter() : c.getBefore(); + AirContentRevision afterRevision = myIsReversePath ? c.getBefore() : c.getAfter(); FilePatch patch = createPatch(beforeRevision, afterRevision); if (patch != null) result.add(patch); @@ -97,9 +83,11 @@ public class TextPatchBuilder { } @Nullable - private FilePatch createPatch(@Nullable AirContentRevision beforeRevision, @Nullable AirContentRevision afterRevision) + private FilePatch createPatch(@Nullable AirContentRevision beforeRevision, + @Nullable AirContentRevision afterRevision) throws VcsException { if (beforeRevision == null && afterRevision == null) return null; + if (beforeRevision != null && beforeRevision.getPath().isDirectory()) return null; if (afterRevision != null && afterRevision.getPath().isDirectory()) return null; @@ -206,10 +194,6 @@ public class TextPatchBuilder { } @NotNull - private static DiffString[] tokenize(@NotNull DiffString text) { - return text.length() == 0 ? new DiffString[]{text} : text.tokenize(); - } - private FilePatch buildBinaryPatch(@Nullable AirContentRevision beforeRevision, @Nullable AirContentRevision afterRevision) throws VcsException { assert beforeRevision != null || afterRevision != null; @@ -222,18 +206,6 @@ public class TextPatchBuilder { return patch; } - private static void addLineToHunk(@NotNull PatchHunk hunk, @NotNull DiffString line, @NotNull PatchLine.Type type) { - PatchLine patchLine; - if (!line.endsWith('\n')) { - patchLine = new PatchLine(type, line.toString()); - patchLine.setSuppressNewLine(true); - } - else { - patchLine = new PatchLine(type, line.substring(0, line.length() - 1).toString()); - } - hunk.addLine(patchLine); - } - @NotNull private TextFilePatch buildMovedFile(@NotNull AirContentRevision beforeRevision, @NotNull AirContentRevision afterRevision) throws VcsException { @@ -294,6 +266,18 @@ public class TextPatchBuilder { return result; } + private static void addLineToHunk(@NotNull PatchHunk hunk, @NotNull DiffString line, @NotNull PatchLine.Type type) { + PatchLine patchLine; + if (!line.endsWith('\n')) { + patchLine = new PatchLine(type, line.toString()); + patchLine.setSuppressNewLine(true); + } + else { + patchLine = new PatchLine(type, line.substring(0, line.length() - 1).toString()); + } + hunk.addLine(patchLine); + } + @NotNull private String getRelativePath(@NotNull String secondPath) { String baseModified = FileUtil.toSystemIndependentName(myBasePath); @@ -304,15 +288,6 @@ public class TextPatchBuilder { return relPath; } - @NotNull - private static String getRevisionName(@NotNull AirContentRevision revision) { - String revisionName = revision.getRevisionNumber(); - if (revisionName != null) { - return MessageFormat.format(REVISION_NAME_TEMPLATE, revisionName); - } - return MessageFormat.format(DATE_NAME_TEMPLATE, Long.toString(revision.getPath().lastModified())); - } - @NotNull private TextFilePatch buildPatchHeading(@NotNull AirContentRevision beforeRevision, @NotNull AirContentRevision afterRevision) { @@ -331,6 +306,15 @@ public class TextPatchBuilder { result.setAfterVersionId(getRevisionName(afterRevision)); } + @NotNull + private static String getRevisionName(@NotNull AirContentRevision revision) { + String revisionName = revision.getRevisionNumber(); + if (revisionName != null) { + return MessageFormat.format(REVISION_NAME_TEMPLATE, revisionName); + } + return MessageFormat.format(DATE_NAME_TEMPLATE, Long.toString(revision.getPath().lastModified())); + } + @NotNull private static DiffString getContent(@NotNull AirContentRevision revision) throws VcsException { String beforeContent = revision.getContentAsString(); @@ -339,4 +323,13 @@ public class TextPatchBuilder { } return DiffString.create(beforeContent); } + + @NotNull + private static DiffString[] tokenize(@NotNull DiffString text) { + return text.length() == 0 ? new DiffString[]{text} : text.tokenize(); + } + + private void checkCanceled() { + if (myCancelChecker != null) myCancelChecker.run(); + } }