Skip to content

Commit 289a218

Browse files
committed
GH-1810: avoid duplicate node definitions in node handler
1 parent 82114bc commit 289a218

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

  • headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/commands

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/commands/JsonNodeHandler.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 the original author or authors.
2+
* Copyright 2025 - 2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -241,12 +241,33 @@ private Node addChildFoo(Consumer<Node> consumer) {
241241

242242
var node = new Node(this.current);
243243
consumer.accept(node);
244-
245244
assignNodeId(node, current);
245+
246+
// check whether a node with the same ID already exists
247+
// (this can happen if there are methods as well as types found for the same stereotype, for example)
248+
// in this case, do not add the new node, but use the existing one
249+
Node alreadyExistingNode = getNodeById(this.current.children, node);
246250

247-
this.current.children.add(node);
251+
if (alreadyExistingNode != null) {
252+
return alreadyExistingNode;
253+
}
254+
else {
255+
this.current.children.add(node);
256+
return node;
257+
}
248258

249-
return node;
259+
}
260+
261+
private Node getNodeById(List<Node> children, Node node) {
262+
Object id = node.attributes.get(NODE_ID);
263+
if (id == null) return null;
264+
265+
for (Node child : children) {
266+
if (child.attributes.containsKey(NODE_ID) && child.attributes.get(NODE_ID).equals(id)) {
267+
return child;
268+
}
269+
}
270+
return null;
250271
}
251272

252273
@Override

0 commit comments

Comments
 (0)