| 69 | } |
| 70 | |
| 71 | class SimpleTypesRenderer extends ConvenienceRenderer { |
| 72 | constructor(graph: TypeGraph, private readonly inlineUnions: boolean) { |
| 73 | super(graph); |
| 74 | } |
| 75 | |
| 76 | protected topLevelNameStyle(rawName: string): string { |
| 77 | return simpleNameStyle(rawName, true); |
| 78 | } |
| 79 | |
| 80 | protected get namedTypeNamer(): Namer { |
| 81 | return new Namer(n => simpleNameStyle(n, true), []); |
| 82 | } |
| 83 | |
| 84 | protected get classPropertyNamer(): Namer { |
| 85 | return new Namer(n => simpleNameStyle(n, false), []); |
| 86 | } |
| 87 | |
| 88 | protected get unionMemberNamer(): null { |
| 89 | return null; |
| 90 | } |
| 91 | |
| 92 | protected get enumCaseNamer(): Namer { |
| 93 | return new Namer(n => simpleNameStyle(n, true), []); |
| 94 | } |
| 95 | |
| 96 | protected namedTypeToNameForTopLevel(type: Type): NamedType | null { |
| 97 | if (type.isNamedType()) { |
| 98 | return type; |
| 99 | } |
| 100 | return null; |
| 101 | } |
| 102 | |
| 103 | sourceFor = (t: Type): Sourcelike => { |
| 104 | return matchTypeExhaustive<Sourcelike>( |
| 105 | t, |
| 106 | _anyType => "Any", |
| 107 | _nullType => "Null", |
| 108 | _boolType => "Bool", |
| 109 | _integerType => "Int", |
| 110 | _doubleType => "Double", |
| 111 | _stringType => "String", |
| 112 | arrayType => ["List<", this.sourceFor(arrayType.items), ">"], |
| 113 | classType => this.nameForNamedType(classType), |
| 114 | mapType => ["Map<String, ", this.sourceFor(mapType.values), ">"], |
| 115 | enumType => this.nameForNamedType(enumType), |
| 116 | unionType => { |
| 117 | const nullable = nullableFromUnion(unionType); |
| 118 | if (nullable) return ["Maybe<", this.sourceFor(nullable), ">"]; |
| 119 | |
| 120 | if (this.inlineUnions) { |
| 121 | const children = unionType.children.map((c: Type) => this.sourceFor(c)); |
| 122 | return intercalate(" | ", children).toArray(); |
| 123 | } else { |
| 124 | return this.nameForNamedType(unionType); |
| 125 | } |
| 126 | }, |
| 127 | _dateType => "Date", |
| 128 | _timeType => "Time", |
nothing calls this directly
no test coverage detected
searching dependent graphs…