[external system][IDEA-349206] fix ProjectNode leak

GitOrigin-RevId: f4bdd494035d2a4d082e30e870a88c81b7fb4949
This commit is contained in:
Alexander.Glukhov
2024-03-18 18:08:06 +00:00
committed by intellij-monorepo-bot
parent 1a219c043b
commit 5b176dd7f0
3 changed files with 11 additions and 9 deletions
@@ -145,7 +145,7 @@ public class ExternalProjectsStructure extends SimpleTreeStructure implements Di
final ExternalSystemNode<?>[] cached = currentNode.getCached();
if (cached == null) {
//noinspection unchecked
currentNode.mergeWith(newNode);
currentNode.setFrom(newNode);
return;
}
final List<Object> duplicates = new ArrayList<>();
@@ -158,7 +158,9 @@ public class ExternalProjectsStructure extends SimpleTreeStructure implements Di
}
}
// new data comparing to old node
Map<Object, ExternalSystemNode<?>> newDataMap = new LinkedHashMap<>();
// old nodes that exist in the old node as well as in the new node
Map<Object, ExternalSystemNode<?>> unchangedNewDataMap = new LinkedHashMap<>();
for (ExternalSystemNode<?> node : newNode.getChildren()) {
Object key = node.getData() != null ? node.getData() : node.getName();
@@ -186,7 +188,7 @@ public class ExternalProjectsStructure extends SimpleTreeStructure implements Di
updateFrom(currentNode);
//noinspection unchecked
currentNode.mergeWith(newNode);
currentNode.setFrom(newNode);
currentNode.addAll(newDataMap.values());
}
@@ -424,7 +424,8 @@ public abstract class ExternalSystemNode<T> extends SimpleNode implements Compar
return StringUtil.compare(this.getName(), node.getName(), true);
}
public void mergeWith(ExternalSystemNode<T> node) {
setDataNode(node.myDataNode);
public void setFrom(@NotNull ExternalSystemNode<T> newNode) {
setDataNode(newNode.myDataNode);
setParent(newNode.myParent);
}
}
@@ -116,11 +116,10 @@ public class ModuleNode extends ExternalSystemNode<ModuleData> {
}
@Override
public void mergeWith(ExternalSystemNode<ModuleData> node) {
super.mergeWith(node);
ModuleNode moduleNode = node instanceof ModuleNode ? ((ModuleNode)node) : null;
if (moduleNode != null) {
myAllModules = moduleNode.myAllModules;
public void setFrom(@NotNull ExternalSystemNode<ModuleData> node) {
super.setFrom(node);
if (node instanceof ModuleNode moduleNode) {
myAllModules = moduleNode.myAllModules;
}
}
}