UNPKG

node-web-mvc

Version:
82 lines (81 loc) 3.33 kB
"use strict"; /** * @module MethodParameter * @description 请求参数配置类 */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Javascript_1 = __importDefault(require("../../interface/Javascript")); const RuntimeAnnotation_1 = __importDefault(require("../annotations/annotation/RuntimeAnnotation")); const MultipartFile_1 = __importDefault(require("../http/MultipartFile")); class MethodParameter { /** * 判断当前参数是否存在指定注解 */ hasParameterAnnotation(annotationType) { return !!this.getParameterAnnotation(annotationType); } hasClassAnnotation(annotationType) { return !!RuntimeAnnotation_1.default.getClassAnnotation(this.beanType, annotationType); } hasMethodAnnotation(annotationType) { return !!RuntimeAnnotation_1.default.getMethodAnnotation(this.beanType, this.method, annotationType); } /** * 获取当前参数注解 */ getParameterAnnotation(annotationType) { var _a; return (_a = RuntimeAnnotation_1.default.getMethodParamAnnotation(this.beanType, this.method, this.paramName, annotationType)) === null || _a === void 0 ? void 0 : _a.nativeAnnotation; } /** * 获取当前参数上的所有注解 * @returns */ getParameterAnnotations() { return RuntimeAnnotation_1.default.getMethodParamAnnotations(this.beanType, this.method, this.paramName); } /** * 判断当前paramterType类型是否为指定类型(包含继承判定) */ isParamAssignableOf(parentType) { if (!parentType) return false; // 判断 参数类型是否继承与parentType或者等于parentType return Javascript_1.default.createTyper(this.parameterType).isType(parentType); } isExtParamAssignableOf(i, parentType) { const type = this.getParameterGenericTypeOf(i); if (!type) { return false; } return Javascript_1.default.createTyper(type).isType(parentType); } getParameterGenericTypeOf(i) { var _a, _b, _c; return (_c = (_b = (_a = this.runtimeType) === null || _a === void 0 ? void 0 : _a.args) === null || _b === void 0 ? void 0 : _b[i]) === null || _c === void 0 ? void 0 : _c.clazz; } isMultipartAccept() { var _a, _b; return (this.isParamAssignableOf(MultipartFile_1.default) || ((_a = this.runtimeType) === null || _a === void 0 ? void 0 : _a.clazz) instanceof MultipartFile_1.default || ((_b = this.runtimeType) === null || _b === void 0 ? void 0 : _b.array) && this.isExtParamAssignableOf(0, MultipartFile_1.default)); } /** * 构造一个方法参数 * @param options 参数配置 * @param paramType 参数类型 * @param annotation 所属原始注解 */ constructor(beanType, method, paramName, paramIndex, parameterType) { this.beanType = beanType; this.method = method; this.paramName = paramName; this.paramIndex = paramIndex; this.parameterType = parameterType.clazz; this.runtimeType = parameterType; } } exports.default = MethodParameter;