Skip to content

Commit

Permalink
fix: visit non-attached java-docs (comments) same as the rest of the … (
Browse files Browse the repository at this point in the history
#378)

* fix: visit non-attached java-docs (comments) same as the rest of the java-docs

fix: correct the non-attached java-doc position in tree

fix: bug

* fix: update tests accordingly
  • Loading branch information
pouryafard75 authored Dec 13, 2024
1 parent 690c881 commit 7c3df61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public boolean visit(LineComment node) {
}

public boolean visit(Javadoc node) {
//We have to check if the java doc is attached to any program element or not
//We have to check if the Javadoc is attached to any program element or not
//The attached ones, have been already visited, and we do not want to add them twice.
if (node.getParent() == null)
//Then it is javadoc which is attached to any program element,
//So it will be visited as same as the other comments but with JavaDoc label
//Then it is Javadoc attached to any program element,
//So we do as the same as the other Javadocs in the original visitors
return visitComment(node);
return true;
}
Expand All @@ -65,6 +65,15 @@ public boolean visitComment(Comment node) {
int start = node.getStartPosition();
int end = start + node.getLength();
Tree parent = findMostInnerEnclosingParent(context.getRoot(), start, end);
if (node instanceof Javadoc) {
trees.push(parent);
node.accept(JdtWithCommentsVisitor.this);
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
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ public void testComments2() throws IOException {
+ " PrimitiveType: boolean [60,67]\n"
+ " SimpleName: b [68,69]\n"
+ " Block [76,142]\n"
+ " Javadoc: /**\n"
+ " * test2 \n"
+ " */ [86,119]\n"
+ " Javadoc [86,119]\n"
+ " TagElement [101,107]\n"
+ " TextElement: test2 [101,107]\n"
+ " ExpressionStatement [128,136]\n"
+ " MethodInvocation [128,135]\n"
+ " SimpleName: sleep [128,133]";
Expand Down

0 comments on commit 7c3df61

Please sign in to comment.