Skip to content

Commit

Permalink
refactor!: use proper extension function names
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This changes the names of extension functions
  • Loading branch information
oSumAtrIX committed Jun 7, 2023
1 parent eafe1c6 commit efdd01a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -308,14 +306,14 @@ object InstructionExtensions {
* @return The instruction.
*/
@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.
* @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.
Expand All @@ -324,5 +322,5 @@ object InstructionExtensions {
* @return The instruction.
*/
@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)
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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,
Expand All @@ -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<BuilderInstruction21t>(insnIndex)
val insn = method.getInstruction<BuilderInstruction21t>(insnIndex)
assertTrue(insn.target.isPlaced, "Label was not placed")
assertEquals(labelIndex, insn.target.location.index)
}
Expand Down

4 comments on commit efdd01a

@LisoUseInAIKyrios
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file needs updating. It's failing to compile:

InstructionExtensionsTest.kt:37:9 Unresolved reference: addInstructions

@oSumAtrIX
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that is odd, compilation worked for me, I locally ran all patches for YouTube on this revision.

@LisoUseInAIKyrios
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try compiling using command line:
gradlew build

@oSumAtrIX
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not home until late, if you can, you can open a PR with a fix

Please sign in to comment.