Skip to content

Add support for markdown javadoc#433

Open
Goldmensch wants to merge 5 commits into
palantir:developfrom
Goldmensch:md_javadocs
Open

Add support for markdown javadoc#433
Goldmensch wants to merge 5 commits into
palantir:developfrom
Goldmensch:md_javadocs

Conversation

@Goldmensch
Copy link
Copy Markdown

closes #234

Just adds the changes from #390

( I can't find the time to setup the project on my nixos machine currently, so hopefully all changes are still compatible)

@changelog-app
Copy link
Copy Markdown

changelog-app Bot commented Mar 11, 2026

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Add support for markdown javadoc

Check the box to generate changelog(s)

  • Generate changelog entry

@palantirtech
Copy link
Copy Markdown
Member

Thanks for your interest in palantir/javapoet, @Goldmensch! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@Goldmensch
Copy link
Copy Markdown
Author

Goldmensch commented Apr 9, 2026

@pkoenig10 could this be merged please?

Copy link
Copy Markdown
Member

@pkoenig10 pkoenig10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here. Approach generally looks good, couple of more minor comments.

// Emit a newline character. Make sure blank lines in Javadoc & comments look good.
if (!first) {
if ((javadoc || comment) && trailingNewline) {
if ((comment != null) && trailingNewline) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((comment != null) && trailingNewline) {
if (comment != null && trailingNewline) {

return JavaFile.builder(tacosPackage, typeSpec).build().toString();
}

private String toStringWithMarkdownJavadocs(TypeSpec typeSpec) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private String toStringWithMarkdownJavadocs(TypeSpec typeSpec) {
private String toStringWithMarkdownJavadoc(TypeSpec typeSpec) {

Comment thread README.md
Comment on lines +922 to +923
To output Markdown styled Javadoc (see [JEP 467](https://openjdk.org/jeps/467)),
th method `useMarkdownJavadoc()` of the `JavaFile` builder has to be called:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To output Markdown styled Javadoc (see [JEP 467](https://openjdk.org/jeps/467)),
th method `useMarkdownJavadoc()` of the `JavaFile` builder has to be called:
To emit Markdown Javadoc (see [JEP 467](https://openjdk.org/jeps/467)),
use `JavaFile.Builder.useMarkdownJavadoc()`:

Comment thread README.md
javaFile.writeTo(System.out);
```

which outputs:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consistent wording

Suggested change
which outputs:
Which generates this:

Comment thread README.md
Comment on lines +925 to +959
```java
TypeSpec emptyClass = TypeSpec.classBuilder("EmptyClass")
.addJavadoc("# Empty Class\n"
+ "\n"
+ "A representation of nothing: /* empty */\n")
.addJavadoc("\n")
.addJavadoc("This is not to be confused with the [$T] datatype which\n"
+ "is an uninstantiable placeholder class to hold a reference\n"
+ "to the *Class* object representing the Java keyword `void`.\n", Void.class)
.build();

JavaFile javaFile = JavaFile.builder("com.example.empty", emptyClass)
.useMarkdownJavadoc() // sets the Markdown output flag
.build();

javaFile.writeTo(System.out);
```

which outputs:

```java
package com.example.empty;

import java.lang.Void;

/// # Empty Class
///
/// A representation of nothing: /* empty */
///
/// This is not to be confused with the [Void] datatype which
/// is an uninstantiable placeholder class to hold a reference
/// to the *Class* object representing the Java keyword `void`.
class EmptyClass {
}
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update this to use the same example (or as similar as possible) as in the non-Markdown example?

}

@Test
public void withParameterMarkdownJavaDoc() throws IOException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test feels somewhat arbitrary - we don't have similar tests for the other types which can contain Javadoc (ex FieldSpec or ParameterSpec). It also requires this awkward TestUtil.codeWriterWithMarkdownJavadoc, which I'd prefer to avoid introducing.

I think we can just remove this test. It's sufficient to test CodeWriter and JavaFile.

}

@Test
public void recordWithMarkdownJavadoc() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should probably be on JavaFileTest, not TypeSpecTest - the useMarkdownJavadoc option is part of JavaFile.

return JavaFile.builder(tacosPackage, typeSpec).build().toString();
}

private String toStringWithMarkdownJavadocs(TypeSpec typeSpec) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private String toStringWithMarkdownJavadocs(TypeSpec typeSpec) {
private String toStringWithMarkdownJavadoc(TypeSpec typeSpec) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for JEP 467 Markdown Javadoc comments?

3 participants