diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderDebugItem.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderDebugItem.java new file mode 100644 index 00000000..702121f9 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderDebugItem.java @@ -0,0 +1,26 @@ +package org.jf.dexlib2.builder; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.*; +import org.jf.dexlib2.iface.reference.StringReference; +import org.jf.dexlib2.iface.reference.TypeReference; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public abstract class BuilderDebugItem implements DebugItem { + @Nullable MethodLocation location; + + public BuilderDebugItem(@Nonnull MethodLocation location) { + this.location = location; + } + + @Override public int getCodeAddress() { + if (location == null) { + throw new IllegalStateException("Cannot get the address of a BuilderDebugItem that isn't associated with " + + "a method."); + } + return location.getCodeAddress(); + } + +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java index db21fab7..5508977a 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java @@ -41,7 +41,7 @@ public class MethodImplementationBuilder { if (label.isPlaced()) { throw new IllegalArgumentException("There is already a label with that name."); } else { - currentLocation.addLabel(label); + currentLocation.getLabels().add(label); } } else { label = currentLocation.addNewLabel(); @@ -86,25 +86,32 @@ public class MethodImplementationBuilder { } public void addLineNumber(int lineNumber) { + currentLocation.addLineNumber(lineNumber); } public void addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type, @Nullable StringReference signature) { + currentLocation.addStartLocal(registerNumber, name, type, signature); } public void addEndLocal(int registerNumber) { + currentLocation.addEndLocal(registerNumber); } public void addRestartLocal(int registerNumber) { + currentLocation.addRestartLocal(registerNumber); } public void addPrologue() { + currentLocation.addPrologue(); } public void addEpilogue() { + currentLocation.addEpilogue(); } public void addSetSourceFile(@Nullable BuilderStringReference sourceFile) { + currentLocation.addSetSourceFile(sourceFile); } public void addInstruction10t(@Nonnull Opcode opcode, diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java index 97b6b1e9..700a8157 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java @@ -1,13 +1,15 @@ package org.jf.dexlib2.builder; import com.google.common.collect.Lists; +import org.jf.dexlib2.builder.debug.*; import org.jf.dexlib2.iface.instruction.Instruction; +import org.jf.dexlib2.iface.reference.StringReference; +import org.jf.dexlib2.iface.reference.TypeReference; +import org.jf.dexlib2.writer.builder.BuilderStringReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; public class MethodLocation { @Nullable Instruction instruction; @@ -15,6 +17,7 @@ public class MethodLocation { int index; private List