### ArkAnalyzer Get Class Methods Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Demonstrates retrieving all methods from a specific class using 'serviceClass.getMethods()' and from the entire scene using 'scene.getMethods()'. The example extracts and logs the names of these methods. ```typescript let serviceClass: ArkClass = classes[5]; let methods: ArkMethod[] = serviceClass.getMethods(); let methodNames: string[] = methods.map(mthd => mthd.name); console.log(methodNames); ``` ```typescript let methods1: ArkMethod[] = scene.getMethods(); let methodNames1: string[] = methods1.map(mthd => mthd.name); console.log(methodNames1); ``` -------------------------------- ### ArkAnalyzer Get Classes Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Shows how to obtain all classes from the project using 'scene.getClasses()', from a specific file using 'files[index].getClasses()', and from a namespace using 'namespaces[index].getClasses()'. It returns 'ArkClass' objects, and the example extracts their names. ```typescript let classes: ArkClass[] = scene.getClasses(); let classNames: string[] = classes.map(cls => cls.name); console.log(classNames); ``` ```typescript let classes2: ArkClass[] = files[2].getClasses(); let classNames2: string[] = classes2.map(cls => cls.name); console.log(classNames2); ``` ```typescript let classes3: ArkClass[] = namespaces[0].getClasses(); let classNames3: string[] = classes3.map(cls => cls.name); console.log(classNames3); ``` -------------------------------- ### Perform Null Pointer Analysis starting from a specific method Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md This example demonstrates how to initiate a null pointer analysis within the Arkanalyzer. It starts from a specified entry method (e.g., 'U2') and checks for potential issues where program properties might be accessed via undefined or null pointers, which could lead to crashes or undefined behavior. This analysis helps in identifying potential runtime errors. ```typescript const config_path = resources/UndefinedVariable/UndefinedVariable.json"; const scene = new Scene(config); const defaultMethod = scene.getFiles()[0] .getDefaultClass() .getDefaultArkMethod(); const method = ModelUtils.getMethodWithName("U2",defaultMethod!); if(method) { let len = method.getParameters().length; const problem = new UndefinedVariableChecker( [...method.getCfg().getBlocks()][0].getStmts()[len], method); const solver = new UndefinedVariableSolver(problem, scene); solver.solve(); } ``` -------------------------------- ### ArkAnalyzer Get All Files Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Retrieves all files within the analyzed project using the 'scene.getFiles()' method. The output is a list of file paths. This is a fundamental step in code analysis with ArkAnalyzer. ```typescript let files: ArkFile[] = scene.getFiles(); let fileNames: string[] = files.map(file => file.name); console.log(fileNames); ``` -------------------------------- ### ArkAnalyzer Get Class Fields Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Illustrates how to get all fields (properties) of a specific class. It first retrieves the 'ArkClass' object and then calls its 'getFields()' method. The example extracts and logs the names of these fields. ```typescript let bookClass: ArkClass = classes[3]; let fields: ArkField[] = bookClass.getFields(); let fieldNames: string[] = fields.map(fld => fld.name); console.log(fieldNames); ``` -------------------------------- ### getStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/IndexedAccessTypeNode.md Gets the start position of the node. ```APIDOC ## GET /getStart ### Description Gets the start position of the node. This method can optionally take a `sourceFile` and `includeJsDocComment` parameter. ### Method GET ### Endpoint /getStart ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to consider. - **includeJsDocComment** (boolean) - Optional - Whether to include the JSDoc comment in the start position calculation. ### Response #### Success Response (200) - **position** (number) - The start position of the node. #### Response Example ```json { "position": 100 } ``` ``` -------------------------------- ### ArkAnalyzer Get Method CFG Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Shows how to obtain the Control Flow Graph (CFG) for a method. It involves getting the 'ArkMethod' object, then its body using 'getBody()', and finally the CFG using 'getCfg()'. The CFG data structure contains blocks, statement mappings, and definition-use chains. ```typescript let methods: ArkMethod[] = scene.getMethods(); let methodCfg: Cfg = methods[0].getBody().getCfg(); ``` -------------------------------- ### getStart() Method Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/InterfaceDeclaration.md Gets the start position of the node. ```APIDOC ## GET /getStart ### Description Gets the character position where the node starts. ### Method GET ### Endpoint /getStart ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to consider. - **includeJsDocComment** (boolean) - Optional - Whether to include the JSDoc comment in the start position. ### Response #### Success Response (200) - **startPosition** (number) - The start position of the node. #### Response Example ```json { "startPosition": 15 } ``` ``` -------------------------------- ### Build and Retrieve Def-Use Chains for ArkMethod Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md This example demonstrates how to obtain the Def-Use Chain for a given ArkMethod. The Def-Use Chain tracks variable definitions and their subsequent uses within a function. It's important to note that this analysis is limited to local variables and does not cover object properties or array elements. ```typescript const arkMethod: ArkMethod; const cfg = arkMethod.getBody().getCfg(); cfg.buildDefUseChain(); const chains = cfg.getDefUseChains() ``` -------------------------------- ### Set Analysis Entry Points and Infer Types Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Configures the analysis by specifying the method signature to be used as an entry point and performing type inference across the project. This is a prerequisite for generating call graphs. ```typescript // 加入需要进行分析的方法签名,method 是文件中默认类下 main 方法 let methodSignature = method.getSignature() let entryPoints: MethodSignature[] = [methodSignature] // 进行类型推导 projectScene.inferTypes() ``` -------------------------------- ### getStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/PropertyAccessChain.md Gets the starting position of a node within the source file. Inherited from PropertyAccessExpression. ```APIDOC ## getStart() ### Description Gets the starting position of a node within the source file. Inherited from PropertyAccessExpression. ### Method GET (Assumed, as it's a retrieval function) ### Endpoint /arkanalyzer/getStart ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file context. - **includeJsDocComment** (boolean) - Optional - Whether to include the start of a JsDoc comment. ### Request Example ```json { "sourceFile": "", "includeJsDocComment": true } ``` ### Response #### Success Response (200) - **startPosition** (number) - The starting position of the node. #### Response Example ```json { "startPosition": 100 } ``` ``` -------------------------------- ### getStart() Method Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/TemplateMiddle.md Gets the starting position of the node in the source file, optionally including JSDoc comments. ```APIDOC ## getStart() ### Description Gets the character position where the node begins in the source file. Optionally includes JSDoc comments. ### Method `getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Returns the starting position as a number. #### Response Example ```json { "example": "100" } ``` #### Inherited from [`TemplateLiteralLikeNode`](TemplateLiteralLikeNode.md).[`getStart`](TemplateLiteralLikeNode.md#getstart) ``` -------------------------------- ### Node getFullStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/Declaration.md Gets the full start position of the Node. ```APIDOC ## GET /node/fullStart ### Description Gets the full start position of the Node. ### Method GET ### Endpoint /node/fullStart ### Response #### Success Response (200) - **fullStart** (number) - The full start position of the Node. #### Response Example ```json { "fullStart": 0 } ``` ``` -------------------------------- ### getFullStart() Method Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/TemplateMiddle.md Gets the starting position of the node, including leading trivia. ```APIDOC ## getFullStart() ### Description Gets the starting character position of the node, including any leading whitespace or comments (trivia). ### Method `getFullStart(): number` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Returns the full starting position as a number. #### Response Example ```json { "example": "95" } ``` #### Inherited from [`TemplateLiteralLikeNode`](TemplateLiteralLikeNode.md).[`getFullStart`](TemplateLiteralLikeNode.md#getfullstart) ``` -------------------------------- ### getStart API Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/SuperPropertyAccessExpression.md Gets the starting position of a node within the source file, with an option to include JSDoc comments. ```APIDOC ## getStart() ### Description Gets the starting position of a node within the source file, with an option to include JSDoc comments. ### Method GET ### Endpoint `/arkanalyzer/getStart` ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to analyze. - **includeJsDocComment** (boolean) - Optional - Whether to include JSDoc comments in the start position calculation. ### Response #### Success Response (200) - **startPosition** (number) - The starting position of the node. #### Response Example { "startPosition": 5 } ``` -------------------------------- ### getFullStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/IndexedAccessTypeNode.md Gets the full start position of the node, including leading trivia. ```APIDOC ## GET /getFullStart ### Description Gets the full start position of the node, including any leading trivia. This method does not take any parameters. ### Method GET ### Endpoint /getFullStart ### Response #### Success Response (200) - **position** (number) - The full start position of the node. #### Response Example ```json { "position": 567 } ``` ``` -------------------------------- ### getStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/TemplateTail.md Gets the start position of the node in the source file, optionally including JSDoc comments. ```APIDOC ## getStart() ### Description Gets the start position of the node in the source file. An optional `sourceFile` and a boolean `includeJsDocComment` can be provided. ### Method N/A (Method of a class) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript node.getStart(sourceFile?, includeJsDocComment?); ``` ### Response #### Success Response (200) Returns a `number` representing the start position. #### Response Example ```json 118 ``` ``` -------------------------------- ### Node getStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/Declaration.md Gets the start position of the Node. Optionally, a SourceFile and a flag to include JSDoc comments can be provided. ```APIDOC ## GET /node/start ### Description Gets the start position of the Node. Optionally, a SourceFile and a flag to include JSDoc comments can be provided. ### Method GET ### Endpoint /node/start ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to consider. - **includeJsDocComment** (boolean) - Optional - Whether to include JSDoc comments in the start position. ### Response #### Success Response (200) - **start** (number) - The start position of the Node. #### Response Example ```json { "start": 0 } ``` ``` -------------------------------- ### TypeScript Define Class: BookService Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Defines a 'BookService' class in TypeScript, responsible for managing a collection of 'Library.Book' objects. It includes methods to add books and retrieve all books. This service interacts with the 'Library.Book' class. ```typescript import { Library } from "../models/book"; export class BookService { private books: Library.Book[] = []; public addBook(book: Library.Book): void { this.books.push(book); } public getAllBooks(): Library.Book[] { return this.books; } } ``` -------------------------------- ### TypeScript Main Entry Point: index.ts Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md The main entry point for the sample application, written in TypeScript. It instantiates 'BookService', adds a book, retrieves all books, and logs them to the console. This demonstrates basic usage of the 'Book' and 'BookService' classes. ```typescript import { Library } from "./models/book"; import { BookService } from "./services/bookService"; const bookService = new BookService(); bookService.addBook(new Library.Book("The Hobbit", "J.R.R. Tolkien")); const books = bookService.getAllBooks(); console.log(books); ``` -------------------------------- ### projectStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/classes/PointerAnalysis.md Initiates the analysis process for an entire project. Allows control over whether to display generated methods. ```APIDOC ## projectStart() ### Description Starts the pointer analysis for the entire project. Can be configured to include or exclude generated methods from the analysis. ### Method POST ### Endpoint /api/pointerAnalysis/projectStart ### Parameters #### Request Body - **displayGeneratedMethod** (boolean) - If true, generated methods will be included in the analysis; otherwise, they will be excluded. ### Request Example ```json { "displayGeneratedMethod": true } ``` ### Response #### Success Response (200) - **return** (void) - Indicates the project analysis has started. #### Response Example ```json { "example": null } ``` ``` -------------------------------- ### Configure ArkAnalyzer Scene with JSON Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md This snippet demonstrates how to configure ArkAnalyzer by loading project settings from a JSON file using the SceneConfig class. It initializes a Scene object for project analysis. The input is a JSON file path and project details, while the output is a configured Scene object. ```typescript import { SceneConfig, Scene } from "./bundle"; const config_path = "tests/example.json"; let config: SceneConfig = new SceneConfig(); config.buildFromJson(config_path); let scene: Scene = new Scene(config); ``` -------------------------------- ### start() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/classes/PointerAnalysis.md Starts the main pointer analysis process. This is a protected method. ```APIDOC ## start() ### Description Initiates the core pointer analysis execution. This is a protected method, typically called after setup is complete. ### Method POST ### Endpoint /api/pointerAnalysis/start ### Parameters None ### Response #### Success Response (200) - **return** (void) - Indicates the analysis has started. #### Response Example ```json { "example": null } ``` ``` -------------------------------- ### ArkAnalyzer Get Namespaces Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Demonstrates how to retrieve all namespaces defined in the project using 'scene.getNamespaces()' and from a specific file using 'files[index].getNamespaces()'. It returns an array of 'ArkNamespace' objects, from which names are extracted. ```typescript let namespaces: ArkNamespace[] = scene.getNamespaces(); let namespaceNames: string[] = namespaces.map(ns => ns.name); console.log(namespaceNames); ``` ```typescript let namespaces2: ArkNamespace[] = files[1].getNamespaces(); let namespaceNames2: string[] = namespaces2.map(ns => ns.name); console.log(namespaceNames2); ``` -------------------------------- ### Find All Log Points Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md Identifies all logging points within the codebase by analyzing the generated call graph. This process involves generating a call graph (using CHA in the example) and then inspecting the relationships to find calls to logging methods. ```typescript import { Logger } from "./log" abstract class Animal { sound(): void { } } class Dog extends Animal { sound(): void { Logger.warn("dog sound") } } class Cat extends Animal { sound(): void { Logger.error("dog sound") } } function main() { makeSound(new Dog()) Logger.info("create new dog") } function makeSound(animal: Animal) { animal.sound() } // 通过上述方法生成方法调用图(这里以 CHA 为例),得到下面的结果 // console output shows the call graph with log points identified ``` -------------------------------- ### InstallTypes Interface Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/namespaces/server/interfaces/InstallTypes.md Details of the InstallTypes interface and its properties. ```APIDOC ## Interface: InstallTypes Defined in: `node_modules/ohos-typescript/lib/typescript.d.ts:6065` ### Description The InstallTypes interface represents event data related to the installation of typings packages. ### Extends - `ProjectResponse` ### Extended by - `BeginInstallTypes` - `EndInstallTypes` ### Properties #### eventId - **eventId** (`number`) - Readonly - Defined in: `node_modules/ohos-typescript/lib/typescript.d.ts:6067` - Description: A unique identifier for the event. #### kind - **kind** (`"event::beginInstallTypes"` | `"event::endInstallTypes"`) - Readonly - Defined in: `node_modules/ohos-typescript/lib/typescript.d.ts:6066` - Description: The type of the event, indicating the start or end of typings installation. - Overrides: `ProjectResponse.kind` #### packagesToInstall - **packagesToInstall** (readonly `string[]`) - Readonly - Defined in: `node_modules/ohos-typescript/lib/typescript.d.ts:6069` - Description: An array of package names that need to be installed. #### projectName - **projectName** (`string`) - Readonly - Defined in: `node_modules/ohos-typescript/lib/typescript.d.ts:6060` - Description: The name of the project for which typings are being installed. - Inherited from: `ProjectResponse.projectName` #### typingsInstallerVersion - **typingsInstallerVersion** (`string`) - Readonly - Defined in: `node_modules/ohos-typescript/lib/typescript.d.ts:6068` - Description: The version of the typings installer being used. ``` -------------------------------- ### Get Start Position Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/TypeElement.md Returns the start position of the node. This method is inherited from NamedDeclaration. ```APIDOC ## GET /start-position ### Description Returns the start position of the node. This method is inherited from NamedDeclaration. ### Method GET ### Endpoint /start-position ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to consider. - **includeJsDocComment** (boolean) - Optional - Whether to include JsDoc comments in the start position calculation. ### Response #### Success Response (200) - **start** (number) - The start position of the node. #### Response Example ```json { "start": 100 } ``` ``` -------------------------------- ### getStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/JsxFragment.md Retrieves the starting position of a source file. This method can optionally consider JSDoc comments. ```APIDOC ## getStart() ### Description Retrieves the starting position of a source file. This method can optionally consider JSDoc comments. ### Method GET ### Endpoint /arkanalyzer/sourcefile/start ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to analyze. - **includeJsDocComment** (boolean) - Optional - Whether to include JSDoc comments in the analysis. ### Response #### Success Response (200) - **startPosition** (number) - The starting position of the source file. #### Response Example ```json { "startPosition": 100 } ``` ``` -------------------------------- ### Get Full Start Position Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/TypeElement.md Returns the full start position of the node, including leading trivia. This method is inherited from NamedDeclaration. ```APIDOC ## GET /full-start-position ### Description Returns the full start position of the node, including leading trivia. This method is inherited from NamedDeclaration. ### Method GET ### Endpoint /full-start-position ### Response #### Success Response (200) - **fullStart** (number) - The full start position of the node. #### Response Example ```json { "fullStart": 567 } ``` ``` -------------------------------- ### Install Package Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/LanguageServiceHost.md Installs a package and applies code actions based on the installation result. ```APIDOC ## installPackage(options) ### Description Installs a package and applies code actions based on the installation result. ### Method POST (assumed, as it takes parameters) ### Endpoint /gowaylee/arkanalyzer/package/install ### Parameters #### Request Body - **options** (InstallPackageOptions) - Options for installing the package. ### Request Example ```json { "options": { "packageName": "lodash", "installTypings": true } } ``` ### Response #### Success Response (200) - **ApplyCodeActionCommandResult** (object) - The result of applying code actions after installation. #### Response Example ```json { "command": "installPackage", "diagnostic": null, "references": [] } ``` ``` -------------------------------- ### SolutionBuilderHostBase Interface Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/SolutionBuilderHostBase.md Documentation for the SolutionBuilderHostBase interface, which extends ProgramHost and is extended by SolutionBuilderHost and SolutionBuilderWithWatchHost. ```APIDOC ## Interface: SolutionBuilderHostBase Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5935 ### Description Represents the base host for a solution builder in ArkAnalyzer. ### Type Parameters * **T** (`T` extends `BuilderProgram`) * The type parameter for the builder program. ### Properties * **createProgram**: `CreateProgram`<`T`> * **Description**: Used to create the program when the need for program creation or recreation is detected. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5812 * **Inherited from**: `ProgramHost` * **getCustomTransformers**? (`project`: `string`): `undefined` | `CustomTransformers` * **Description**: Optional function to retrieve custom transformers for the project. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5942 * **reportDiagnostic**: `DiagnosticReporter` * **Description**: A reporter for diagnostics. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5947 * **reportSolutionBuilderStatus**: `DiagnosticReporter` * **Description**: A reporter for solution builder status. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5948 ### Methods * **afterProgramEmitAndDiagnostics**? (`program`: `T`): `void` * **Description**: Optional callback after program emit and diagnostics are completed. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5949 * **createDirectory**? (`path`: `string`): `void` * **Description**: Creates a directory at the specified path. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5936 * **createHash**? (`data`: `string`): `string` * **Description**: Creates a hash for the given data. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5818 * **Inherited from**: `ProgramHost` * **deleteFile** (`fileName`: `string`): `void` * **Description**: Deletes a file with the specified name. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5945 * **directoryExists**? (`path`: `string`): `boolean` * **Description**: Checks if a directory exists at the specified path. Used for module resolution and handling directory structure. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5830 * **Inherited from**: `ProgramHost` * **fileExists** (`path`: `string`): `boolean` * **Description**: Checks if a file exists at the specified path. Used for source files and module files if module resolution is not provided. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5823 * **Inherited from**: `ProgramHost` * **getCurrentDirectory** (): `string` * **Description**: Gets the current working directory. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5815 * **Inherited from**: `ProgramHost` * **getDefaultLibFileName** (`options`: `CompilerOptions`): `string` * **Description**: Gets the default library file name. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5816 * **Inherited from**: `ProgramHost` * **getDefaultLibLocation**? (): `string` * **Description**: Gets the default library location. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5817 * **Inherited from**: `ProgramHost` * **getDirectories**? (`path`: `string`): `string`[] * **Description**: Gets the subdirectories of a given path. Used in resolutions and handling directory structure. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5832 * **Inherited from**: `ProgramHost` * **getEnvironmentVariable**? (`name`: `string`): `undefined` | `string` * **Description**: Gets the value of an environment variable. * **Defined in**: node_modules/ohos-typescript/lib/typescript.d.ts:5840 * **Inherited from**: `ProgramHost` ``` -------------------------------- ### Get Node Full Start Position - TypeScript Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/NonNullExpression.md Returns the starting character position of the node, including any leading trivia (like whitespace or comments). This is a zero-based index. ```typescript getFullStart(): number; ``` -------------------------------- ### getStart API Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/TsConfigSourceFile.md Gets the start position of the current node. ```APIDOC ## getStart() ### Description Gets the start position of the current node. ### Method GET ### Endpoint /api/arkanalyzer/getStart ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to analyze. - **includeJsDocComment** (boolean) - Optional - Whether to include JsDoc comments in the start position. ### Response #### Success Response (200) - **startPosition** (number) - The start position of the node. ``` -------------------------------- ### ArkAnalyzer Scene Configuration JSON Structure Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/QuickStart.md This JSON structure defines the configuration for an ArkAnalyzer project. It includes essential paths like the target project directory and SDK paths. This configuration is used to initialize the Scene object for static code analysis. ```json { "targetProjectName": "Example",//项目名称 "targetProjectDirectory": "tests/resources/example",//项目所在位置路径 "ohosSdkPath": "",//ohos sdk api 路径,项目不包含 ohos api 时为空 "kitSdkPath": "",//ohos 套件 api 路径,项目不包含 ohos api 时为空 "systemSdkPath": "",//系统 sdk 路径,项目不包含 ohos api 时为空 "otherSdks": []//其他 sdk,一般为空 } ``` -------------------------------- ### createCompilerHost Function Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/functions/createCompilerHost.md Creates a CompilerHost instance with the specified options and optional parent node settings. ```APIDOC ## createCompilerHost() ### Description Creates a CompilerHost instance with the specified options and optional parent node settings. ### Method Not applicable (this is a function definition, not an HTTP endpoint) ### Endpoint Not applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example Not applicable ### Response #### Success Response (200) - **compilerHost** (CompilerHost) - The created CompilerHost instance. #### Response Example Not applicable ### Function Signature `createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost` ### Parameters #### options - **options** (CompilerOptions) - The compiler options to use for the host. #### setParentNodes? - **setParentNodes** (boolean) - Optional. Whether to set parent nodes. ### Returns - **CompilerHost** - The created CompilerHost instance. ``` -------------------------------- ### Token API - getStart Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/PunctuationToken.md Gets the starting position of the token. ```APIDOC ## GET /tokens/start ### Description Gets the starting position of the token within its source file. This method is inherited from the Token class. ### Method GET ### Endpoint /tokens/start ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file context. - **includeJsDocComment** (boolean) - Optional - Whether to include the JSDoc comment in the start position calculation. ### Response #### Success Response (200) - **start** (number) - The starting position of the token. #### Response Example ```json { "start": 12 } ``` ``` -------------------------------- ### createProgram (Overload 2) Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/functions/createProgram.md Creates a new 'Program' instance from root file names, compiler options, and optional host, old program, and configuration file parsing diagnostics. ```APIDOC ## Function: createProgram() ### Description Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions' that represent a compilation unit. Creating a program proceeds from a set of root files, expanding the set of inputs by following imports and triple-slash-reference-path directives transitively. '@types' and triple-slash-reference-types are also pulled in. ### Method POST (or equivalent for function call) ### Endpoint /gowaylee/arkanalyzer/createProgram ### Parameters #### Request Body - **rootNames** (string[]) - Required - A set of root files. - **options** (CompilerOptions) - Required - The compiler options which should be used. - **host** (CompilerHost) - Optional - The host interacts with the underlying file system. - **oldProgram** (Program) - Optional - Reuses an old program structure. - **configFileParsingDiagnostics** (Diagnostic[]) - Optional - error during config file parsing ### Request Example ```json { "rootNames": ["file1.ts", "file2.ts"], "options": { ... }, "host": { ... }, "oldProgram": { ... }, "configFileParsingDiagnostics": [ ... ] } ``` ### Response #### Success Response (200) - **Program** (Program) - A 'Program' object. #### Response Example ```json { "program": { ... } } ``` ``` -------------------------------- ### Token API - getFullStart Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/PunctuationToken.md Gets the full starting position of the token. ```APIDOC ## GET /tokens/full-start ### Description Gets the full starting position of the token. This method is inherited from the Token class. ### Method GET ### Endpoint /tokens/full-start ### Response #### Success Response (200) - **start** (number) - The full starting position of the token. #### Response Example ```json { "start": 10 } ``` ``` -------------------------------- ### Install Project Dependencies with npm Source: https://github.com/gowaylee/arkanalyzer/blob/master/README.md Installs all the necessary dependencies for the project using npm. This command should be run in the project's root directory. ```shell npm install ``` -------------------------------- ### createWatchProgram (for files and compiler options) Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/functions/createWatchProgram.md This function creates a watch program from a host, specifically for handling root files and compiler options. It is generic and can work with different types of BuilderProgram. ```APIDOC ## createWatchProgram /api/watch/files ### Description Creates the watch from the host for root files and compiler options. ### Method POST ### Endpoint /api/watch/files ### Parameters #### Request Body - **host** (WatchCompilerHostOfFilesAndCompilerOptions) - Required - The host object containing watch configuration for files and compiler options. ### Request Example ```json { "host": { ... } } ``` ### Response #### Success Response (200) - **WatchOfFilesAndCompilerOptions** (object) - An object representing the watch configuration for files and compiler options. #### Response Example ```json { "watchConfig": { ... } } ``` ``` -------------------------------- ### getStart Method Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/NullLiteral.md Gets the start position of the node. ```APIDOC ## getStart Method ### Description Returns the character position where the node begins, optionally including JSDoc comments. ### Method `getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number` ### Endpoint N/A (Method of a TypeScript AST node) ### Parameters - **sourceFile?** ([`SourceFile`](SourceFile.md)) - Optional - The source file context. - **includeJsDocComment?** (boolean) - Optional - Whether to include JSDoc comments in the start position. ### Returns - `number` - The start position of the node. ### Inherited from [`PrimaryExpression`](PrimaryExpression.md).[`getStart`](PrimaryExpression.md#getstart) ### Defined in `node_modules/ohos-typescript/lib/typescript.d.ts:6092 ``` -------------------------------- ### Get Type Method - TypeScript with Example Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/classes/ArkAwaitExpr.md Returns the type of the ArkAwaitExpr. This method overrides the getType from AbstractExpr and includes an example demonstrating its usage in determining types of values in a declaration statement. ```typescript getType(): Type // Example: let leftValue: Value; let rightValue: Value; ... if (leftValue.getType() instanceof UnknownType && !(rightValue.getType() instanceof UnknownType) && !(rightValue.getType() instanceof UndefinedType)) { ... } ``` -------------------------------- ### SolutionBuilderHost Interface Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/SolutionBuilderHost.md Documentation for the SolutionBuilderHost interface, which extends SolutionBuilderHostBase and defines methods for program creation, diagnostics reporting, and file system operations. ```APIDOC ## Interface: SolutionBuilderHost Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5951 ### Description Represents the host for a solution builder, providing capabilities for program creation, diagnostics reporting, and file system interactions. ### Type Parameters * **T** * Constraint: `T` extends `BuilderProgram` * Description: The type of the program being built. ### Properties * **createProgram** (`CreateProgram`) - Required * Description: Used to create the program when a need for program creation or recreation is detected. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5812 * Inherited from: `SolutionBuilderHostBase` * **reportDiagnostic** (`DiagnosticReporter`) - Required * Description: A function to report diagnostic messages. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5947 * Inherited from: `SolutionBuilderHostBase` * **reportErrorSummary**? (`ReportEmitErrorSummary`) - Optional * Description: An optional function to report a summary of emit errors. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5952 * **reportSolutionBuilderStatus** (`DiagnosticReporter`) - Required * Description: A function to report the status of the solution builder. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5948 * Inherited from: `SolutionBuilderHostBase` ### Methods * **afterProgramEmitAndDiagnostics?** (`program: T`) => `void` - Optional * Description: A hook called after program emit and diagnostics are complete. * Parameters: * `program` (`T`) - The program that was emitted. * Returns: `void` * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5949 * Inherited from: `SolutionBuilderHostBase` * **createDirectory?** (`path: string`) => `void` - Optional * Description: Creates a directory at the specified path. * Parameters: * `path` (`string`) - The path of the directory to create. * Returns: `void` * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5936 * Inherited from: `SolutionBuilderHostBase` * **createHash?** (`data: string`) => `string` - Optional * Description: Creates a hash for the given data. * Parameters: * `data` (`string`) - The data to hash. * Returns: `string` - The generated hash. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5818 * Inherited from: `SolutionBuilderHostBase` * **deleteFile** (`fileName: string`) => `void` - Required * Description: Deletes the file at the specified path. * Parameters: * `fileName` (`string`) - The path of the file to delete. * Returns: `void` * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5945 * Inherited from: `SolutionBuilderHostBase` * **directoryExists?** (`path: string`) => `boolean` - Optional * Description: Checks if a directory exists at the specified path. If provided, used for module resolution as well as to handle directory structure. * Parameters: * `path` (`string`) - The path of the directory to check. * Returns: `boolean` - True if the directory exists, false otherwise. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5830 * Inherited from: `SolutionBuilderHostBase` * **fileExists** (`path: string`) => `boolean` - Required * Description: Checks if a file exists at the specified path. Use to check file presence for source files and if resolveModuleNames is not provided (compiler is in charge of module resolution) then module files as well. * Parameters: * `path` (`string`) - The path of the file to check. * Returns: `boolean` - True if the file exists, false otherwise. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5823 * Inherited from: `SolutionBuilderHostBase` * **getCurrentDirectory**() => `string` - Required * Description: Gets the current working directory. * Returns: `string` - The current directory path. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5815 * Inherited from: `SolutionBuilderHostBase` * **getCustomTransformers?** (`project: string`) => `undefined` | `CustomTransformers` - Optional * Description: Gets custom transformers for the program. * Parameters: * `project` (`string`) - The project name. * Returns: `undefined` | `CustomTransformers` - The custom transformers or undefined if none are provided. * Defined in: node_modules/ohos-typescript/lib/typescript.d.ts:5942 * Inherited from: `SolutionBuilderHostBase` ``` -------------------------------- ### Get Node Start Position - TypeScript Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/NonNullExpression.md Returns the character position marking the start of the node's text in the source file, optionally including JSDoc comments. This is a zero-based index. ```typescript getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; ``` -------------------------------- ### getFullStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/TemplateTail.md Gets the full start position of the node, including leading trivia. ```APIDOC ## getFullStart() ### Description Gets the full start position of the node, including any leading trivia (like whitespace or comments). ### Method N/A (Method of a class) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript node.getFullStart(); ``` ### Response #### Success Response (200) Returns a `number` representing the full start position. #### Response Example ```json 100 ``` ``` -------------------------------- ### ArkPtrInvokeExpr Constructor Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/classes/ArkPtrInvokeExpr.md Initializes a new instance of ArkPtrInvokeExpr. ```APIDOC ## new ArkPtrInvokeExpr ### Description Constructs a new ArkPtrInvokeExpr. ### Method CONSTRUCTOR ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```typescript new ArkPtrInvokeExpr(methodSignature, ptr, args, realGenericTypes?) ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### getFullStart Method Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/NullLiteral.md Gets the full start position of the node. ```APIDOC ## getFullStart Method ### Description Returns the character position where the node begins, including any preceding trivia (like comments or whitespace). ### Method `getFullStart(): number` ### Endpoint N/A (Method of a TypeScript AST node) ### Parameters N/A ### Returns - `number` - The full start position of the node. ### Inherited from [`PrimaryExpression`](PrimaryExpression.md).[`getFullStart`](PrimaryExpression.md#getfullstart) ### Defined in `node_modules/ohos-typescript/lib/typescript.d.ts:6093 ``` -------------------------------- ### ArkFile Constructor Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/classes/ArkFile.md Initializes a new instance of the ArkFile class. ```APIDOC ## new ArkFile() ### Description Initializes a new instance of the ArkFile class. ### Method Constructor ### Parameters #### Path Parameters - **language** (Language) - Required - The language of the file. ### Response #### Success Response (200) - **instance** (ArkFile) - A new instance of ArkFile. #### Response Example ```json { "instance": "ArkFile" } ``` ``` -------------------------------- ### getStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/Node.md Gets the start position of the node, optionally including JSDoc comments. ```APIDOC ## getStart() ### Description Gets the starting position (index) of the node. Optionally, JSDoc comments preceding the node can be included in the start position calculation. ### Method GET (Implied, as it's a getter method) ### Endpoint Not applicable (this is a method within a Node object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript // Assuming 'node' is an instance of Node const startPosition = node.getStart(); // To include JSDoc comments: // const startPositionWithJsDoc = node.getStart(sourceFile, true); ``` ### Response #### Success Response (200) - **startPosition** (number) - The zero-based index representing the start of the node. #### Response Example ```json { "startPosition": 10 } ``` ``` -------------------------------- ### Install ArkAnalyzer Dependencies Source: https://github.com/gowaylee/arkanalyzer/blob/master/README.en.md Installs the necessary dependency libraries for the ArkAnalyzer project using npm. This command should be run after navigating into the 'arkanalyzer' directory. ```shell cd arkanalyzer npm install ``` -------------------------------- ### getFullStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/Node.md Gets the full start position of the node, including preceding trivia. ```APIDOC ## getFullStart() ### Description Gets the starting position of the node, including any leading trivia (like whitespace or comments). ### Method GET (Implied, as it's a getter method) ### Endpoint Not applicable (this is a method within a Node object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript // Assuming 'node' is an instance of Node const fullStartPosition = node.getFullStart(); ``` ### Response #### Success Response (200) - **fullStartPosition** (number) - The zero-based index representing the start of the node, including leading trivia. #### Response Example ```json { "fullStartPosition": 0 } ``` ``` -------------------------------- ### Node getStart() Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/Bundle.md Retrieves the start position of the node. Inherited from Node. ```APIDOC ## GET /node/getStart ### Description Retrieves the start position of the node. ### Method GET ### Endpoint /node/getStart ### Parameters #### Query Parameters - **sourceFile** (SourceFile) - Optional - The source file to consider. - **includeJsDocComment** (boolean) - Optional - Whether to include the JSDoc comment in the start position. ### Response #### Success Response (200) - **startPosition** (number) - The start position of the node. #### Response Example ```json { "startPosition": 110 } ``` ``` -------------------------------- ### getFullStart() Method Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/interfaces/InterfaceDeclaration.md Gets the full start position of the node, including leading trivia. ```APIDOC ## GET /getFullStart ### Description Gets the full start position of the node, including any leading trivia. ### Method GET ### Endpoint /getFullStart ### Response #### Success Response (200) - **fullStartPosition** (number) - The full start position of the node. #### Response Example ```json { "fullStartPosition": 0 } ``` ``` -------------------------------- ### InstallPackageRequest Interface Source: https://github.com/gowaylee/arkanalyzer/blob/master/docs/api_docs/ArkAnalyzer/namespaces/ts/namespaces/server/interfaces/InstallPackageRequest.md This interface defines the structure for requests to install packages. It includes properties for the package name, project details, and the file being processed. ```APIDOC ## InstallPackageRequest Interface ### Description Represents a request to install a package. This interface extends `TypingInstallerRequestWithProjectName` and adds specific details for package installation. ### Properties #### fileName - **fileName** (Path) - Readonly - The path to the file associated with the installation request. #### kind - **kind** (string) - Readonly - The type of request, fixed to "installPackage". #### packageName - **packageName** (string) - Readonly - The name of the package to be installed. #### projectName - **projectName** (string) - Readonly - The name of the project where the package installation is occurring. Inherited from `TypingInstallerRequestWithProjectName`. #### projectRootPath - **projectRootPath** (Path) - Readonly - The root path of the project. ### Example ```json { "kind": "installPackage", "fileName": "/path/to/file.ts", "packageName": "example-package", "projectName": "my-project", "projectRootPath": "/path/to/project" } ``` ```