feat: add overload to get instruction as type

This commit is contained in:
oSumAtrIX 2023-05-05 23:36:30 +02:00
parent d83e9372bb
commit 49c173dc14
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
2 changed files with 11 additions and 3 deletions

View file

@ -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.

View file

@ -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)
}