refactor: Convert method bodies to single expression functions

This commit is contained in:
oSumAtrIX 2024-07-26 03:09:03 +02:00
parent d21128fe2e
commit b41a542952
24 changed files with 125 additions and 255 deletions

View file

@ -9,21 +9,13 @@ class MutableAnnotation(annotation: Annotation) : BaseAnnotation() {
private val type = annotation.type
private val _elements by lazy { annotation.elements.map { element -> element.toMutable() }.toMutableSet() }
override fun getType(): String {
return type
}
override fun getType(): String = type
override fun getElements(): MutableSet<MutableAnnotationElement> {
return _elements
}
override fun getElements(): MutableSet<MutableAnnotationElement> = _elements
override fun getVisibility(): Int {
return visibility
}
override fun getVisibility(): Int = visibility
companion object {
fun Annotation.toMutable(): MutableAnnotation {
return MutableAnnotation(this)
}
fun Annotation.toMutable(): MutableAnnotation = MutableAnnotation(this)
}
}

View file

@ -18,17 +18,11 @@ class MutableAnnotationElement(annotationElement: AnnotationElement) : BaseAnnot
this.value = value
}
override fun getName(): String {
return name
}
override fun getName(): String = name
override fun getValue(): EncodedValue {
return value
}
override fun getValue(): EncodedValue = value
companion object {
fun AnnotationElement.toMutable(): MutableAnnotationElement {
return MutableAnnotationElement(this)
}
fun AnnotationElement.toMutable(): MutableAnnotationElement = MutableAnnotationElement(this)
}
}

View file

@ -8,7 +8,9 @@ import com.android.tools.smali.dexlib2.iface.ClassDef
import com.android.tools.smali.dexlib2.util.FieldUtil
import com.android.tools.smali.dexlib2.util.MethodUtil
class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
class MutableClass(classDef: ClassDef) :
BaseTypeReference(),
ClassDef {
// Class
private var type = classDef.type
private var sourceFile = classDef.sourceFile
@ -46,57 +48,31 @@ class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
this.superclass = superclass
}
override fun getType(): String {
return type
}
override fun getType(): String = type
override fun getAccessFlags(): Int {
return accessFlags
}
override fun getAccessFlags(): Int = accessFlags
override fun getSourceFile(): String? {
return sourceFile
}
override fun getSourceFile(): String? = sourceFile
override fun getSuperclass(): String? {
return superclass
}
override fun getSuperclass(): String? = superclass
override fun getInterfaces(): MutableList<String> {
return _interfaces
}
override fun getInterfaces(): MutableList<String> = _interfaces
override fun getAnnotations(): MutableSet<MutableAnnotation> {
return _annotations
}
override fun getAnnotations(): MutableSet<MutableAnnotation> = _annotations
override fun getStaticFields(): MutableSet<MutableField> {
return _staticFields
}
override fun getStaticFields(): MutableSet<MutableField> = _staticFields
override fun getInstanceFields(): MutableSet<MutableField> {
return _instanceFields
}
override fun getInstanceFields(): MutableSet<MutableField> = _instanceFields
override fun getFields(): MutableSet<MutableField> {
return _fields
}
override fun getFields(): MutableSet<MutableField> = _fields
override fun getDirectMethods(): MutableSet<MutableMethod> {
return _directMethods
}
override fun getDirectMethods(): MutableSet<MutableMethod> = _directMethods
override fun getVirtualMethods(): MutableSet<MutableMethod> {
return _virtualMethods
}
override fun getVirtualMethods(): MutableSet<MutableMethod> = _virtualMethods
override fun getMethods(): MutableSet<MutableMethod> {
return _methods
}
override fun getMethods(): MutableSet<MutableMethod> = _methods
companion object {
fun ClassDef.toMutable(): MutableClass {
return MutableClass(this)
}
fun ClassDef.toMutable(): MutableClass = MutableClass(this)
}
}

View file

@ -7,7 +7,9 @@ import com.android.tools.smali.dexlib2.HiddenApiRestriction
import com.android.tools.smali.dexlib2.base.reference.BaseFieldReference
import com.android.tools.smali.dexlib2.iface.Field
class MutableField(field: Field) : Field, BaseFieldReference() {
class MutableField(field: Field) :
BaseFieldReference(),
Field {
private var definingClass = field.definingClass
private var name = field.name
private var type = field.type
@ -37,37 +39,21 @@ class MutableField(field: Field) : Field, BaseFieldReference() {
this.initialValue = initialValue
}
override fun getDefiningClass(): String {
return this.definingClass
}
override fun getDefiningClass(): String = this.definingClass
override fun getName(): String {
return this.name
}
override fun getName(): String = this.name
override fun getType(): String {
return this.type
}
override fun getType(): String = this.type
override fun getAnnotations(): MutableSet<MutableAnnotation> {
return this._annotations
}
override fun getAnnotations(): MutableSet<MutableAnnotation> = this._annotations
override fun getAccessFlags(): Int {
return this.accessFlags
}
override fun getAccessFlags(): Int = this.accessFlags
override fun getHiddenApiRestrictions(): MutableSet<HiddenApiRestriction> {
return this._hiddenApiRestrictions
}
override fun getHiddenApiRestrictions(): MutableSet<HiddenApiRestriction> = this._hiddenApiRestrictions
override fun getInitialValue(): MutableEncodedValue? {
return this.initialValue
}
override fun getInitialValue(): MutableEncodedValue? = this.initialValue
companion object {
fun Field.toMutable(): MutableField {
return MutableField(this)
}
fun Field.toMutable(): MutableField = MutableField(this)
}
}

View file

@ -7,7 +7,9 @@ import com.android.tools.smali.dexlib2.base.reference.BaseMethodReference
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
import com.android.tools.smali.dexlib2.iface.Method
class MutableMethod(method: Method) : Method, BaseMethodReference() {
class MutableMethod(method: Method) :
BaseMethodReference(),
Method {
private var definingClass = method.definingClass
private var name = method.name
private var accessFlags = method.accessFlags
@ -36,45 +38,25 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() {
this.returnType = returnType
}
override fun getDefiningClass(): String {
return definingClass
}
override fun getDefiningClass(): String = definingClass
override fun getName(): String {
return name
}
override fun getName(): String = name
override fun getParameterTypes(): MutableList<CharSequence> {
return _parameterTypes
}
override fun getParameterTypes(): MutableList<CharSequence> = _parameterTypes
override fun getReturnType(): String {
return returnType
}
override fun getReturnType(): String = returnType
override fun getAnnotations(): MutableSet<MutableAnnotation> {
return _annotations
}
override fun getAnnotations(): MutableSet<MutableAnnotation> = _annotations
override fun getAccessFlags(): Int {
return accessFlags
}
override fun getAccessFlags(): Int = accessFlags
override fun getHiddenApiRestrictions(): MutableSet<HiddenApiRestriction> {
return _hiddenApiRestrictions
}
override fun getHiddenApiRestrictions(): MutableSet<HiddenApiRestriction> = _hiddenApiRestrictions
override fun getParameters(): MutableList<MutableMethodParameter> {
return _parameters
}
override fun getParameters(): MutableList<MutableMethodParameter> = _parameters
override fun getImplementation(): MutableMethodImplementation? {
return _implementation
}
override fun getImplementation(): MutableMethodImplementation? = _implementation
companion object {
fun Method.toMutable(): MutableMethod {
return MutableMethod(this)
}
fun Method.toMutable(): MutableMethod = MutableMethod(this)
}
}

View file

@ -5,7 +5,9 @@ import com.android.tools.smali.dexlib2.base.BaseMethodParameter
import com.android.tools.smali.dexlib2.iface.MethodParameter
// TODO: finish overriding all members if necessary
class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, BaseMethodParameter() {
class MutableMethodParameter(parameter: MethodParameter) :
BaseMethodParameter(),
MethodParameter {
private var type = parameter.type
private var name = parameter.name
private var signature = parameter.signature
@ -13,25 +15,15 @@ class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, Base
parameter.annotations.map { annotation -> annotation.toMutable() }.toMutableSet()
}
override fun getType(): String {
return type
}
override fun getType(): String = type
override fun getName(): String? {
return name
}
override fun getName(): String? = name
override fun getSignature(): String? {
return signature
}
override fun getSignature(): String? = signature
override fun getAnnotations(): MutableSet<MutableAnnotation> {
return _annotations
}
override fun getAnnotations(): MutableSet<MutableAnnotation> = _annotations
companion object {
fun MethodParameter.toMutable(): MutableMethodParameter {
return MutableMethodParameter(this)
}
fun MethodParameter.toMutable(): MutableMethodParameter = MutableMethodParameter(this)
}
}

View file

@ -14,21 +14,15 @@ class MutableAnnotationEncodedValue(annotationEncodedValue: AnnotationEncodedVal
annotationEncodedValue.elements.map { annotationElement -> annotationElement.toMutable() }.toMutableSet()
}
override fun getType(): String {
return this.type
}
override fun getType(): String = this.type
fun setType(type: String) {
this.type = type
}
override fun getElements(): MutableSet<out AnnotationElement> {
return _elements
}
override fun getElements(): MutableSet<out AnnotationElement> = _elements
companion object {
fun AnnotationEncodedValue.toMutable(): MutableAnnotationEncodedValue {
return MutableAnnotationEncodedValue(this)
}
fun AnnotationEncodedValue.toMutable(): MutableAnnotationEncodedValue = MutableAnnotationEncodedValue(this)
}
}

View file

@ -5,18 +5,16 @@ import com.android.tools.smali.dexlib2.base.value.BaseArrayEncodedValue
import com.android.tools.smali.dexlib2.iface.value.ArrayEncodedValue
import com.android.tools.smali.dexlib2.iface.value.EncodedValue
class MutableArrayEncodedValue(arrayEncodedValue: ArrayEncodedValue) : BaseArrayEncodedValue(), MutableEncodedValue {
class MutableArrayEncodedValue(arrayEncodedValue: ArrayEncodedValue) :
BaseArrayEncodedValue(),
MutableEncodedValue {
private val _value by lazy {
arrayEncodedValue.value.map { encodedValue -> encodedValue.toMutable() }.toMutableList()
}
override fun getValue(): MutableList<out EncodedValue> {
return _value
}
override fun getValue(): MutableList<out EncodedValue> = _value
companion object {
fun ArrayEncodedValue.toMutable(): MutableArrayEncodedValue {
return MutableArrayEncodedValue(this)
}
fun ArrayEncodedValue.toMutable(): MutableArrayEncodedValue = MutableArrayEncodedValue(this)
}
}

View file

@ -8,17 +8,13 @@ class MutableBooleanEncodedValue(booleanEncodedValue: BooleanEncodedValue) :
MutableEncodedValue {
private var value = booleanEncodedValue.value
override fun getValue(): Boolean {
return this.value
}
override fun getValue(): Boolean = this.value
fun setValue(value: Boolean) {
this.value = value
}
companion object {
fun BooleanEncodedValue.toMutable(): MutableBooleanEncodedValue {
return MutableBooleanEncodedValue(this)
}
fun BooleanEncodedValue.toMutable(): MutableBooleanEncodedValue = MutableBooleanEncodedValue(this)
}
}

View file

@ -3,20 +3,18 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseByteEncodedValue
import com.android.tools.smali.dexlib2.iface.value.ByteEncodedValue
class MutableByteEncodedValue(byteEncodedValue: ByteEncodedValue) : BaseByteEncodedValue(), MutableEncodedValue {
class MutableByteEncodedValue(byteEncodedValue: ByteEncodedValue) :
BaseByteEncodedValue(),
MutableEncodedValue {
private var value = byteEncodedValue.value
override fun getValue(): Byte {
return this.value
}
override fun getValue(): Byte = this.value
fun setValue(value: Byte) {
this.value = value
}
companion object {
fun ByteEncodedValue.toMutable(): MutableByteEncodedValue {
return MutableByteEncodedValue(this)
}
fun ByteEncodedValue.toMutable(): MutableByteEncodedValue = MutableByteEncodedValue(this)
}
}

View file

@ -3,20 +3,18 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseCharEncodedValue
import com.android.tools.smali.dexlib2.iface.value.CharEncodedValue
class MutableCharEncodedValue(charEncodedValue: CharEncodedValue) : BaseCharEncodedValue(), MutableEncodedValue {
class MutableCharEncodedValue(charEncodedValue: CharEncodedValue) :
BaseCharEncodedValue(),
MutableEncodedValue {
private var value = charEncodedValue.value
override fun getValue(): Char {
return this.value
}
override fun getValue(): Char = this.value
fun setValue(value: Char) {
this.value = value
}
companion object {
fun CharEncodedValue.toMutable(): MutableCharEncodedValue {
return MutableCharEncodedValue(this)
}
fun CharEncodedValue.toMutable(): MutableCharEncodedValue = MutableCharEncodedValue(this)
}
}

View file

@ -8,17 +8,13 @@ class MutableDoubleEncodedValue(doubleEncodedValue: DoubleEncodedValue) :
MutableEncodedValue {
private var value = doubleEncodedValue.value
override fun getValue(): Double {
return this.value
}
override fun getValue(): Double = this.value
fun setValue(value: Double) {
this.value = value
}
companion object {
fun DoubleEncodedValue.toMutable(): MutableDoubleEncodedValue {
return MutableDoubleEncodedValue(this)
}
fun DoubleEncodedValue.toMutable(): MutableDoubleEncodedValue = MutableDoubleEncodedValue(this)
}
}

View file

@ -4,20 +4,18 @@ import com.android.tools.smali.dexlib2.base.value.BaseEnumEncodedValue
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.value.EnumEncodedValue
class MutableEnumEncodedValue(enumEncodedValue: EnumEncodedValue) : BaseEnumEncodedValue(), MutableEncodedValue {
class MutableEnumEncodedValue(enumEncodedValue: EnumEncodedValue) :
BaseEnumEncodedValue(),
MutableEncodedValue {
private var value = enumEncodedValue.value
override fun getValue(): FieldReference {
return this.value
}
override fun getValue(): FieldReference = this.value
fun setValue(value: FieldReference) {
this.value = value
}
companion object {
fun EnumEncodedValue.toMutable(): MutableEnumEncodedValue {
return MutableEnumEncodedValue(this)
}
fun EnumEncodedValue.toMutable(): MutableEnumEncodedValue = MutableEnumEncodedValue(this)
}
}

View file

@ -5,24 +5,20 @@ import com.android.tools.smali.dexlib2.base.value.BaseFieldEncodedValue
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.value.FieldEncodedValue
class MutableFieldEncodedValue(fieldEncodedValue: FieldEncodedValue) : BaseFieldEncodedValue(), MutableEncodedValue {
class MutableFieldEncodedValue(fieldEncodedValue: FieldEncodedValue) :
BaseFieldEncodedValue(),
MutableEncodedValue {
private var value = fieldEncodedValue.value
override fun getValueType(): Int {
return ValueType.FIELD
}
override fun getValueType(): Int = ValueType.FIELD
override fun getValue(): FieldReference {
return this.value
}
override fun getValue(): FieldReference = this.value
fun setValue(value: FieldReference) {
this.value = value
}
companion object {
fun FieldEncodedValue.toMutable(): MutableFieldEncodedValue {
return MutableFieldEncodedValue(this)
}
fun FieldEncodedValue.toMutable(): MutableFieldEncodedValue = MutableFieldEncodedValue(this)
}
}

View file

@ -3,20 +3,18 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseFloatEncodedValue
import com.android.tools.smali.dexlib2.iface.value.FloatEncodedValue
class MutableFloatEncodedValue(floatEncodedValue: FloatEncodedValue) : BaseFloatEncodedValue(), MutableEncodedValue {
class MutableFloatEncodedValue(floatEncodedValue: FloatEncodedValue) :
BaseFloatEncodedValue(),
MutableEncodedValue {
private var value = floatEncodedValue.value
override fun getValue(): Float {
return this.value
}
override fun getValue(): Float = this.value
fun setValue(value: Float) {
this.value = value
}
companion object {
fun FloatEncodedValue.toMutable(): MutableFloatEncodedValue {
return MutableFloatEncodedValue(this)
}
fun FloatEncodedValue.toMutable(): MutableFloatEncodedValue = MutableFloatEncodedValue(this)
}
}

View file

@ -3,20 +3,18 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseIntEncodedValue
import com.android.tools.smali.dexlib2.iface.value.IntEncodedValue
class MutableIntEncodedValue(intEncodedValue: IntEncodedValue) : BaseIntEncodedValue(), MutableEncodedValue {
class MutableIntEncodedValue(intEncodedValue: IntEncodedValue) :
BaseIntEncodedValue(),
MutableEncodedValue {
private var value = intEncodedValue.value
override fun getValue(): Int {
return this.value
}
override fun getValue(): Int = this.value
fun setValue(value: Int) {
this.value = value
}
companion object {
fun IntEncodedValue.toMutable(): MutableIntEncodedValue {
return MutableIntEncodedValue(this)
}
fun IntEncodedValue.toMutable(): MutableIntEncodedValue = MutableIntEncodedValue(this)
}
}

View file

@ -3,20 +3,18 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseLongEncodedValue
import com.android.tools.smali.dexlib2.iface.value.LongEncodedValue
class MutableLongEncodedValue(longEncodedValue: LongEncodedValue) : BaseLongEncodedValue(), MutableEncodedValue {
class MutableLongEncodedValue(longEncodedValue: LongEncodedValue) :
BaseLongEncodedValue(),
MutableEncodedValue {
private var value = longEncodedValue.value
override fun getValue(): Long {
return this.value
}
override fun getValue(): Long = this.value
fun setValue(value: Long) {
this.value = value
}
companion object {
fun LongEncodedValue.toMutable(): MutableLongEncodedValue {
return MutableLongEncodedValue(this)
}
fun LongEncodedValue.toMutable(): MutableLongEncodedValue = MutableLongEncodedValue(this)
}
}

View file

@ -9,17 +9,13 @@ class MutableMethodEncodedValue(methodEncodedValue: MethodEncodedValue) :
MutableEncodedValue {
private var value = methodEncodedValue.value
override fun getValue(): MethodReference {
return this.value
}
override fun getValue(): MethodReference = this.value
fun setValue(value: MethodReference) {
this.value = value
}
companion object {
fun MethodEncodedValue.toMutable(): MutableMethodEncodedValue {
return MutableMethodEncodedValue(this)
}
fun MethodEncodedValue.toMutable(): MutableMethodEncodedValue = MutableMethodEncodedValue(this)
}
}

View file

@ -9,17 +9,13 @@ class MutableMethodHandleEncodedValue(methodHandleEncodedValue: MethodHandleEnco
MutableEncodedValue {
private var value = methodHandleEncodedValue.value
override fun getValue(): MethodHandleReference {
return this.value
}
override fun getValue(): MethodHandleReference = this.value
fun setValue(value: MethodHandleReference) {
this.value = value
}
companion object {
fun MethodHandleEncodedValue.toMutable(): MutableMethodHandleEncodedValue {
return MutableMethodHandleEncodedValue(this)
}
fun MethodHandleEncodedValue.toMutable(): MutableMethodHandleEncodedValue = MutableMethodHandleEncodedValue(this)
}
}

View file

@ -9,17 +9,13 @@ class MutableMethodTypeEncodedValue(methodTypeEncodedValue: MethodTypeEncodedVal
MutableEncodedValue {
private var value = methodTypeEncodedValue.value
override fun getValue(): MethodProtoReference {
return this.value
}
override fun getValue(): MethodProtoReference = this.value
fun setValue(value: MethodProtoReference) {
this.value = value
}
companion object {
fun MethodTypeEncodedValue.toMutable(): MutableMethodTypeEncodedValue {
return MutableMethodTypeEncodedValue(this)
}
fun MethodTypeEncodedValue.toMutable(): MutableMethodTypeEncodedValue = MutableMethodTypeEncodedValue(this)
}
}

View file

@ -3,10 +3,10 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseNullEncodedValue
import com.android.tools.smali.dexlib2.iface.value.ByteEncodedValue
class MutableNullEncodedValue : BaseNullEncodedValue(), MutableEncodedValue {
class MutableNullEncodedValue :
BaseNullEncodedValue(),
MutableEncodedValue {
companion object {
fun ByteEncodedValue.toMutable(): MutableByteEncodedValue {
return MutableByteEncodedValue(this)
}
fun ByteEncodedValue.toMutable(): MutableByteEncodedValue = MutableByteEncodedValue(this)
}
}

View file

@ -3,20 +3,18 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseShortEncodedValue
import com.android.tools.smali.dexlib2.iface.value.ShortEncodedValue
class MutableShortEncodedValue(shortEncodedValue: ShortEncodedValue) : BaseShortEncodedValue(), MutableEncodedValue {
class MutableShortEncodedValue(shortEncodedValue: ShortEncodedValue) :
BaseShortEncodedValue(),
MutableEncodedValue {
private var value = shortEncodedValue.value
override fun getValue(): Short {
return this.value
}
override fun getValue(): Short = this.value
fun setValue(value: Short) {
this.value = value
}
companion object {
fun ShortEncodedValue.toMutable(): MutableShortEncodedValue {
return MutableShortEncodedValue(this)
}
fun ShortEncodedValue.toMutable(): MutableShortEncodedValue = MutableShortEncodedValue(this)
}
}

View file

@ -9,17 +9,13 @@ class MutableStringEncodedValue(stringEncodedValue: StringEncodedValue) :
MutableEncodedValue {
private var value = stringEncodedValue.value
override fun getValue(): String {
return this.value
}
override fun getValue(): String = this.value
fun setValue(value: String) {
this.value = value
}
companion object {
fun ByteEncodedValue.toMutable(): MutableByteEncodedValue {
return MutableByteEncodedValue(this)
}
fun ByteEncodedValue.toMutable(): MutableByteEncodedValue = MutableByteEncodedValue(this)
}
}

View file

@ -3,20 +3,18 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseTypeEncodedValue
import com.android.tools.smali.dexlib2.iface.value.TypeEncodedValue
class MutableTypeEncodedValue(typeEncodedValue: TypeEncodedValue) : BaseTypeEncodedValue(), MutableEncodedValue {
class MutableTypeEncodedValue(typeEncodedValue: TypeEncodedValue) :
BaseTypeEncodedValue(),
MutableEncodedValue {
private var value = typeEncodedValue.value
override fun getValue(): String {
return this.value
}
override fun getValue(): String = this.value
fun setValue(value: String) {
this.value = value
}
companion object {
fun TypeEncodedValue.toMutable(): MutableTypeEncodedValue {
return MutableTypeEncodedValue(this)
}
fun TypeEncodedValue.toMutable(): MutableTypeEncodedValue = MutableTypeEncodedValue(this)
}
}