MCPcopy Create free account
hub / github.com/glideapps/quicktype / SwiftRenderer

Class SwiftRenderer

src/Language/Swift.ts:189–748  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187const lowerNamingFunction = funPrefixNamer(s => swiftNameStyle(false, s));
188
189class SwiftRenderer extends ConvenienceRenderer {
190 constructor(graph: TypeGraph, private readonly _justTypes: boolean, private readonly _useClasses: boolean) {
191 super(graph);
192 }
193
194 protected get forbiddenNamesForGlobalNamespace(): string[] {
195 return keywords;
196 }
197
198 protected forbiddenForClassProperties(
199 _c: ClassType,
200 _classNamed: Name
201 ): { names: Name[]; namespaces: Namespace[] } {
202 return { names: [], namespaces: [this.globalNamespace] };
203 }
204
205 protected forbiddenForEnumCases(_e: EnumType, _enumNamed: Name): { names: Name[]; namespaces: Namespace[] } {
206 return { names: [], namespaces: [this.globalNamespace] };
207 }
208
209 protected topLevelNameStyle(rawName: string): string {
210 return swiftNameStyle(true, rawName);
211 }
212
213 protected get namedTypeNamer(): Namer {
214 return upperNamingFunction;
215 }
216
217 protected get classPropertyNamer(): Namer {
218 return lowerNamingFunction;
219 }
220
221 protected get unionMemberNamer(): Namer {
222 return lowerNamingFunction;
223 }
224
225 protected get enumCaseNamer(): Namer {
226 return lowerNamingFunction;
227 }
228
229 protected namedTypeToNameForTopLevel(type: Type): NamedType | null {
230 if (type.isNamedType()) {
231 return type;
232 }
233 return null;
234 }
235
236 private emitBlock = (line: Sourcelike, f: () => void): void => {
237 this.emitLine(line, " {");
238 this.indent(f);
239 this.emitLine("}");
240 };
241
242 private swift3OrPlainCase = (swift3OrPlain: Sourcelike, swift4NonPlain: Sourcelike): Sourcelike => {
243 if (this._justTypes) return swift3OrPlain;
244 else return swift4NonPlain;
245 };
246

Callers

nothing calls this directly

Calls 6

matchTypeFunction · 0.90
maybeAnnotatedFunction · 0.90
nullableFromUnionFunction · 0.90
modifySourceFunction · 0.90
removeNullFromUnionFunction · 0.90
filterTypesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…