private static void generateField( ClassDefinition definition, Block constructor, StateField stateField) { FieldDefinition field = definition.declareField( a(PRIVATE), UPPER_CAMEL.to(LOWER_CAMEL, stateField.getName()) + "Value", stateField.getType()); // Generate getter definition .declareMethod(a(PUBLIC), stateField.getGetterName(), type(stateField.getType())) .getBody() .pushThis() .getField(field) .ret(stateField.getType()); // Generate setter definition .declareMethod( a(PUBLIC), stateField.getSetterName(), type(void.class), arg("value", stateField.getType())) .getBody() .pushThis() .getVariable("value") .putField(field) .ret(); constructor.pushThis(); pushInitialValue(constructor, stateField); constructor.putField(field); }
private static Method getSetter(Class<?> clazz, StateField field) { try { return clazz.getMethod(field.getSetterName(), field.getType()); } catch (NoSuchMethodException e) { throw Throwables.propagate(e); } }
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(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( a(PUBLIC), stateField.getSetterName(), type(void.class), 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; }