Commit 9be73a3
committed
refactor: Lombok @ToString/@EqualsAndHashCode across jllama production sources
Apply the BAF/plugin Lombok migration pattern to java-llama.cpp. Value-shaped
types get @tostring + @EqualsAndHashCode; mutable lifecycle handles and
operational classes get @tostring only (identity is the correct equals
semantics); classes with semantically-meaningful handwritten toString
implementations keep their custom toString and gain @EqualsAndHashCode only.
Build wiring fixes (mirrors BAF/plugin):
- pom.xml: add Lombok to <annotationProcessorPaths> AND extend the explicit
-processor argument list to include both Lombok SPI processors
(AnnotationProcessorHider$AnnotationProcessor and $ClaimingProcessor)
alongside the existing Checker Framework NullnessChecker.
- lombok.config: switch callSuper default from "call" to "skip" since most
value classes extend Object directly.
Value types (Lombok @tostring + @EqualsAndHashCode):
- Pair, ChatChoice, ChatResponse, ContentPart, ToolDefinition
Value types with derived/aggregated toString fields:
- Usage (totalTokens via @ToString.Include on the getter)
- TokenLogprob (topLogprobs rendered as size via @ToString.Include)
- Timings (full field dump)
Value types with semantically-meaningful handwritten toString preserved
(@EqualsAndHashCode only, toString documented as intentional):
- ChatMessage ("role: content" conversation-trace format)
- ToolCall ("name(args)[id]" function-call syntax)
- CompletionResult, LlamaOutput (return generated text verbatim — public
API contract)
- ModelMeta, ServerMetrics (re-serialise to compact JSON for assertEquals)
- JsonParameters (emits actual JSON the native server consumes)
- CliParameters (emits CLI argv-style string for the native binary)
Subclasses of JsonParameters/CliParameters get @EqualsAndHashCode(callSuper=true):
- InferenceParameters, ModelParameters
Operational / lifecycle classes (Lombok @tostring only; identity-equals is
correct; native handles and lambdas excluded from rendered output):
- LlamaModel (parser collaborators rendered, native ctx handle visible)
- LlamaIterator, LlamaIterable, LlamaPublisher (owning model excluded —
recursive native-state dump)
- Session (model + lambdas + lock excluded)
- CancellationToken, ChatRequest (lambdas excluded)
- LlamaLoader, LlamaSystemProperties, NativeLibraryPermissionSetter,
ProcessRunner, Java8CompatibilityHelper
Test update:
- PairTest.testHashCodeMatchesObjectsHash renamed and rewritten to
verify the hashCode contract (non-zero, varies by field) rather than
pinning to Objects.hash. The PIT-mutation-killing intent is preserved
but no longer assumes the specific implementation.
Intentionally skipped (rationale documented inline):
- OSInfo — vendored from sqlite-jdbc with explicit "only deviations" policy;
adding Lombok would diverge further. Spotless line-wrapping is incidental.
- LlamaException, ModelUnavailableException — extend Throwable, which
already provides toString and identity-equals.
- StopReason, LogLevel — enums, inherit toString from Enum.
- LoadProgressCallback, ToolHandler — interfaces.
- SkipDownloadFailureTranslator, TimingsLogger — non-instantiable utility
classes (private constructor + all-static methods).
All 888 runnable tests pass; the single RerankingModelTest error is a
pre-existing UnsatisfiedLinkError on this sandbox (no native library
built in restricted-network env, per CLAUDE.md).
https://claude.ai/code/session_01LzoKmqzgtQsELS5tsH4Wog1 parent baffa37 commit 9be73a3
40 files changed
Lines changed: 325 additions & 132 deletions
File tree
- src
- main/java/net/ladenthin/llama
- json
- test/java/net/ladenthin/llama
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
380 | 384 | | |
381 | | - | |
| 385 | + | |
382 | 386 | | |
383 | 387 | | |
384 | 388 | | |
385 | 389 | | |
386 | 390 | | |
387 | 391 | | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
388 | 397 | | |
389 | 398 | | |
390 | 399 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
34 | 41 | | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| 14 | + | |
| 15 | + | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
26 | 34 | | |
| 35 | + | |
27 | 36 | | |
28 | 37 | | |
29 | 38 | | |
| |||
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
35 | 48 | | |
36 | 49 | | |
37 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
15 | 26 | | |
16 | 27 | | |
17 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
| 27 | + | |
19 | 28 | | |
20 | 29 | | |
21 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
0 commit comments