BytecodeExpression stateFactory = thisVariable.getField(stateFieldAndDescriptor.getStateFactoryField()); body.append(thisVariable.setField(stateField, stateFactory.invoke(createState, Object.class).cast(stateField.getType())));
public SetFieldBytecodeExpression(@Nullable BytecodeExpression instance, FieldDefinition field, BytecodeExpression value) { this(instance, requireNonNull(field, "field is null").getDeclaringClass().getType(), field.getName(), value, field.getType()); if (instance == null) { checkArgument(field.getAccess().contains(STATIC), "Field is not static: %s", field); } else { checkArgument(!field.getAccess().contains(STATIC), "Field is static: %s", field); } }
public BytecodeBlock getStaticField(FieldDefinition field) { getStaticField(field.getDeclaringClass().getType(), field.getName(), field.getType()); return this; }
@Override public Void visitField(ClassDefinition classDefinition, FieldDefinition fieldDefinition) { // print annotations first for (AnnotationDefinition annotationDefinition : fieldDefinition.getAnnotations()) { visitAnnotation(fieldDefinition, annotationDefinition); } // print field declaration line().addAll(fieldDefinition.getAccess()).add(fieldDefinition.getType().getJavaClassName()).add(fieldDefinition.getName()).add(";").print(); printLine(); return null; }
public FieldDefinition declareField(EnumSet<Access> access, String name, Class<?> type) { FieldDefinition fieldDefinition = new FieldDefinition(this, access, name, type); fields.add(fieldDefinition); return fieldDefinition; }
public T visitField(ClassDefinition classDefinition, FieldDefinition fieldDefinition) { for (AnnotationDefinition annotationDefinition : fieldDefinition.getAnnotations()) { visitAnnotation(fieldDefinition, annotationDefinition); } return null; }
field.visit(visitor);
public GetFieldBytecodeExpression(@Nullable BytecodeExpression instance, FieldDefinition field) { this(instance, requireNonNull(field, "field is null").getDeclaringClass().getType(), field.getName(), field.getType()); if (instance == null) { checkArgument(field.getAccess().contains(STATIC), "Field is not static: %s", field); } else { checkArgument(!field.getAccess().contains(STATIC), "Field is static: %s", field); } }
public BytecodeBlock getField(FieldDefinition field) { getField(field.getDeclaringClass().getType(), field.getName(), field.getType()); return this; }
/** * Defines the constructor with a parameter for the ThriftType and the delegate codecs. The * constructor simply assigns these parameters to the class fields. */ private void defineConstructor() { // declare constructor with argument names matching the fields List<Parameter> arguments = parameters.getFields().stream() .map(field -> arg(field.getName(), field.getType())) .collect(toImmutableList()); MethodDefinition constructor = classDefinition.declareConstructor(a(PUBLIC), arguments); // invoke super (Object) constructor constructor.getBody() .comment("super()") .append(constructor.getThis()) .invokeConstructor(Object.class); // this.foo = foo; for (int i = 0; i < parameters.getFields().size(); i++) { FieldDefinition field = parameters.getFields().get(i); Parameter argument = arguments.get(i); constructor.getBody().append( constructor.getThis().setField(field, argument)); } // return; (implicit) constructor.getBody().ret(); }
public FieldDefinition declareField(EnumSet<Access> access, String name, ParameterizedType type) { FieldDefinition fieldDefinition = new FieldDefinition(this, access, name, type); fields.add(fieldDefinition); return fieldDefinition; }
ifStatement.condition(notEqual(hashChannel, constantNull(hashChannelField.getType()))); ifStatement.ifTrue( bigintType.invoke(
public BytecodeBlock putField(FieldDefinition field) { checkArgument(!field.getAccess().contains(STATIC), "Field is static: %s", field); putField(field.getDeclaringClass().getType(), field.getName(), field.getType()); return this; }
public BytecodeBlock putStaticField(FieldDefinition field) { putStaticField(field.getDeclaringClass().getType(), field.getName(), field.getType()); return this; }
.ifFalse(thisVariable.setField( hashChannelField, constantNull(hashChannelField.getType())))); constructor.ret();
private static FieldDefinition generateGroupedField(ClassDefinition definition, MethodDefinition constructor, MethodDefinition 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 MethodDefinition getter = definition.declareMethod(a(PUBLIC), stateField.getGetterName(), type(stateField.getType())); getter.getBody() .append(getter.getThis().getField(field).invoke( "get", stateField.getType(), getter.getThis().invoke("getGroupId", long.class)) .ret()); // Generate setter Parameter value = arg("value", stateField.getType()); MethodDefinition setter = definition.declareMethod(a(PUBLIC), stateField.getSetterName(), type(void.class), value); setter.getBody() .append(setter.getThis().getField(field).invoke( "set", void.class, setter.getThis().invoke("getGroupId", long.class), value)) .ret(); Scope ensureCapacityScope = ensureCapacity.getScope(); ensureCapacity.getBody() .append(ensureCapacity.getThis().getField(field).invoke("ensureCapacity", void.class, ensureCapacityScope.getVariable("size"))); // Initialize field in constructor constructor.getBody() .append(constructor.getThis().setField(field, newInstance(field.getType(), stateField.initialValueExpression()))); return field; }
BytecodeExpression stateFactory = thisVariable.getField(stateFieldAndDescriptor.getStateFactoryField()); body.append(thisVariable.setField(stateField, stateFactory.invoke(createState, Object.class).cast(stateField.getType())));
BytecodeExpression stateFactory = thisVariable.getField(stateFieldAndDescriptor.getStateFactoryField()); body.append(thisVariable.setField(stateField, stateFactory.invoke(createState, Object.class).cast(stateField.getType())));