}
private static FieldDefinition generateGroupedField(ClassDefinition definition, Block constructor, Block ensureCapacity, StateField stateField)
{
Class<?> bigArrayType = getBigArrayType(stateField.getType());
FieldDefinition field = definition.declareField(a(PRIVATE), UPPER_CAMEL.to(LOWER_CAMEL, stateField.getName()) + "Values", bigArrayType);
// Generate getter
definition.declareMethod(new CompilerContext(null), a(PUBLIC), stateField.getGetterName(), type(stateField.getType()))
.getBody()
.comment("return field.get(getGroupId());")
.pushThis()
.getField(field)
.pushThis()
.invokeVirtual(AbstractGroupedAccumulatorState.class, "getGroupId", long.class)
.invokeVirtual(bigArrayType, "get", stateField.getType(), long.class)
.ret(stateField.getType());
// Generate setter
definition.declareMethod(new CompilerContext(null), a(PUBLIC), stateField.getSetterName(), type(void.class), NamedParameterDefinition.arg("value", stateField.getType()))
.getBody()
.comment("return field.set(getGroupId(), value);")
.pushThis()
.getField(field)
.pushThis()
.invokeVirtual(AbstractGroupedAccumulatorState.class, "getGroupId", long.class)
.getVariable("value")
.invokeVirtual(bigArrayType, "set", void.class, long.class, stateField.getType())
.ret();
ensureCapacity.pushThis()
.getField(field)
.getVariable("size")
.invokeVirtual(field.getType(), "ensureCapacity", type(void.class), type(long.class));
// Initialize field in constructor
constructor.pushThis()
.newObject(field.getType())
.dup();
pushInitialValue(constructor, stateField);
constructor.invokeConstructor(field.getType(), type(stateField.getType()));
constructor.putField(field);
return field;
}