GP-0: Adding Markdown support to Doclets

This commit is contained in:
Ryan Kurtz
2026-07-09 05:56:38 -04:00
parent ee4fba705a
commit c7057c192b
3 changed files with 28 additions and 47 deletions

View File

@@ -47,7 +47,7 @@ public class FileHeader implements StructConverter, Writeable {
/// The name to use when converting into a structure data type /// The name to use when converting into a structure data type
public final static String NAME = "IMAGE_FILE_HEADER"; public final static String NAME = "IMAGE_FILE_HEADER";
/// The size of the {@code IMAGE_FILE_HEADER} in bytes /// The size of the `IMAGE_FILE_HEADER` in bytes
public final static int IMAGE_SIZEOF_FILE_HEADER = 20; public final static int IMAGE_SIZEOF_FILE_HEADER = 20;
/// Relocation info stripped from file /// Relocation info stripped from file

View File

@@ -35,7 +35,7 @@ import jdk.javadoc.doclet.*;
/** /**
* Doclet that outputs javadoc in JSON format (instead of HTML). Things like Python can then * Doclet that outputs javadoc in JSON format (instead of HTML). Things like Python can then
* read in the JSON and easily access all of the javadoc elements. * read in the JSON and easily access all of the javadoc elements.
* * <p>
* To run: gradle zipJavadocs * To run: gradle zipJavadocs
*/ */
public class JsonDoclet implements Doclet { public class JsonDoclet implements Doclet {
@@ -134,10 +134,9 @@ public class JsonDoclet implements Doclet {
} }
/** /**
* Converts a class {@link TypeElement} to a {@link JsonObject}. * {@return a class {@link TypeElement} converted to a {@link JsonObject}}
* *
* @param classElement the class {@link TypeElement} to convert * @param classElement the class {@link TypeElement} to convert
* @return A json object that represents the class.
*/ */
private JsonObject classToJson(TypeElement classElement) { private JsonObject classToJson(TypeElement classElement) {
JsonObject classObj = new JsonObject(); JsonObject classObj = new JsonObject();
@@ -361,90 +360,71 @@ public class JsonDoclet implements Doclet {
} }
/** /**
* Gets the long type name of the given {@link TypeMirror type}. * {@return the long type name of the given {@link TypeMirror type}}
* *
* @param type The type to get the long type name of. * @param type The type to get the long type name of.
* @return The long type name of the given {@link TypeMirror type}.
*/ */
private String getTypeLong(TypeMirror type) { private String getTypeLong(TypeMirror type) {
return type.toString(); return type.toString();
} }
/** /**
* Gets the short type name of the given {@link TypeMirror type}. * {@return the short type name of the given {@link TypeMirror type}}
* *
* @param type The type to get the short type name of. * @param type The type to get the short type name of.
* @return The short type name of the given {@link TypeMirror type}.
*/ */
private String getTypeShort(TypeMirror type) { private String getTypeShort(TypeMirror type) {
switch (type.getKind()) { return switch (type.getKind()) {
case DECLARED: case DECLARED -> ((DeclaredType) type).asElement().getSimpleName().toString();
return ((DeclaredType) type).asElement().getSimpleName().toString(); default -> type.toString();
default: };
return type.toString();
}
} }
/** /**
* Gets the comment from the given {@link DocTree}. * {@return the comment from the given {@link DocTree}}
* *
* @param docTree The {@link DocTree} to get the comment from. * @param docTree The {@link DocTree} to get the comment from.
* @return The comment from the given {@link DocTree}.
*/ */
private String getComment(DocTree docTree) { private String getComment(DocTree docTree) {
switch (docTree.getKind()) { return switch (docTree.getKind()) {
case COMMENT: case COMMENT -> ((CommentTree) docTree).getBody();
return ((CommentTree) docTree).getBody(); case LINK -> ((LinkTree) docTree).getReference().getSignature();
case LINK: case PARAM -> getComment(((ParamTree) docTree).getDescription());
return ((LinkTree) docTree).getReference().getSignature(); case RETURN -> getComment(((ReturnTree) docTree).getDescription());
case PARAM: case TEXT -> ((TextTree) docTree).getBody();
return getComment(((ParamTree) docTree).getDescription()); case THROWS -> getComment(((ThrowsTree) docTree).getDescription());
case RETURN: case MARKDOWN -> ((RawTextTree) docTree).getContent();
return getComment(((ReturnTree) docTree).getDescription()); default -> "";
case TEXT: };
return ((TextTree) docTree).getBody();
case THROWS:
return getComment(((ThrowsTree) docTree).getDescription());
default:
return "";
}
} }
/** /**
* Gets the comment from the given {@link List} of {@link DocTree}s. Each list element * {@return the comment from the given {@link List} of {@link DocTree}s}
* represents a line. The final comment is simply all the lines concatenated. * <p>
* Each list element represents a line. The final comment is simply all the lines concatenated.
* *
* @param docTreeList The {@link DocTree} {@link List} to get the comment from. * @param docTreeList The {@link DocTree} {@link List} to get the comment from.
* @return The comment from the given {@link DocTree} {@link List}.
*/ */
private String getComment(List<? extends DocTree> docTreeList) { private String getComment(List<? extends DocTree> docTreeList) {
return docTreeList.stream().map(e -> getComment(e)).collect(Collectors.joining()); return docTreeList.stream().map(e -> getComment(e)).collect(Collectors.joining());
} }
/** /**
* Gets the comment from the given {@link DocCommentTree}. * {@return the comment from the given {@link DocCommentTree}}
* *
* @param docCommentTree The {@link DocCommentTree} to get the comment from. * @param docCommentTree The {@link DocCommentTree} to get the comment from.
* @return The comment from the given {DocCommentTree DocTree}.
*/ */
private String getComment(DocCommentTree docCommentTree) { private String getComment(DocCommentTree docCommentTree) {
if (docCommentTree != null) { return docCommentTree != null ? getComment(docCommentTree.getFullBody()) : "";
return getComment(docCommentTree.getFullBody());
}
return "";
} }
/** /**
* Gets the full unprocessed javadoc from the given {@link DocCommentTree}. * {@return the full unprocessed javadoc from the given {@link DocCommentTree}}
* *
* @param docCommentTree The {@link DocCommentTree} to get the javadoc from. * @param docCommentTree The {@link DocCommentTree} to get the javadoc from.
* @return the full unprocessed javadoc from the given {@link DocCommentTree}.
*/ */
private String getJavadoc(DocCommentTree docCommentTree) { private String getJavadoc(DocCommentTree docCommentTree) {
if (docCommentTree != null) { return docCommentTree != null ? docCommentTree.toString() : "";
return docCommentTree.toString();
}
return "";
} }
/** /**

View File

@@ -169,6 +169,7 @@ public class JavadocConverter extends DocConverter {
// NOTE: each tag is responsible for its own line endings // NOTE: each tag is responsible for its own line endings
return switch (tag.getKind()) { return switch (tag.getKind()) {
case DOC_ROOT -> tag.toString(); // not sure what would be an appropriate replacement case DOC_ROOT -> tag.toString(); // not sure what would be an appropriate replacement
case MARKDOWN -> tag.toString();
case PARAM -> convertParamTag(el, (ParamTree) tag); case PARAM -> convertParamTag(el, (ParamTree) tag);
case RETURN -> convertReturnTag((ExecutableElement) el, (ReturnTree) tag); case RETURN -> convertReturnTag((ExecutableElement) el, (ReturnTree) tag);
case THROWS -> convertThrowsTag((ExecutableElement) el, (ThrowsTree) tag); case THROWS -> convertThrowsTag((ExecutableElement) el, (ThrowsTree) tag);