* Convert a jsii type to a union of Java types
(
typeref: spec.TypeReference,
{ typeSymGen = undefined as SymGen | undefined } = {},
)
| 3034 | * Convert a jsii type to a union of Java types |
| 3035 | */ |
| 3036 | private toJavaTypes( |
| 3037 | typeref: spec.TypeReference, |
| 3038 | { typeSymGen = undefined as SymGen | undefined } = {}, |
| 3039 | ): JavaType[] { |
| 3040 | typeSymGen = typeSymGen ?? newTypeSymGen(); |
| 3041 | |
| 3042 | if (spec.isPrimitiveTypeReference(typeref)) { |
| 3043 | return [this.toJavaPrimitive(typeref.primitive)]; |
| 3044 | } else if (spec.isCollectionTypeReference(typeref)) { |
| 3045 | return [ |
| 3046 | this.toJavaCollection(typeref, { |
| 3047 | typeSymGen, |
| 3048 | }), |
| 3049 | ]; |
| 3050 | } else if (spec.isNamedTypeReference(typeref)) { |
| 3051 | const literal = literalTypeReference(typeref); |
| 3052 | return literal |
| 3053 | ? [mkStatic(literal)] |
| 3054 | : [mkStatic(this.toNativeFqn(typeref.fqn))]; |
| 3055 | } else if (spec.isUnionTypeReference(typeref)) { |
| 3056 | return typeref.union.types.flatMap((subtype) => |
| 3057 | this.toJavaTypes(subtype, { typeSymGen }), |
| 3058 | ); |
| 3059 | } else if (spec.isIntersectionTypeReference(typeref)) { |
| 3060 | const typeVariable = typeSymGen(); |
| 3061 | |
| 3062 | return [ |
| 3063 | mkParam( |
| 3064 | typeVariable, |
| 3065 | `${typeVariable} extends ${typeref.intersection.types |
| 3066 | // Take the first type of any given union (an intersect-of-union |
| 3067 | // would have been rejected by jsii-compiler anyway) |
| 3068 | .map((t) => displayStatic(this.toJavaTypes(t)[0])) |
| 3069 | .join(' & ')}`, |
| 3070 | ), |
| 3071 | ]; |
| 3072 | } |
| 3073 | throw new Error(`Unrenderable type reference: ${JSON.stringify(typeref)}`); |
| 3074 | } |
| 3075 | |
| 3076 | private toJavaCollection( |
| 3077 | ref: spec.CollectionTypeReference, |
no test coverage detected