Skip to content

Commit

Permalink
Abort sibling finder if same start position
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker committed Apr 2, 2024
1 parent 95a2ae0 commit d7ea1a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d7ea1a4

Please sign in to comment.