Refactor the MethodAnalyzer API so that the instructions are returned as a read-only list

git-svn-id: https://smali.googlecode.com/svn/trunk@662 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com
2010-03-03 03:26:17 +00:00
parent 7974e53f15
commit ef24b31c98
4 changed files with 51 additions and 57 deletions

View File

@ -170,6 +170,8 @@ public class AnalyzedInstruction implements Comparable<AnalyzedInstruction> {
* @return a boolean value indicating whether this instruction is a beginning instruction
*/
public boolean isBeginningInstruction() {
//if this instruction has no predecessors, it is either the fake "StartOfMethod" instruction or it is an
//unreachable instruction.
if (predecessors.size() == 0) {
return false;
}

View File

@ -110,12 +110,13 @@ public class MethodAnalyzer {
return analyzerState == VERIFIED;
}
public AnalyzedInstruction[] analyze() {
public void analyze() {
assert encodedMethod != null;
assert encodedMethod.codeItem != null;
if (analyzerState >= ANALYZED) {
return makeInstructionArray();
//the instructions have already been analyzed, so there is nothing to do
return;
}
CodeItem codeItem = encodedMethod.codeItem;
@ -273,7 +274,6 @@ public class MethodAnalyzer {
}
analyzerState = ANALYZED;
return makeInstructionArray();
}
private int getThisRegister() {
@ -309,12 +309,11 @@ public class MethodAnalyzer {
return startOfMethod;
}
public AnalyzedInstruction[] makeInstructionArray() {
AnalyzedInstruction[] instructionArray = new AnalyzedInstruction[instructions.size()];
for (int i=0; i<instructions.size(); i++) {
instructionArray[i] = instructions.valueAt(i);
}
return instructionArray;
/**
* @return a read-only list containing the instructions for tihs method.
*/
public List<AnalyzedInstruction> getInstructions() {
return instructions.getValues();
}
public ValidationException getValidationException() {

View File

@ -16,6 +16,10 @@
package org.jf.dexlib.Util;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* SparseArrays map integers to Objects. Unlike a normal array of Objects,
* there can be gaps in the indices. It is intended to be more efficient
@ -340,6 +344,14 @@ public class SparseArray<E> {
return ~high;
}
/**
* @return a read-only list of the values in this SparseArray which are in ascending order, based on their
* associated key
*/
public List<E> getValues() {
return Collections.unmodifiableList(Arrays.asList((E[])mValues));
}
private int[] mKeys;
private Object[] mValues;
private int mSize;