public override ThriftStructMetadata Build() { // this code assumes that metadata is clean this.MetadataErrors.ThrowIfHasErrors(); // builder constructor injection ThriftMethodInjection builderMethodInjection = BuildBuilderConstructorInjections(); // constructor injection (or factory method for builder) ThriftConstructorInjection constructorInjections = BuildConstructorInjection(); // fields injections IEnumerable <ThriftFieldMetadata> fieldsMetadata = this.BuildFieldInjections(); // methods injections IEnumerable <ThriftMethodInjection> methodInjections = BuildMethodInjections(); return(new ThriftStructMetadata( this.StructName, this.ExtractStructIdlAnnotations(), this.StructType, this.BuilderType, MetadataType.Struct, fieldsMetadata, methodInjections, builderMethodInjection, //documentation, constructorInjections )); }
protected ThriftMethodInjection BuildBuilderConstructorInjections() { ThriftMethodInjection builderMethodInjection = null; if (this.BuilderType != null) { MethodInjection builderMethod = _builderMethodInjections.First(); builderMethodInjection = new ThriftMethodInjection(builderMethod.Method, BuildParameterInjections(builderMethod.getParameters())); } return(builderMethodInjection); }
public ThriftStructMetadata( String structName, IDictionary <String, String> idlAnnotations, Type structType, Type builderType, MetadataType metadataType, //List<String> documentation, IEnumerable <ThriftFieldMetadata> fields = null, IEnumerable <ThriftMethodInjection> methodInjections = null, ThriftMethodInjection builderMethod = null, ThriftConstructorInjection constructorInjection = null) { //Guard.ArgumentNotNull(builderType, nameof(builderType)); Guard.ArgumentNullOrWhiteSpaceString(structName, nameof(structName)); Guard.ArgumentNotNull(idlAnnotations, nameof(idlAnnotations)); Guard.ArgumentNotNull(metadataType, nameof(metadataType)); Guard.ArgumentNotNull(structType, nameof(structType)); //Guard.ArgumentNotNull(documentation, nameof(documentation)); Guard.ArgumentNotNull(fields, nameof(fields)); this.BuilderType = builderType; this.StructName = structName; this._idlAnnotations = idlAnnotations; this.MetadataType = metadataType; this.StructType = structType; this._builderMethod = builderMethod; this._methodInjections = methodInjections ?? Enumerable.Empty <ThriftMethodInjection>(); //this.documentation = documentation.AsReadOnly(); var dic = (fields ?? Enumerable.Empty <ThriftFieldMetadata>()).ToDictionary(m => m.Id); this._fields = new SortedDictionary <short, ThriftFieldMetadata>(dic); // this.fields = ImmutableSortedMap.copyOf(uniqueIndex(checkNotNull(fields, "fields is null"), new Function<ThriftFieldMetadata, Short>() // { // @Override // public Short apply(ThriftFieldMetadata input) // { // return input.getId(); // } //})); //this.methodInjections = ImmutableList.copyOf(checkNotNull(methodInjections, "methodInjections is null")); this._constructorInjection = constructorInjection; this._methodInjections = methodInjections ?? Enumerable.Empty <ThriftMethodInjection>(); }
//private IEnumerable<String> documentation; public ThriftFieldMetadata( short id, bool isRecursiveReference, Requiredness requiredness, //IEnumerable<KeyValuePair<String, String>> idlAnnotations, IThriftTypeReference thriftTypeReference, String name, FieldKind fieldKind, IEnumerable <IThriftInjection> injections = null, ThriftConstructorInjection constructorInjection = null, ThriftMethodInjection methodInjection = null, IThriftExtraction extraction = null, TypeCoercion coercion = null ) { Guard.ArgumentNotNull(thriftTypeReference, nameof(thriftTypeReference)); Guard.ArgumentNotNull(fieldKind, nameof(fieldKind)); Guard.ArgumentNullOrWhiteSpaceString(name, nameof(name)); Guard.ArgumentNotNull(thriftTypeReference, nameof(thriftTypeReference)); Guard.ArgumentNullOrWhiteSpaceString(name, nameof(name)); //Guard.ArgumentNotNull(constructorInjection, nameof(constructorInjection)); //Guard.ArgumentNotNull(methodInjection, nameof(methodInjection)); //Guard.ArgumentNotNull(extraction, nameof(extraction)); //Guard.ArgumentNotNull(coercion, nameof(coercion)); this.IsRecursiveReference = isRecursiveReference; this.Required = requiredness; this._thriftTypeReference = thriftTypeReference; this._fieldKind = fieldKind; this.Name = name; this.Injections = injections ?? Enumerable.Empty <IThriftInjection>(); this._constructorInjection = constructorInjection; this._methodInjection = methodInjection; this._extraction = extraction; this._coercion = coercion; switch (fieldKind) { case FieldKind.ThriftField: Guard.ArgumentCondition(id >= 0, "isLegacyId must be specified on fields with negative IDs", nameof(id)); break; case FieldKind.ThriftUnionId: Guard.ArgumentCondition(id == short.MinValue, "thrift union id must be short.MinValue", nameof(id)); break; } Guard.ArgumentCondition(injections.Any() || extraction != null || constructorInjection != null || methodInjection != null, "A thrift field must have an injection or extraction point"); this.Id = id; if (extraction != null) { if (extraction is ThriftFieldExtractor) { ThriftFieldExtractor e = (ThriftFieldExtractor)extraction; //this.documentation = ThriftCatalog.getThriftDocumentation(e.getField()); } else if (extraction != null && extraction is ThriftMethodExtractor) { ThriftMethodExtractor e = (ThriftMethodExtractor)extraction; //this.documentation = ThriftCatalog.getThriftDocumentation(e.getMethod()); } } //this.idlAnnotations = idlAnnotations; }
public bool TryGetBuilderMethod(out ThriftMethodInjection builderMethod) { builderMethod = this._builderMethod; return(builderMethod != null); }