mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-06-13 05:37:38 +02:00
feat: add overload to get instruction as type
This commit is contained in:
@ -101,12 +101,20 @@ fun MutableMethod.removeInstruction(index: Int) = this.implementation!!.removeIn
|
||||
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.
|
||||
* @return The instruction.
|
||||
*/
|
||||
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.
|
||||
* @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)
|
||||
}
|
||||
|
||||
@ -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")
|
||||
assertEquals(labelIndex, insn.target.location.index)
|
||||
}
|
||||
|
Reference in New Issue
Block a user