UNPKG

node-web-mvc

Version:
167 lines (166 loc) 6.75 kB
import ElementType from './ElementType'; import { ClazzType } from '../../../interface/declare'; import { IAnnotationClazz, IAnnotationOrClazz, MetaRuntimeTypeInfo } from './type'; import IRuntimeAnnotation from './IRuntimeAnnotation'; type GetTargetAnnotationType<T> = T extends { NativeAnnotation: abstract new (...args: any) => infer A; } ? A : T extends abstract new (...args: any[]) => infer A ? A : T; export default class RuntimeAnnotation<A = any> implements IRuntimeAnnotation { private readonly meta; /** * 标注的类或者函数 */ readonly target: Function; /** * 标注类的构造函数 */ get ctor(): ClazzType; /** * 当前标注的方法 */ get method(): Function; readonly methodName: string; /** * 标注目标名称 * 当elementType为以下值分别对应 * Type: 无值 * Property: 属性名 * Method: 方法名 * Parameter: 参数名 */ readonly name: string; /** * 标注参数的下表 */ readonly paramIndex: number; /** * 参数名称 */ readonly paramName: string; /** * 如果是标注在属性上,此属性会指向属性的descritpor */ readonly descriptor: any; readonly nativeAnnotation: GetTargetAnnotationType<A>; readonly elementType: ElementType; readonly ownerAnnotation: RuntimeAnnotation<A>; parameters: string[]; /** * 如果当前注解为:函数注解,则能获取到返回结果类型 */ get returnType(): MetaRuntimeTypeInfo; /** * 如果当前为函数注解,则能获取到当前函数的参数类型 */ get paramTypes(): MetaRuntimeTypeInfo[]; /** * 如果当前注解为参数注解,则能获取到当前参数的类型 * @param ctor */ get paramType(): MetaRuntimeTypeInfo; /** * 当注解,作用在属性上时,的类型 */ get dataType(): MetaRuntimeTypeInfo; /** * 获取所有指定类型的注解 * @param type 注解类型 */ static getTypedRuntimeAnnotations<C extends IAnnotationClazz>(type: C, match?: (m: RuntimeAnnotation) => boolean): RuntimeAnnotation<C>[]; /** * 获取指定类型的注解 * @param type 注解类型 */ static getTypedRuntimeAnnotation<C extends IAnnotationClazz>(type: C, match?: (m: RuntimeAnnotation) => boolean): RuntimeAnnotation<C>; /** * 根据现有注解来获取相同作用于下对应的指定类型的注解 * @param anno 当前注解 * @param type 要获取的注解类型 */ static getAnnotationsByAnno<C extends IAnnotationClazz>(anno: RuntimeAnnotation, type: C): RuntimeAnnotation<C>[]; /** * 获取指定类的所有注解信息 * @param {Function} clazz 被修饰的类 */ static getClassAnnotations<C extends IAnnotationOrClazz>(clazz: Function): RuntimeAnnotation[]; static getClassAnnotations<C extends IAnnotationOrClazz>(clazz: Function, annotationType: C): RuntimeAnnotation<C>[]; /** * 获取指定类的指定类型的注解信息 * @param {Function} clazz 被修饰的类 * @param {Function} type 注解类型 */ static getClassAnnotation<C extends IAnnotationOrClazz>(clazz: Function, annotationType: C): RuntimeAnnotation<C>; /** * 判断当前类是否存在指定类型的注解 * @param {Function} clazz 被修饰的类 * @param {Function} type 注解类型 */ static hasClassAnnotation<C extends IAnnotationOrClazz>(clazz: Function, type: C): boolean; /** * 获取指定类型的多个注解信息 * @param {Function} type 注解类型 * @param {Function} clazz 被修饰的类 */ static getAnnotations<C extends IAnnotationOrClazz>(annotationType: C | C[], clazz?: Function): RuntimeAnnotation<C>[]; /** * 获取指定类型的注解信息 * @param {Function} type 注解类型 * @param {Function} clazz 被修饰的类 */ static getAnnotation<C extends IAnnotationOrClazz>(annotationType: C, clazz?: Function): RuntimeAnnotation<C>; /** * 获取指定函数的注解 * @param clazz 函数所在类 * @param method 函数名称 */ static getMethodAnnotations<C extends IAnnotationOrClazz>(clazz: Function, method: string | Function): RuntimeAnnotation[]; static getMethodAnnotations<C extends IAnnotationOrClazz>(clazz: Function, method: string | Function, annotationType: C): RuntimeAnnotation<C>[]; /** * 获取指定函数的指定注解 * @param clazz 函数所在类 * @param method 函数名称 */ static getMethodAnnotation<C extends IAnnotationOrClazz>(clazz: Function, method: string | Function, annotationType: C): RuntimeAnnotation<C>; /** * 获取指定函数的参数注解 * @param clazz 函数所在类 * @param method 函数名称 */ static getMethodParamAnnotations<C extends IAnnotationOrClazz>(clazz: Function, method: string, paramName: string): RuntimeAnnotation[]; static getMethodParamAnnotations<C extends IAnnotationOrClazz>(clazz: Function, method: string, paramName: string, annotationType: C): RuntimeAnnotation<C>[]; /** * 获取指定函数指定名称参数注解 * @param clazz 函数所在类 * @param method 函数名称 * @param paramName 参数下标 */ static getMethodParamAnnotation<C extends IAnnotationOrClazz>(clazz: Function, method: string, paramName: string, annotationType?: C): RuntimeAnnotation<C>; /** * 获取指定类的属性上的注解信息 * @param clazz 属性所在类 * @param name 属性名称 * @param annotationType 要获取的注解类型,如果不指定则返回该属性上的所有注解 */ static getPropertyAnnotations<C extends IAnnotationOrClazz>(clazz: Function, name: string, annotationType?: C): RuntimeAnnotation<C>[]; /** * 获取指定类的属性上的注解信息 * @param clazz 属性所在类 * @param name 属性名称 * @param annotationType 要获取的注解类型 */ static getPropertyAnnotation<C extends IAnnotationOrClazz>(clazz: Function, name: string, annotationType?: C): RuntimeAnnotation<C>; /** * 获取指定类的所有属性名称 * @param clazz * @returns */ static getClazzPropertyKeys(clazz: Function): string[]; /** * 合并配置值到nativeAnnotation上 * @param nativeAnnotation * @param initializer */ private static mergeAnnotationValues; constructor(meta: any, NativeAnnotation: IAnnotationClazz, elementTypes: ElementType[], initializer: any, ownerAnnotation?: RuntimeAnnotation); } export {};