diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java index a6f537a1..34898fe1 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderExceptionHandler.java @@ -9,7 +9,7 @@ import javax.annotation.Nullable; class BuilderExceptionHandler { static ExceptionHandler newExceptionHandler(@Nullable final TypeReference exceptionType, - @Nonnull final LabelMethodItem handler) { + @Nonnull final Label handler) { if (exceptionType == null) { return newExceptionHandler(handler); } @@ -28,7 +28,7 @@ class BuilderExceptionHandler { }; } - static ExceptionHandler newExceptionHandler(@Nonnull final LabelMethodItem handler) { + static ExceptionHandler newExceptionHandler(@Nonnull final Label handler) { return new BaseExceptionHandler() { @Nullable @Override public String getExceptionType() { return null; @@ -41,7 +41,7 @@ class BuilderExceptionHandler { } static ExceptionHandler newExceptionHandler(@Nullable final String exceptionType, - @Nonnull final LabelMethodItem handler) { + @Nonnull final Label handler) { if (exceptionType == null) { return newExceptionHandler(handler); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java index 20a22ccf..8c927111 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/BuilderTryBlock.java @@ -12,27 +12,26 @@ import java.util.List; class BuilderTryBlock extends BaseTryBlock { // We only ever have one exception handler per try block. They are later merged as needed in TryListBuilder @Nonnull public final ExceptionHandler exceptionHandler; - @Nonnull public final LabelMethodItem start; + @Nonnull public final Label start; // The end location is exclusive, it should point to the codeAddress of the instruction immediately after the last // covered instruction. - @Nonnull public final LabelMethodItem end; + @Nonnull public final Label end; - public BuilderTryBlock(@Nonnull LabelMethodItem start, @Nonnull LabelMethodItem end, - @Nullable String exceptionType, @Nonnull LabelMethodItem handler) { + public BuilderTryBlock(@Nonnull Label start, @Nonnull Label end, @Nullable String exceptionType, + @Nonnull Label handler) { this.start = start; this.end = end; this.exceptionHandler = BuilderExceptionHandler.newExceptionHandler(exceptionType, handler); } - public BuilderTryBlock(@Nonnull LabelMethodItem start, @Nonnull LabelMethodItem end, - @Nullable TypeReference exceptionType, @Nonnull LabelMethodItem handler) { + public BuilderTryBlock(@Nonnull Label start, @Nonnull Label end, @Nullable TypeReference exceptionType, + @Nonnull Label handler) { this.start = start; this.end = end; this.exceptionHandler = BuilderExceptionHandler.newExceptionHandler(exceptionType, handler); } - public BuilderTryBlock(@Nonnull LabelMethodItem start, @Nonnull LabelMethodItem end, - @Nonnull LabelMethodItem handler) { + public BuilderTryBlock(@Nonnull Label start, @Nonnull Label end, @Nonnull Label handler) { this.start = start; this.end = end; this.exceptionHandler = BuilderExceptionHandler.newExceptionHandler(handler); diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/InstructionMethodItem.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/InstructionMethodItem.java deleted file mode 100644 index c5cdc017..00000000 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/InstructionMethodItem.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.jf.dexlib2.builder; - -import org.jf.dexlib2.iface.instruction.Instruction; - -class InstructionMethodItem extends MethodItem { - public Instruction instruction; -} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/Label.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/Label.java new file mode 100644 index 00000000..c6375e55 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/Label.java @@ -0,0 +1,31 @@ +package org.jf.dexlib2.builder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class Label { + @Nullable MethodLocation location; + + Label() { + } + + Label(MethodLocation location) { + this.location = location; + } + + public int getCodeAddress() { + return getLocation().getCodeAddress(); + } + + @Nonnull + public MethodLocation getLocation() { + if (location == null) { + throw new IllegalStateException("Cannot get the location of a label that hasn't been placed yet."); + } + return location; + } + + public boolean isPlaced() { + return location != null; + } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/LabelMethodItem.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/LabelMethodItem.java deleted file mode 100644 index 3fe10414..00000000 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/LabelMethodItem.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.jf.dexlib2.builder; - -public class LabelMethodItem extends MethodItem { - LabelMethodItem() { - } - - LabelMethodItem(MethodLocation location) { - this.location = location; - } - - public int getCodeAddress() { - return getLocation().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 54093268..db21fab7 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodImplementationBuilder.java @@ -13,7 +13,7 @@ import java.util.List; public class MethodImplementationBuilder { // Contains all named labels - both placed and unplaced - private final HashMap labels = new HashMap(); + private final HashMap labels = new HashMap(); @Nonnull private final MutableMethodImplementation impl; @@ -34,8 +34,8 @@ public class MethodImplementationBuilder { * @return A LabelRef representing the label */ @Nonnull - public LabelMethodItem addLabel(@Nonnull String name) { - LabelMethodItem label = labels.get(name); + public Label addLabel(@Nonnull String name) { + Label label = labels.get(name); if (label != null) { if (label.isPlaced()) { @@ -62,26 +62,26 @@ public class MethodImplementationBuilder { * @return A LabelRef representing the label */ @Nonnull - public LabelMethodItem getLabel(@Nonnull String name) { - LabelMethodItem label = labels.get(name); + public Label getLabel(@Nonnull String name) { + Label label = labels.get(name); if (label == null) { - label = new LabelMethodItem(); + label = new Label(); labels.put(name, label); } return label; } - public void addCatch(@Nullable TypeReference type, @Nonnull LabelMethodItem from, - @Nonnull LabelMethodItem to, @Nonnull LabelMethodItem handler) { + public void addCatch(@Nullable TypeReference type, @Nonnull Label from, + @Nonnull Label to, @Nonnull Label handler) { impl.addCatch(type, from, to, handler); } - public void addCatch(@Nullable String type, @Nonnull LabelMethodItem from, @Nonnull LabelMethodItem to, - @Nonnull LabelMethodItem handler) { + public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to, + @Nonnull Label handler) { impl.addCatch(type, from, to, handler); } - public void addCatch(@Nonnull LabelMethodItem from, @Nonnull LabelMethodItem to, @Nonnull LabelMethodItem handler) { + public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) { impl.addCatch(from, to, handler); } @@ -108,7 +108,7 @@ public class MethodImplementationBuilder { } public void addInstruction10t(@Nonnull Opcode opcode, - @Nonnull LabelMethodItem label) { + @Nonnull Label label) { } public void addInstruction10x(@Nonnull Opcode opcode) { @@ -134,7 +134,7 @@ public class MethodImplementationBuilder { } public void addInstruction20t(@Nonnull Opcode opcode, - @Nonnull LabelMethodItem label) { + @Nonnull Label label) { } public void addInstruction21c(@Nonnull Opcode opcode, @@ -159,7 +159,7 @@ public class MethodImplementationBuilder { public void addInstruction21t(@Nonnull Opcode opcode, int registerA, - @Nonnull LabelMethodItem label) { + @Nonnull Label label) { } public void addInstruction22b(@Nonnull Opcode opcode, @@ -183,7 +183,7 @@ public class MethodImplementationBuilder { public void addInstruction22t(@Nonnull Opcode opcode, int registerA, int registerB, - @Nonnull LabelMethodItem labelMethodItem) { + @Nonnull Label labelMethodItem) { } public void addInstruction22x(@Nonnull Opcode opcode, @@ -198,7 +198,7 @@ public class MethodImplementationBuilder { } public void addInstruction30t(@Nonnull Opcode opcode, - @Nonnull LabelMethodItem label) { + @Nonnull Label label) { } public void addInstruction31c(@Nonnull Opcode opcode, @@ -213,7 +213,7 @@ public class MethodImplementationBuilder { public void addInstruction31t(@Nonnull Opcode opcode, int registerA, - @Nonnull LabelMethodItem label) { + @Nonnull Label label) { } public void addInstruction32x(@Nonnull Opcode opcode, @@ -242,7 +242,7 @@ public class MethodImplementationBuilder { long literal) { } - public void addPackedSwitchPayload(int startKey, @Nullable List switchElements) { + public void addPackedSwitchPayload(int startKey, @Nullable List switchElements) { } public void addSparseSwitchPayload(@Nullable List switchElements) { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodItem.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodItem.java deleted file mode 100644 index f5ba7d0a..00000000 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodItem.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.jf.dexlib2.builder; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -class MethodItem { - @Nullable - MethodLocation location; - - @Nonnull - public MethodLocation getLocation() { - if (location == null) { - throw new IllegalStateException("Cannot get the address of MethodItem that hasn't been added to a method."); - } - return location; - } - - public boolean isPlaced() { - return location != null; - } -} 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 80fc854c..97b6b1e9 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java @@ -14,7 +14,7 @@ public class MethodLocation { int codeAddress; int index; - private List labels = Lists.newArrayList(); + private List