diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java index 869731d2d90b..1e879da7e922 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/DataNode.java @@ -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 implements Serializable { private static final Logger LOG = Logger.getInstance(DataNode.class); @NotNull private final List> myChildren = ContainerUtilRt.newArrayList(); + @NotNull private final List> myChildrenView = Collections.unmodifiableList(myChildren); @NotNull private final Key myKey; private transient T myData; @@ -73,18 +71,6 @@ public class DataNode implements Serializable { return result; } - @NotNull - public DataNode createOrReplaceChild(@NotNull Key key, @NotNull T data) { - for (Iterator> iterator = myChildren.iterator(); iterator.hasNext(); ) { - DataNode child = iterator.next(); - if (child.getKey().equals(key)) { - iterator.remove(); - break; - } - } - return createChild(key, data); - } - @NotNull public Key getKey() { return myKey; @@ -237,7 +223,7 @@ public class DataNode implements Serializable { @NotNull public Collection> getChildren() { - return myChildren; + return myChildrenView; } private void writeObject(ObjectOutputStream out) throws IOException { @@ -304,7 +290,7 @@ public class DataNode implements Serializable { public void clear(boolean removeFromGraph) { if (removeFromGraph && myParent != null) { - for (Iterator> iterator = myParent.getChildren().iterator(); iterator.hasNext(); ) { + for (Iterator> 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 implements Serializable { myRawData = null; myChildren.clear(); } + + public DataNode graphCopy() { + return nodeCopy(this, null); + } + + private static DataNode nodeCopy(@NotNull DataNode dataNode, @Nullable DataNode newParent) { + DataNode copy = new DataNode(dataNode.myKey, dataNode.myData, newParent); + copy.myRawData = dataNode.myRawData; + for (DataNode child : dataNode.myChildren) { + copy.addChild(nodeCopy(child, copy)); + } + return copy; + } } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java index 4b487ca55232..0c61d23d6a7a 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java @@ -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);