dnault / therapi-runtime-javadoc

Read Javadoc comments at run time.
Apache License 2.0
117 stars 19 forks source link

@Code tag doesn't always get reformatted #38

Closed jhameier closed 4 years ago

jhameier commented 4 years ago

I noticed when running the formatter over a doc with slightly different code blocks that some appear to get formatted with <code> tags and others do not.

The driver:

import com.github.therapi.runtimejavadoc.ClassJavadoc;
import com.github.therapi.runtimejavadoc.CommentFormatter;
import com.github.therapi.runtimejavadoc.MethodJavadoc;
import com.github.therapi.runtimejavadoc.RuntimeJavadoc;

public class Driver {

  public static void main(String[] args) {
    ClassJavadoc javadoc = RuntimeJavadoc.getJavadoc(Test.class);
    MethodJavadoc methodJavadoc = javadoc.getMethods().get(0);
    String format = new CommentFormatter().format(methodJavadoc.getComment());
    System.out.println(format);
  }
}

The Test file:

public class Test {

  /**
   * <pre>{@code
   *    <Class>
   *         <Load>ask</Load>
   *         <ConstructArg>
   *            <ArgName>facilities</ArgName>
   *            <ArgType>java.lang.String</ArgType>
   *            <ArgValue>ZDC,ZOB,ZNY</ArgValue>
   *         </ConstructArg>
   *     </Class>
   * }</pre>
   *
   * <pre>{@code
   * echo 'net.ipv4.igmp_max_memberships=1024' > /usr/lib/sysctl.d/51-adsb.conf
   * }</pre>
   */
  public void testMethod() {}
}

The output:

<pre>{@code
    <Class>
         <Load>ask</Load>
         <ConstructArg>
            <ArgName>facilities</ArgName>
            <ArgType>java.lang.String</ArgType>
            <ArgValue>ZDC,ZOB,ZNY</ArgValue>
         </ConstructArg>
     </Class>
 }</pre>

 <pre><code>echo 'net.ipv4.igmp_max_memberships=1024' &gt; /usr/lib/sysctl.d/51-adsb.conf
 </code></pre>
jhameier commented 4 years ago

On an aside in intellij

image

dnault commented 4 years ago

Regarding the aside, the JsonObject class marked in red is part of the Minimal-Json library that is bundled and repackaged with the reader. The Gradle "shadow" plugin is relocating the dependency classes, but doesn't update the sources. See https://github.com/johnrengelman/shadow/issues/41

Not much we can do about that, short of switching to Maven or undertaking the huge effort of enhancing the shadow plugin.

dnault commented 4 years ago

Hi John, Thanks for reporting this. I have a hunch the code that parses the "{@code ...}" inline tag does not expect a line break within the tag. I can take a look.

jhameier commented 4 years ago

Yea, but strange thing is that both @code tags have a line break after them but the first doesn't get changed and the second one does. It also removes the line break when it changes the @code tag to the tag.