mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external system: do not modify data graph of the running import
This commit is contained in:
+17
-18
@@ -24,10 +24,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class provides a generic graph infrastructure with ability to store particular data. The main purpose is to
|
||||
@@ -48,6 +45,7 @@ public class DataNode<T> implements Serializable {
|
||||
private static final Logger LOG = Logger.getInstance(DataNode.class);
|
||||
|
||||
@NotNull private final List<DataNode<?>> myChildren = ContainerUtilRt.newArrayList();
|
||||
@NotNull private final List<DataNode<?>> myChildrenView = Collections.unmodifiableList(myChildren);
|
||||
|
||||
@NotNull private final Key<T> myKey;
|
||||
private transient T myData;
|
||||
@@ -73,18 +71,6 @@ public class DataNode<T> implements Serializable {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public <T> DataNode<T> createOrReplaceChild(@NotNull Key<T> key, @NotNull T data) {
|
||||
for (Iterator<DataNode<?>> iterator = myChildren.iterator(); iterator.hasNext(); ) {
|
||||
DataNode<?> child = iterator.next();
|
||||
if (child.getKey().equals(key)) {
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return createChild(key, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Key<T> getKey() {
|
||||
return myKey;
|
||||
@@ -237,7 +223,7 @@ public class DataNode<T> implements Serializable {
|
||||
|
||||
@NotNull
|
||||
public Collection<DataNode<?>> getChildren() {
|
||||
return myChildren;
|
||||
return myChildrenView;
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
@@ -304,7 +290,7 @@ public class DataNode<T> implements Serializable {
|
||||
|
||||
public void clear(boolean removeFromGraph) {
|
||||
if (removeFromGraph && myParent != null) {
|
||||
for (Iterator<DataNode<?>> iterator = myParent.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
for (Iterator<DataNode<?>> iterator = myParent.myChildren.iterator(); iterator.hasNext(); ) {
|
||||
DataNode<?> dataNode = iterator.next();
|
||||
if (System.identityHashCode(dataNode) == System.identityHashCode(this)) {
|
||||
iterator.remove();
|
||||
@@ -316,4 +302,17 @@ public class DataNode<T> implements Serializable {
|
||||
myRawData = null;
|
||||
myChildren.clear();
|
||||
}
|
||||
|
||||
public DataNode<T> graphCopy() {
|
||||
return nodeCopy(this, null);
|
||||
}
|
||||
|
||||
private static <T> DataNode<T> nodeCopy(@NotNull DataNode<T> dataNode, @Nullable DataNode<?> newParent) {
|
||||
DataNode<T> copy = new DataNode<T>(dataNode.myKey, dataNode.myData, newParent);
|
||||
copy.myRawData = dataNode.myRawData;
|
||||
for (DataNode<?> child : dataNode.myChildren) {
|
||||
copy.addChild(nodeCopy(child, copy));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@ public class ExternalProjectsDataStorage implements SettingsSavingComponent {
|
||||
InternalExternalProjectInfo merged = new InternalExternalProjectInfo(
|
||||
projectSystemId,
|
||||
projectPath,
|
||||
externalProjectStructure
|
||||
externalProjectStructure != null ? externalProjectStructure.graphCopy() : null
|
||||
);
|
||||
merged.setLastImportTimestamp(lastImportTimestamp);
|
||||
merged.setLastSuccessfulImportTimestamp(lastSuccessfulImportTimestamp);
|
||||
|
||||
Reference in New Issue
Block a user