- AugmentationCodecContext(final AugmentationCodecPrototype prototype) {
- super(prototype, new CodecDataObjectAnalysis<>(prototype, CodecItemFactory.of(), null));
+ private static final MethodType CONSTRUCTOR_TYPE = MethodType.methodType(void.class,
+ AbstractDataObjectCodecContext.class, DataContainerNode.class);
+ private static final MethodType DATAOBJECT_TYPE = MethodType.methodType(DataObject.class,
+ AugmentationCodecContext.class, DataContainerNode.class);
+
+ private final MethodHandle proxyConstructor;
+
+ private AugmentationCodecContext(final AugmentationCodecPrototype<D> prototype,
+ final DataContainerAnalysis<AugmentRuntimeType> analysis) {
+ super(prototype, analysis);
+
+ final var bindingClass = CodecDataObjectGenerator.generate(prototype.contextFactory().getLoader(),
+ prototype.javaClass(), analysis.leafContexts, analysis.daoProperties, null);
+
+ final MethodHandle ctor;
+ try {
+ ctor = MethodHandles.publicLookup().findConstructor(bindingClass, CONSTRUCTOR_TYPE);
+ } catch (NoSuchMethodException | IllegalAccessException e) {
+ throw new LinkageError("Failed to find contructor for class " + bindingClass, e);
+ }
+
+ proxyConstructor = ctor.asType(DATAOBJECT_TYPE);
+ }
+
+ AugmentationCodecContext(final AugmentationCodecPrototype<D> prototype) {
+ this(prototype, new DataContainerAnalysis<>(prototype, CodecItemFactory.of()));