forked from SMAT-Lab/ArkAnalyzer-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { SceneConfig, Scene, ArkFile, ArkNamespace, ArkClass, ArkField, ArkMethod, Cfg } from "./bundle"; | ||
|
||
const config_path = "./target_project/project_config.json"; | ||
let config: SceneConfig = new SceneConfig(); | ||
config.buildFromJson(config_path); | ||
|
||
let scene: Scene = new Scene(config); | ||
|
||
//ex01.1:获取所有文件 | ||
let files: ArkFile[] = scene.getFiles(); | ||
let fileNames: string[] = files.map(file => file.name); | ||
console.log(fileNames); | ||
|
||
//ex01.2:获取命名空间 | ||
let namespaces: ArkNamespace[] = scene.getAllNamespacesUnderTargetProject(); | ||
let namespaceNames: string[] = namespaces.map(ns => ns.name); | ||
console.log(namespaceNames); | ||
|
||
let namespaces2: ArkNamespace[] = files[1].getNamespaces(); | ||
let namespaceNames2: string[] = namespaces2.map(ns => ns.name); | ||
console.log(namespaceNames2); | ||
|
||
//ex01.3:获取所有类 | ||
let classes: ArkClass[] = scene.getAllClassesUnderTargetProject(); | ||
let classNames: string[] = classes.map(cls => cls.name); | ||
console.log(classNames); | ||
|
||
let classes2: ArkClass[] = files[2].getClasses(); | ||
let classNames2: string[] = classes2.map(cls => cls.name); | ||
console.log(classNames2); | ||
|
||
let classes3: ArkClass[] = namespaces[0].getClasses(); | ||
let classNames3: string[] = classes3.map(cls => cls.name); | ||
console.log(classNames3); | ||
|
||
//ex01.4:获取所有属性 | ||
let bookClass: ArkClass = classes[3]; | ||
let fields: ArkField[] = bookClass.getFields(); | ||
let fieldNames: string[] = fields.map(fld => fld.name); | ||
console.log(fieldNames); | ||
|
||
//ex01.5:获取所有方法 | ||
let serviceClass: ArkClass = classes[5]; | ||
let methods: ArkMethod[] = serviceClass.getMethods(); | ||
let methodNames: string[] = methods.map(mthd => mthd.name); | ||
console.log(methodNames); | ||
|
||
let methods1: ArkMethod[] = scene.getAllMethodsUnderTargetProject(); | ||
let methods2: ArkMethod[] = files[2].getAllMethodsUnderThisFile(); | ||
|
||
let methodNames1: string[] = methods1.map(mthd => mthd.name); | ||
let methodNames2: string[] = methods2.map(mthd => mthd.name); | ||
|
||
console.log(methodNames1); | ||
console.log(methodNames2); | ||
|
||
//ex01.6:获取方法CFG | ||
let addBookMethod: ArkMethod = methods[0]; | ||
let addBookCfg: Cfg = addBookMethod.getBody().getCfg(); | ||
|
||
//ex01.7:三地址码打印并观察语法糖变化 | ||
|
||
|
||
|
||
console.log("finish") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"targetProjectName": "target_project", | ||
"targetProjectDirectory": "target_project", | ||
|
||
"logPath": "out\\log.txt", | ||
"ohosSdkPath": "", | ||
"kitSdkPath": "", | ||
"systemSdkPath": "", | ||
"otherSdks": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export namespace Library { | ||
export class Book { | ||
public title: string; | ||
public author: string; | ||
constructor(title: string,author: string) { | ||
this.title = title; | ||
this.author = author; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/1_basic_usage/target_project/src/services/bookService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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; | ||
} | ||
} |