From efdd01a9886b6f06af213731824621964367b2a3 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 7 Jun 2023 03:35:01 +0200 Subject: [PATCH] refactor!: use proper extension function names BREAKING CHANGE: This changes the names of extension functions --- .../revanced/patcher/extensions/Extensions.kt | 3 ++- .../patcher/extensions/InstructionExtensions.kt | 10 ++++------ .../util/smali/InlineSmaliCompilerTest.kt | 16 ++++++++-------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt index 211670e7..a3ef1a15 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt @@ -5,10 +5,11 @@ import org.jf.dexlib2.AccessFlags /** * Create a label for the instruction at given index. + * * @param index The index to create the label for the instruction at. * @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]. diff --git a/src/main/kotlin/app/revanced/patcher/extensions/InstructionExtensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/InstructionExtensions.kt index f1834d3e..72d14104 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/InstructionExtensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/InstructionExtensions.kt @@ -290,15 +290,13 @@ object InstructionExtensions { fun MutableMethod.replaceInstructions(index: Int, smaliInstructions: String) = implementation!!.replaceInstructions(index, smaliInstructions.toInstructions(this)) -// TODO: Use proper names for functions below. - /** * Get an instruction at the given index. * * @param index The index to get the instruction at. * @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. @@ -308,14 +306,14 @@ object InstructionExtensions { * @return The instruction. */ @Suppress("UNCHECKED_CAST") - fun MutableMethodImplementation.instruction(index: Int): T = instruction(index) as T + fun MutableMethodImplementation.getInstruction(index: Int): T = getInstruction(index) as T /** * Get an instruction at the given index. * @param index The index to get the instruction at. * @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. @@ -324,5 +322,5 @@ object InstructionExtensions { * @return The instruction. */ @Suppress("UNCHECKED_CAST") - fun MutableMethod.instruction(index: Int): T = implementation!!.instruction(index) + fun MutableMethod.getInstruction(index: Int): T = implementation!!.getInstruction(index) } \ No newline at end of file diff --git a/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt b/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt index 137d23f7..ddd14ffb 100644 --- a/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt +++ b/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt @@ -1,9 +1,9 @@ package app.revanced.patcher.util.smali -import app.revanced.patcher.extensions.InstructionExtensions.InstructionExtensions.addInstructions -import app.revanced.patcher.extensions.InstructionExtensions.InstructionExtensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.InstructionExtensions.InstructionExtensions.instruction -import app.revanced.patcher.extensions.label +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.newLabel import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode @@ -45,7 +45,7 @@ internal class InlineSmaliCompilerTest { """ ) - val insn = method.instruction(insnIndex) + val insn = method.getInstruction(insnIndex) 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.implementation!!.instructions.size, @@ -71,10 +71,10 @@ internal class InlineSmaliCompilerTest { if-eqz v0, :test return-void """, - ExternalLabel("test", method.instruction(1)) + ExternalLabel("test", method.getInstruction(1)) ) - val insn = method.instruction(insnIndex) + val insn = method.getInstruction(insnIndex) assertTrue(insn.target.isPlaced, "Label was not placed") assertEquals(labelIndex, insn.target.location.index) }