From 39f508479752f4086364513fc76ff9a88a67fdda Mon Sep 17 00:00:00 2001 From: Pouryafard75 Date: Wed, 27 Nov 2024 10:56:13 -0500 Subject: [PATCH] fix: correct the non-attached java-doc position in tree --- .../gen/jdt/JdtWithCommentsVisitor.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gen.jdt/src/main/java/com/github/gumtreediff/gen/jdt/JdtWithCommentsVisitor.java b/gen.jdt/src/main/java/com/github/gumtreediff/gen/jdt/JdtWithCommentsVisitor.java index d075537d..17f9a1fa 100644 --- a/gen.jdt/src/main/java/com/github/gumtreediff/gen/jdt/JdtWithCommentsVisitor.java +++ b/gen.jdt/src/main/java/com/github/gumtreediff/gen/jdt/JdtWithCommentsVisitor.java @@ -57,7 +57,7 @@ public boolean visit(Javadoc node) { if (node.getParent() == null) //Then it is Javadoc attached to any program element, //So we do as the same as the other Javadocs in the original visitors - node.accept(JdtWithCommentsVisitor.this); + return visitComment(node); return true; } @@ -65,6 +65,21 @@ public boolean visitComment(Comment node) { int start = node.getStartPosition(); int end = start + node.getLength(); Tree parent = findMostInnerEnclosingParent(context.getRoot(), start, end); + if (node.getParent() == null) { + //The attached ones have been already visited, and we do not want to add them twice. + //Then it is Javadoc attached to any program element, + //So we do as the same as the other Javadocs in the original visitors + trees.push(parent); + node.accept(JdtWithCommentsVisitor.this); + + //fix the order in among the children + Tree wrongOrderChild = parent.getChild(parent.getChildren().size() - 1); + parent.getChildren().remove(wrongOrderChild); + insertChildProperly(parent, wrongOrderChild); + + trees.pop(); + return true; + } Tree t = context.createTree(nodeAsSymbol(node), new String(scanner.getSource(), start, end - start)); t.setPos(start); t.setLength(node.getLength());