Repository navigation
java: declare anonymous classes and lambdas in field initializers and initializer blocks - #5
Merged
Merged
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gson's TypeAdapters.java declares 25 of its 31
TypeAdapter.writeoverrides 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