[code-reflection] RFR: Code reflection synthetic class generation moved to JavaCompiler::genCode
Paul Sandoz
psandoz at openjdk.org
Fri Nov 21 03:15:32 UTC 2025
On Thu, 20 Nov 2025 20:23:50 GMT, Adam Sotona <asotona 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`.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/689#discussion_r2548203931
More information about the babylon-dev
mailing list