Skip to content

Commit 0314fcf

Browse files
committed
Merge branch 'update-user-data'
2 parents 848f1e2 + b8a26bc commit 0314fcf

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AstTraversalUtil.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.util.Optional;
1919

2020
import net.sourceforge.pmd.lang.ast.Node;
21+
import net.sourceforge.pmd.util.DataMap;
22+
import net.sourceforge.pmd.util.DataMap.SimpleDataKey;
2123
import net.sourceforge.pmd.util.fxdesigner.util.codearea.PmdCoordinatesSystem.TextPos2D;
2224

2325
import javafx.scene.control.TreeItem;
@@ -38,6 +40,10 @@ public static Node getRoot(Node n) {
3840
? n : getRoot(n.getParent());
3941
}
4042

43+
44+
private static final SimpleDataKey<Node> NEW_TREE_BRIDGE_KEY = DataMap.simpleDataKey("new.tree");
45+
46+
4147
/**
4248
* Tries hard to find the node in [myRoot] that corresponds most closely
4349
* to the given [node], which may be from another tree.
@@ -54,9 +60,12 @@ public static Optional<Node> mapToMyTree(final Node myRoot, final Node node, Tex
5460
return Optional.of(node); // same tree, don't set cache
5561
}
5662

57-
// user data of a node is the node it maps to in the other tree
58-
if (node.getUserData() instanceof Node) {
59-
return Optional.of((Node) node.getUserData());
63+
{
64+
// user data of a node is the node it maps to in the other tree
65+
Node newNode = node.getUserMap().get(NEW_TREE_BRIDGE_KEY);
66+
if (newNode != null) {
67+
return Optional.of(newNode);
68+
}
6069
}
6170

6271
Optional<Node> result =
@@ -75,7 +84,7 @@ public static Optional<Node> mapToMyTree(final Node myRoot, final Node node, Tex
7584
// the [node] is mapped to the [result]
7685
// since several nodes may map to the same node in another tree,
7786
// it's not safe to set both cache entries
78-
result.ifPresent(node::setUserData);
87+
result.ifPresent(n -> node.getUserMap().set(NEW_TREE_BRIDGE_KEY, n));
7988

8089
return result;
8190
}

0 commit comments

Comments
 (0)