mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-13 02:14:27 +01:00
feat: add overload to get instruction as type
This commit is contained in:
parent
d83e9372bb
commit
49c173dc14
2 changed files with 11 additions and 3 deletions
|
@ -101,12 +101,20 @@ fun MutableMethod.removeInstruction(index: Int) = this.implementation!!.removeIn
|
||||||
fun MutableMethod.label(index: Int) = this.implementation!!.newLabelForIndex(index)
|
fun MutableMethod.label(index: Int) = this.implementation!!.newLabelForIndex(index)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the instruction at the given index in the method's implementation.
|
* Get an instruction at the given index in the method's implementation.
|
||||||
* @param index The index to get the instruction at.
|
* @param index The index to get the instruction at.
|
||||||
* @return The instruction.
|
* @return The instruction.
|
||||||
*/
|
*/
|
||||||
fun MutableMethod.instruction(index: Int): BuilderInstruction = this.implementation!!.instructions[index]
|
fun MutableMethod.instruction(index: Int): BuilderInstruction = this.implementation!!.instructions[index]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an instruction at the given index in the method's implementation.
|
||||||
|
* @param index The index to get the instruction at.
|
||||||
|
* @param T The type of instruction to return.
|
||||||
|
* @return The instruction.
|
||||||
|
*/
|
||||||
|
fun <T> MutableMethod.instruction(index: Int): T = instruction(index) as T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add smali instructions to the method.
|
* Add smali instructions to the method.
|
||||||
* @param index The index to insert the instructions at.
|
* @param index The index to insert the instructions at.
|
||||||
|
|
|
@ -44,7 +44,7 @@ internal class InlineSmaliCompilerTest {
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
val insn = method.instruction(insnIndex) as BuilderInstruction21t
|
val insn = method.instruction<BuilderInstruction21t>(insnIndex)
|
||||||
assertEquals(targetIndex, insn.target.location.index)
|
assertEquals(targetIndex, insn.target.location.index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ internal class InlineSmaliCompilerTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val insn = method.instruction(insnIndex) as BuilderInstruction21t
|
val insn = method.instruction<BuilderInstruction21t>(insnIndex)
|
||||||
assertTrue(insn.target.isPlaced, "Label was not placed")
|
assertTrue(insn.target.isPlaced, "Label was not placed")
|
||||||
assertEquals(labelIndex, insn.target.location.index)
|
assertEquals(labelIndex, insn.target.location.index)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue