Remove the Instruction template parameter from ClassSection

This commit is contained in:
Ben Gruver 2013-08-24 21:36:21 -07:00
parent 6f135aeb74
commit ca5de1d803
7 changed files with 23 additions and 22 deletions

View File

@ -34,6 +34,7 @@ package org.jf.dexlib2.writer;
import org.jf.dexlib2.iface.ExceptionHandler; import org.jf.dexlib2.iface.ExceptionHandler;
import org.jf.dexlib2.iface.TryBlock; import org.jf.dexlib2.iface.TryBlock;
import org.jf.dexlib2.iface.debug.DebugItem; import org.jf.dexlib2.iface.debug.DebugItem;
import org.jf.dexlib2.iface.instruction.Instruction;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -43,7 +44,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public interface ClassSection<StringKey extends CharSequence, TypeKey extends CharSequence, TypeListKey, ClassKey, public interface ClassSection<StringKey extends CharSequence, TypeKey extends CharSequence, TypeListKey, ClassKey,
FieldKey, MethodKey, AnnotationSetKey, EncodedValue, Insn> extends IndexSection<ClassKey> { FieldKey, MethodKey, AnnotationSetKey, EncodedValue> extends IndexSection<ClassKey> {
@Nonnull Collection<? extends ClassKey> getSortedClasses(); @Nonnull Collection<? extends ClassKey> getSortedClasses();
@Nullable Map.Entry<? extends ClassKey, Integer> getClassEntryByType(@Nullable TypeKey key); @Nullable Map.Entry<? extends ClassKey, Integer> getClassEntryByType(@Nullable TypeKey key);
@ -74,7 +75,7 @@ public interface ClassSection<StringKey extends CharSequence, TypeKey extends Ch
@Nullable Iterable<? extends StringKey> getParameterNames(@Nonnull MethodKey key); @Nullable Iterable<? extends StringKey> getParameterNames(@Nonnull MethodKey key);
int getRegisterCount(@Nonnull MethodKey key); int getRegisterCount(@Nonnull MethodKey key);
@Nullable Iterable<? extends Insn> getInstructions(@Nonnull MethodKey key); @Nullable Iterable<? extends Instruction> getInstructions(@Nonnull MethodKey key);
@Nonnull List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks(@Nonnull MethodKey key); @Nonnull List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks(@Nonnull MethodKey key);
@Nullable TypeKey getExceptionType(@Nonnull ExceptionHandler handler); @Nullable TypeKey getExceptionType(@Nonnull ExceptionHandler handler);

View File

@ -117,7 +117,7 @@ public abstract class DexWriter<
protected final FieldSection<StringKey, TypeKey, FieldRefKey, FieldKey> fieldSection; protected final FieldSection<StringKey, TypeKey, FieldRefKey, FieldKey> fieldSection;
protected final MethodSection<StringKey, TypeKey, ProtoKey, MethodRefKey, MethodKey> methodSection; protected final MethodSection<StringKey, TypeKey, ProtoKey, MethodRefKey, MethodKey> methodSection;
protected final ClassSection<StringKey, TypeKey, TypeListKey, ClassKey, FieldKey, MethodKey, AnnotationSetKey, protected final ClassSection<StringKey, TypeKey, TypeListKey, ClassKey, FieldKey, MethodKey, AnnotationSetKey,
EncodedValue, Insn> classSection; EncodedValue> classSection;
protected final TypeListSection<TypeKey, TypeListKey> typeListSection; protected final TypeListSection<TypeKey, TypeListKey> typeListSection;
protected final AnnotationSection<StringKey, TypeKey, AnnotationKey, AnnotationElement, EncodedValue> annotationSection; protected final AnnotationSection<StringKey, TypeKey, AnnotationKey, AnnotationElement, EncodedValue> annotationSection;
@ -131,7 +131,7 @@ public abstract class DexWriter<
FieldSection<StringKey, TypeKey, FieldRefKey, FieldKey> fieldSection, FieldSection<StringKey, TypeKey, FieldRefKey, FieldKey> fieldSection,
MethodSection<StringKey, TypeKey, ProtoKey, MethodRefKey, MethodKey> methodSection, MethodSection<StringKey, TypeKey, ProtoKey, MethodRefKey, MethodKey> methodSection,
ClassSection<StringKey, TypeKey, TypeListKey, ClassKey, FieldKey, MethodKey, AnnotationSetKey, ClassSection<StringKey, TypeKey, TypeListKey, ClassKey, FieldKey, MethodKey, AnnotationSetKey,
EncodedValue, Insn> classSection, EncodedValue> classSection,
TypeListSection<TypeKey, TypeListKey> typeListSection, TypeListSection<TypeKey, TypeListKey> typeListSection,
AnnotationSection<StringKey, TypeKey, AnnotationKey, AnnotationElement, AnnotationSection<StringKey, TypeKey, AnnotationKey, AnnotationElement,
EncodedValue> annotationSection, EncodedValue> annotationSection,
@ -789,7 +789,7 @@ public abstract class DexWriter<
Iterable<MethodKey> methods = Iterables.concat(directMethods, virtualMethods); Iterable<MethodKey> methods = Iterables.concat(directMethods, virtualMethods);
for (MethodKey methodKey: methods) { for (MethodKey methodKey: methods) {
Iterable<? extends Insn> instructions = classSection.getInstructions(methodKey); Iterable<? extends Instruction> instructions = classSection.getInstructions(methodKey);
int debugItemOffset = classSection.getDebugItemOffset(methodKey); int debugItemOffset = classSection.getDebugItemOffset(methodKey);
if (instructions == null && debugItemOffset == NO_OFFSET) { if (instructions == null && debugItemOffset == NO_OFFSET) {
@ -813,8 +813,8 @@ public abstract class DexWriter<
if (instructions != null) { if (instructions != null) {
tryBlocks = TryListBuilder.massageTryBlocks(tryBlocks); tryBlocks = TryListBuilder.massageTryBlocks(tryBlocks);
InstructionWriteUtil<Insn, StringRef, BaseReference> instrWriteUtil = InstructionWriteUtil<StringRef, BaseReference> instrWriteUtil =
new InstructionWriteUtil<Insn, StringRef, BaseReference>(instructions, stringSection, instructionFactory); new InstructionWriteUtil<StringRef, BaseReference>(instructions, stringSection, instructionFactory);
writer.writeUshort(instrWriteUtil.getOutParamCount()); writer.writeUshort(instrWriteUtil.getOutParamCount());
writer.writeUshort(tryBlocks.size()); writer.writeUshort(tryBlocks.size());
writer.writeInt(debugItemOffset); writer.writeInt(debugItemOffset);
@ -824,7 +824,7 @@ public abstract class DexWriter<
methodSection); methodSection);
writer.writeInt(instrWriteUtil.getCodeUnitCount()); writer.writeInt(instrWriteUtil.getCodeUnitCount());
for (Insn instruction: instrWriteUtil.getInstructions()) { for (Instruction instruction: instrWriteUtil.getInstructions()) {
switch (instruction.getOpcode().format) { switch (instruction.getOpcode().format) {
case Format10t: case Format10t:
instructionWriter.write((Instruction10t)instruction); instructionWriter.write((Instruction10t)instruction);

View File

@ -58,7 +58,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
public class BuilderClassPool implements ClassSection<BuilderStringReference, BuilderTypeReference, BuilderTypeList, public class BuilderClassPool implements ClassSection<BuilderStringReference, BuilderTypeReference, BuilderTypeList,
BuilderClassDef, BuilderField, BuilderMethod, BuilderAnnotationSet, BuilderEncodedValue, BuilderInstruction> { BuilderClassDef, BuilderField, BuilderMethod, BuilderAnnotationSet, BuilderEncodedValue> {
@Nonnull private final ConcurrentMap<String, BuilderClassDef> internedItems = @Nonnull private final ConcurrentMap<String, BuilderClassDef> internedItems =
Maps.newConcurrentMap(); Maps.newConcurrentMap();

View File

@ -60,7 +60,7 @@ import java.util.Map.Entry;
public class ClassPool implements ClassSection<CharSequence, CharSequence, public class ClassPool implements ClassSection<CharSequence, CharSequence,
TypeListPool.Key<? extends Collection<? extends CharSequence>>, PoolClassDef, Field, PoolMethod, TypeListPool.Key<? extends Collection<? extends CharSequence>>, PoolClassDef, Field, PoolMethod,
Set<? extends Annotation>, Set<? extends Annotation>,
EncodedValue, Instruction> { EncodedValue> {
@Nonnull private HashMap<String, PoolClassDef> internedItems = Maps.newHashMap(); @Nonnull private HashMap<String, PoolClassDef> internedItems = Maps.newHashMap();
@Nonnull private final StringPool stringPool; @Nonnull private final StringPool stringPool;

View File

@ -53,13 +53,13 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class InstructionWriteUtil<Insn extends Instruction, StringRef extends StringReference, public class InstructionWriteUtil<StringRef extends StringReference,
BaseReference extends Reference> { BaseReference extends Reference> {
private final StringIndexProvider<StringRef> stringIndexProvider; private final StringIndexProvider<StringRef> stringIndexProvider;
private final InstructionFactory<? extends Insn, BaseReference> instructionFactory; private final InstructionFactory<? extends Instruction, BaseReference> instructionFactory;
private final Iterable<? extends Insn> originalInstructions; private final Iterable<? extends Instruction> originalInstructions;
private List<Insn> instructions; private List<Instruction> instructions;
private ArrayList<Integer> codeOffsetShifts; private ArrayList<Integer> codeOffsetShifts;
private HashMap<Integer,Format> offsetToNewInstructionMap; private HashMap<Integer,Format> offsetToNewInstructionMap;
@ -70,9 +70,9 @@ public class InstructionWriteUtil<Insn extends Instruction, StringRef extends St
int getItemIndex(@Nonnull StringRef reference); int getItemIndex(@Nonnull StringRef reference);
} }
public InstructionWriteUtil(@Nonnull Iterable<? extends Insn> instructions, public InstructionWriteUtil(@Nonnull Iterable<? extends Instruction> instructions,
@Nonnull StringIndexProvider<StringRef> stringIndexProvider, @Nonnull StringIndexProvider<StringRef> stringIndexProvider,
@Nonnull InstructionFactory<? extends Insn, BaseReference> instructionFactory) { @Nonnull InstructionFactory<? extends Instruction, BaseReference> instructionFactory) {
this.stringIndexProvider = stringIndexProvider; this.stringIndexProvider = stringIndexProvider;
this.instructionFactory = instructionFactory; this.instructionFactory = instructionFactory;
this.originalInstructions = instructions; this.originalInstructions = instructions;
@ -82,7 +82,7 @@ public class InstructionWriteUtil<Insn extends Instruction, StringRef extends St
} }
private void calculateMaxOutParamCount() { private void calculateMaxOutParamCount() {
for (Insn instruction: originalInstructions) { for (Instruction instruction: originalInstructions) {
codeUnitCount += instruction.getCodeUnits(); codeUnitCount += instruction.getCodeUnits();
if (instruction.getOpcode().referenceType == ReferenceType.METHOD) { if (instruction.getOpcode().referenceType == ReferenceType.METHOD) {
ReferenceInstruction refInsn = (ReferenceInstruction)instruction; ReferenceInstruction refInsn = (ReferenceInstruction)instruction;
@ -94,7 +94,7 @@ public class InstructionWriteUtil<Insn extends Instruction, StringRef extends St
} }
} }
} }
public Iterable<? extends Insn> getInstructions() { public Iterable<? extends Instruction> getInstructions() {
if (instructions != null) { if (instructions != null) {
return instructions; return instructions;
} else { } else {
@ -228,8 +228,8 @@ public class InstructionWriteUtil<Insn extends Instruction, StringRef extends St
instructions = Lists.newArrayList(); instructions = Lists.newArrayList();
int currentCodeOffset = 0; int currentCodeOffset = 0;
for (Insn instruction: originalInstructions) { for (Instruction instruction: originalInstructions) {
Insn modifiedInstruction = null; Instruction modifiedInstruction = null;
switch (instruction.getOpcode().format) { switch (instruction.getOpcode().format) {
case Format10t: { case Format10t: {
Instruction10t instr = (Instruction10t)instruction; Instruction10t instr = (Instruction10t)instruction;

View File

@ -56,7 +56,7 @@ public class JumboStringConversionTest {
private MockStringIndexProvider mockStringIndexProvider; private MockStringIndexProvider mockStringIndexProvider;
ArrayList<String> mJumboStrings; ArrayList<String> mJumboStrings;
private class InsnWriteUtil extends InstructionWriteUtil<Instruction, StringReference, Reference> { private class InsnWriteUtil extends InstructionWriteUtil<StringReference, Reference> {
public InsnWriteUtil(@Nonnull MethodImplementation implementation) { public InsnWriteUtil(@Nonnull MethodImplementation implementation) {
super(implementation.getInstructions(), mockStringIndexProvider, ImmutableInstructionFactory.INSTANCE); super(implementation.getInstructions(), mockStringIndexProvider, ImmutableInstructionFactory.INSTANCE);
} }

View File

@ -51,7 +51,7 @@ import java.util.ArrayList;
public class PayloadAlignmentTest { public class PayloadAlignmentTest {
private MockStringIndexProvider mockStringIndexProvider; private MockStringIndexProvider mockStringIndexProvider;
private class InsnWriteUtil extends InstructionWriteUtil<Instruction, StringReference, Reference> { private class InsnWriteUtil extends InstructionWriteUtil<StringReference, Reference> {
public InsnWriteUtil(@Nonnull MethodImplementation implementation) { public InsnWriteUtil(@Nonnull MethodImplementation implementation) {
super(implementation.getInstructions(), mockStringIndexProvider, ImmutableInstructionFactory.INSTANCE); super(implementation.getInstructions(), mockStringIndexProvider, ImmutableInstructionFactory.INSTANCE);
} }