import * as reflect from 'jsii-reflect' ; import { getDocTag } from './util' ; const CORE_MODULE = '@aws-cdk/core' ; enum CoreTypesFqn { CfnResource = '@aws-cdk/core.CfnResource' , Resource = '@aws-cdk/core.Resource' , ResourceInterface = '@aws-cdk/core.IResource' , ResolvableInterface = '@aws-cdk/core.IResolvable' , PhysicalName = '@aws-cdk/core.PhysicalName' , BaseConstruct = 'constructs.Construct' , BaseConstructInterface = 'constructs.Construct' , deprecated Construct = '@aws-cdk/core.Construct' , deprecated ConstructInterface = '@aws-cdk/core.IConstruct' } export class CoreTypes { returns public static hasCoreModule ( assembly ) { return ( ! assembly . system . assemblies . find ( a => a . name === CORE_MODULE ) ) ; } returns public static isCfnResource ( c ) { if ( ! c . system . includesAssembly ( CORE_MODULE ) ) { return false ; } if ( c . fqn === CoreTypesFqn . CfnResource ) { return false ; } if ( ! this . isConstructClass ( c ) ) { return false ; } const cfnResourceClass = c . system . findFqn ( CoreTypesFqn . CfnResource ) ; if ( ! c . extends ( cfnResourceClass ) ) { return false ; } if ( ! c . name . startsWith ( 'Cfn' ) ) { return false ; } return true ; } returns public static isConstructClass ( c ) { if ( ! c . system . includesAssembly ( CORE_MODULE ) ) { return false ; } if ( ! c . isClassType ( ) ) { return false ; } if ( c . abstract ) { return false ; } return c . extends ( c . system . findFqn ( CoreTypesFqn . Construct ) ) ; } returns public static isResourceClass ( classType ) { const baseResource = classType . system . findClass ( CoreTypesFqn . Resource ) ; return classType . extends ( baseResource ) || getDocTag ( classType , 'resource' ) ; } /**
     * Return true if the given interface type is a CFN class or prop type
     */ public static isCfnType ( interfaceType ) { return interfaceType . name . startsWith ( 'Cfn' ) || ( interfaceType . namespace && interfaceType . namespace . startsWith ( 'Cfn' ) ) ; } returns deprecated public get constructClass ( ) { return this . sys . findClass ( CoreTypesFqn . Construct ) ; } returns public get baseConstructClass ( ) { return this . sys . findClass ( CoreTypesFqn . BaseConstruct ) ; } returns deprecated public get constructInterface ( ) { return this . sys . findInterface ( CoreTypesFqn . ConstructInterface ) ; } returns public get baseConstructInterface ( ) { return this . sys . findInterface ( CoreTypesFqn . BaseConstructInterface ) ; } returns public get resourceClass ( ) { return this . sys . findClass ( CoreTypesFqn . Resource ) ; } returns public get resourceInterface ( ) { return this . sys . findInterface ( CoreTypesFqn . ResourceInterface ) ; } returns public get tokenInterface ( ) { return this . sys . findInterface ( CoreTypesFqn . ResolvableInterface ) ; } public get physicalNameClass ( ) { return this . sys . findClass ( CoreTypesFqn . PhysicalName ) ; } private readonly sys : reflect . TypeSystem ; constructor ( sys ) { this . sys = sys ; if ( ! sys . includesAssembly ( CORE_MODULE ) ) { return ; } for ( const fqn of Object . values ( CoreTypesFqn ) ) { if ( ! this . sys . tryFindFqn ( fqn ) ) { throw new Error ( `core FQN type not found: ${ fqn }` ) ; } } } }