Skip to content

java: declare anonymous classes and lambdas in field initializers and initializer blocks - #5

Merged
tabladrum merged 2 commits into
mainfrom
fix/java-initializer-declarations
Oct 12, 2026
Merged

tabladrum merged 2 commits into
mainfrom
fix/java-initializer-declarations

Conversation

@tabladrum

Copy link
Copy Markdown
Contributor

gson's TypeAdapters.java declares 25 of its 31 TypeAdapter.write overrides as anonymous classes assigned to static fields. The Java visitor only looked for anonymous classes and lambdas inside method bodies, so none of them became a symbol, and grove's change_impact reported the family closed at 6 of 31.

Field declarators, static { } blocks and instance initializer blocks now go through the same nested-executable walk as method bodies. Test added with all three forms plus a lambda in a field initializer.

Companion: grove's javac resolver now emits every declaration it attributes and adds the ones the parser lacks, so a future parser gap of this kind is filled by the compiler and reported. On gson's full index the parser gap is now 17 symbols (one-line empty anonymous classes in tests and a benchmark), down from 25 adapters plus those.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KXa6Cv1ZUXcdMqXcJfQFhX

tabladrum and others added 2 commits October 11, 2026 22:00
… initializer blocks

gson TypeAdapters.java declares 25 of its 31 TypeAdapter.write overrides as
anonymous classes assigned to static fields (CLASS = new TypeAdapter<>() {
...}). The Java visitor only looked for anonymous classes and lambdas inside
method bodies, so none of them was a symbol, and grove's change_impact
reported the family closed at 6 of 31 (2026-10-12).

Field declarators, `static { }` blocks and instance initializer blocks now
go through the same nested-executable walk as method bodies.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KXa6Cv1ZUXcdMqXcJfQFhX
…nt arguments

A census against javac's declarations (grove: compiler-declared symbols)
found the same walker gap in two more places: `url -> new Monitor() {...}`
(dubbo MonitorFilterTest), `() -> new SubTypeToken<Integer>() {}` (gson,
commons-lang TypeLiteralTest), where the anonymous class IS the lambda's
expression body, and `TWEETS(new TypeToken<List<Tweet>>() {})` (gson
ParseBenchmark), an enum constant's constructor argument. The walker only
inspected children, so neither was declared.

Lambdas now walk their own node; enum constants walk their arguments. With
this, javac declares nothing the parser lacks on gson, commons-lang or dubbo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KXa6Cv1ZUXcdMqXcJfQFhX
@tabladrum
tabladrum merged commit 3d30489 into main Oct 12, 2026
3 checks passed
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.

1 participant