summaryrefslogtreecommitdiffstats
path: root/dx/src/com/android/dx/merge
diff options
context:
space:
mode:
Diffstat (limited to 'dx/src/com/android/dx/merge')
-rw-r--r--dx/src/com/android/dx/merge/DexMerger.java161
-rw-r--r--dx/src/com/android/dx/merge/IndexMap.java97
-rw-r--r--dx/src/com/android/dx/merge/InstructionTransformer.java2
-rw-r--r--dx/src/com/android/dx/merge/SortableType.java14
-rw-r--r--dx/src/com/android/dx/merge/TypeList.java57
5 files changed, 138 insertions, 193 deletions
diff --git a/dx/src/com/android/dx/merge/DexMerger.java b/dx/src/com/android/dx/merge/DexMerger.java
index 319153f39..329920e31 100644
--- a/dx/src/com/android/dx/merge/DexMerger.java
+++ b/dx/src/com/android/dx/merge/DexMerger.java
@@ -16,18 +16,19 @@
package com.android.dx.merge;
-import com.android.dx.dex.SizeOf;
-import com.android.dx.dex.TableOfContents;
-import com.android.dx.io.Annotation;
-import com.android.dx.io.ClassData;
-import com.android.dx.io.ClassDef;
-import com.android.dx.io.Code;
-import com.android.dx.io.DexBuffer;
+import com.android.dex.Annotation;
+import com.android.dex.ClassData;
+import com.android.dex.ClassDef;
+import com.android.dex.Code;
+import com.android.dex.Dex;
+import com.android.dex.DexException;
+import com.android.dex.FieldId;
+import com.android.dex.MethodId;
+import com.android.dex.ProtoId;
+import com.android.dex.SizeOf;
+import com.android.dex.TableOfContents;
+import com.android.dex.TypeList;
import com.android.dx.io.DexHasher;
-import com.android.dx.io.FieldId;
-import com.android.dx.io.MethodId;
-import com.android.dx.io.ProtoId;
-import com.android.dx.util.DexException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -39,43 +40,43 @@ import java.util.List;
* Combine two dex files into one.
*/
public final class DexMerger {
- private final DexBuffer dexA;
- private final DexBuffer dexB;
+ private final Dex dexA;
+ private final Dex dexB;
private final CollisionPolicy collisionPolicy;
private final WriterSizes writerSizes;
- private final DexBuffer dexOut = new DexBuffer();
+ private final Dex dexOut = new Dex();
- private final DexBuffer.Section headerOut;
+ private final Dex.Section headerOut;
/** All IDs and definitions sections */
- private final DexBuffer.Section idsDefsOut;
+ private final Dex.Section idsDefsOut;
- private final DexBuffer.Section mapListOut;
+ private final Dex.Section mapListOut;
- private final DexBuffer.Section typeListOut;
+ private final Dex.Section typeListOut;
- private final DexBuffer.Section classDataOut;
+ private final Dex.Section classDataOut;
- private final DexBuffer.Section codeOut;
+ private final Dex.Section codeOut;
- private final DexBuffer.Section stringDataOut;
+ private final Dex.Section stringDataOut;
- private final DexBuffer.Section debugInfoOut;
+ private final Dex.Section debugInfoOut;
- private final DexBuffer.Section encodedArrayOut;
+ private final Dex.Section encodedArrayOut;
/** annotations directory on a type */
- private final DexBuffer.Section annotationsDirectoryOut;
+ private final Dex.Section annotationsDirectoryOut;
/** sets of annotations on a member, parameter or type */
- private final DexBuffer.Section annotationSetOut;
+ private final Dex.Section annotationSetOut;
/** parameter lists */
- private final DexBuffer.Section annotationSetRefListOut;
+ private final Dex.Section annotationSetRefListOut;
/** individual annotations, each containing zero or more fields */
- private final DexBuffer.Section annotationOut;
+ private final Dex.Section annotationOut;
private final TableOfContents contentsOut;
@@ -87,12 +88,12 @@ public final class DexMerger {
/** minimum number of wasted bytes before it's worthwhile to compact the result */
private int compactWasteThreshold = 1024 * 1024; // 1MiB
- public DexMerger(DexBuffer dexA, DexBuffer dexB, CollisionPolicy collisionPolicy)
+ public DexMerger(Dex dexA, Dex dexB, CollisionPolicy collisionPolicy)
throws IOException {
this(dexA, dexB, collisionPolicy, new WriterSizes(dexA, dexB));
}
- private DexMerger(DexBuffer dexA, DexBuffer dexB, CollisionPolicy collisionPolicy,
+ private DexMerger(Dex dexA, Dex dexB, CollisionPolicy collisionPolicy,
WriterSizes writerSizes) throws IOException {
this.dexA = dexA;
this.dexB = dexB;
@@ -156,7 +157,7 @@ public final class DexMerger {
this.compactWasteThreshold = compactWasteThreshold;
}
- private DexBuffer mergeDexBuffers() throws IOException {
+ private Dex mergeDexes() throws IOException {
mergeStringIds();
mergeTypeIds();
mergeTypeLists();
@@ -181,9 +182,9 @@ public final class DexMerger {
return dexOut;
}
- public DexBuffer merge() throws IOException {
+ public Dex merge() throws IOException {
long start = System.nanoTime();
- DexBuffer result = mergeDexBuffers();
+ Dex result = mergeDexes();
/*
* We use pessimistic sizes when merging dex files. If those sizes
@@ -194,8 +195,8 @@ public final class DexMerger {
int wastedByteCount = writerSizes.size() - compactedSizes.size();
if (wastedByteCount > + compactWasteThreshold) {
DexMerger compacter = new DexMerger(
- dexOut, new DexBuffer(), CollisionPolicy.FAIL, compactedSizes);
- result = compacter.mergeDexBuffers();
+ dexOut, new Dex(), CollisionPolicy.FAIL, compactedSizes);
+ result = compacter.mergeDexes();
System.out.printf("Result compacted from %.1fKiB to %.1fKiB to save %.1fKiB%n",
dexOut.getLength() / 1024f,
result.getLength() / 1024f,
@@ -221,9 +222,9 @@ public final class DexMerger {
* merged dex file. Populates maps from old to new indices in the process.
*/
abstract class IdMerger<T extends Comparable<T>> {
- private final DexBuffer.Section out;
+ private final Dex.Section out;
- protected IdMerger(DexBuffer.Section out) {
+ protected IdMerger(Dex.Section out) {
this.out = out;
}
@@ -236,8 +237,8 @@ public final class DexMerger {
TableOfContents.Section bSection = getSection(dexB.getTableOfContents());
getSection(contentsOut).off = out.getPosition();
- DexBuffer.Section inA = aSection.exists() ? dexA.open(aSection.off) : null;
- DexBuffer.Section inB = bSection.exists() ? dexB.open(bSection.off) : null;
+ Dex.Section inA = aSection.exists() ? dexA.open(aSection.off) : null;
+ Dex.Section inB = bSection.exists() ? dexB.open(bSection.off) : null;
int aOffset = -1;
int bOffset = -1;
int aIndex = 0;
@@ -320,14 +321,14 @@ public final class DexMerger {
getSection(contentsOut).size = outCount;
}
- private List<UnsortedValue> readUnsortedValues(DexBuffer source, IndexMap indexMap) {
+ private List<UnsortedValue> readUnsortedValues(Dex source, IndexMap indexMap) {
TableOfContents.Section section = getSection(source.getTableOfContents());
if (!section.exists()) {
return Collections.emptyList();
}
List<UnsortedValue> result = new ArrayList<UnsortedValue>();
- DexBuffer.Section in = source.open(section.off);
+ Dex.Section in = source.open(section.off);
for (int i = 0; i < section.size; i++) {
int offset = in.getPosition();
T value = read(in, indexMap, 0);
@@ -337,18 +338,18 @@ public final class DexMerger {
}
abstract TableOfContents.Section getSection(TableOfContents tableOfContents);
- abstract T read(DexBuffer.Section in, IndexMap indexMap, int index);
+ abstract T read(Dex.Section in, IndexMap indexMap, int index);
abstract void updateIndex(int offset, IndexMap indexMap, int oldIndex, int newIndex);
abstract void write(T value);
class UnsortedValue implements Comparable<UnsortedValue> {
- final DexBuffer source;
+ final Dex source;
final IndexMap indexMap;
final T value;
final int index;
final int offset;
- UnsortedValue(DexBuffer source, IndexMap indexMap, T value, int index, int offset) {
+ UnsortedValue(Dex source, IndexMap indexMap, T value, int index, int offset) {
this.source = source;
this.indexMap = indexMap;
this.value = value;
@@ -362,10 +363,10 @@ public final class DexMerger {
}
}
- private IndexMap getIndexMap(DexBuffer dexBuffer) {
- if (dexBuffer == dexA) {
+ private IndexMap getIndexMap(Dex dex) {
+ if (dex == dexA) {
return aIndexMap;
- } else if (dexBuffer == dexB) {
+ } else if (dex == dexB) {
return bIndexMap;
} else {
throw new IllegalArgumentException();
@@ -378,7 +379,7 @@ public final class DexMerger {
return tableOfContents.stringIds;
}
- @Override String read(DexBuffer.Section in, IndexMap indexMap, int index) {
+ @Override String read(Dex.Section in, IndexMap indexMap, int index) {
return in.readString();
}
@@ -400,7 +401,7 @@ public final class DexMerger {
return tableOfContents.typeIds;
}
- @Override Integer read(DexBuffer.Section in, IndexMap indexMap, int index) {
+ @Override Integer read(Dex.Section in, IndexMap indexMap, int index) {
int stringIndex = in.readInt();
return indexMap.adjustString(stringIndex);
}
@@ -424,7 +425,7 @@ public final class DexMerger {
return tableOfContents.typeLists;
}
- @Override TypeList read(DexBuffer.Section in, IndexMap indexMap, int index) {
+ @Override TypeList read(Dex.Section in, IndexMap indexMap, int index) {
return indexMap.adjustTypeList(in.readTypeList());
}
@@ -444,7 +445,7 @@ public final class DexMerger {
return tableOfContents.protoIds;
}
- @Override ProtoId read(DexBuffer.Section in, IndexMap indexMap, int index) {
+ @Override ProtoId read(Dex.Section in, IndexMap indexMap, int index) {
return indexMap.adjust(in.readProtoId());
}
@@ -467,7 +468,7 @@ public final class DexMerger {
return tableOfContents.fieldIds;
}
- @Override FieldId read(DexBuffer.Section in, IndexMap indexMap, int index) {
+ @Override FieldId read(Dex.Section in, IndexMap indexMap, int index) {
return indexMap.adjust(in.readFieldId());
}
@@ -490,7 +491,7 @@ public final class DexMerger {
return tableOfContents.methodIds;
}
- @Override MethodId read(DexBuffer.Section in, IndexMap indexMap, int index) {
+ @Override MethodId read(Dex.Section in, IndexMap indexMap, int index) {
return indexMap.adjust(in.readMethodId());
}
@@ -513,7 +514,7 @@ public final class DexMerger {
return tableOfContents.annotations;
}
- @Override Annotation read(DexBuffer.Section in, IndexMap indexMap, int index) {
+ @Override Annotation read(Dex.Section in, IndexMap indexMap, int index) {
return indexMap.adjust(in.readAnnotation());
}
@@ -533,7 +534,7 @@ public final class DexMerger {
contentsOut.classDefs.size = types.length;
for (SortableType type : types) {
- DexBuffer in = type.getBuffer();
+ Dex in = type.getDex();
IndexMap indexMap = (in == dexA) ? aIndexMap : bIndexMap;
transformClassDef(in, type.getClassDef(), indexMap);
}
@@ -581,7 +582,7 @@ public final class DexMerger {
* Reads just enough data on each class so that we can sort it and then find
* it later.
*/
- private void readSortableTypes(SortableType[] sortableTypes, DexBuffer buffer,
+ private void readSortableTypes(SortableType[] sortableTypes, Dex buffer,
IndexMap indexMap) {
for (ClassDef classDef : buffer.classDefs()) {
SortableType sortableType = indexMap.adjust(new SortableType(buffer, classDef));
@@ -612,40 +613,40 @@ public final class DexMerger {
transformStaticValues(dexB, bIndexMap);
}
- private void transformAnnotationSets(DexBuffer in, IndexMap indexMap) {
+ private void transformAnnotationSets(Dex in, IndexMap indexMap) {
TableOfContents.Section section = in.getTableOfContents().annotationSets;
if (section.exists()) {
- DexBuffer.Section setIn = in.open(section.off);
+ Dex.Section setIn = in.open(section.off);
for (int i = 0; i < section.size; i++) {
transformAnnotationSet(indexMap, setIn);
}
}
}
- private void transformAnnotationSetRefLists(DexBuffer in, IndexMap indexMap) {
+ private void transformAnnotationSetRefLists(Dex in, IndexMap indexMap) {
TableOfContents.Section section = in.getTableOfContents().annotationSetRefLists;
if (section.exists()) {
- DexBuffer.Section setIn = in.open(section.off);
+ Dex.Section setIn = in.open(section.off);
for (int i = 0; i < section.size; i++) {
transformAnnotationSetRefList(indexMap, setIn);
}
}
}
- private void transformAnnotationDirectories(DexBuffer in, IndexMap indexMap) {
+ private void transformAnnotationDirectories(Dex in, IndexMap indexMap) {
TableOfContents.Section section = in.getTableOfContents().annotationsDirectories;
if (section.exists()) {
- DexBuffer.Section directoryIn = in.open(section.off);
+ Dex.Section directoryIn = in.open(section.off);
for (int i = 0; i < section.size; i++) {
transformAnnotationDirectory(directoryIn, indexMap);
}
}
}
- private void transformStaticValues(DexBuffer in, IndexMap indexMap) {
+ private void transformStaticValues(Dex in, IndexMap indexMap) {
TableOfContents.Section section = in.getTableOfContents().encodedArrays;
if (section.exists()) {
- DexBuffer.Section staticValuesIn = in.open(section.off);
+ Dex.Section staticValuesIn = in.open(section.off);
for (int i = 0; i < section.size; i++) {
transformStaticValues(staticValuesIn, indexMap);
}
@@ -656,7 +657,7 @@ public final class DexMerger {
* Reads a class_def_item beginning at {@code in} and writes the index and
* data.
*/
- private void transformClassDef(DexBuffer in, ClassDef classDef, IndexMap indexMap) {
+ private void transformClassDef(Dex in, ClassDef classDef, IndexMap indexMap) {
idsDefsOut.assertFourByteAligned();
idsDefsOut.writeInt(classDef.getTypeIndex());
idsDefsOut.writeInt(classDef.getAccessFlags());
@@ -686,7 +687,7 @@ public final class DexMerger {
* Transform all annotations on a class.
*/
private void transformAnnotationDirectory(
- DexBuffer.Section directoryIn, IndexMap indexMap) {
+ Dex.Section directoryIn, IndexMap indexMap) {
contentsOut.annotationsDirectories.size++;
annotationsDirectoryOut.assertFourByteAligned();
indexMap.putAnnotationDirectoryOffset(
@@ -734,7 +735,7 @@ public final class DexMerger {
/**
* Transform all annotations on a single type, member or parameter.
*/
- private void transformAnnotationSet(IndexMap indexMap, DexBuffer.Section setIn) {
+ private void transformAnnotationSet(IndexMap indexMap, Dex.Section setIn) {
contentsOut.annotationSets.size++;
annotationSetOut.assertFourByteAligned();
indexMap.putAnnotationSetOffset(setIn.getPosition(), annotationSetOut.getPosition());
@@ -750,7 +751,7 @@ public final class DexMerger {
/**
* Transform all annotation set ref lists.
*/
- private void transformAnnotationSetRefList(IndexMap indexMap, DexBuffer.Section refListIn) {
+ private void transformAnnotationSetRefList(IndexMap indexMap, Dex.Section refListIn) {
contentsOut.annotationSetRefLists.size++;
annotationSetRefListOut.assertFourByteAligned();
indexMap.putAnnotationSetRefListOffset(
@@ -763,7 +764,7 @@ public final class DexMerger {
}
}
- private void transformClassData(DexBuffer in, ClassData classData, IndexMap indexMap) {
+ private void transformClassData(Dex in, ClassData classData, IndexMap indexMap) {
contentsOut.classDatas.size++;
ClassData.Field[] staticFields = classData.getStaticFields();
@@ -792,7 +793,7 @@ public final class DexMerger {
}
}
- private void transformMethods(DexBuffer in, IndexMap indexMap, ClassData.Method[] methods) {
+ private void transformMethods(Dex in, IndexMap indexMap, ClassData.Method[] methods) {
int lastOutMethodIndex = 0;
for (ClassData.Method method : methods) {
int outMethodIndex = indexMap.adjustMethod(method.getMethodIndex());
@@ -811,7 +812,7 @@ public final class DexMerger {
}
}
- private void transformCode(DexBuffer in, Code code, IndexMap indexMap) {
+ private void transformCode(Dex in, Code code, IndexMap indexMap) {
contentsOut.codes.size++;
codeOut.assertFourByteAligned();
@@ -849,7 +850,7 @@ public final class DexMerger {
* Unfortunately they're in the opposite order in the dex file so we
* need to transform them out-of-order.
*/
- DexBuffer.Section triesSection = dexOut.open(codeOut.getPosition());
+ Dex.Section triesSection = dexOut.open(codeOut.getPosition());
codeOut.skip(tries.length * SizeOf.TRY_ITEM);
int[] offsets = transformCatchHandlers(indexMap, catchHandlers);
transformTries(triesSection, tries, offsets);
@@ -870,7 +871,7 @@ public final class DexMerger {
return offsets;
}
- private void transformTries(DexBuffer.Section out, Code.Try[] tries,
+ private void transformTries(Dex.Section out, Code.Try[] tries,
int[] catchHandlerOffsets) {
for (Code.Try tryItem : tries) {
out.writeInt(tryItem.getStartAddress());
@@ -890,7 +891,7 @@ public final class DexMerger {
private static final byte DBG_SET_EPILOGUE_BEGIN = 0x08;
private static final byte DBG_SET_FILE = 0x09;
- private void transformDebugInfoItem(DexBuffer.Section in, IndexMap indexMap) {
+ private void transformDebugInfoItem(Dex.Section in, IndexMap indexMap) {
contentsOut.debugInfos.size++;
int lineStart = in.readUleb128();
debugInfoOut.writeUleb128(lineStart);
@@ -982,7 +983,7 @@ public final class DexMerger {
}
}
- private void transformStaticValues(DexBuffer.Section in, IndexMap indexMap) {
+ private void transformStaticValues(Dex.Section in, IndexMap indexMap) {
contentsOut.encodedArrays.size++;
indexMap.putStaticValuesOffset(in.getPosition(), encodedArrayOut.getPosition());
indexMap.adjustEncodedArray(in.readEncodedArray()).writeTo(encodedArrayOut);
@@ -1017,7 +1018,7 @@ public final class DexMerger {
/**
* Compute sizes for merging a and b.
*/
- public WriterSizes(DexBuffer a, DexBuffer b) {
+ public WriterSizes(Dex a, Dex b) {
plus(a.getTableOfContents(), false);
plus(b.getTableOfContents(), false);
}
@@ -1071,8 +1072,8 @@ public final class DexMerger {
debugInfo += contents.debugInfos.byteCount * 2;
}
- typeList = DexBuffer.fourByteAlign(typeList);
- code = DexBuffer.fourByteAlign(code);
+ typeList = Dex.fourByteAlign(typeList);
+ code = Dex.fourByteAlign(code);
}
public int size() {
@@ -1088,9 +1089,9 @@ public final class DexMerger {
return;
}
- DexBuffer dexA = new DexBuffer(new File(args[1]));
- DexBuffer dexB = new DexBuffer(new File(args[2]));
- DexBuffer merged = new DexMerger(dexA, dexB, CollisionPolicy.KEEP_FIRST).merge();
+ Dex dexA = new Dex(new File(args[1]));
+ Dex dexB = new Dex(new File(args[2]));
+ Dex merged = new DexMerger(dexA, dexB, CollisionPolicy.KEEP_FIRST).merge();
merged.writeTo(new File(args[0]));
}
diff --git a/dx/src/com/android/dx/merge/IndexMap.java b/dx/src/com/android/dx/merge/IndexMap.java
index 9d6ef7abb..739238a0a 100644
--- a/dx/src/com/android/dx/merge/IndexMap.java
+++ b/dx/src/com/android/dx/merge/IndexMap.java
@@ -16,36 +16,37 @@
package com.android.dx.merge;
-import com.android.dx.dex.TableOfContents;
-import com.android.dx.io.Annotation;
-import com.android.dx.io.ClassDef;
-import com.android.dx.io.DexBuffer;
-import com.android.dx.io.EncodedValue;
-import com.android.dx.io.EncodedValueReader;
-import static com.android.dx.io.EncodedValueReader.ENCODED_ANNOTATION;
-import static com.android.dx.io.EncodedValueReader.ENCODED_ARRAY;
-import static com.android.dx.io.EncodedValueReader.ENCODED_BOOLEAN;
-import static com.android.dx.io.EncodedValueReader.ENCODED_BYTE;
-import static com.android.dx.io.EncodedValueReader.ENCODED_CHAR;
-import static com.android.dx.io.EncodedValueReader.ENCODED_DOUBLE;
-import static com.android.dx.io.EncodedValueReader.ENCODED_ENUM;
-import static com.android.dx.io.EncodedValueReader.ENCODED_FIELD;
-import static com.android.dx.io.EncodedValueReader.ENCODED_FLOAT;
-import static com.android.dx.io.EncodedValueReader.ENCODED_INT;
-import static com.android.dx.io.EncodedValueReader.ENCODED_LONG;
-import static com.android.dx.io.EncodedValueReader.ENCODED_METHOD;
-import static com.android.dx.io.EncodedValueReader.ENCODED_NULL;
-import static com.android.dx.io.EncodedValueReader.ENCODED_SHORT;
-import static com.android.dx.io.EncodedValueReader.ENCODED_STRING;
-import static com.android.dx.io.EncodedValueReader.ENCODED_TYPE;
-import com.android.dx.io.FieldId;
-import com.android.dx.io.MethodId;
-import com.android.dx.io.ProtoId;
+import com.android.dex.Annotation;
+import com.android.dex.util.ByteOutput;
+import com.android.dex.ClassDef;
+import com.android.dex.Dex;
+import com.android.dex.DexException;
+import com.android.dex.EncodedValue;
+import com.android.dex.EncodedValueReader;
+import static com.android.dex.EncodedValueReader.ENCODED_ANNOTATION;
+import static com.android.dex.EncodedValueReader.ENCODED_ARRAY;
+import static com.android.dex.EncodedValueReader.ENCODED_BOOLEAN;
+import static com.android.dex.EncodedValueReader.ENCODED_BYTE;
+import static com.android.dex.EncodedValueReader.ENCODED_CHAR;
+import static com.android.dex.EncodedValueReader.ENCODED_DOUBLE;
+import static com.android.dex.EncodedValueReader.ENCODED_ENUM;
+import static com.android.dex.EncodedValueReader.ENCODED_FIELD;
+import static com.android.dex.EncodedValueReader.ENCODED_FLOAT;
+import static com.android.dex.EncodedValueReader.ENCODED_INT;
+import static com.android.dex.EncodedValueReader.ENCODED_LONG;
+import static com.android.dex.EncodedValueReader.ENCODED_METHOD;
+import static com.android.dex.EncodedValueReader.ENCODED_NULL;
+import static com.android.dex.EncodedValueReader.ENCODED_SHORT;
+import static com.android.dex.EncodedValueReader.ENCODED_STRING;
+import static com.android.dex.EncodedValueReader.ENCODED_TYPE;
+import com.android.dex.EncodedValueCodec;
+import com.android.dex.FieldId;
+import com.android.dex.Leb128;
+import com.android.dex.MethodId;
+import com.android.dex.ProtoId;
+import com.android.dex.TableOfContents;
+import com.android.dex.TypeList;
import com.android.dx.util.ByteArrayAnnotatedOutput;
-import com.android.dx.util.ByteOutput;
-import com.android.dx.util.DexException;
-import com.android.dx.util.EncodedValueUtils;
-import com.android.dx.util.Leb128Utils;
import java.util.HashMap;
/**
@@ -54,7 +55,7 @@ import java.util.HashMap;
* {@code strings[5]}.
*/
public final class IndexMap {
- private final DexBuffer target;
+ private final Dex target;
public final int[] stringIds;
public final short[] typeIds;
public final short[] protoIds;
@@ -67,7 +68,7 @@ public final class IndexMap {
private final HashMap<Integer, Integer> annotationDirectoryOffsets;
private final HashMap<Integer, Integer> staticValuesOffsets;
- public IndexMap(DexBuffer target, TableOfContents tableOfContents) {
+ public IndexMap(Dex target, TableOfContents tableOfContents) {
this.target = target;
this.stringIds = new int[tableOfContents.stringIds.size];
this.typeIds = new short[tableOfContents.typeIds.size];
@@ -219,7 +220,7 @@ public final class IndexMap {
}
public SortableType adjust(SortableType sortableType) {
- return new SortableType(sortableType.getBuffer(), adjust(sortableType.getClassDef()));
+ return new SortableType(sortableType.getDex(), adjust(sortableType.getClassDef()));
}
public EncodedValue adjustEncodedValue(EncodedValue encodedValue) {
@@ -257,47 +258,47 @@ public final class IndexMap {
// TODO: extract this into a helper class, EncodedValueWriter
switch (reader.peek()) {
case ENCODED_BYTE:
- EncodedValueUtils.writeSignedIntegralValue(out, ENCODED_BYTE, reader.readByte());
+ EncodedValueCodec.writeSignedIntegralValue(out, ENCODED_BYTE, reader.readByte());
break;
case ENCODED_SHORT:
- EncodedValueUtils.writeSignedIntegralValue(out, ENCODED_SHORT, reader.readShort());
+ EncodedValueCodec.writeSignedIntegralValue(out, ENCODED_SHORT, reader.readShort());
break;
case ENCODED_INT:
- EncodedValueUtils.writeSignedIntegralValue(out, ENCODED_INT, reader.readInt());
+ EncodedValueCodec.writeSignedIntegralValue(out, ENCODED_INT, reader.readInt());
break;
case ENCODED_LONG:
- EncodedValueUtils.writeSignedIntegralValue(out, ENCODED_LONG, reader.readLong());
+ EncodedValueCodec.writeSignedIntegralValue(out, ENCODED_LONG, reader.readLong());
break;
case ENCODED_CHAR:
- EncodedValueUtils.writeUnsignedIntegralValue(out, ENCODED_CHAR, reader.readChar());
+ EncodedValueCodec.writeUnsignedIntegralValue(out, ENCODED_CHAR, reader.readChar());
break;
case ENCODED_FLOAT:
// Shift value left 32 so that right-zero-extension works.
long longBits = ((long) Float.floatToIntBits(reader.readFloat())) << 32;
- EncodedValueUtils.writeRightZeroExtendedValue(out, ENCODED_FLOAT, longBits);
+ EncodedValueCodec.writeRightZeroExtendedValue(out, ENCODED_FLOAT, longBits);
break;
case ENCODED_DOUBLE:
- EncodedValueUtils.writeRightZeroExtendedValue(
+ EncodedValueCodec.writeRightZeroExtendedValue(
out, ENCODED_DOUBLE, Double.doubleToLongBits(reader.readDouble()));
break;
case ENCODED_STRING:
- EncodedValueUtils.writeUnsignedIntegralValue(
+ EncodedValueCodec.writeUnsignedIntegralValue(
out, ENCODED_STRING, adjustString(reader.readString()));
break;
case ENCODED_TYPE:
- EncodedValueUtils.writeUnsignedIntegralValue(
+ EncodedValueCodec.writeUnsignedIntegralValue(
out, ENCODED_TYPE, adjustType(reader.readType()));
break;
case ENCODED_FIELD:
- EncodedValueUtils.writeUnsignedIntegralValue(
+ EncodedValueCodec.writeUnsignedIntegralValue(
out, ENCODED_FIELD, adjustField(reader.readField()));
break;
case ENCODED_ENUM:
- EncodedValueUtils.writeUnsignedIntegralValue(
+ EncodedValueCodec.writeUnsignedIntegralValue(
out, ENCODED_ENUM, adjustField(reader.readEnum()));
break;
case ENCODED_METHOD:
- EncodedValueUtils.writeUnsignedIntegralValue(
+ EncodedValueCodec.writeUnsignedIntegralValue(
out, ENCODED_METHOD, adjustMethod(reader.readMethod()));
break;
case ENCODED_ARRAY:
@@ -323,17 +324,17 @@ public final class IndexMap {
private void transformAnnotation(EncodedValueReader reader) {
int fieldCount = reader.readAnnotation();
- Leb128Utils.writeUnsignedLeb128(out, adjustType(reader.getAnnotationType()));
- Leb128Utils.writeUnsignedLeb128(out, fieldCount);
+ Leb128.writeUnsignedLeb128(out, adjustType(reader.getAnnotationType()));
+ Leb128.writeUnsignedLeb128(out, fieldCount);
for (int i = 0; i < fieldCount; i++) {
- Leb128Utils.writeUnsignedLeb128(out, adjustString(reader.readAnnotationName()));
+ Leb128.writeUnsignedLeb128(out, adjustString(reader.readAnnotationName()));
transform(reader);
}
}
private void transformArray(EncodedValueReader reader) {
int size = reader.readArray();
- Leb128Utils.writeUnsignedLeb128(out, size);
+ Leb128.writeUnsignedLeb128(out, size);
for (int i = 0; i < size; i++) {
transform(reader);
}
diff --git a/dx/src/com/android/dx/merge/InstructionTransformer.java b/dx/src/com/android/dx/merge/InstructionTransformer.java
index 6051e17d8..aa67a8815 100644
--- a/dx/src/com/android/dx/merge/InstructionTransformer.java
+++ b/dx/src/com/android/dx/merge/InstructionTransformer.java
@@ -16,11 +16,11 @@
package com.android.dx.merge;
+import com.android.dex.DexException;
import com.android.dx.io.CodeReader;
import com.android.dx.io.Opcodes;
import com.android.dx.io.instructions.DecodedInstruction;
import com.android.dx.io.instructions.ShortArrayCodeOutput;
-import com.android.dx.util.DexException;
final class InstructionTransformer {
private final IndexMap indexMap;
diff --git a/dx/src/com/android/dx/merge/SortableType.java b/dx/src/com/android/dx/merge/SortableType.java
index 838ea28aa..2ae68fb23 100644
--- a/dx/src/com/android/dx/merge/SortableType.java
+++ b/dx/src/com/android/dx/merge/SortableType.java
@@ -16,8 +16,8 @@
package com.android.dx.merge;
-import com.android.dx.io.ClassDef;
-import com.android.dx.io.DexBuffer;
+import com.android.dex.ClassDef;
+import com.android.dex.Dex;
import java.util.Comparator;
/**
@@ -43,17 +43,17 @@ final class SortableType {
}
};
- private final DexBuffer buffer;
+ private final Dex dex;
private ClassDef classDef;
private int depth = -1;
- public SortableType(DexBuffer buffer, ClassDef classDef) {
- this.buffer = buffer;
+ public SortableType(Dex dex, ClassDef classDef) {
+ this.dex = dex;
this.classDef = classDef;
}
- public DexBuffer getBuffer() {
- return buffer;
+ public Dex getDex() {
+ return dex;
}
public ClassDef getClassDef() {
diff --git a/dx/src/com/android/dx/merge/TypeList.java b/dx/src/com/android/dx/merge/TypeList.java
deleted file mode 100644
index 62984e2b7..000000000
--- a/dx/src/com/android/dx/merge/TypeList.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.dx.merge;
-
-import com.android.dx.io.DexBuffer;
-import com.android.dx.util.Unsigned;
-import java.util.Arrays;
-
-public final class TypeList implements Comparable<TypeList> {
-
- public static final TypeList EMPTY = new TypeList(null, new short[0]);
-
- private final DexBuffer buffer;
- private final short[] types;
-
- public TypeList(DexBuffer buffer, short[] types) {
- this.buffer = buffer;
- this.types = types;
- }
-
- public short[] getTypes() {
- return types;
- }
-
- public int compareTo(TypeList other) {
- for (int i = 0; i < types.length && i < other.types.length; i++) {
- if (types[i] != other.types[i]) {
- return Unsigned.compare(types[i], other.types[i]);
- }
- }
- return Unsigned.compare(types.length, other.types.length);
- }
-
- @Override public String toString() {
- StringBuilder result = new StringBuilder();
- result.append("(");
- for (int i = 0, typesLength = types.length; i < typesLength; i++) {
- result.append(buffer != null ? buffer.typeNames().get(types[i]) : types[i]);
- }
- result.append(")");
- return result.toString();
- }
-}