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

Method namedTypeToNameForTopLevel

src/Language/Java.ts:208–224  ·  view source on GitHub ↗
(type: Type)

Source from the content-addressed store, hash-verified

206
207 // FIXME: This is the same as for C#.
208 protected namedTypeToNameForTopLevel(type: Type): NamedType | null {
209 const definedTypes = type.directlyReachableTypes(t => {
210 if ((!(t instanceof UnionType) && t.isNamedType()) || (t instanceof UnionType && !nullableFromUnion(t))) {
211 return OrderedSet([t]);
212 }
213 return null;
214 });
215 assert(definedTypes.size <= 1, "Cannot have more than one defined type per top-level");
216
217 // If the top-level type doesn't contain any classes or unions
218 // we have to define a class just for the `FromJson` method, in
219 // emitFromJsonForTopLevel.
220
221 const first = definedTypes.first();
222 if (first === undefined) return null;
223 return first;
224 }
225
226 fieldOrMethodName = (methodName: string, topLevelName: Name): Sourcelike => {
227 if (this.topLevels.size === 1) {

Callers

nothing calls this directly

Calls 2

nullableFromUnionFunction · 0.90
assertFunction · 0.90

Tested by

no test coverage detected