How to use the jsii-reflect.ClassType function in jsii-reflect

To help you get started, we’ve selected a few jsii-reflect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / decdk / lib / jsii2schema.ts View on Github external
if (typeOrTypeRef.type) {
      type = typeOrTypeRef.type;
    } else {
      return false;
    }
  }

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

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

  return false;
}
github aws / jsii / packages / jsii-diff / lib / types.ts View on Github external
function dispatch(apiElement: ApiElement, fns: {
  method(m: reflect.Method): T;
  init(m: reflect.Initializer): T;
  property(m: reflect.Property): T;
  enumMember(m: reflect.EnumMember): T;
  enumType(m: reflect.EnumType): T;
  klass(m: reflect.ClassType): T;
  iface(m: reflect.InterfaceType): T;
}) {

  if (apiElement instanceof reflect.Method) { return fns.method(apiElement); }
  if (apiElement instanceof reflect.Property) { return fns.property(apiElement); }
  if (apiElement instanceof reflect.EnumMember) { return fns.enumMember(apiElement); }
  if (apiElement instanceof reflect.ClassType) { return fns.klass(apiElement); }
  if (apiElement instanceof reflect.InterfaceType) { return fns.iface(apiElement); }
  if (apiElement instanceof reflect.Initializer) { return fns.init(apiElement); }
  if (apiElement instanceof reflect.EnumType) { return fns.enumType(apiElement); }

  throw new Error(`Unrecognized violator: ${apiElement}`);
}
github aws / aws-cdk / packages / decdk / lib / jsii2schema.ts View on Github external
function schemaForEnumLikeClass(type: jsiiReflect.Type | undefined, ctx: SchemaContext) {
  if (type) {
    ctx = ctx.child('enum-like', type.toString());
  }

  if (!type || !(type instanceof jsiiReflect.ClassType)) {
    return undefined;
  }

  const enumLikeProps = enumLikeClassProperties(type);
  const enumLikeMethods = enumLikeClassMethods(type);

  if (enumLikeProps.length === 0 && enumLikeMethods.length === 0) {
    return undefined;
  }

  const anyOf = new Array();

  if (enumLikeProps.length > 0) {
    anyOf.push({ enum: enumLikeProps.map(m => m.name) });
  }
github aws / aws-cdk / tools / awslint / lib / rules / util.ts View on Github external
return baseTag;
        }
      }
    }
  }

  if (documentable instanceof reflect.ClassType || documentable instanceof reflect.InterfaceType) {
    for (const base of documentable.interfaces) {
      const baseTag = getDocTag(base, tag);
      if (baseTag) {
         return baseTag;
      }
    }
  }

  if (documentable instanceof reflect.ClassType && documentable.base) {
    const baseTag = getDocTag(documentable.base, tag);
    if (baseTag) {
      return baseTag;
    }
  }

  return undefined;
}