From a6c17364ad265d632980b2be01936c22b63b7196 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Thu, 24 Nov 2016 15:27:43 +0300 Subject: [PATCH] patch: Used "ThrowableComputable" instead of "TransparentlyFailedValueI" --- .../openapi/diff/impl/patch/PatchReader.java | 39 +++++++++---------- .../patch/ApplyPatchDefaultExecutor.java | 19 +++++---- .../vcs/changes/patch/ApplyPatchExecutor.java | 4 +- .../changes/patch/ImportToShelfExecutor.java | 6 +-- .../patch/UnshelvePatchDefaultExecutor.java | 4 +- .../changes/shelf/ShelveChangesManager.java | 4 +- .../ApplyPatchSaveToFileExecutor.java | 4 +- .../treeConflict/MergeFromTheirsResolver.java | 3 +- 8 files changed, 40 insertions(+), 43 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/PatchReader.java b/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/PatchReader.java index 9879162a1c31..8b96d0a85475 100644 --- a/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/PatchReader.java +++ b/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/PatchReader.java @@ -19,13 +19,11 @@ package com.intellij.openapi.diff.impl.patch; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Couple; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FileStatus; -import com.intellij.openapi.vcs.changes.TransparentlyFailedValue; -import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI; import com.intellij.util.SmartList; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,6 +32,9 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.intellij.util.containers.ContainerUtil.filter; +import static com.intellij.util.containers.ContainerUtil.findAll; + public class PatchReader { @NonNls public static final String NO_NEWLINE_SIGNATURE = UnifiedDiffWriter.NO_NEWLINE_SIGNATURE; private final List myLines; @@ -134,7 +135,7 @@ public class PatchReader { @NotNull public List getTextPatches() { - return ContainerUtil.findAll(myPatches, TextFilePatch.class); + return findAll(myPatches, TextFilePatch.class); } @NotNull @@ -184,25 +185,23 @@ public class PatchReader { myPatches = myPatchContentParser.getResult(); } - public TransparentlyFailedValueI>, PatchSyntaxException> getAdditionalInfo(final Set filterByPaths) { - final TransparentlyFailedValue>, PatchSyntaxException> - value = new TransparentlyFailedValue<>(); + @NotNull + public ThrowableComputable>, PatchSyntaxException> getAdditionalInfo(@Nullable Set paths) { + ThrowableComputable>, PatchSyntaxException> result; + PatchSyntaxException e = myAdditionalInfoParser.getSyntaxException(); - final Map> map = myAdditionalInfoParser.getResultMap(); - final Map>newMap = new HashMap<>(); - - for (Map.Entry> entry : map.entrySet()) { - final Map innerMap = entry.getValue(); - if (filterByPaths == null || filterByPaths.contains(entry.getKey())) { - newMap.put(entry.getKey(), innerMap); - } - } - value.set(newMap); - final PatchSyntaxException e = myAdditionalInfoParser.getSyntaxException(); if (e != null) { - value.fail(e); + result = () -> { + throw e; + }; } - return value; + else { + Map> additionalInfo = + filter(myAdditionalInfoParser.getResultMap(), path -> paths == null || paths.contains(path)); + result = () -> additionalInfo; + } + + return result; } private static class AdditionalInfoParser implements Parser { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java index 6cd0630a0b69..2173f5fdd422 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java @@ -20,9 +20,9 @@ import com.intellij.openapi.diff.impl.patch.formove.PatchApplier; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vcs.changes.CommitContext; import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI; import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; @@ -54,7 +54,7 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor remaining, @NotNull MultiMap patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable String fileName, - @Nullable TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo) { + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo) { final CommitContext commitContext = new CommitContext(); applyAdditionalInfoBefore(myProject, additionalInfo, commitContext); final Collection appliers = getPatchAppliers(patchGroupsToApply, localList, commitContext); @@ -62,7 +62,7 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor>, PatchSyntaxException> additionalInfo, + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo, @NotNull CommitContext commitContext, @NotNull Collection appliers) { final ApplyPatchStatus applyPatchStatus = PatchApplier.executePatchGroup(appliers, localList); @@ -92,8 +92,8 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor>, PatchSyntaxException> additionalInfo, - CommitContext commitContext) { + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo, + CommitContext commitContext) { applyAdditionalInfoImpl(project, additionalInfo, commitContext, new Consumer() { @Override public void consume(InfoGroup infoGroup) { @@ -103,8 +103,8 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor>, PatchSyntaxException> additionalInfo, - CommitContext commitContext) { + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo, + CommitContext commitContext) { applyAdditionalInfoImpl(project, additionalInfo, commitContext, new Consumer() { @Override public void consume(InfoGroup infoGroup) { @@ -114,14 +114,13 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor>, PatchSyntaxException> additionalInfo, + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo, CommitContext commitContext, final Consumer worker) { final PatchEP[] extensions = Extensions.getExtensions(PatchEP.EP_NAME, project); if (extensions.length == 0) return; if (additionalInfo != null) { try { - final Map> map = additionalInfo.get(); - for (Map.Entry> entry : map.entrySet()) { + for (Map.Entry> entry : additionalInfo.compute().entrySet()) { final String path = entry.getKey(); final Map innerMap = entry.getValue(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchExecutor.java index b01500f7d430..bd9f0dff260a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchExecutor.java @@ -17,8 +17,8 @@ package com.intellij.openapi.vcs.changes.patch; import com.intellij.openapi.diff.impl.patch.FilePatch; import com.intellij.openapi.diff.impl.patch.PatchSyntaxException; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.Nls; @@ -40,5 +40,5 @@ public interface ApplyPatchExecutor { void apply(@NotNull List remaining, @NotNull final MultiMap patchGroupsToApply, @Nullable final LocalChangeList localList, @Nullable String fileName, - @Nullable TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo); + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ImportToShelfExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ImportToShelfExecutor.java index 6970c812ce69..a1eda409eb85 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ImportToShelfExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ImportToShelfExecutor.java @@ -23,12 +23,12 @@ import com.intellij.openapi.diff.impl.patch.TextFilePatch; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.CommitContext; import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI; import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; import com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList; import com.intellij.openapi.vcs.changes.shelf.ShelvedChangesViewManager; @@ -65,7 +65,7 @@ public class ImportToShelfExecutor implements ApplyPatchExecutor remaining, @NotNull final MultiMap patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable final String fileName, - @Nullable final TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo) { + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo) { if (fileName == null) { LOG.error("Patch file name shouldn't be null"); return; @@ -94,7 +94,7 @@ public class ImportToShelfExecutor implements ApplyPatchExecutor extensions = new HashMap<>(); - for (Map.Entry> entry : additionalInfo.get().entrySet()) { + for (Map.Entry> entry : additionalInfo.compute().entrySet()) { final String filePath = entry.getKey(); Map extToValue = entry.getValue(); for (Map.Entry innerEntry : extToValue.entrySet()) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java index 083c1a3676c0..dab626a51ba5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java @@ -21,9 +21,9 @@ import com.intellij.openapi.diff.impl.patch.FilePatch; import com.intellij.openapi.diff.impl.patch.PatchSyntaxException; import com.intellij.openapi.diff.impl.patch.formove.PatchApplier; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vcs.changes.CommitContext; import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI; import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; import com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFilePatch; import com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList; @@ -53,7 +53,7 @@ public class UnshelvePatchDefaultExecutor extends ApplyPatchDefaultExecutor { @NotNull MultiMap patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable String fileName, - @Nullable TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo) { + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo) { final CommitContext commitContext = new CommitContext(); applyAdditionalInfoBefore(myProject, additionalInfo, commitContext); final Collection appliers = getPatchAppliers(patchGroupsToApply, localList, commitContext); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java index 229c6e2eb1d6..17d3b50648c0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java @@ -966,9 +966,7 @@ public class ShelveChangesManager extends AbstractProjectComponent implements JD char[] text = FileUtil.loadFileText(new File(patchPath), CharsetToolkit.UTF8); PatchReader reader = new PatchReader(new CharArrayCharSequence(text), loadContent); final List textFilePatches = reader.readTextPatches(); - final TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo = reader.getAdditionalInfo( - null); - ApplyPatchDefaultExecutor.applyAdditionalInfoBefore(project, additionalInfo, commitContext); + ApplyPatchDefaultExecutor.applyAdditionalInfoBefore(project, reader.getAdditionalInfo(null), commitContext); return textFilePatches; } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/ApplyPatchSaveToFileExecutor.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/ApplyPatchSaveToFileExecutor.java index 1f68657a2de5..9af2bda25f7f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/ApplyPatchSaveToFileExecutor.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/ApplyPatchSaveToFileExecutor.java @@ -24,9 +24,9 @@ import com.intellij.openapi.fileChooser.FileSaverDescriptor; import com.intellij.openapi.fileChooser.FileSaverDialog; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vcs.changes.CommitContext; import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI; import com.intellij.openapi.vcs.changes.patch.ApplyPatchExecutor; import com.intellij.openapi.vcs.changes.patch.PatchWriter; import com.intellij.openapi.vcs.changes.patch.TextFilePatchInProgress; @@ -74,7 +74,7 @@ public class ApplyPatchSaveToFileExecutor implements ApplyPatchExecutor patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable String fileName, - @Nullable TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo) { + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo) { FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Save Patch to", ""), myProject); VirtualFileWrapper targetFile = dialog.save(myProject.getBaseDir(), "TheirsChanges.patch"); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java index dc54821a3b1d..064dea116e69 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/MergeFromTheirsResolver.java @@ -31,6 +31,7 @@ import com.intellij.openapi.ui.MessageDialogBuilder; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.actions.BackgroundTaskGroup; import com.intellij.openapi.vcs.changes.*; @@ -202,7 +203,7 @@ public class MergeFromTheirsResolver extends BackgroundTaskGroup { @NotNull MultiMap patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable String fileName, - @Nullable TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo) { + @Nullable ThrowableComputable>, PatchSyntaxException> additionalInfo) { List patches = null; VcsException exception = null; try {