return defineClass(definition, clazz, classLoader);
}
private static <T> Class<? extends T> generateGroupedStateClass(Class<T> clazz, DynamicClassLoader classLoader)
{
ClassDefinition definition = new ClassDefinition(new CompilerContext(null),
a(PUBLIC, FINAL),
typeFromPathName("Grouped" + clazz.getSimpleName() + "_" + CLASS_ID.incrementAndGet()),
type(AbstractGroupedAccumulatorState.class),
type(clazz),
type(GroupedAccumulator.class));
List<StateField> fields = enumerateFields(clazz);
// Create constructor
Block constructor = definition.declareConstructor(new CompilerContext(null), a(PUBLIC))
.getBody()
.pushThis()
.invokeConstructor(AbstractGroupedAccumulatorState.class);
// Create ensureCapacity
Block ensureCapacity = definition.declareMethod(new CompilerContext(null), a(PUBLIC), "ensureCapacity", type(void.class), arg("size", long.class)).getBody();
// Generate fields, constructor, and ensureCapacity
List<FieldDefinition> fieldDefinitions = new ArrayList<>();
for (StateField field : fields) {
fieldDefinitions.add(generateGroupedField(definition, constructor, ensureCapacity, field));
}
constructor.ret();
ensureCapacity.ret();
// Generate getEstimatedSize
Block getEstimatedSize = definition.declareMethod(new CompilerContext(null), a(PUBLIC), "getEstimatedSize", type(long.class))
.getBody()
.comment("long size = 0;")
.push(0L);
for (FieldDefinition field : fieldDefinitions) {
getEstimatedSize