public ClassDefinition( EnumSet<Access> access, ParameterizedType type, ParameterizedType superClass, ParameterizedType... interfaces) { requireNonNull(access, "access is null"); requireNonNull(type, "type is null"); requireNonNull(superClass, "superClass is null"); requireNonNull(interfaces, "interfaces is null"); this.access = access; this.type = type; this.superClass = superClass; this.interfaces.addAll(ImmutableList.copyOf(interfaces)); classInitializer = new MethodDefinition(this, a(STATIC), "<clinit>", ParameterizedType.type(void.class), ImmutableList.of()); }
public MethodDefinition declareMethod( EnumSet<Access> access, String name, ParameterizedType returnType, Iterable<Parameter> parameters) { MethodDefinition methodDefinition = new MethodDefinition(this, access, name, returnType, parameters); for (MethodDefinition method : methods) { if (name.equals(method.getName()) && method.getParameterTypes().equals(methodDefinition.getParameterTypes())) { throw new IllegalArgumentException("Method with same name and signature already exists: " + name); } } methods.add(methodDefinition); return methodDefinition; }
/** * Defines the generics bridge method with untyped args to the type specific read method. */ private void defineReadBridgeMethod() { Parameter protocol = arg("protocol", TProtocolReader.class); MethodDefinition method = new MethodDefinition( classDefinition, a(PUBLIC, BRIDGE, SYNTHETIC), "read", type(Object.class), protocol) .addException(Exception.class); method.getBody().append(method.getThis() .invoke("read", structType, ImmutableList.of(protocol)) .ret()); classDefinition.addMethod(method); }
/** * Defines the generics bridge method with untyped args to the type specific write method. */ private void defineWriteBridgeMethod() { Parameter struct = arg("struct", Object.class); Parameter protocol = arg("protocol", TProtocolWriter.class); MethodDefinition method = new MethodDefinition( classDefinition, a(PUBLIC, BRIDGE, SYNTHETIC), "write", null, struct, protocol) .addException(Exception.class); method.getBody().append(method.getThis() .invoke("write", type(void.class), ImmutableList.of(structType, protocol.getType()), ImmutableList.of(struct.cast(structType), protocol)) .ret()); classDefinition.addMethod(method); }