export function isConstruct()

in src/jsii2schema.ts [535:573]


export function isConstruct(typeOrTypeRef: jsiiReflect.TypeReference | jsiiReflect.Type): boolean {
  let type: jsiiReflect.Type;

  if (typeOrTypeRef instanceof jsiiReflect.Type) {
    type = typeOrTypeRef;
  } else {
    if (typeOrTypeRef.arrayOfType) {
      return isConstruct(typeOrTypeRef.arrayOfType);
    }

    if (typeOrTypeRef.mapOfType) {
      return isConstruct(typeOrTypeRef.mapOfType);
    }

    if (typeOrTypeRef.unionOfTypes) {
      return typeOrTypeRef.unionOfTypes.some(x => isConstruct(x));
    }

    if (typeOrTypeRef.type) {
      type = typeOrTypeRef.type;
    } else {
      return false;
    }
  }

  // if it is an interface, it should extend constructs.IConstruct
  if (type instanceof jsiiReflect.InterfaceType) {
    const constructIface = type.system.findFqn('constructs.IConstruct');
    return type.extends(constructIface);
  }

  // if it is a class, it should extend constructs.Construct
  if (type instanceof jsiiReflect.ClassType) {
    const constructClass = type.system.findFqn('constructs.Construct');
    return type.extends(constructClass);
  }

  return false;
}