Skip to content

Commit c71387e

Browse files
dfa1claude
andauthored
refactor: use Markdown reference links in Javadoc, ban {@link} via checkstyle (#32)
Converts all 57 {@link ...} / {@linkplain ...} inline tags in /// Markdown Javadoc to Markdown reference links ([ClassName#method(ParamType)]), matching the project's stated convention. Adds a checkstyle RegexpSingleline that bans {@link}/{@linkplain} in /// lines so the old style cannot creep back, mirroring the existing {@code} ban. Also fixes a latent bug in both rules' messages: checkstyle renders them with MessageFormat, which threw "can't parse argument number" on the literal {@code}/{@link} braces whenever a violation actually fired — reworded to avoid braces. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 751ead5 commit c71387e

16 files changed

Lines changed: 59 additions & 51 deletions

checkstyle.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
<property name="format" value="^\s*///.*\{@code\s"/>
2222
<property name="minimum" value="0"/>
2323
<property name="maximum" value="0"/>
24-
<property name="message" value="Use backtick syntax instead of {@code} in Markdown Javadoc (///). Example: `value` instead of {@code value}."/>
24+
<property name="message" value="Use backtick syntax instead of the @code tag in Markdown Javadoc (///). Example: `value`."/>
25+
</module>
26+
27+
<!-- Ban {@link}/{@linkplain} in /// Markdown Javadoc — use Markdown reference links instead. -->
28+
<module name="RegexpSingleline">
29+
<property name="format" value="^\s*///.*\{@link(plain)?\s"/>
30+
<property name="minimum" value="0"/>
31+
<property name="maximum" value="0"/>
32+
<property name="message" value="Use Markdown reference links instead of the @link / @linkplain tag in Markdown Javadoc (///). Example: [ClassName#method(ParamType)]."/>
2533
</module>
2634

2735
<!-- Ban HTML block/structure tags in /// Markdown Javadoc.

zstd/src/main/java/io/github/dfa1/zstd/Bindings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// [official manual](https://facebook.github.io/zstd/doc/api_manual_latest.html).
1515
///
1616
/// `size_t` and `unsigned long long` are modelled as
17-
/// {@link java.lang.foreign.ValueLayout#JAVA_LONG} (LP64); the public API guards
17+
/// [java.lang.foreign.ValueLayout#JAVA_LONG] (LP64); the public API guards
1818
/// against negative interpretations where zstd uses sentinel values.
1919
///
2020
/// For the full coverage map — every public zstd symbol, what is bound, and which

zstd/src/main/java/io/github/dfa1/zstd/NativeCall.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/// Package-private helpers that adapt raw FFM downcalls to the zstd error
88
/// convention: run a native call, decode a zstd `size_t` error code into a
9-
/// {@link ZstdException}, and guard native-segment arguments. Shared by the
9+
/// [ZstdException], and guard native-segment arguments. Shared by the
1010
/// binding classes so the conventions live in one place.
1111
final class NativeCall {
1212

@@ -17,7 +17,7 @@ interface ZstdCall {
1717
}
1818

1919
/// Invokes a size-returning zstd call and converts a zstd error code into a
20-
/// {@link ZstdException}.
20+
/// [ZstdException].
2121
static long checkReturnValue(ZstdCall c) {
2222
long code;
2323
try {
@@ -38,7 +38,7 @@ interface NativeFactory {
3838
}
3939

4040
/// Runs a zstd `create`-style call and rejects the `NULL` it returns on
41-
/// allocation failure, raising a {@link ZstdException} that names the call.
41+
/// allocation failure, raising a [ZstdException] that names the call.
4242
static MemorySegment createOrThrow(String what, NativeFactory factory) {
4343
MemorySegment p;
4444
try {
@@ -97,7 +97,7 @@ static void requireNative(MemorySegment seg, String name) {
9797
}
9898

9999
/// Rethrows any `Throwable` as if unchecked, laundering the checked
100-
/// `Throwable` that {@link java.lang.invoke.MethodHandle#invokeExact} declares.
100+
/// `Throwable` that [java.lang.invoke.MethodHandle#invokeExact] declares.
101101
/// The shared sink for every binding class's native-call catch blocks.
102102
@SuppressWarnings("unchecked")
103103
static <E extends Throwable> RuntimeException rethrow(Throwable t) throws E {

zstd/src/main/java/io/github/dfa1/zstd/NativeLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.Locale;
1717

1818
/// Infrastructure — loads the bundled `libzstd` shared library and binds
19-
/// native symbols to {@link MethodHandle}s via the Foreign Function & Memory API.
19+
/// native symbols to [MethodHandle]s via the Foreign Function & Memory API.
2020
///
2121
/// The library is resolved only from the platform-specific native JAR on the
2222
/// classpath, extracted to a temp file, and loaded once at class-init time.

zstd/src/main/java/io/github/dfa1/zstd/NativeObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
/// Base class for wrappers that own a native zstd pointer.
77
///
8-
/// The pointer lives in an {@link AtomicReference} that is swapped to
9-
/// {@link MemorySegment#NULL} on {@link #close()}, so {@link #tryClose} runs
8+
/// The pointer lives in an [AtomicReference] that is swapped to
9+
/// [MemorySegment#NULL] on [#close()], so [#tryClose] runs
1010
/// exactly once even under concurrent or repeated close calls.
1111
public abstract class NativeObject implements AutoCloseable {
1212

@@ -46,6 +46,6 @@ public final void close() {
4646
/// Releases the native resource. Called exactly once with a non-NULL pointer.
4747
///
4848
/// @param ptr the non-NULL native pointer to free
49-
/// @throws Throwable if the native free call fails; the exception is swallowed by {@link #close()}
49+
/// @throws Throwable if the native free call fails; the exception is swallowed by [#close()]
5050
protected abstract void tryClose(MemorySegment ptr) throws Throwable;
5151
}

zstd/src/main/java/io/github/dfa1/zstd/Zstd.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
/// One-shot, stateless zstd compression and decompression over `byte[]`.
1111
///
1212
/// Every method is thread-safe and allocates its own native scratch buffers.
13-
/// For repeated calls on a hot path, reuse a {@link ZstdCompressCtx} /
14-
/// {@link ZstdDecompressCtx} instead to avoid re-allocating per call.
13+
/// For repeated calls on a hot path, reuse a [ZstdCompressCtx] /
14+
/// [ZstdDecompressCtx] instead to avoid re-allocating per call.
1515
///
1616
/// {@snippet :
1717
/// byte[] packed = Zstd.compress("hello world".getBytes());
@@ -35,7 +35,7 @@ public static byte[] compress(byte[] src) {
3535
/// Compresses `src` at the given level.
3636
///
3737
/// @param src bytes to compress
38-
/// @param level compression level in [{@link #minCompressionLevel()}, {@link #maxCompressionLevel()}];
38+
/// @param level compression level in [[#minCompressionLevel()], [#maxCompressionLevel()]];
3939
/// higher is smaller but slower
4040
/// @return a self-describing zstd frame
4141
public static byte[] compress(byte[] src, int level) {
@@ -56,7 +56,7 @@ public static byte[] compress(byte[] src, int level) {
5656
/// @param compressed a complete zstd frame
5757
/// @return the original bytes
5858
/// @throws ZstdException if the frame is invalid or its content size is not stored;
59-
/// use {@link #decompress(byte[], int)} for the latter
59+
/// use [#decompress(byte[], int)] for the latter
6060
public static byte[] decompress(byte[] compressed) {
6161
Objects.requireNonNull(compressed, "compressed");
6262
long size = requireStoredContentSize(frameContentSize(compressed));
@@ -82,8 +82,8 @@ public static byte[] decompress(byte[] compressed, int maxSize) {
8282
}
8383

8484
/// Decompressed size recorded in a zstd frame's header, read directly from a
85-
/// native {@link MemorySegment} with no copy — use it to size the destination
86-
/// for the zero-copy {@link ZstdDecompressCtx#decompress(MemorySegment, MemorySegment)}.
85+
/// native [MemorySegment] with no copy — use it to size the destination
86+
/// for the zero-copy [ZstdDecompressCtx#decompress(MemorySegment, MemorySegment)].
8787
///
8888
/// @param frame a complete zstd frame
8989
/// @return the decompressed length in bytes
@@ -196,7 +196,7 @@ public static int minCompressionLevel() {
196196
}
197197
}
198198

199-
/// The level used by {@link #compress(byte[])}.
199+
/// The level used by [#compress(byte[])].
200200
///
201201
/// @return the default compression level
202202
public static int defaultCompressionLevel() {

zstd/src/main/java/io/github/dfa1/zstd/ZstdCompressCtx.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
/// A reusable compression context.
88
///
9-
/// Reusing one context across many {@link #compress} calls amortises native
10-
/// state allocation, making it cheaper than the stateless {@link Zstd#compress}
9+
/// Reusing one context across many [#compress] calls amortises native
10+
/// state allocation, making it cheaper than the stateless [Zstd#compress]
1111
/// on hot paths. Not thread-safe: confine an instance to one thread or pool it.
1212
///
1313
/// {@snippet :
@@ -31,7 +31,7 @@ private static MemorySegment create() {
3131
return NativeCall.createOrThrow("ZSTD_createCCtx", () -> (MemorySegment) Bindings.CREATE_CCTX.invokeExact());
3232
}
3333

34-
/// Sets the compression level for subsequent {@link #compress} calls.
34+
/// Sets the compression level for subsequent [#compress] calls.
3535
///
3636
/// @param level the compression level to use
3737
/// @return `this`, for chaining
@@ -42,7 +42,7 @@ public ZstdCompressCtx level(int level) {
4242
}
4343

4444
/// Sets an advanced compression parameter for subsequent
45-
/// {@link #compress(byte[])} / {@link #compress(MemorySegment, MemorySegment)}
45+
/// [#compress(byte[])] / [#compress(MemorySegment, MemorySegment)]
4646
/// calls. The setting is sticky across calls until changed.
4747
///
4848
/// Advanced parameters do not apply to the dictionary `compress` overloads.
@@ -233,8 +233,8 @@ private void setParam(ZstdCompressParameter parameter, int value) {
233233
/// Compresses `src` against `dict` at this context's level.
234234
///
235235
/// The dictionary is re-digested on every call; for repeated compression
236-
/// against the same dictionary, digest it once into a {@link ZstdCompressDict}
237-
/// and use {@link #compress(byte[], ZstdCompressDict)}.
236+
/// against the same dictionary, digest it once into a [ZstdCompressDict]
237+
/// and use [#compress(byte[], ZstdCompressDict)].
238238
///
239239
/// @param src the bytes to compress
240240
/// @param dict the dictionary to compress against
@@ -255,7 +255,7 @@ public byte[] compress(byte[] src, ZstdDictionary dict) {
255255
}
256256

257257
/// Compresses `src` against a pre-digested `dict` (the level was
258-
/// fixed when the {@link ZstdCompressDict} was built).
258+
/// fixed when the [ZstdCompressDict] was built).
259259
///
260260
/// @param src the bytes to compress
261261
/// @param dict the pre-digested compression dictionary
@@ -275,12 +275,12 @@ public byte[] compress(byte[] src, ZstdCompressDict dict) {
275275
}
276276

277277
/// Zero-copy compression: reads `src` and writes the frame straight into
278-
/// `dst`, both native {@link MemorySegment}s the caller owns. No heap
278+
/// `dst`, both native [MemorySegment]s the caller owns. No heap
279279
/// `byte[]` bounce — hand zstd the segment addresses directly. This is
280280
/// the fast path when your bytes are already off-heap (e.g. an mmap slice and
281281
/// an arena-allocated output); see `docs/zero-copy.md`.
282282
///
283-
/// Size `dst` with {@link Zstd#compressBound(long)} to guarantee it fits.
283+
/// Size `dst` with [Zstd#compressBound(long)] to guarantee it fits.
284284
///
285285
/// @param dst the native destination buffer to write the frame into
286286
/// @param src the native source bytes to compress
@@ -308,7 +308,7 @@ public long compress(MemorySegment dst, MemorySegment src, ZstdCompressDict dict
308308
}
309309

310310
/// Zero-copy compression that allocates the output for you: reserves a
311-
/// worst-case buffer ({@link Zstd#compressBound(long)}) in `arena`,
311+
/// worst-case buffer ([Zstd#compressBound(long)]) in `arena`,
312312
/// compresses into it, and returns a slice trimmed to the actual frame length.
313313
/// The returned segment is owned by `arena`.
314314
///

zstd/src/main/java/io/github/dfa1/zstd/ZstdCompressDict.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
/// A dictionary digested once for compression at a fixed level.
88
///
99
/// Building a `ZstdCompressDict` pre-processes the dictionary so that each
10-
/// {@link ZstdCompressCtx#compress(byte[], ZstdCompressDict)} call skips that
10+
/// [ZstdCompressCtx#compress(byte[], ZstdCompressDict)] call skips that
1111
/// cost — the right choice when compressing many payloads against the same
12-
/// dictionary. The raw {@link ZstdDictionary} bytes are copied into native
12+
/// dictionary. The raw [ZstdDictionary] bytes are copied into native
1313
/// memory, so the source may be discarded afterwards.
1414
///
1515
/// Immutable once built and safe to share across threads (the digested dictionary is read-only).

zstd/src/main/java/io/github/dfa1/zstd/ZstdCompressStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import static java.lang.foreign.ValueLayout.JAVA_LONG;
99

1010
/// A low-level, zero-copy streaming compressor driven with native
11-
/// {@link MemorySegment} buffers — no heap `byte[]` bounce.
11+
/// [MemorySegment] buffers — no heap `byte[]` bounce.
1212
///
1313
/// Use this when both ends are already off-heap and you want full control over
1414
/// buffering; for ordinary `java.io` pipelines prefer [ZstdOutputStream].

zstd/src/main/java/io/github/dfa1/zstd/ZstdDecompressCtx.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/// A reusable decompression context.
88
///
9-
/// Reusing one context across many {@link #decompress} calls amortises native
9+
/// Reusing one context across many [#decompress] calls amortises native
1010
/// state allocation. Not thread-safe: confine an instance to one thread or pool it.
1111
public final class ZstdDecompressCtx extends NativeObject {
1212

@@ -175,8 +175,8 @@ public byte[] decompress(byte[] compressed, int maxSize) {
175175
/// Decompresses a frame that was compressed against `dict`.
176176
///
177177
/// The dictionary is re-digested on every call; for repeated use digest it
178-
/// once into a {@link ZstdDecompressDict} and use
179-
/// {@link #decompress(byte[], int, ZstdDecompressDict)}.
178+
/// once into a [ZstdDecompressDict] and use
179+
/// [#decompress(byte[], int, ZstdDecompressDict)].
180180
///
181181
/// @param compressed a complete zstd frame
182182
/// @param maxSize upper bound on the decompressed length
@@ -216,14 +216,14 @@ public byte[] decompress(byte[] compressed, int maxSize, ZstdDecompressDict dict
216216
}
217217

218218
/// Zero-copy decompression: reads the frame from `src` and writes the
219-
/// result straight into `dst`, both native {@link MemorySegment}s the
219+
/// result straight into `dst`, both native [MemorySegment]s the
220220
/// caller owns. No heap `byte[]` bounce — the segment addresses go
221221
/// directly to zstd. This is the fast path when input is an mmap slice and
222222
/// output is an arena buffer that becomes the materialized array as-is;
223223
/// see `docs/zero-copy.md`.
224224
///
225225
/// Size `dst` to the decompressed length (read it from the frame with
226-
/// {@link Zstd#decompress(byte[])}'s header logic, or known out-of-band).
226+
/// [Zstd#decompress(byte[])]'s header logic, or known out-of-band).
227227
///
228228
/// @param dst the native destination buffer to write the result into
229229
/// @param src the native source frame to decompress
@@ -256,7 +256,7 @@ public long decompress(MemorySegment dst, MemorySegment src, ZstdDecompressDict
256256
/// segment is owned by `arena` and ready to use as a backing buffer.
257257
///
258258
/// Requires the frame to store its decompressed size (frames produced by this
259-
/// library do); for size-less frames use {@link #decompress(MemorySegment, MemorySegment)}
259+
/// library do); for size-less frames use [#decompress(MemorySegment, MemorySegment)]
260260
/// with a destination you size yourself.
261261
///
262262
/// @param arena the arena to allocate the output segment in

0 commit comments

Comments
 (0)