From ca282c5d08aaa6b7683c47870c829686721d3314 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 12 Oct 2017 17:31:49 +0300 Subject: [PATCH] diff: extract base class for DiffRequestChain --- .../diff/chains/DiffRequestChainBase.java | 41 +++++++++++++++++++ .../diff/chains/SimpleDiffRequestChain.java | 15 +------ .../patch/ApplyPatchDifferentiatedDialog.java | 21 ++-------- .../changes/ui/ChangeDiffRequestChain.java | 21 ++-------- 4 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 platform/diff-api/src/com/intellij/diff/chains/DiffRequestChainBase.java diff --git a/platform/diff-api/src/com/intellij/diff/chains/DiffRequestChainBase.java b/platform/diff-api/src/com/intellij/diff/chains/DiffRequestChainBase.java new file mode 100644 index 000000000000..d82ae189fee2 --- /dev/null +++ b/platform/diff-api/src/com/intellij/diff/chains/DiffRequestChainBase.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.diff.chains; + +import com.intellij.openapi.util.UserDataHolderBase; + +public abstract class DiffRequestChainBase extends UserDataHolderBase implements DiffRequestChain { + private int myIndex; + + public DiffRequestChainBase() { + this(0); + } + + public DiffRequestChainBase(int index) { + myIndex = index; + } + + @Override + public int getIndex() { + return myIndex; + } + + @Override + public void setIndex(int index) { + assert index >= 0 && index < getRequests().size(); + myIndex = index; + } +} diff --git a/platform/diff-api/src/com/intellij/diff/chains/SimpleDiffRequestChain.java b/platform/diff-api/src/com/intellij/diff/chains/SimpleDiffRequestChain.java index 64ee859c2b13..1226c6d516c0 100644 --- a/platform/diff-api/src/com/intellij/diff/chains/SimpleDiffRequestChain.java +++ b/platform/diff-api/src/com/intellij/diff/chains/SimpleDiffRequestChain.java @@ -19,7 +19,6 @@ import com.intellij.diff.requests.DiffRequest; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.util.UserDataHolder; -import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -27,9 +26,8 @@ import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; -public class SimpleDiffRequestChain extends UserDataHolderBase implements DiffRequestChain { +public class SimpleDiffRequestChain extends DiffRequestChainBase { @NotNull private final List myRequests; - private int myIndex = 0; public SimpleDiffRequestChain(@NotNull DiffRequest request) { this(Collections.singletonList(request)); @@ -45,17 +43,6 @@ public class SimpleDiffRequestChain extends UserDataHolderBase implements DiffRe return myRequests; } - @Override - public int getIndex() { - return myIndex; - } - - @Override - public void setIndex(int index) { - assert index >= 0 && index < myRequests.size(); - myIndex = index; - } - public static class DiffRequestProducerWrapper implements DiffRequestProducer { @NotNull private final DiffRequest myRequest; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java index a64815690bd8..cfc93bc867c9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java @@ -18,7 +18,7 @@ package com.intellij.openapi.vcs.changes.patch; import com.intellij.diff.DiffDialogHints; import com.intellij.diff.DiffManager; import com.intellij.diff.actions.impl.GoToChangePopupBuilder; -import com.intellij.diff.chains.DiffRequestChain; +import com.intellij.diff.chains.DiffRequestChainBase; import com.intellij.diff.chains.DiffRequestProducer; import com.intellij.diff.chains.DiffRequestProducerException; import com.intellij.diff.requests.DiffRequest; @@ -1184,17 +1184,15 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { }; } - private static class MyDiffRequestChain extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain { + private static class MyDiffRequestChain extends DiffRequestChainBase implements GoToChangePopupBuilder.Chain { private final List myRequests; private final List myChanges; - private int myIndex; public MyDiffRequestChain(@NotNull List requests, @NotNull List changes, int index) { + super(index); assert requests.size() == changes.size(); myRequests = requests; myChanges = changes; - - myIndex = index >= 0 ? index : 0; } @NotNull @@ -1203,21 +1201,10 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { return myRequests; } - @Override - public int getIndex() { - return myIndex; - } - - @Override - public void setIndex(int index) { - assert index >= 0 && index < myRequests.size(); - myIndex = index; - } - @NotNull @Override public AnAction createGoToChangeAction(@NotNull Consumer onSelected) { - return new ChangeGoToChangePopupAction(this, myIndex) { + return new ChangeGoToChangePopupAction(this, getIndex()) { @NotNull @Override protected DefaultTreeModel buildTreeModel(@NotNull Project project, boolean showFlatten) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeDiffRequestChain.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeDiffRequestChain.java index 67b85297dade..8cb10954a175 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeDiffRequestChain.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangeDiffRequestChain.java @@ -16,11 +16,10 @@ package com.intellij.openapi.vcs.changes.ui; import com.intellij.diff.actions.impl.GoToChangePopupBuilder; -import com.intellij.diff.chains.DiffRequestChain; +import com.intellij.diff.chains.DiffRequestChainBase; import com.intellij.diff.chains.DiffRequestProducer; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.changes.actions.diff.ChangeGoToChangePopupAction; @@ -32,13 +31,12 @@ import org.jetbrains.annotations.Nullable; import javax.swing.tree.DefaultTreeModel; import java.util.List; -public class ChangeDiffRequestChain extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain { +public class ChangeDiffRequestChain extends DiffRequestChainBase implements GoToChangePopupBuilder.Chain { @NotNull private final List myProducers; - private int myIndex; public ChangeDiffRequestChain(@NotNull List producers, int index) { + super(index); myProducers = producers; - myIndex = index; } @Override @@ -47,21 +45,10 @@ public class ChangeDiffRequestChain extends UserDataHolderBase implements DiffRe return myProducers; } - @Override - public int getIndex() { - return myIndex; - } - - @Override - public void setIndex(int index) { - assert index >= 0 && index < myProducers.size(); - myIndex = index; - } - @NotNull @Override public AnAction createGoToChangeAction(@NotNull Consumer onSelected) { - return new ChangeGoToChangePopupAction(this, myIndex) { + return new ChangeGoToChangePopupAction(this, getIndex()) { @NotNull @Override protected DefaultTreeModel buildTreeModel(@NotNull Project project, boolean showFlatten) {