Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:

# One explicit job per target, so every binary we ship is traceable to a named run.
native:
name: native (${{ matrix.platform }})
name: native (${{ matrix.runner }})
needs: build
runs-on: ${{ matrix.runner }}
timeout-minutes: 90
Expand All @@ -170,17 +170,15 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- platform: linux-x86-64
runner: ubuntu-latest
- platform: linux-aarch64
runner: ubuntu-24.04-arm
- platform: macos-aarch64
runner: macos-15
- platform: macos-x86-64
runner: macos-15-intel
- platform: windows-x86-64
runner: windows-latest
runner:
- ubuntu-latest
- ubuntu-24.04-arm
# macOS arm64 is left out: GitHub's runners for it are scarce, and from 17 to 19 November 2026 it found
# none for 13 of the job's 21 pull-request runs, each failing after 15 minutes of waiting. The release
# still builds it.
# - macos-15
- macos-15-intel
- windows-latest

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ mise run ci:native # actually run the linux-aarch64 native job

Two caveats:

- **act cannot containerise macOS**, so the `macos-aarch64` leg has to be checked by building the
- **act cannot containerise macOS**, so the `macos-15-intel` leg has to be checked by building the
native image on a Mac.
- **On an Apple Silicon host** the `ubuntu-24.04` container runs as arm64, so the job labelled
`linux-x86-64` produces an aarch64 binary locally. Fine for exercising the workflow, not a
`ubuntu-latest` produces an aarch64 binary locally. Fine for exercising the workflow, not a
substitute for real CI.

## License and attribution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tasks.withType(JavaCompile).configureEach {
nullaway {
handleTestAssertionLibraries = true
}
error('AlmostJavadoc')
error('CanonicalAnnotationSyntax')
error('CollectorMutability')
error('DefaultCharset')
Expand Down
2 changes: 1 addition & 1 deletion mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ run = "act push --job build --env JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Ho

[tasks."ci:native"]
description = "Run the linux-aarch64 native job locally in Docker"
run = "act push --job native --matrix platform:linux-aarch64"
run = "act push --job native --matrix runner:ubuntu-24.04-arm"

# ---- GitHub Actions secrets ----
# Read from 1Password at apply time; nothing secret is stored in the repo. Requires gh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ boolean tryConsume(String expected) {
return true;
}

/*
/**
* Like {@link #tryConsume}, but for a match of the pattern at the start of the remaining input.
*
* @param pattern the pattern to search for, which must be anchored to match only at position 0
*/
boolean tryConsumeRegex(Pattern pattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
/**
* Strips the margin from every continuation line: the {@code *} prefix (with the space after it) from lines that
* have one, and the comment's own indentation from lines that do not. What remains of a bare line's indentation is
* relative to the comment, as on {@code *} lines after their {@code * }, so a {@code <pre>{@code} block written

Check warning on line 83 in open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java

View workflow job for this annotation

GitHub Actions / build

[UnrecognisedJavadocTag] This Javadoc tag '{@code <pre>{@code' wasn't recognised by the parser. Is it malformed somehow, perhaps with mismatched braces?
* without the {@code *} margin keeps its shape for {@link #deindentPreCodeBlocks}.
*
* <p>The indentation stripped from bare lines is the smaller of the shortest {@code *} prefix and the shortest
Expand Down Expand Up @@ -173,7 +173,8 @@
result = joinAdjacentLiteralsAndAdjacentWhitespace(result);
result = inferParagraphTags(result);
result = optionalizeSpacesAfterLinks(result);
return deindentPreCodeBlocks(result);
result = deindentPreCodeBlocks(result);
return removeTrailingParagraphTags(result);
}

private Token readToken() throws LexException {
Expand Down Expand Up @@ -574,6 +575,35 @@
}
}

/**
* Remove the {@code <p>} tags at the end of the comment, and the whitespace and {@code </p>} tags among them.
* Nothing follows such a tag, but the writer would still put it on a line of its own after a blank one.
*
* <p>A {@code <p>} with attributes stays: its {@code id} may be the target of a link.
*/
private static List<Token> removeTrailingParagraphTags(List<Token> input) {
// The last token is always END_JAVADOC, and the scan stops at BEGIN_JAVADOC at the latest.
int end = input.size() - 1;
int cut = end;
for (int i = end - 1; i >= 0; i--) {
Token token = input.get(i);
if (token.getType() == PARAGRAPH_OPEN_TAG
&& BARE_PARAGRAPH_OPEN_PATTERN.matcher(token.getValue()).matches()) {
cut = i;
} else if (token.getType() != WHITESPACE && token.getType() != PARAGRAPH_CLOSE_TAG) {
break;
}
}
if (cut == end) {
return input;
}
var output = new ArrayList<Token>(input.subList(0, cut));
output.add(input.get(end));
return List.copyOf(output);
}

private static final Pattern BARE_PARAGRAPH_OPEN_PATTERN = compile("<p\\s*/?\\s*>", CASE_INSENSITIVE);

private static final CharMatcher NEWLINE = CharMatcher.is('\n');

private static boolean hasMultipleNewlines(String s) {
Expand Down Expand Up @@ -617,15 +647,15 @@
private static final Pattern BR_PATTERN = openTagPattern("br");
private static final Pattern SNIPPET_TAG_OPEN_PATTERN = compile("^[{]@snippet\\b");
private static final Pattern INLINE_TAG_OPEN_PATTERN = compile("^[{]@\\w*");
/*
* We exclude < so that we don't swallow following HTML tags. This lets us fix up "foo<p>" (~400
* hits in Google-internal code). We will join unnecessarily split "words" (like "foo<b>bar</b>")
* in a later step. There's a similar story for braces. I'm not sure I actually need to exclude @
* or *. TODO(cpovirk): Try removing them.
/**
* We exclude {@code <} so that we don't swallow following HTML tags. This lets us fix up {@code foo<p>} (~400
* hits in Google-internal code). We will join unnecessarily split "words" (like {@code foo<b>bar</b>}) in a later
* step. There's a similar story for braces. I'm not sure I actually need to exclude {@code @} or {@code *}.
* TODO(cpovirk): Try removing them.
*
* Thanks to the "rejoin" step in joinAdjacentLiteralsAndAdjacentWhitespace(), we could get away
* with matching only one character here. That would eliminate the need for the regex entirely.
* That might be faster or slower than what we do now.
* <p>Thanks to the "rejoin" step in {@link #joinAdjacentLiteralsAndAdjacentWhitespace}, we could get away with
* matching only one character here. That would eliminate the need for the regex entirely. That might be faster or
* slower than what we do now.
*/
private static final Pattern LITERAL_PATTERN = compile("^.[^ \t\n@<{}*]*", DOTALL);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,73 @@ void removeInitialParagraphTag() {
doFormatTest(input, expected);
}

@Test
void removeTrailingParagraphTag() {
String[] input = {
"/**", //
" * The client's first name.",
" *",
" * <p>",
" */",
"class Test {}",
};
String[] expected = {
"/** The client's first name. */", //
"class Test {}",
};
doFormatTest(input, expected);
}

@Test
void removeEveryTrailingParagraphTag() {
String[] input = {
"class Test {",
" /**",
" * Returns nothing.",
" *",
" * @param x the x",
" * <p>",
" */",
" void f(int x) {}",
"",
" /**",
" * Closed and repeated.",
" *",
" * <p></p>",
" * <P/>",
" */",
" void g() {}",
"}",
};
String[] expected = {
"class Test {",
" /**",
" * Returns nothing.",
" *",
" * @param x the x",
" */",
" void f(int x) {}",
"",
" /** Closed and repeated. */",
" void g() {}",
"}",
};
doFormatTest(input, expected);
}

@Test
void keepTrailingParagraphTagWithAttributes() {
String[] input = {
"/**", //
" * Ends with an anchor.",
" *",
" * <p id=\"end\">",
" */",
"class Test {}",
};
doFormatTest(input, input);
}

@Test
void inferParagraphTags() {
String[] input = {
Expand Down
Loading