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 { TypeNode } from "./TypeNode" 33import { FunctionSignature } from "./FunctionSignature" 34import { Es2pandaScriptFunctionFlags } from "./../Es2pandaEnums" 35import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" 36import { Expression } from "./Expression" 37import { TSInterfaceDeclaration } from "./TSInterfaceDeclaration" 38export class ETSFunctionType extends TypeNode { 39 constructor(pointer: KNativePointer) { 40 assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_ETS_FUNCTION_TYPE) 41 super(pointer) 42 43 } 44 static createETSFunctionType(signature: FunctionSignature | undefined, funcFlags: Es2pandaScriptFunctionFlags): ETSFunctionType { 45 return new ETSFunctionType(global.generatedEs2panda._CreateETSFunctionTypeIr(global.context, passNode(signature), funcFlags)) 46 } 47 static updateETSFunctionType(original: ETSFunctionType | undefined, signature: FunctionSignature | undefined, funcFlags: Es2pandaScriptFunctionFlags): ETSFunctionType { 48 return new ETSFunctionType(global.generatedEs2panda._UpdateETSFunctionTypeIr(global.context, passNode(original), passNode(signature), funcFlags)) 49 } 50 get typeParams(): TSTypeParameterDeclaration | undefined { 51 return unpackNode(global.generatedEs2panda._ETSFunctionTypeIrTypeParamsConst(global.context, this.peer)) 52 } 53 get params(): readonly Expression[] { 54 return unpackNodeArray(global.generatedEs2panda._ETSFunctionTypeIrParamsConst(global.context, this.peer)) 55 } 56 get returnType(): TypeNode | undefined { 57 return unpackNode(global.generatedEs2panda._ETSFunctionTypeIrReturnTypeConst(global.context, this.peer)) 58 } 59 get functionalInterface(): TSInterfaceDeclaration | undefined { 60 return unpackNode(global.generatedEs2panda._ETSFunctionTypeIrFunctionalInterfaceConst(global.context, this.peer)) 61 } 62 /** @deprecated */ 63 setFunctionalInterface(functionalInterface: TSInterfaceDeclaration): this { 64 global.generatedEs2panda._ETSFunctionTypeIrSetFunctionalInterface(global.context, this.peer, passNode(functionalInterface)) 65 return this 66 } 67 get flags(): Es2pandaScriptFunctionFlags { 68 return global.generatedEs2panda._ETSFunctionTypeIrFlags(global.context, this.peer) 69 } 70 get isThrowing(): boolean { 71 return global.generatedEs2panda._ETSFunctionTypeIrIsThrowingConst(global.context, this.peer) 72 } 73 get isRethrowing(): boolean { 74 return global.generatedEs2panda._ETSFunctionTypeIrIsRethrowingConst(global.context, this.peer) 75 } 76 get isExtensionFunction(): boolean { 77 return global.generatedEs2panda._ETSFunctionTypeIrIsExtensionFunctionConst(global.context, this.peer) 78 } 79} 80export function isETSFunctionType(node: AstNode): node is ETSFunctionType { 81 return node instanceof ETSFunctionType 82} 83if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_ETS_FUNCTION_TYPE)) { 84 nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_ETS_FUNCTION_TYPE, ETSFunctionType) 85} 86