Misc cleanup

git-svn-id: https://smali.googlecode.com/svn/trunk@202 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-06-21 08:22:27 +00:00
parent ed91584410
commit f730ada982
10 changed files with 24 additions and 43 deletions

View File

@ -124,15 +124,15 @@ public class AnnotationDirectoryItem extends OffsettedItem<AnnotationDirectoryIt
}
public List<MethodAnnotation> getMethodAnnotations() {
return (List<MethodAnnotation>)methodAnnotationList.clone();
return Collections.unmodifiableList(methodAnnotationList);
}
public List<FieldAnnotation> getFieldAnnotations() {
return (List<FieldAnnotation>)fieldAnnotationList.clone();
return Collections.unmodifiableList(fieldAnnotationList);
}
public List<ParameterAnnotation> getParameterAnnotations() {
return (List<ParameterAnnotation>)parameterAnnotationList.clone();
return Collections.unmodifiableList(parameterAnnotationList);
}

View File

@ -36,6 +36,7 @@ import org.jf.dexlib.util.Input;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Collections;
public class CodeItem extends OffsettedItem<CodeItem> {
private final ArrayList<InstructionField> instructionList;
@ -119,11 +120,11 @@ public class CodeItem extends OffsettedItem<CodeItem> {
}
public List<InstructionField> getInstructions() {
return (List<InstructionField>)instructionList.clone();
return Collections.unmodifiableList(instructionList);
}
public List<TryItem> getTries() {
return (List<TryItem>)tryItems.clone();
return Collections.unmodifiableList(tryItems);
}
public DebugInfoItem getDebugInfo() {
@ -437,18 +438,8 @@ public class CodeItem extends OffsettedItem<CodeItem> {
}
}
//TODO: GROT
public int getHandlerCount() {
return list.size();
}
//TODO: GROT
public EncodedTypeAddrPair getHandler(int index) {
return list.get(index);
}
public List<EncodedTypeAddrPair> getHandlers() {
return (List<EncodedTypeAddrPair>)list.clone();
return Collections.unmodifiableList(list);
}
}

View File

@ -36,6 +36,7 @@ import org.jf.dexlib.util.Input;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
public class DebugInfoItem extends OffsettedItem<DebugInfoItem> {
private final ArrayList<IndexedItemReference<StringIdItem>> parameterNames =
@ -95,7 +96,7 @@ public class DebugInfoItem extends OffsettedItem<DebugInfoItem> {
}
public List<DebugInstruction> getDebugInstructions() {
return (List<DebugInstruction>)instructionFields.clone();
return Collections.unmodifiableList(instructionFields);
}
public List<String> getParameterNames() {

View File

@ -86,6 +86,6 @@ public class AnnotationEncodedValueSubField extends CompositeField<AnnotationEnc
}
public List<AnnotationElement> getAnnotationElements() {
return (List<AnnotationElement>)annotationElementList.clone();
return Collections.unmodifiableList(annotationElementList);
}
}

View File

@ -32,6 +32,7 @@ import org.jf.dexlib.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
public class ArrayEncodedValueSubField extends CompositeField<ArrayEncodedValueSubField>
implements EncodedValueSubField<ArrayEncodedValueSubField>
@ -85,6 +86,6 @@ public class ArrayEncodedValueSubField extends CompositeField<ArrayEncodedValueS
}
public List<EncodedValue> getValues() {
return (List<EncodedValue>)encodedValues.clone();
return Collections.unmodifiableList(encodedValues);
}
}

View File

@ -29,29 +29,22 @@
package org.jf.dexlib;
import org.jf.dexlib.util.AnnotatedOutput;
import org.jf.dexlib.util.ByteArray;
import org.jf.dexlib.util.Input;
public class FixedByteArrayField implements Field<FixedByteArrayField> {
public class FixedSizeByteArrayField implements Field<FixedSizeByteArrayField> {
protected byte[] value;
private final String fieldName;
public FixedByteArrayField(int size, String fieldName) {
public FixedSizeByteArrayField(int size, String fieldName) {
value = new byte[size];
this.fieldName = fieldName;
}
public FixedByteArrayField(byte[] bytes, String fieldName) {
public FixedSizeByteArrayField(byte[] bytes, String fieldName) {
this.value = bytes.clone();
this.fieldName = fieldName;
}
public FixedByteArrayField(ByteArray byteArray, String fieldName) {
value = new byte[byteArray.size()];
byteArray.getBytes(value, 0);
this.fieldName = fieldName;
}
public void writeTo(AnnotatedOutput out) {
if (fieldName != null) {
out.annotate(fieldName);
@ -67,7 +60,7 @@ public class FixedByteArrayField implements Field<FixedByteArrayField> {
return offset + value.length;
}
public void copyTo(DexFile dexFile, FixedByteArrayField copy) {
public void copyTo(DexFile dexFile, FixedSizeByteArrayField copy) {
copy.value = value.clone();
}
}

View File

@ -45,9 +45,9 @@ public class HeaderItem extends IndexedItem<HeaderItem> {
/** the endianness tag */
private static final int ENDIAN_TAG = 0x12345678;
private final FixedByteArrayField magicField;
private final FixedSizeByteArrayField magicField;
private final IntegerField checksumField;
private final FixedByteArrayField signatureField;
private final FixedSizeByteArrayField signatureField;
private final IntegerField fileSizeField;
private final IntegerField headerSizeField;
private final IntegerField endianTagField;
@ -69,14 +69,14 @@ public class HeaderItem extends IndexedItem<HeaderItem> {
try
{
fields = new Field[] {
magicField = new FixedByteArrayField(MAGIC.getBytes("US-ASCII"), "magic"),
magicField = new FixedSizeByteArrayField(MAGIC.getBytes("US-ASCII"), "magic"),
checksumField = new IntegerField("checksum") {
public void writeTo(AnnotatedOutput out) {
cacheValue(0);
super.writeTo(out);
}
},
signatureField = new FixedByteArrayField(20, "signature") {
signatureField = new FixedSizeByteArrayField(20, "signature") {
public void writeTo(AnnotatedOutput out) {
for (int i = 0; i < value.length; i++) {
value[i] = 0;

View File

@ -45,12 +45,6 @@ public class NullTerminatedByteArrayField implements Field<NullTerminatedByteArr
this.value = value.clone();
}
public NullTerminatedByteArrayField(ByteArray byteArray, String fieldName) {
this(fieldName);
value = new byte[byteArray.size()];
byteArray.getBytes(value, 0);
}
public void writeTo(AnnotatedOutput out) {
out.annotate(fieldName);
out.write(value);

View File

@ -65,7 +65,6 @@ public abstract class OffsettedSection<T extends OffsettedItem<T>> extends Secti
T item = getByOffset(in.getCursor());
item.readFrom(in, i);
//TODO: why are we aligning afterwards?
in.alignTo(item.getAlignment());
}
//sort the items list by offset

View File

@ -65,10 +65,12 @@ public class TryListBuilderTest
Assert.assertTrue(encodedCatchHandler.getCatchAllAddress() == catchAllAddress);
Assert.assertTrue(encodedCatchHandler.getHandlerCount() == handlers.length);
List<CodeItem.EncodedTypeAddrPair> typeAddrPairs = encodedCatchHandler.getHandlers();
Assert.assertTrue(typeAddrPairs.size() == handlers.length);
for (int i=0; i<handlers.length; i++) {
CodeItem.EncodedTypeAddrPair typeAddrPair = encodedCatchHandler.getHandler(i);
CodeItem.EncodedTypeAddrPair typeAddrPair = typeAddrPairs.get(i);
Handler handler = handlers[i];
Assert.assertTrue(typeAddrPair.getTypeReferenceField().getTypeDescriptor().compareTo(handler.type) == 0);