mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs]: refactoring: get rid of unnecessary inheritance, delete unused
This commit is contained in:
-75
@@ -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<VirtualFile> keys();
|
||||
|
||||
@Override
|
||||
public void cleanAndAdjustScope(final VcsModifiableDirtyScope scope) {
|
||||
if (myProject.isDisposed()) return;
|
||||
final Iterator<VirtualFile> 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<AbstractVcs>() {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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<T> extends AbstractIgnoredFilesHolder {
|
||||
public class RecursiveFileHolder<T> implements IgnoredFilesHolder {
|
||||
|
||||
protected final Project myProject;
|
||||
protected final ProjectLevelVcsManager myVcsManager;
|
||||
protected final HolderType myHolderType;
|
||||
protected final TreeMap<VirtualFile, T> myMap;
|
||||
protected final TreeMap<VirtualFile, T> 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<T> extends AbstractIgnoredFilesHolder {
|
||||
myDirMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<VirtualFile> keys() {
|
||||
return myMap.keySet();
|
||||
}
|
||||
@@ -71,7 +73,7 @@ public class RecursiveFileHolder<T> extends AbstractIgnoredFilesHolder {
|
||||
if (floor == null) return false;
|
||||
final SortedMap<VirtualFile, T> 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<T> extends AbstractIgnoredFilesHolder {
|
||||
return myMap.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAndAdjustScope(final VcsModifiableDirtyScope scope) {
|
||||
if (myProject.isDisposed()) return;
|
||||
final Iterator<VirtualFile> 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;
|
||||
|
||||
@@ -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<Pair<Boolean, String
|
||||
super(project, holderType);
|
||||
}
|
||||
|
||||
public void takeFrom(final SwitchedFileHolder holder) {
|
||||
myMap.clear();
|
||||
myMap.putAll(holder.myMap);
|
||||
}
|
||||
|
||||
public synchronized SwitchedFileHolder copy() {
|
||||
final SwitchedFileHolder copyHolder = new SwitchedFileHolder(myProject, myHolderType);
|
||||
copyHolder.myMap.putAll(myMap);
|
||||
@@ -52,6 +46,10 @@ public class SwitchedFileHolder extends RecursiveFileHolder<Pair<Boolean, String
|
||||
return scope.belongsTo(VcsUtil.getFilePath(file));
|
||||
}
|
||||
|
||||
private boolean fileDropped(final VirtualFile file) {
|
||||
return !file.isValid() || myVcsManager.getVcsFor(file) == null;
|
||||
}
|
||||
|
||||
public Map<VirtualFile, String> getFilesMapCopy() {
|
||||
final HashMap<VirtualFile, String> result = new HashMap<>();
|
||||
for (final VirtualFile vf : myMap.keySet()) {
|
||||
@@ -79,7 +77,7 @@ public class SwitchedFileHolder extends RecursiveFileHolder<Pair<Boolean, String
|
||||
if (floor == null) return false;
|
||||
final SortedMap<VirtualFile, Pair<Boolean, String>> floorMap = myMap.headMap(floor, true);
|
||||
for (VirtualFile parent : floorMap.keySet()) {
|
||||
if (VfsUtil.isAncestor(parent, file, false)) {
|
||||
if (VfsUtilCore.isAncestor(parent, file, false)) {
|
||||
final Pair<Boolean, String> value = floorMap.get(parent);
|
||||
return parent.equals(file) || value.getFirst();
|
||||
}
|
||||
@@ -93,27 +91,10 @@ public class SwitchedFileHolder extends RecursiveFileHolder<Pair<Boolean, String
|
||||
if (floor == null) return null;
|
||||
final SortedMap<VirtualFile, Pair<Boolean, String>> 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<Boolean, String>, Pair<Boolean, String>> {
|
||||
private final static MyOptimizeProcessor ourInstance = new MyOptimizeProcessor();
|
||||
|
||||
public static MyOptimizeProcessor getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(final Pair<Boolean, String> parentPair, final Pair<Boolean, String> childPair) {
|
||||
return Boolean.TRUE.equals(parentPair.getFirst()) && parentPair.getSecond().equals(childPair.getSecond());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user