1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { 17 global, 18 passNode, 19 passNodeArray, 20 unpackNonNullableNode, 21 unpackNode, 22 unpackNodeArray, 23 assertValidPeer, 24 AstNode, 25 Es2pandaAstNodeType, 26 KNativePointer, 27 nodeByType, 28 ArktsObject, 29 unpackString 30} from "../../reexport-for-generated" 31 32import { Expression } from "./Expression" 33import { Identifier } from "./Identifier" 34import { TypeNode } from "./TypeNode" 35import { Es2pandaModifierFlags } from "./../Es2pandaEnums" 36import { AnnotationUsage } from "./AnnotationUsage" 37export class TSTypeParameter extends Expression { 38 constructor(pointer: KNativePointer) { 39 assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER) 40 super(pointer) 41 42 } 43 static createTSTypeParameter(name?: Identifier, constraint?: TypeNode, defaultType?: TypeNode): TSTypeParameter { 44 return new TSTypeParameter(global.generatedEs2panda._CreateTSTypeParameter(global.context, passNode(name), passNode(constraint), passNode(defaultType))) 45 } 46 static updateTSTypeParameter(original?: TSTypeParameter, name?: Identifier, constraint?: TypeNode, defaultType?: TypeNode): TSTypeParameter { 47 return new TSTypeParameter(global.generatedEs2panda._UpdateTSTypeParameter(global.context, passNode(original), passNode(name), passNode(constraint), passNode(defaultType))) 48 } 49 static create1TSTypeParameter(name: Identifier | undefined, constraint: TypeNode | undefined, defaultType: TypeNode | undefined, flags: Es2pandaModifierFlags): TSTypeParameter { 50 return new TSTypeParameter(global.generatedEs2panda._CreateTSTypeParameter1(global.context, passNode(name), passNode(constraint), passNode(defaultType), flags)) 51 } 52 static update1TSTypeParameter(original: TSTypeParameter | undefined, name: Identifier | undefined, constraint: TypeNode | undefined, defaultType: TypeNode | undefined, flags: Es2pandaModifierFlags): TSTypeParameter { 53 return new TSTypeParameter(global.generatedEs2panda._UpdateTSTypeParameter1(global.context, passNode(original), passNode(name), passNode(constraint), passNode(defaultType), flags)) 54 } 55 get name(): Identifier | undefined { 56 return unpackNode(global.generatedEs2panda._TSTypeParameterNameConst(global.context, this.peer)) 57 } 58 get constraint(): TypeNode | undefined { 59 return unpackNode(global.generatedEs2panda._TSTypeParameterConstraintConst(global.context, this.peer)) 60 } 61 /** @deprecated */ 62 setConstraint(constraint: TypeNode): this { 63 global.generatedEs2panda._TSTypeParameterSetConstraint(global.context, this.peer, passNode(constraint)) 64 return this 65 } 66 get defaultType(): TypeNode | undefined { 67 return unpackNode(global.generatedEs2panda._TSTypeParameterDefaultTypeConst(global.context, this.peer)) 68 } 69 /** @deprecated */ 70 setDefaultType(defaultType: TypeNode): this { 71 global.generatedEs2panda._TSTypeParameterSetDefaultType(global.context, this.peer, passNode(defaultType)) 72 return this 73 } 74 get annotations(): readonly AnnotationUsage[] { 75 return unpackNodeArray(global.generatedEs2panda._TSTypeParameterAnnotationsConst(global.context, this.peer)) 76 } 77 /** @deprecated */ 78 setAnnotations(annotations: readonly AnnotationUsage[]): this { 79 global.generatedEs2panda._TSTypeParameterSetAnnotations(global.context, this.peer, passNodeArray(annotations), annotations.length) 80 return this 81 } 82} 83export function isTSTypeParameter(node: AstNode): node is TSTypeParameter { 84 return node instanceof TSTypeParameter 85} 86if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER)) { 87 nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_TS_TYPE_PARAMETER, TSTypeParameter) 88}