| 165 | } |
| 166 | |
| 167 | class JavaRenderer extends ConvenienceRenderer { |
| 168 | constructor(graph: TypeGraph, private readonly _packageName: string, private readonly _justTypes: boolean) { |
| 169 | super(graph); |
| 170 | } |
| 171 | |
| 172 | protected get forbiddenNamesForGlobalNamespace(): string[] { |
| 173 | return keywords; |
| 174 | } |
| 175 | |
| 176 | protected forbiddenForClassProperties( |
| 177 | _c: ClassType, |
| 178 | _classNamed: Name |
| 179 | ): { names: Name[]; namespaces: Namespace[] } { |
| 180 | return { names: [], namespaces: [this.globalNamespace] }; |
| 181 | } |
| 182 | |
| 183 | protected topLevelNameStyle(rawName: string): string { |
| 184 | return javaNameStyle(true, false, rawName); |
| 185 | } |
| 186 | |
| 187 | protected get namedTypeNamer(): Namer { |
| 188 | return typeNamingFunction; |
| 189 | } |
| 190 | |
| 191 | protected get classPropertyNamer(): Namer { |
| 192 | return propertyNamingFunction; |
| 193 | } |
| 194 | |
| 195 | protected get unionMemberNamer(): Namer { |
| 196 | return propertyNamingFunction; |
| 197 | } |
| 198 | |
| 199 | protected get enumCaseNamer(): Namer { |
| 200 | return enumCaseNamingFunction; |
| 201 | } |
| 202 | |
| 203 | protected unionNeedsName(u: UnionType): boolean { |
| 204 | return !nullableFromUnion(u); |
| 205 | } |
| 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…