MCPcopy Index your code
hub / github.com/aws/jsii / toJavaTypes

Method toJavaTypes

packages/jsii-pacmak/lib/targets/java.ts:3036–3074  ·  view source on GitHub ↗

* Convert a jsii type to a union of Java types

(
    typeref: spec.TypeReference,
    { typeSymGen = undefined as SymGen | undefined } = {},
  )

Source from the content-addressed store, hash-verified

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,

Callers 11

emitStaticInitializerMethod · 0.95
emitConstPropertyMethod · 0.95
emitPropertyMethod · 0.95
filterTypeMethod · 0.95
toJavaPropMethod · 0.95
emitClassBuilderMethod · 0.95
getClassBaseMethod · 0.95
toDecoratedJavaTypesMethod · 0.95
toJavaTypeNoGenericsMethod · 0.95
toSingleJavaTypeMethod · 0.95
renderMethodCallMethod · 0.95

Calls 9

toJavaPrimitiveMethod · 0.95
toJavaCollectionMethod · 0.95
toNativeFqnMethod · 0.95
literalTypeReferenceFunction · 0.90
newTypeSymGenFunction · 0.85
mkStaticFunction · 0.85
mkParamFunction · 0.85
displayStaticFunction · 0.85
stringifyMethod · 0.80

Tested by

no test coverage detected