From d7ea1a42d3b51e02e56404253530edeaa17bdeea Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Tue, 2 Apr 2024 15:09:32 -0400 Subject: [PATCH] Abort sibling finder if same start position Signed-off-by: Rob Stryker --- .../eclipse/jdt/core/dom/JavacConverter.java | 1 - .../javac/dom/FindNextJavadocableSibling.java | 37 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index 3a890e0860f..031811bba97 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -558,7 +558,6 @@ private MethodDeclaration convertMethodDecl(JCMethodDecl javac, ASTNode parent) private VariableDeclaration convertVariableDeclaration(JCVariableDecl javac) { // if (singleDecl) { SingleVariableDeclaration res = this.ast.newSingleVariableDeclaration(); - String z = javac.toString(); commonSettings(res, javac); if (convert(javac.getName()) instanceof SimpleName simpleName) { res.setName(simpleName); 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 b5e69f4588b..eff74e00227 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 @@ -15,24 +15,47 @@ import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.PackageDeclaration; public class FindNextJavadocableSibling extends ASTVisitor { public ASTNode nextNode = null; - private int javadocOffsetEnd; - public FindNextJavadocableSibling(int javadocOffsetEnd) { - this.javadocOffsetEnd = javadocOffsetEnd; + private int javadocStart; + private int javadocLength; + private boolean done = false; + public FindNextJavadocableSibling(int javadocStart, int javadocLength) { + this.javadocStart = javadocStart; + this.javadocLength = javadocLength; } + public boolean preVisit2(ASTNode node) { + if( done ) + return false; + + preVisit(node); + return true; + } + @Override public void preVisit(ASTNode node) { - if (node.getStartPosition() > this.javadocOffsetEnd && - isJavadocAble(node) && - (this.nextNode == null || this.nextNode.getStartPosition() > node.getStartPosition())) { + // If there's any overlap, abort. + //int nodeEnd = node.getStartPosition() + node.getLength(); + int jdocEnd = this.javadocStart + this.javadocLength; + + if( isJavadocAble(node)) { + if( node.getStartPosition() == this.javadocStart ) { this.nextNode = node; + done = true; + return; } + if (node.getStartPosition() > jdocEnd && + (this.nextNode == null || this.nextNode.getStartPosition() > node.getStartPosition())) { + this.nextNode = node; + } + } } private static boolean isJavadocAble(ASTNode node) { - return node instanceof AbstractTypeDeclaration || + return node instanceof PackageDeclaration || + node instanceof AbstractTypeDeclaration || node instanceof FieldDeclaration || node instanceof MethodDeclaration; }