[code-reflection] RFR: Code reflection synthetic class generation moved to JavaCompiler::genCode
Adam Sotona
asotona at openjdk.org
Fri Nov 21 03:15:33 UTC 2025
On Fri, 21 Nov 2025 01:11:01 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> Prototype of code reflection synthetic class generation move to `JavaCompiler::genCode`.
>>
>> - collected ops are attached to the `ReflectMethods.JCReflectMethodsClassDecl`, an internal extension of `JCTree.JCClassDecl`
>> - new `genCode` method is added to `CodeReflectionTransformer` interface
>> - `JavaCompiler` calls `CodeReflectionTransformer::genCode` inside its `genCode` method
>> - implementation in `ReflectMethods.Provider` calls `OpBuilder` and `BytecodeGenerator` and generates the synthetic inner class
>
> src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/ReflectMethods.java line 2695:
>
>> 2693: }
>> 2694:
>> 2695: private static class OpMap extends LinkedHashMap<String, Op> {
>
> Make it a record holding a `SequencedMap`, with a constructor that creates a linked hash map instance. You can also include methods that defer to the map if needed. Then you don't need the serialVersionUID, and if the compiler allows it you can pattern match on the record's map component to directly operate on the map in `genCode`.
I found a way avoiding modification of the `JCTree.JCClassDecl` API.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/689#discussion_r2548395321
More information about the babylon-dev
mailing list