Skip to content

Commit

Permalink
Handle the nested javadoc syntax '@see {@link ...}' better
Browse files Browse the repository at this point in the history
  • Loading branch information
testforstephen committed Aug 15, 2024
1 parent 52fe964 commit e5af720
Showing 1 changed file with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,42 +138,46 @@ private void commonSettings(ASTNode res, DCTree javac) {
Javadoc convertJavadoc() {
Javadoc res = this.ast.newJavadoc();
res.setSourceRange(this.initialOffset, this.endOffset - this.initialOffset);
if( this.javacConverter.ast.apiLevel == AST.JLS2_INTERNAL) {
String rawContent = this.javacConverter.rawText.substring(this.initialOffset, this.endOffset);
try {
res.setComment(rawContent);
} catch( IllegalArgumentException iae) {
// Ignore
try {
if( this.javacConverter.ast.apiLevel == AST.JLS2_INTERNAL) {
String rawContent = this.javacConverter.rawText.substring(this.initialOffset, this.endOffset);
try {
res.setComment(rawContent);
} catch( IllegalArgumentException iae) {
// Ignore
}
}
}
if (this.buildJavadoc) {
List<? extends IDocElement> elements = Stream.of(docComment.preamble, docComment.fullBody, docComment.postamble, docComment.tags)
.flatMap(List::stream)
.flatMap(this::convertElement)
.toList();
TagElement host = null;
for (IDocElement docElement : elements) {
if (docElement instanceof TagElement tag && !isInline(tag)) {
if (host != null) {
res.tags().add(host);
host = null;
}
res.tags().add(tag);
} else {
if (host == null) {
host = this.ast.newTagElement();
if(docElement instanceof ASTNode astn) {
host.setSourceRange(astn.getStartPosition(), astn.getLength());
if (this.buildJavadoc) {
List<? extends IDocElement> elements = Stream.of(docComment.preamble, docComment.fullBody, docComment.postamble, docComment.tags)
.flatMap(List::stream)
.flatMap(this::convertElement)
.toList();
TagElement host = null;
for (IDocElement docElement : elements) {
if (docElement instanceof TagElement tag && !isInline(tag)) {
if (host != null) {
res.tags().add(host);
host = null;
}
res.tags().add(tag);
} else {
if (host == null) {
host = this.ast.newTagElement();
if(docElement instanceof ASTNode astn) {
host.setSourceRange(astn.getStartPosition(), astn.getLength());
}
} else if (docElement instanceof ASTNode extraNode){
host.setSourceRange(host.getStartPosition(), extraNode.getStartPosition() + extraNode.getLength() - host.getStartPosition());
}
} else if (docElement instanceof ASTNode extraNode){
host.setSourceRange(host.getStartPosition(), extraNode.getStartPosition() + extraNode.getLength() - host.getStartPosition());
host.fragments().add(docElement);
}
host.fragments().add(docElement);
}
if (host != null) {
res.tags().add(host);
}
}
if (host != null) {
res.tags().add(host);
}
} catch (Exception ex) {
ILog.get().error("Failed to convert Javadoc", ex);
}
return res;
}
Expand Down Expand Up @@ -472,8 +476,11 @@ private MethodRef matchesMethodReference(DCErroneous tree, String body) {
if( hash != -1 ) {
int startPosition = this.docComment.getSourcePosition(tree.getStartPosition()) + 4;
String prefix = value.substring(0, hash);
int link = prefix.indexOf("@link");
prefix = prefix.substring(link + 5);
startPosition = startPosition + link + 5;
MethodRef ref = this.ast.newMethodRef();
if( prefix != null && !prefix.isEmpty() && !prefix.trim().isEmpty()) {
if( prefix != null && !prefix.isBlank()) {
Name n = toName(prefix, startPosition);
ref.setQualifier(n);
}
Expand Down

0 comments on commit e5af720

Please sign in to comment.