mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-14 18:37:06 +02:00
refactor!: use proper extension function names
BREAKING CHANGE: This changes the names of extension functions
This commit is contained in:
parent
eafe1c631f
commit
efdd01a988
@ -5,10 +5,11 @@ import org.jf.dexlib2.AccessFlags
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a label for the instruction at given index.
|
* Create a label for the instruction at given index.
|
||||||
|
*
|
||||||
* @param index The index to create the label for the instruction at.
|
* @param index The index to create the label for the instruction at.
|
||||||
* @return The label.
|
* @return The label.
|
||||||
*/
|
*/
|
||||||
fun MutableMethod.label(index: Int) = implementation!!.newLabelForIndex(index)
|
fun MutableMethod.newLabel(index: Int) = implementation!!.newLabelForIndex(index)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a bitwise OR operation between two [AccessFlags].
|
* Perform a bitwise OR operation between two [AccessFlags].
|
||||||
|
@ -290,15 +290,13 @@ object InstructionExtensions {
|
|||||||
fun MutableMethod.replaceInstructions(index: Int, smaliInstructions: String) =
|
fun MutableMethod.replaceInstructions(index: Int, smaliInstructions: String) =
|
||||||
implementation!!.replaceInstructions(index, smaliInstructions.toInstructions(this))
|
implementation!!.replaceInstructions(index, smaliInstructions.toInstructions(this))
|
||||||
|
|
||||||
// TODO: Use proper names for functions below.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instruction at the given index.
|
* Get an instruction at the given index.
|
||||||
*
|
*
|
||||||
* @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 MutableMethodImplementation.instruction(index: Int): BuilderInstruction = instructions[index]
|
fun MutableMethodImplementation.getInstruction(index: Int): BuilderInstruction = instructions[index]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instruction at the given index.
|
* Get an instruction at the given index.
|
||||||
@ -308,14 +306,14 @@ object InstructionExtensions {
|
|||||||
* @return The instruction.
|
* @return The instruction.
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun <T> MutableMethodImplementation.instruction(index: Int): T = instruction(index) as T
|
fun <T> MutableMethodImplementation.getInstruction(index: Int): T = getInstruction(index) as T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instruction at the given index.
|
* Get an instruction at the given index.
|
||||||
* @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 = implementation!!.instruction(index)
|
fun MutableMethod.getInstruction(index: Int): BuilderInstruction = implementation!!.getInstruction(index)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instruction at the given index.
|
* Get an instruction at the given index.
|
||||||
@ -324,5 +322,5 @@ object InstructionExtensions {
|
|||||||
* @return The instruction.
|
* @return The instruction.
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun <T> MutableMethod.instruction(index: Int): T = implementation!!.instruction<T>(index)
|
fun <T> MutableMethod.getInstruction(index: Int): T = implementation!!.getInstruction<T>(index)
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package app.revanced.patcher.util.smali
|
package app.revanced.patcher.util.smali
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.InstructionExtensions.addInstructionsWithLabels
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.InstructionExtensions.instruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.extensions.label
|
import app.revanced.patcher.extensions.newLabel
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
||||||
@ -45,7 +45,7 @@ internal class InlineSmaliCompilerTest {
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
val insn = method.instruction<BuilderInstruction21t>(insnIndex)
|
val insn = method.getInstruction<BuilderInstruction21t>(insnIndex)
|
||||||
assertEquals(targetIndex, insn.target.location.index)
|
assertEquals(targetIndex, insn.target.location.index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ internal class InlineSmaliCompilerTest {
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(labelIndex, method.label(labelIndex).location.index)
|
assertEquals(labelIndex, method.newLabel(labelIndex).location.index)
|
||||||
|
|
||||||
method.addInstructionsWithLabels(
|
method.addInstructionsWithLabels(
|
||||||
method.implementation!!.instructions.size,
|
method.implementation!!.instructions.size,
|
||||||
@ -71,10 +71,10 @@ internal class InlineSmaliCompilerTest {
|
|||||||
if-eqz v0, :test
|
if-eqz v0, :test
|
||||||
return-void
|
return-void
|
||||||
""",
|
""",
|
||||||
ExternalLabel("test", method.instruction(1))
|
ExternalLabel("test", method.getInstruction(1))
|
||||||
)
|
)
|
||||||
|
|
||||||
val insn = method.instruction<BuilderInstruction21t>(insnIndex)
|
val insn = method.getInstruction<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…
x
Reference in New Issue
Block a user