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 { ClassElement } from "./ClassElement" 33import { Es2pandaMethodDefinitionKind } from "./../Es2pandaEnums" 34import { Expression } from "./Expression" 35import { Es2pandaModifierFlags } from "./../Es2pandaEnums" 36import { ScriptFunction } from "./ScriptFunction" 37export class MethodDefinition extends ClassElement { 38 constructor(pointer: KNativePointer) { 39 assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_METHOD_DEFINITION) 40 super(pointer) 41 42 } 43 static createMethodDefinition(kind: Es2pandaMethodDefinitionKind, key: Expression | undefined, value: Expression | undefined, modifiers: Es2pandaModifierFlags, isComputed: boolean): MethodDefinition { 44 return new MethodDefinition(global.generatedEs2panda._CreateMethodDefinition(global.context, kind, passNode(key), passNode(value), modifiers, isComputed)) 45 } 46 static updateMethodDefinition(original: MethodDefinition | undefined, kind: Es2pandaMethodDefinitionKind, key: Expression | undefined, value: Expression | undefined, modifiers: Es2pandaModifierFlags, isComputed: boolean): MethodDefinition { 47 return new MethodDefinition(global.generatedEs2panda._UpdateMethodDefinition(global.context, passNode(original), kind, passNode(key), passNode(value), modifiers, isComputed)) 48 } 49 get kind(): Es2pandaMethodDefinitionKind { 50 return global.generatedEs2panda._MethodDefinitionKindConst(global.context, this.peer) 51 } 52 get isConstructor(): boolean { 53 return global.generatedEs2panda._MethodDefinitionIsConstructorConst(global.context, this.peer) 54 } 55 get isExtensionMethod(): boolean { 56 return global.generatedEs2panda._MethodDefinitionIsExtensionMethodConst(global.context, this.peer) 57 } 58 get overloads(): readonly MethodDefinition[] { 59 return unpackNodeArray(global.generatedEs2panda._MethodDefinitionOverloadsConst(global.context, this.peer)) 60 } 61 get baseOverloadMethod(): MethodDefinition | undefined { 62 return unpackNode(global.generatedEs2panda._MethodDefinitionBaseOverloadMethodConst(global.context, this.peer)) 63 } 64 get asyncPairMethod(): MethodDefinition | undefined { 65 return unpackNode(global.generatedEs2panda._MethodDefinitionAsyncPairMethodConst(global.context, this.peer)) 66 } 67 /** @deprecated */ 68 setOverloads(overloads: readonly MethodDefinition[]): this { 69 global.generatedEs2panda._MethodDefinitionSetOverloads(global.context, this.peer, passNodeArray(overloads), overloads.length) 70 return this 71 } 72 /** @deprecated */ 73 clearOverloads(): this { 74 global.generatedEs2panda._MethodDefinitionClearOverloads(global.context, this.peer) 75 return this 76 } 77 /** @deprecated */ 78 addOverload(overload: MethodDefinition): this { 79 global.generatedEs2panda._MethodDefinitionAddOverload(global.context, this.peer, passNode(overload)) 80 return this 81 } 82 /** @deprecated */ 83 setBaseOverloadMethod(baseOverloadMethod: MethodDefinition): this { 84 global.generatedEs2panda._MethodDefinitionSetBaseOverloadMethod(global.context, this.peer, passNode(baseOverloadMethod)) 85 return this 86 } 87 /** @deprecated */ 88 setAsyncPairMethod(method: MethodDefinition): this { 89 global.generatedEs2panda._MethodDefinitionSetAsyncPairMethod(global.context, this.peer, passNode(method)) 90 return this 91 } 92} 93export function isMethodDefinition(node: AstNode): node is MethodDefinition { 94 return node instanceof MethodDefinition 95} 96if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_METHOD_DEFINITION)) { 97 nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_METHOD_DEFINITION, MethodDefinition) 98} 99