From fa51a58a92f5231acacd1419fad9fe7d4f12aa57 Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Wed, 8 May 2024 16:46:52 -0400 Subject: [PATCH] Fix for ASTConverterTest2.test0569 - javadoc assigned to wrong node Signed-off-by: Rob Stryker --- .../javac/dom/FindNextJavadocableSibling.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/FindNextJavadocableSibling.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/FindNextJavadocableSibling.java index eff74e00227..d3cd34385ef 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/FindNextJavadocableSibling.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/FindNextJavadocableSibling.java @@ -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; @@ -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. @@ -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; + } } }