/** * Returns the fields as a list of parameter declarations for inclusion in Java source. E.g.: * * <code> * org.example.Record field1, List<Integer> field2, Map<String, Integer> field3, Integer field4 * </code> * * @param fields provides the fields to construct a parameter declaration list for. * @return the fields as a list of parameter declarations. */ public String fieldAndTypeList(List<RecordTemplateSpec.Field> fields) { StringBuilder sb = new StringBuilder(); Iterator<RecordTemplateSpec.Field> iter = fields.iterator(); while(iter.hasNext()) { RecordTemplateSpec.Field field = iter.next(); sb.append(toOptionalType(field.getType(), field.getSchemaField().getOptional())); sb.append(" "); sb.append(escapeKeyword(field.getSchemaField().getName())); if (iter.hasNext()) sb.append(", "); } return sb.toString(); }
public static Set<ClassTemplateSpec> directReferencedTypes(ClassTemplateSpec spec) { Set<ClassTemplateSpec> results = new HashSet<ClassTemplateSpec>(); if (spec instanceof RecordTemplateSpec) { RecordTemplateSpec recordSpec = (RecordTemplateSpec)spec; for (RecordTemplateSpec.Field field: recordSpec.getFields()) { results.add(field.getType()); } } else if (spec instanceof UnionTemplateSpec) { UnionTemplateSpec unionSpec = (UnionTemplateSpec)spec; for (UnionTemplateSpec.Member member: unionSpec.getMembers()) { results.add(member.getClassTemplateSpec()); } } else if (spec instanceof CourierMapTemplateSpec) { CourierMapTemplateSpec mapSpec = (CourierMapTemplateSpec)spec; if (mapSpec.getKeyClass() != null) { results.add(mapSpec.getKeyClass()); } results.add(mapSpec.getValueClass()); } else if (spec instanceof ArrayTemplateSpec) { ArrayTemplateSpec arraySpec = (ArrayTemplateSpec)spec; results.add(arraySpec.getItemClass()); } return results; }
public String typeName() { // To resolve type name we have to determine whether to use the DataSchema in _field.getType() or // the one in _field.getSchemaField().getType(). We reach first for the schemaField as it does not swallow // Typerefs. (e.g. if a type was defined as CustomInt, it will give us the string CustomInt, whereas // field.getType() would dereference all the way to the bottom). // // The only problem with schemaField is that it _does_ swallow the type names for enclosed unions. ARGH // can we catch a break?? Thankfully in the case of the enclosed union it ends up returning null, so // we back off to _field.getType() if schemaField returned null. TSTypeSyntax candidateSyntax = createTypeSyntax(_schemaField().getType()); if (candidateSyntax.typeName() == null || "".equals(candidateSyntax)) { candidateSyntax = createTypeSyntax(_field.getType()); } return typeNameQualifiedByEnclosingClass(candidateSyntax); }
fieldType = field.getType(); return toLiteral(fieldType.getSchema(), field.getSchemaField().getDefault());
private ClassTemplateSpec selectFieldType(RecordTemplateSpec.Field field) { return getDereferencedType(field.getCustomInfo(), field.getType()); }