@Override public ThriftStructMetadata build() { // this code assumes that metadata is clean metadataErrors.throwIfHasErrors(); // builder constructor injection ThriftMethodInjection builderMethodInjection = buildBuilderConstructorInjections(); // constructor injection (or factory method for builder) ThriftConstructorInjection constructorInjection = buildConstructorInjection(); // fields injections Iterable<ThriftFieldMetadata> fieldsMetadata = buildFieldInjections(); // methods injections List<ThriftMethodInjection> methodInjections = buildMethodInjections(); return new ThriftStructMetadata( structName, structType, builderType, MetadataType.UNION, Optional.fromNullable(builderMethodInjection), ImmutableList.copyOf(documentation), ImmutableList.copyOf(fieldsMetadata), Optional.fromNullable(constructorInjection), methodInjections ); }
@Override public ThriftStructMetadata build() { // this code assumes that metadata is clean metadataErrors.throwIfHasErrors(); // builder constructor injection ThriftMethodInjection builderMethodInjection = buildBuilderConstructorInjections(); // constructor injection (or factory method for builder) ThriftConstructorInjection constructorInjections = buildConstructorInjection(); // fields injections Iterable<ThriftFieldMetadata> fieldsMetadata = buildFieldInjections(); // methods injections List<ThriftMethodInjection> methodInjections = buildMethodInjections(); return new ThriftStructMetadata( structName, structType, builderType, MetadataType.STRUCT, Optional.fromNullable(builderMethodInjection), ImmutableList.copyOf(documentation), ImmutableList.copyOf(fieldsMetadata), Optional.of(constructorInjections), methodInjections ); }
@Override public ThriftStructMetadata build() { // this code assumes that metadata is clean metadataErrors.throwIfHasErrors(); // builder constructor injection ThriftMethodInjection builderMethodInjection = buildBuilderConstructorInjections(); // constructor injection (or factory method for builder) ThriftConstructorInjection constructorInjection = buildConstructorInjection(); // fields injections Iterable<ThriftFieldMetadata> fieldsMetadata = buildFieldInjections(); // methods injections List<ThriftMethodInjection> methodInjections = buildMethodInjections(); return new ThriftStructMetadata( structName, extractStructIdlAnnotations(), structType, builderType, MetadataType.UNION, Optional.fromNullable(builderMethodInjection), ImmutableList.copyOf(documentation), ImmutableList.copyOf(fieldsMetadata), Optional.fromNullable(constructorInjection), methodInjections ); }
@Override public ThriftStructMetadata build() { // this code assumes that metadata is clean metadataErrors.throwIfHasErrors(); // builder constructor injection ThriftMethodInjection builderMethodInjection = buildBuilderConstructorInjections(); // constructor injection (or factory method for builder) ThriftConstructorInjection constructorInjections = buildConstructorInjection(); // fields injections Iterable<ThriftFieldMetadata> fieldsMetadata = buildFieldInjections(); // methods injections List<ThriftMethodInjection> methodInjections = buildMethodInjections(); return new ThriftStructMetadata( structName, extractStructIdlAnnotations(), structType, builderType, MetadataType.STRUCT, Optional.fromNullable(builderMethodInjection), ImmutableList.copyOf(documentation), ImmutableList.copyOf(fieldsMetadata), Optional.of(constructorInjections), methodInjections ); }
private <T extends AbstractThriftMetadataBuilder> ThriftStructMetadata buildMetadata( Class<?> structClass, Class<T> metadataBuilderType) throws Exception { ThriftCatalog catalog = new ThriftCatalog(); AbstractThriftMetadataBuilder builder = metadataBuilderType.getConstructor(ThriftCatalog.class, Type.class) .newInstance(catalog, structClass); assertNotNull(builder); assertNotNull(builder.getMetadataErrors()); builder.getMetadataErrors().throwIfHasErrors(); assertEquals(builder.getMetadataErrors().getWarnings().size(), 0); return builder.build(); }
private ThriftStructMetadata testMetadataBuild(Class<?> structClass, int expectedConstructorParameters, int expectedMethodInjections) { ThriftCatalog catalog = new ThriftCatalog(); ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(catalog, structClass); assertNotNull(builder); assertNotNull(builder.getMetadataErrors()); builder.getMetadataErrors().throwIfHasErrors(); assertEquals(builder.getMetadataErrors().getWarnings().size(), 0); ThriftStructMetadata metadata = builder.build(); assertNotNull(metadata); assertEquals(MetadataType.UNION, metadata.getMetadataType()); verifyField(metadata, 1, "stringValue"); verifyField(metadata, 2, "longValue"); verifyField(metadata, 3, "fruitValue"); if (expectedConstructorParameters == 0) { assertTrue(metadata.getConstructorInjection().isPresent()); ThriftConstructorInjection constructorInjection = metadata.getConstructorInjection().get(); assertEquals(constructorInjection.getParameters().size(), 0); } else { for (ThriftFieldMetadata fieldMetadata : metadata.getFields(FieldKind.THRIFT_FIELD)) { assertTrue(fieldMetadata.getConstructorInjection().isPresent()); assertEquals(fieldMetadata.getConstructorInjection().get().getParameters().size(), expectedConstructorParameters); } } assertEquals(metadata.getMethodInjections().size(), expectedMethodInjections); return metadata; }