@Override public String typeName() { // Sadly the behavior of this function is indirectly controlled by the one calling it: TSRecordFieldSyntax. // That class has the unfortunate behavior that it can produce 2 different ClassTemplateSpecs, one of which works for // some cases, and one of which works for the others. See its own "typeName" definition for details but essentially // it will give us one of the ClassTemplateSpecs and call typeName. If we then return null // then it will give it a shot with the other ClassTemplateSpec. Unfortunately we have to do this because if // we try to just use the first one, we will return "Array<null>". This is also why we special-case unions here. // we have to access a specific ClassTemplate boolean itemIsUnion = _template.getItemClass() instanceof UnionTemplateSpec; TSTypeSyntax itemTypeSyntax = itemIsUnion? createTypeSyntax(_template.getItemClass()): _itemTypeSyntax(); String itemTypeName = typeNameQualifiedByEnclosingClass(itemTypeSyntax); return itemTypeName == null? null: "Array<" + itemTypeName + ">"; }
private ClassTemplateSpec selectArrayItemsType(ArrayTemplateSpec arraySpec) { return getDereferencedType(arraySpec.getCustomInfo(), arraySpec.getItemClass()); }
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; }
return "[String: " + toTypeString(((CourierMapTemplateSpec) spec).getValueClass()) + "]"; } else if (schemaType == Type.ARRAY) { return "[" + toTypeString(((ArrayTemplateSpec) spec).getItemClass()) + "]"; } else { throw new IllegalArgumentException("unrecognized type: " + schemaType);
return "Map<String, " + toType(((CourierMapTemplateSpec) spec).getValueClass(), Optionality.REQUIRED_FIELDS_MAY_BE_ABSENT) + ">"; } else if (schemaType == Type.ARRAY) { return "List<" + toType(((ArrayTemplateSpec) spec).getItemClass(), Optionality.REQUIRED_FIELDS_MAY_BE_ABSENT) + ">"; } else { throw new IllegalArgumentException("unrecognized type: " + schemaType);