import { SceneConfig, SceneOptions, Sdk } from './Config'; import { VisibleValue } from './core/common/VisibleValue'; import { ArkClass } from './core/model/ArkClass'; import { ArkFile, Language } from './core/model/ArkFile'; import { ArkMethod } from './core/model/ArkMethod'; import { ArkModule, ModuleID } from './core/model/ArkModule'; import { ArkNamespace } from './core/model/ArkNamespace'; import { ClassSignature, FileSignature, MethodSignature, NamespaceSignature } from './core/model/ArkSignature'; import { ModuleAnalysisConfig, ModuleAnalysisCallback } from './frontend/common/ModuleAnalysisConfig'; import { MemoryMonitor } from './frontend/common/MemoryMonitor'; import { ModuleCache } from './frontend/common/ModuleCache'; import { Local } from './core/base/Local'; import { ArkExport } from './core/model/ArkExport'; import { CallGraph } from './callgraph/model/CallGraph'; import { ModuleDepGraph } from './core/graph/ModuleDepGraph'; export declare enum SceneBuildStage { BUILD_INIT = 0, SDK_INFERRED = 1, CLASS_DONE = 2, METHOD_DONE = 3, CLASS_COLLECTED = 4, METHOD_COLLECTED = 5, TYPE_INFERRED = 6 } /** * The Scene class includes everything in the analyzed project. * We should be able to re-generate the project's code based on this class. */ export declare class Scene { private projectName; private projectFiles; private realProjectDir; private includeDirs; private ccjsonPath; private cppAstPath; private moduleScenesMap; private modulePath2NameMap; private moduleSdkMap; private projectSdkMap; private visibleValue; private filesMap; private namespacesMap; private classesMap; private methodsMap; /** Custom @Component name → ClassSignature; written at ArkClass build, kept after module unload for ViewTree stubs. */ private customComponentMap; private sdkArkFilesMap; private sdkGlobalMap; private ohPkgContentMap; private ohPkgFilePath; private ohPkgContent; private overRides; private overRideDependencyMap; private globalModule2PathMapping?; private baseUrl?; private buildStage; private fileLanguages; private options; /** The SceneConfig used to build this scene, retained for later queries (e.g. SDK list). */ private sceneConfig?; /** Maps ArkModule objects to dense integer ModuleIDs via the objectIdentity strategy. */ private moduleCanonicalizer; /** Module dependency graph, used for SCCDetection. Built during dependency analysis. */ private moduleDepGraph?; /** Whether module preparation has completed (prepareModules + analyzeModuleDependencies, idempotent). */ private modulesRegistered; /** Persistent module cache for cross-call module reuse. */ private moduleCache?; /** Persistent memory monitor for cache eviction. */ private memoryMonitor?; private unhandledFilePaths; private unhandledSdkFilePaths; constructor(); dispose(): void; getOptions(): SceneOptions; getBuildStage(): SceneBuildStage; getOverRides(): Map; getOverRideDependencyMap(): Map; clear(): void; getStage(): SceneBuildStage; /** * Set the current {@link SceneBuildStage}. Used by module-level builders (e.g. * {@link FrontendBuilder.buildModuleMethodBody}) to temporarily open the * {@link buildClassDone} gate so that nested/anonymous method bodies are built * immediately during body construction, then restore the previous stage. */ setBuildStage(stage: SceneBuildStage): void; /** * Build scene object according to the {@link SceneConfig}. This API implements 3 functions. * First is to build scene object from {@link SceneConfig}, second is to generate {@link ArkFile}s, * and the last is to collect project import infomation. * @param sceneConfig - a sceneConfig object, which is usally defined by user or Json file. * @example * 1. Build Scene object from scene config ```typescript // build config const projectDir = ... ...; const sceneConfig = new SceneConfig(); sceneConfig.buildFromProjectDir(projectDir); // build scene const scene = new Scene(); scene.buildSceneFromProjectDir(sceneConfig); ``` */ buildSceneFromProjectDir(sceneConfig: SceneConfig): void; buildSceneFromFiles(sceneConfig: SceneConfig): void; /** * Set the basic information of the scene using a config, * such as the project's name, real path and files. * @param sceneConfig - the config used to set the basic information of scene. */ buildBasicInfo(sceneConfig: SceneConfig): void; private parseBuildProfile; private parseOhPackage; private findTsConfigInfoDeeply; private addTsConfigInfo; /** * Update or add default constructors for all classes in the scene. * * This function iterates through all files and classes in the scene, * builds default constructors for each class, and processes existing constructors * by replacing super constructor calls and adding initialization logic. * * @returns {void} */ private updateOrAddDefaultConstructors; private collectAllMethods; private static freeMethodBodyBuilder; private buildAllMethodBody; private freeAllBodyBuilders; private genArkFiles; private getFilesOrderByDependency; getDependencyFilesDeeply(projectFile: string): void; private isRepeatBuildFile; private addArkFile2ModuleScene; private findDependencyFiles; private parseFrom; private findDependenciesByTsConfig; private parseTsConfigParms; private processFuzzyMapping; private findDependenciesByRule; private findFilesByPathArray; private findFilesByExtNameArray; private findRelativeDependenciesByOhPkg; private findDependenciesByOhPkg; private getDependenciesMapping; private getOriginPath; private addFileNode2DependencyGrap; /** * Loads SDK sources into the scene. C++ SDK files are intentionally skipped: they are not parsed or registered * here (only non-C++ SDK sources are processed). */ private buildSdk; private collectSdkFiles; private parseAndRegisterSdkFile; /** * Build the scene for harmony project. It resolves the file path of the project first, and then fetches * dependencies from this file. Next, build a `ModuleScene` for this project to generate {@link ArkFile}. Finally, * it build bodies of all methods, generate extended classes, and add DefaultConstructors. */ buildScene4HarmonyProject(): void; private buildOhPkgContentMap; buildModuleScene(moduleName: string, modulePath: string, supportFileExts: string[]): void; private processModuleOhPkgContent; /** * Get the absolute path of current project. * @returns The real project's directiory. * @example * 1. get real project directory, such as: ```typescript let projectDir = projectScene.getRealProjectDir(); ``` */ getRealProjectDir(): string; /** * Returns the {@link SceneConfig} used to build this scene, or undefined before * {@link buildBasicInfo} has been called. */ getSceneConfig(): SceneConfig | undefined; /** * Save the {@link SceneConfig} into the scene for later module-level analysis. * Unlike {@link buildBasicInfo}, this method only stores the config (and derives * the real project directory) without building ArkFiles or performing type inference. * This is the lightweight entry point for {@link analyseByModule}. */ config(sceneConfig: SceneConfig): void; /** * Returns all registered {@link ArkModule} objects. */ getModules(): ArkModule[]; /** The module dependency graph, or undefined before dependency analysis. */ getModuleDepGraph(): ModuleDepGraph | undefined; /** Whether module preparation has completed. */ isModulesRegistered(): boolean; getModuleCache(): ModuleCache | undefined; setModuleCache(cache: ModuleCache): void; getMemoryMonitor(): MemoryMonitor | undefined; setMemoryMonitor(monitor: MemoryMonitor): void; /** Get a registered module by its ModuleID. Returns undefined when the id is out of bounds. */ getModule(id: ModuleID): ArkModule | undefined; /** Get the ModuleID assigned to a registered ArkModule. */ getModuleId(module: ArkModule): ModuleID; /** Total number of registered modules. */ getModuleCount(): number; /** Create a {@link ModuleDepGraph} sharing the internal module canonicalizer. */ createModuleDepGraph(): ModuleDepGraph; setModuleDepGraph(graph: ModuleDepGraph): void; setModulesRegistered(value: boolean): void; /** * Perform module-level analysis by iterating modules in topological order and invoking * the callback for each module. * * Flow: prepareModules → analyzeModuleDependencies → buildSdkModules (SDK files parsed + * inferred first) → resolveTargetModuleIds → computeModuleClosureByIds → iterate topoOrder * → loadModule → callback. * Each step is idempotent; repeated calls do not repeat preprocessing. * * - SDK modules are registered and built in one fused step by {@link ModuleBuilder.buildSdkModules} * before the topoOrder loop, so that global APIs are available when project/oh_modules modules * are loaded. SDK modules are not in the module dependency graph and thus never appear in the * topoOrder or callback. * - Target modules are resolved from the config's type filter, explicit include IDs, and * explicit exclude IDs. The transitive closure (targets + dependencies) determines which * modules are loaded. The callback is invoked only for target modules, not their dependencies. * - By default (no explicit selection), all PROJECT and OH_MODULES modules are targets. * * @param callback - Invoked for each target module with the module and the scene. * @param config - Optional configuration for target module selection and load levels. */ analyseByModule(callback: ModuleAnalysisCallback, config?: ModuleAnalysisConfig): void; /** * Returns the **string** name of the project. * @returns The name of the project. */ getProjectName(): string; getProjectFiles(): string[]; getSdkGlobal(globalName: string): ArkExport | null; getSdkGlobalMap(): Map; /** * Returns the file based on its signature. * If no file can be found according to the input signature, **null** will be returned. * A typical {@link ArkFile} contains: file's name (i.e., its relative path), project's name, * project's dir, file's signature etc. * @param fileSignature - the signature of file. * @returns a file defined by ArkAnalyzer. **null** will be returned if no file could be found. * @example * 1. get ArkFile based on file signature. ```typescript if (...) { const fromSignature = new FileSignature(); fromSignature.setProjectName(im.getDeclaringArkFile().getProjectName()); fromSignature.setFileName(fileName); return scene.getFile(fromSignature); } ``` */ getFile(fileSignature: FileSignature): ArkFile | null; getUnhandledFilePaths(): string[]; addUnhandledFilePath(filePath: string): void; getUnhandledSdkFilePaths(): string[]; setFile(file: ArkFile): void; /** * Add an SDK ArkFile to the scene's `sdkArkFilesMap`, keyed by its file signature. * Used by {@link ModuleBuilder.parseAndRegisterSdkFile} during SDK file registration. */ addSdkArkFile(arkFile: ArkFile): void; hasSdkFile(fileSignature: FileSignature): boolean; /** * Get files of a {@link Scene}. Generally, a project includes several ets/ts files that define the different * class. We need to generate {@link ArkFile} objects from these ets/ts files. * @returns The array of {@link ArkFile} from `scene.filesMap.values()`. * @example * 1. In inferSimpleTypes() to check arkClass and arkMethod. * ```typescript * public inferSimpleTypes(): void { * for (let arkFile of this.getFiles()) { * for (let arkClass of arkFile.getClasses()) { * for (let arkMethod of arkClass.getMethods()) { * // ... ...; * } * } * } * } * ``` * 2. To iterate each method * ```typescript * for (const file of this.getFiles()) { * for (const cls of file.getClasses()) { * for (const method of cls.getMethods()) { * // ... ... * } * } * } *``` */ getFiles(): ArkFile[]; getFileLanguages(): Map; getSdkArkFiles(): ArkFile[]; getModuleSdkMap(): Map; getProjectSdkMap(): Map; getNamespace(namespaceSignature: NamespaceSignature): ArkNamespace | null; private getNamespaceBySignature; private getNamespacesMap; getNamespaces(): ArkNamespace[]; /** * Returns the class according to the input class signature. * @param classSignature - signature of the class to be obtained. * @returns A class. */ getClass(classSignature: ClassSignature): ArkClass | null; /** * Register a custom {@code @Component} into {@link customComponentMap}. * Called from ArkClass builders (full Scene build and module load share the same path). * Entries intentionally survive module unload so ViewTree can still resolve signatures. */ registerCustomComponent(cls: ArkClass): void; /** * Remove a custom component entry. Not called on module unload — the map must outlive IR. * Used when an ArkClass is explicitly removed from a live Scene, or via {@link clear}. */ unregisterCustomComponent(cls: ArkClass): void; getCustomComponent(name: string): ClassSignature | undefined; getCustomComponentMap(): Map; private getClassesMap; getClasses(): ArkClass[]; getMethod(methodSignature: MethodSignature, refresh?: boolean): ArkMethod | null; private getMethodsMap; /** * Returns the method associated with the method signature. * If no method is associated with this signature, **null** will be returned. * An {@link ArkMethod} includes: * - Name: the **string** name of method. * - Code: the **string** code of the method. * - Line: a **number** indicating the line location, initialized as -1. * - Column: a **number** indicating the column location, initialized as -1. * - Parameters & Types of parameters: the parameters of method and their types. * - View tree: the view tree of the method. * - ... * * @param methodSignature - the signature of method. * @returns The method associated with the method signature. * @example * 1. get method from getMethod. ```typescript const methodSignatures = this.CHA.resolveCall(xxx, yyy); for (const methodSignature of methodSignatures) { const method = this.scene.getMethod(methodSignature); ... ... } ``` */ getMethods(): ArkMethod[]; addToMethodsMap(method: ArkMethod): void; removeMethod(method: ArkMethod): boolean; removeClass(arkClass: ArkClass): boolean; removeNamespace(namespace: ArkNamespace): boolean; removeFile(file: ArkFile): boolean; /** * Dispose a module's data from all global indices. * * Removes the module's ArkFiles, ArkClasses, ArkMethods, and ArkNamespaces from the Scene's * global maps (filesMap, sdkArkFilesMap, classesMap, methodsMap, namespacesMap) and clears * the oh-package.json5 content cache. After this call, the module's heavy data is no longer * reachable via Scene's global indices and can be garbage-collected. * * The global sdkGlobalMap is NOT cleaned (its keys are flat global names that cannot be * reverse-mapped to a module). SDK modules should not be disposed. * * @param module - The module whose data should be removed from global indices. */ disposeModule(module: ArkModule): void; hasMainMethod(): boolean; getEntryPoints(): MethodSignature[]; /** get values that is visible in curr scope */ getVisibleValue(): VisibleValue; getOhPkgContent(): { [p: string]: unknown; }; getOhPkgContentMap(): Map; getOhPkgFilePath(): string; makeCallGraphCHA(entryPoints: MethodSignature[]): CallGraph; makeCallGraphRTA(entryPoints: MethodSignature[]): CallGraph; /** Obtain the header file directories of the input C++ project dependencies. */ getIncludeDirs(): string[]; getCcjsonPath(): string; setCcjsonPath(ccjsonPath: string): void; getCppAstPath(): string; /** * Infer type for each non-default method. It infers the type of each field/local/reference. * For example, the statement `let b = 5;`, the type of local `b` is `NumberType`; and for the statement `let s = * 'hello';`, the type of local `s` is `StringType`. The detailed types are defined in the Type.ts file. * @example * 1. Infer the type of each class field and method field. ```typescript const scene = new Scene(); scene.buildSceneFromProjectDir(sceneConfig); scene.inferTypes(); ``` */ inferTypes(times?: number): void; /** * @deprecated This method is deprecated and will be removed in the next major release. * Please use the new type inference system instead. * * Scheduled for removal: one month from deprecation date. */ inferTypesOld(): void; /** * Iterate all assignment statements in methods, * and set the type of left operand based on the type of right operand * if the left operand is a local variable as well as an unknown. * @Deprecated * @example * 1. Infer simple type when scene building. ```typescript let scene = new Scene(); scene.buildSceneFromProjectDir(config); scene.inferSimpleTypes(); ``` */ inferSimpleTypes(): void; private addNSClasses; private addNSExportedClasses; private addFileImportedClasses; getClassMap(): Map; private addNSLocals; private addNSExportedLocals; private addFileImportLocals; private handleNestedNSLocals; getGlobalVariableMap(): Map; getStaticInitMethods(): ArkMethod[]; buildClassDone(): boolean; getModuleScene(moduleName: string): ModuleScene | undefined; getModuleSceneMap(): Map; getGlobalModule2PathMapping(): { [k: string]: string[]; } | undefined; getbaseUrl(): string | undefined; } export declare class ModuleScene { private projectScene; private moduleName; private modulePath; private moduleFileMap; private moduleOhPkgFilePath; private ohPkgContent; constructor(projectScene: Scene); getProjectScene(): Scene; ModuleSceneBuilder(moduleName: string, modulePath: string, supportFileExts: string[], recursively?: boolean): void; ModuleScenePartiallyBuilder(moduleName: string, modulePath: string): void; /** * get oh-package.json5 */ private getModuleOhPkgFilePath; /** * get nodule name * @returns return module name */ getModuleName(): string; getModulePath(): string; getOhPkgFilePath(): string; getOhPkgContent(): { [p: string]: unknown; }; getModuleFilesMap(): Map; addArkFile(arkFile: ArkFile): void; private genArkFiles; } //# sourceMappingURL=Scene.d.ts.map