Skip to content

Commit

Permalink
fix: correct the non-attached java-doc position in tree
Browse files Browse the repository at this point in the history
  • Loading branch information
pouryafard75 committed Nov 27, 2024
1 parent fe22ca1 commit 39f5084
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,29 @@ 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;
}

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());
Expand Down

0 comments on commit 39f5084

Please sign in to comment.