@@ -4,24 +4,24 @@ A handful of APIs are available to make patch development easier and more effici
44
55## 📙 Overview
66
7- 1 . 👹 Create mutable replacements of classes with ` BytecodePatchContext.classDefs[ classDef] `
7+ 1 . 👹 Create mutable replacements of classes with ` BytecodePatchContext.classDefs.getOrReplaceMutable( classDef) `
882 . 🏃 Navigate method calls recursively by index with ` navigate(Method) `
993 . 💾 Read and write resource files with ` get(String, Boolean) ` and ` delete(String) `
10104 . 📃 Read and write DOM files using ` document(String) ` and ` document(InputStream) `
1111
1212### 🧰 APIs
1313
14- #### 👹 ` BytecodePatchContext.classDefs[ classDef] `
14+ #### 👹 ` BytecodePatchContext.classDefs.getOrReplaceMutable( classDef) `
1515
1616By default, the classes are immutable, meaning they cannot be modified.
17- To make a class mutable, use the ` BytecodePatchContext.classDefs[ classDef] ` function.
17+ To make a class mutable, use the ` BytecodePatchContext.classDefs.getOrReplaceMutable( classDef) ` function.
1818This function creates a lazy mutable copy of the class definition.
1919Accessing the property will replace the original class definition with the mutable copy,
2020thus allowing you to make changes to the class. Subsequent accesses will return the same mutable copy.
2121
2222``` kt
23- execute {
24- val mutableClass = proxy (classDef)
23+ apply {
24+ val mutableClass = classDefs.getOrReplaceMutable (classDef)
2525 mutableClass.methods.add(Method ())
2626}
2727```
@@ -31,7 +31,7 @@ execute {
3131The ` navigate(Method) ` function allows you to navigate method calls recursively by index.
3232
3333``` kt
34- execute {
34+ apply {
3535 // Sequentially navigate to the instructions at index 1 within 'someMethod'.
3636 val method = navigate(someMethod).to(1 ).original() // original() returns the original immutable method.
3737
@@ -52,7 +52,7 @@ execute {
5252The ` get(String, Boolean) ` function returns a ` File ` object that can be used to read and write resource files.
5353
5454``` kt
55- execute {
55+ apply {
5656 val file = get(" res/values/strings.xml" )
5757 val content = file.readText()
5858 file.writeText(content)
@@ -62,7 +62,7 @@ execute {
6262The ` delete ` function can mark files for deletion when the APK is rebuilt.
6363
6464``` kt
65- execute {
65+ apply {
6666 delete(" res/values/strings.xml" )
6767}
6868```
@@ -72,7 +72,7 @@ execute {
7272The ` document ` function is used to read and write DOM files.
7373
7474``` kt
75- execute {
75+ apply {
7676 document(" res/values/strings.xml" ).use { document ->
7777 val element = doc.createElement(" string" ).apply {
7878 textContent = " Hello, World!"
@@ -85,7 +85,7 @@ execute {
8585You can also read documents from an ` InputStream ` :
8686
8787``` kt
88- execute {
88+ apply {
8989 val inputStream = classLoader.getResourceAsStream(" some.xml" )
9090 document(inputStream).use { document ->
9191 // ...
0 commit comments