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 { ArktsObject } from "./ArktsObject" 17import { global } from "../static/global" 18import { acceptNativeObjectArrayResult, unpackString } from "../utilities/private" 19import { KNativePointer } from "@koalaui/interop" 20import { EtsScript } from "../types" 21 22export class Program extends ArktsObject { 23 constructor(peer: KNativePointer) { 24 super(peer); 25 } 26 27 get astNode(): EtsScript { 28 return new EtsScript(global.es2panda._ProgramAst(global.context, this.peer)); 29 } 30 31 get externalSources(): ExternalSource[] { 32 return acceptNativeObjectArrayResult<ExternalSource>( 33 global.es2panda._ProgramExternalSources(global.context, this.peer), 34 (instance: KNativePointer) => new ExternalSource(instance) 35 ); 36 } 37 38 get programFileName(): string { 39 return unpackString(global.es2panda._ProgramFileNameConst(global.context, this.peer)); 40 } 41 42 get programFileNameWithExtension(): string { 43 return unpackString(global.es2panda._ProgramFileNameWithExtensionConst(global.context, this.peer)); 44 } 45 46 get programGlobalAbsName(): string { 47 return unpackString(global.es2panda._ETSParserGetGlobalProgramAbsName(global.context)); 48 } 49} 50 51export class ExternalSource extends ArktsObject { 52 constructor(peer: KNativePointer) { 53 super(peer) 54 } 55 56 getName(): string { 57 return unpackString(global.es2panda._ExternalSourceName(this.peer)); 58 } 59 60 get programs(): Program[] { 61 return acceptNativeObjectArrayResult<Program>( 62 global.es2panda._ExternalSourcePrograms(this.peer), 63 (instance: KNativePointer) => new Program(instance) 64 ); 65 } 66} 67