Skip to content

Commit cede44f

Browse files
committed
Keep annotated Java 8 signatures aligned across platforms
1 parent 4deb02f commit cede44f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎gradle/normalize-javadoc-trees.gradle‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Java 8's doclet leaves enum siblings in platform-dependent order.
22
// Keep the full hierarchy while giving leaf-only sibling lists a stable order.
33
tasks.withType(Javadoc).configureEach {
4-
inputs.property('javadocTreeOrder', 'lexical leaf siblings 1')
4+
inputs.property('javadocTreeOrder', 'lexical leaf siblings and nullable alignment 2')
55
doLast {
66
fileTree(destinationDir) { include '**/*-tree.html' }.files.each { page ->
77
String original = page.getText('UTF-8')
@@ -12,5 +12,17 @@ tasks.withType(Javadoc).configureEach {
1212
}
1313
if (ordered != original) page.setText(ordered, 'UTF-8')
1414
}
15+
// The Java 8 doclet counts CRLF in @Nullable when aligning wrapped parameters.
16+
fileTree(destinationDir) { include '**/*.html' }.files.each { page ->
17+
String original = page.getText('UTF-8')
18+
String aligned = original.replaceAll(
19+
/(<pre>@Nullable\r?\n)(public[^\r\n]*?\()([^\r\n]*\r?\n)( +)([^ \r\n][^\r\n]*\)<\/pre>)/) {
20+
all, annotation, prefix, first, indentation, last ->
21+
String visible = prefix.replaceAll(/<[^>]+>/, '')
22+
.replace('&nbsp;', ' ').replace('&lt;', '<').replace('&gt;', '>')
23+
annotation + prefix + first + (' ' * visible.length()) + last
24+
}
25+
if (aligned != original) page.setText(aligned, 'UTF-8')
26+
}
1527
}
1628
}

0 commit comments

Comments
 (0)