mirror of
https://github.com/revanced/smali.git
synced 2025-05-23 18:16:23 +02:00
Refactor how parameters/parameter names are handled
This commit is contained in:
parent
87179940cb
commit
12e071db60
@ -112,7 +112,7 @@ public class DexBackedMethodImplementation implements MethodImplementation {
|
||||
public Iterable<? extends DebugItem> getDebugItems() {
|
||||
final int debugInfoOffset = dexBuf.readSmallUint(codeOffset + DEBUG_OFFSET_OFFSET);
|
||||
if (debugInfoOffset > 0) {
|
||||
return new DebugItemList(dexBuf, debugInfoOffset, method);
|
||||
return new DebugItemList(dexBuf, debugInfoOffset, this);
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
@ -135,7 +135,9 @@ public class DexBackedMethodImplementation implements MethodImplementation {
|
||||
return ImmutableList.copyOf(instructions);
|
||||
}
|
||||
|
||||
public List<MethodParameter> getParametersWithNames() {
|
||||
//TODO: reading the method params from the debug_info_item should probably be centralized with other debug stuff
|
||||
@Nullable
|
||||
public VariableSizeList<MethodParameter> getParametersWithNamesOrNull() {
|
||||
final int debugInfoOffset = dexBuf.readSmallUint(codeOffset + DEBUG_OFFSET_OFFSET);
|
||||
if (debugInfoOffset > 0) {
|
||||
DexReader reader = dexBuf.readerAt(debugInfoOffset);
|
||||
@ -168,6 +170,14 @@ public class DexBackedMethodImplementation implements MethodImplementation {
|
||||
@Override public int size() { return methodParametersWithoutNames.size(); }
|
||||
};
|
||||
}
|
||||
return ImmutableList.of();
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<? extends MethodParameter> getParametersWithNames() {
|
||||
List<MethodParameter> parameters = getParametersWithNamesOrNull();
|
||||
if (parameters != null) {
|
||||
return parameters;
|
||||
}
|
||||
return method.getParametersWithoutNames();
|
||||
}
|
||||
}
|
||||
|
@ -32,16 +32,14 @@
|
||||
package org.jf.dexlib2.dexbacked.util;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation;
|
||||
import org.jf.dexlib2.dexbacked.DexBuffer;
|
||||
import org.jf.dexlib2.dexbacked.DexReader;
|
||||
import org.jf.dexlib2.iface.Method;
|
||||
import org.jf.dexlib2.iface.MethodImplementation;
|
||||
import org.jf.dexlib2.iface.MethodParameter;
|
||||
import org.jf.dexlib2.iface.debug.DebugItem;
|
||||
import org.jf.dexlib2.iface.debug.EndLocal;
|
||||
import org.jf.dexlib2.iface.debug.LocalInfo;
|
||||
import org.jf.dexlib2.immutable.debug.*;
|
||||
import org.jf.util.ExceptionWithContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -52,19 +50,13 @@ import java.util.NoSuchElementException;
|
||||
public class DebugItemList implements Iterable<DebugItem> {
|
||||
@Nonnull public final DexBuffer dexBuf;
|
||||
private final int debugInfoOffset;
|
||||
@Nonnull private final Method method;
|
||||
@Nonnull private final MethodImplementation methodImpl;
|
||||
@Nonnull private final DexBackedMethodImplementation methodImpl;
|
||||
|
||||
public DebugItemList(@Nonnull DexBuffer dexBuf,
|
||||
int debugInfoOffset,
|
||||
@Nonnull Method method) {
|
||||
@Nonnull DexBackedMethodImplementation methodImpl) {
|
||||
this.dexBuf = dexBuf;
|
||||
this.debugInfoOffset = debugInfoOffset;
|
||||
this.method = method;
|
||||
MethodImplementation methodImpl = method.getImplementation();
|
||||
if (methodImpl == null) {
|
||||
throw new ExceptionWithContext("Creating a DebugItemList for a method with no implementation. WTF?");
|
||||
}
|
||||
this.methodImpl = methodImpl;
|
||||
}
|
||||
|
||||
@ -86,10 +78,9 @@ public class DebugItemList implements Iterable<DebugItem> {
|
||||
final LocalInfo[] locals = new LocalInfo[registerCount];
|
||||
Arrays.fill(locals, EMPTY_LOCAL_INFO);
|
||||
|
||||
// getParameters returns a VariableSizeList when a method implementation is present. Since we're reading debug
|
||||
// information, the method obviously has an implementation.
|
||||
VariableSizeList<? extends MethodParameter> parameters =
|
||||
(VariableSizeList<? extends MethodParameter>)method.getParameters();
|
||||
// getParametersWithNames returns a VariableSizeList when debug info is present
|
||||
VariableSizeList<? extends MethodParameter> parameters = methodImpl.getParametersWithNamesOrNull();
|
||||
assert parameters != null;
|
||||
final VariableSizeList<? extends MethodParameter>.Iterator parameterIterator = parameters.listIterator();
|
||||
|
||||
{ // local scope for i
|
||||
|
Loading…
x
Reference in New Issue
Block a user