Skip to content

Commit

Permalink
Fix for ASTConverterTest2.test0569 - javadoc assigned to wrong node
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed May 8, 2024
1 parent fb668ad commit 4be3364
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import org.eclipse.jdt.core.dom.PackageDeclaration;

public class FindNextJavadocableSibling extends ASTVisitor {
public ASTNode nextNode = null;
private ASTNode nextNode = null;
private ASTNode nonJavaDocableNextNode = null;
private int javadocStart;
private int javadocLength;
private boolean done = false;
Expand All @@ -34,6 +35,15 @@ public boolean preVisit2(ASTNode node) {
return true;
}

public ASTNode getNextNode() {
if( this.nonJavaDocableNextNode == null || this.nextNode == null)
return this.nextNode;
if( this.nonJavaDocableNextNode.getStartPosition() < this.nextNode.getStartPosition()) {
return null;
}
return this.nextNode;
}

@Override
public void preVisit(ASTNode node) {
// If there's any overlap, abort.
Expand All @@ -50,6 +60,15 @@ public void preVisit(ASTNode node) {
(this.nextNode == null || this.nextNode.getStartPosition() > node.getStartPosition())) {
this.nextNode = node;
}
} else {
// Let's keep track of the non-jdocable next node in case.
// If there's a sysout between the jdoc and a type, it is invalid
if( node.getStartPosition() == this.javadocStart ) {
this.nonJavaDocableNextNode = node;
} else if (node.getStartPosition() > jdocEnd &&
(this.nonJavaDocableNextNode == null || this.nonJavaDocableNextNode.getStartPosition() > node.getStartPosition())) {
this.nonJavaDocableNextNode = node;
}
}
}

Expand Down

0 comments on commit 4be3364

Please sign in to comment.