@@ -312,13 +312,27 @@ private Stream<IDocElement> convertInlineTag(DCTree javac) {
312312 });
313313 res .fragments ().addAll (convertElement (literal .body ).toList ());
314314 } else if (javac instanceof DCLink link ) {
315- res .setTagName (switch (link .getKind ()) {
316- case LINK -> TagElement .TAG_LINK ;
317- case LINK_PLAIN -> TagElement .TAG_LINKPLAIN ;
318- default -> TagElement .TAG_LINK ;
319- });
320- res .fragments ().addAll (convertElement (link .ref ).toList ());
321- link .label .stream ().flatMap (this ::convertElement ).forEach (res .fragments ()::add );
315+ res .setTagName (this .docComment .comment .getStyle () == CommentStyle .JAVADOC_LINE ? TagElement .TAG_LINK :
316+ switch (link .getKind ()) {
317+ case LINK -> TagElement .TAG_LINK ;
318+ case LINK_PLAIN -> TagElement .TAG_LINKPLAIN ;
319+ default -> TagElement .TAG_LINK ;
320+ });
321+ if (link .label != null && !link .label .isEmpty () && link .ref != null && link .label .getFirst ().getStartPosition () < link .ref .getStartPosition ()) {
322+ // markdown style
323+ link .label .stream ().flatMap (this ::convertElement ).forEach (res .fragments ()::add );
324+ res .fragments ().addAll (convertElement (link .ref ).toList ());
325+ // workaround position not set by javadoc (not reported)
326+ } else {
327+ res .fragments ().addAll (convertElement (link .ref ).toList ());
328+ link .label .stream ().flatMap (this ::convertElement ).forEach (res .fragments ()::add );
329+ }
330+ if (res .getStartPosition () < 0 ) {
331+ int start = ((ASTNode )res .fragments ().getFirst ()).getStartPosition () - 1 /* [ */ ;
332+ ASTNode lastChild = (ASTNode )res .fragments ().getLast ();
333+ int end = lastChild .getStartPosition () + lastChild .getLength () + 1 /* ) */ ;
334+ res .setSourceRange (start , end - start );
335+ }
322336 } else if (javac instanceof DCValue dcv ) {
323337 res .setTagName (TagElement .TAG_VALUE );
324338 res .fragments ().addAll (convertElement (dcv .ref ).toList ());
@@ -603,10 +617,29 @@ private Stream<? extends IDocElement> convertElement(DCTree javac) {
603617 if (javac instanceof DCText text ) {
604618 return splitLines (text , false ).map (this ::toTextElement );
605619 } else if (javac instanceof DCRawText rawText ) {
606- TextElement element = this .ast .newTextElement ();
607- commonSettings (element , javac );
608- element .setText (rawText .getContent ());
609- return Stream .of (element );
620+ if (this .docComment .comment .getStyle () == CommentStyle .JAVADOC_LINE && rawText .getContent ().contains ("\n " )) {
621+ // un-combine multiple javadoc lines
622+ String [] segments = rawText .getContent ().split ("\n " );
623+ List <TextElement > regions = new ArrayList <>(segments .length );
624+ int currentStart = this .docComment .getSourcePosition (rawText .getStartPosition ());
625+ for (String segment : segments ) {
626+ int end = this .javacConverter .rawText .indexOf ('\n' , currentStart );
627+ if (end < currentStart ) {
628+ end = this .docComment .getSourcePosition (rawText .getEndPosition ());
629+ }
630+ TextElement element = this .ast .newTextElement ();
631+ element .setSourceRange (currentStart , segment .length ());
632+ element .setText (segment );
633+ regions .add (element );
634+ currentStart = this .javacConverter .rawText .indexOf ("///" , end );
635+ }
636+ return regions .stream ();
637+ } else {
638+ TextElement element = this .ast .newTextElement ();
639+ commonSettings (element , javac );
640+ element .setText (rawText .getContent ());
641+ return Stream .of (element );
642+ }
610643 } else if (javac instanceof DCIdentifier identifier ) {
611644 Name res = this .ast .newName (identifier .getName ().toString ());
612645 commonSettings (res , javac );
0 commit comments