From 12e071db6034f80625f2b4d10e9e30a5fc6861f4 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Sun, 28 Oct 2012 13:13:11 -0700 Subject: [PATCH] Refactor how parameters/parameter names are handled --- .../DexBackedMethodImplementation.java | 16 +++++++++++--- .../dexlib2/dexbacked/util/DebugItemList.java | 21 ++++++------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java index 107bf5be..9a13e5d5 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java @@ -112,7 +112,7 @@ public class DexBackedMethodImplementation implements MethodImplementation { public Iterable 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 getParametersWithNames() { + //TODO: reading the method params from the debug_info_item should probably be centralized with other debug stuff + @Nullable + public VariableSizeList 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 getParametersWithNames() { + List parameters = getParametersWithNamesOrNull(); + if (parameters != null) { + return parameters; + } + return method.getParametersWithoutNames(); } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java index 146dc589..96066162 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java @@ -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 { @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 { 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 parameters = - (VariableSizeList)method.getParameters(); + // getParametersWithNames returns a VariableSizeList when debug info is present + VariableSizeList parameters = methodImpl.getParametersWithNamesOrNull(); + assert parameters != null; final VariableSizeList.Iterator parameterIterator = parameters.listIterator(); { // local scope for i