Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading