From 5672767d125f26b31f577e93ef084173e1bab56b Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 29 Sep 2016 16:52:06 +0300 Subject: [PATCH] [vcs]: refactoring: get rid of unnecessary inheritance, delete unused --- .../changes/AbstractIgnoredFilesHolder.java | 75 ------------------- .../openapi/vcs/changes/ChangeListWorker.java | 1 - .../vcs/changes/RecursiveFileHolder.java | 39 ++++++++-- .../vcs/changes/SwitchedFileHolder.java | 33 ++------ 4 files changed, 38 insertions(+), 110 deletions(-) delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractIgnoredFilesHolder.java diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractIgnoredFilesHolder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractIgnoredFilesHolder.java deleted file mode 100644 index 8b12bf5c0a45..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractIgnoredFilesHolder.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2000-2011 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.openapi.vcs.changes; - -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; -import com.intellij.vcsUtil.VcsUtil; - -import java.util.Collection; -import java.util.Iterator; - -/** - * @author irengrig - * Date: 2/10/11 - * Time: 3:59 PM - */ -abstract class AbstractIgnoredFilesHolder implements FileHolder, IgnoredFilesHolder { - protected final Project myProject; - private final ProjectLevelVcsManager myVcsManager; - - protected AbstractIgnoredFilesHolder(Project project) { - myProject = project; - myVcsManager = ProjectLevelVcsManager.getInstance(project); - } - - protected abstract void removeFile(final VirtualFile file); - protected abstract Collection keys(); - - @Override - public void cleanAndAdjustScope(final VcsModifiableDirtyScope scope) { - if (myProject.isDisposed()) return; - final Iterator iterator = keys().iterator(); - while (iterator.hasNext()) { - final VirtualFile file = iterator.next(); - if (isFileDirty(scope, file)) { - iterator.remove(); - } - } - } - - protected boolean isFileDirty(final VcsDirtyScope scope, final VirtualFile file) { - if (! file.isValid()) return true; - final AbstractVcs vcsArr[] = new AbstractVcs[1]; - if (scope.belongsTo(VcsUtil.getFilePath(file), new Consumer() { - @Override - public void consume(AbstractVcs vcs) { - vcsArr[0] = vcs; - } - })) { - return true; - } - - return vcsArr[0] == null; - } - - protected boolean fileDropped(final VirtualFile file) { - return !file.isValid() || myVcsManager.getVcsFor(file) == null; - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java index 636a86d30873..bdc657fc95e1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java @@ -402,7 +402,6 @@ public class ChangeListWorker implements ChangeListsWriteOperations { for(ChangeList changeList: changedLists) { dispatcher.changeListChanged(changeList); } - mySwitchedHolder.calculateChildren(); for (String name : myListsToDisappear) { final LocalChangeList changeList = myMap.get(name); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RecursiveFileHolder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RecursiveFileHolder.java index a232c1cd5700..3f1f0582aa96 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RecursiveFileHolder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RecursiveFileHolder.java @@ -4,21 +4,24 @@ import com.intellij.openapi.diff.impl.patch.formove.FilePathComparator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.vcsUtil.VcsUtil; import java.util.*; -/** - * @author max - */ -public class RecursiveFileHolder extends AbstractIgnoredFilesHolder { +public class RecursiveFileHolder implements IgnoredFilesHolder { + + protected final Project myProject; + protected final ProjectLevelVcsManager myVcsManager; protected final HolderType myHolderType; protected final TreeMap myMap; protected final TreeMap myDirMap; public RecursiveFileHolder(final Project project, final HolderType holderType) { - super(project); + myProject = project; + myVcsManager = ProjectLevelVcsManager.getInstance(project); myMap = new TreeMap<>(FilePathComparator.getInstance()); myDirMap = new TreeMap<>(FilePathComparator.getInstance()); myHolderType = holderType; @@ -29,7 +32,6 @@ public class RecursiveFileHolder extends AbstractIgnoredFilesHolder { myDirMap.clear(); } - @Override protected Collection keys() { return myMap.keySet(); } @@ -71,7 +73,7 @@ public class RecursiveFileHolder extends AbstractIgnoredFilesHolder { if (floor == null) return false; final SortedMap floorMap = myDirMap.headMap(floor, true); for (VirtualFile parent : floorMap.keySet()) { - if (VfsUtil.isAncestor(parent, file, false)) { + if (VfsUtilCore.isAncestor(parent, file, false)) { return true; } } @@ -82,6 +84,27 @@ public class RecursiveFileHolder extends AbstractIgnoredFilesHolder { return myMap.keySet(); } + @Override + public void cleanAndAdjustScope(final VcsModifiableDirtyScope scope) { + if (myProject.isDisposed()) return; + final Iterator iterator = keys().iterator(); + while (iterator.hasNext()) { + final VirtualFile file = iterator.next(); + if (isFileDirty(scope, file)) { + iterator.remove(); + } + } + } + + protected boolean isFileDirty(final VcsDirtyScope scope, final VirtualFile file) { + if (!file.isValid()) return true; + final AbstractVcs[] vcsArr = new AbstractVcs[1]; + if (scope.belongsTo(VcsUtil.getFilePath(file), vcs -> vcsArr[0] = vcs)) { + return true; + } + return vcsArr[0] == null; + } + public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SwitchedFileHolder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SwitchedFileHolder.java index 4fb3e57315da..b99dd5048eaf 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SwitchedFileHolder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SwitchedFileHolder.java @@ -17,9 +17,8 @@ package com.intellij.openapi.vcs.changes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.PairProcessor; import com.intellij.util.containers.MultiMap; import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.Nullable; @@ -34,11 +33,6 @@ public class SwitchedFileHolder extends RecursiveFileHolder getFilesMapCopy() { final HashMap result = new HashMap<>(); for (final VirtualFile vf : myMap.keySet()) { @@ -79,7 +77,7 @@ public class SwitchedFileHolder extends RecursiveFileHolder> floorMap = myMap.headMap(floor, true); for (VirtualFile parent : floorMap.keySet()) { - if (VfsUtil.isAncestor(parent, file, false)) { + if (VfsUtilCore.isAncestor(parent, file, false)) { final Pair value = floorMap.get(parent); return parent.equals(file) || value.getFirst(); } @@ -93,27 +91,10 @@ public class SwitchedFileHolder extends RecursiveFileHolder> floorMap = myMap.headMap(floor); for (VirtualFile parent : floorMap.keySet()) { - if (VfsUtil.isAncestor(parent, file, false)) { + if (VfsUtilCore.isAncestor(parent, file, false)) { return floorMap.get(parent).getSecond(); } } return null; } - - public void calculateChildren() { - //myMap.optimizeMap(MyOptimizeProcessor.getInstance()); - } - - private static class MyOptimizeProcessor implements PairProcessor, Pair> { - private final static MyOptimizeProcessor ourInstance = new MyOptimizeProcessor(); - - public static MyOptimizeProcessor getInstance() { - return ourInstance; - } - - @Override - public boolean process(final Pair parentPair, final Pair childPair) { - return Boolean.TRUE.equals(parentPair.getFirst()) && parentPair.getSecond().equals(childPair.getSecond()); - } - } }