add getPosition() to LocalVariable

This commit is contained in:
Volker Berlin 2017-04-09 22:21:47 +02:00
parent 14dc89aacb
commit 68aaa5c589
2 changed files with 231 additions and 219 deletions

View File

@ -34,11 +34,9 @@ public class LocalVariable {
private int index;
private boolean declared;
private int position;
protected LocalVariable() {
// nothing
}
private boolean declared;
/**
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13
@ -47,23 +45,35 @@ public class LocalVariable {
* @param input
* the stream of the class
* @throws IOException
* if any I/O error occurs.
*/
LocalVariable( DataInputStream input ) throws IOException {
LocalVariable( DataInputStream input, int position ) throws IOException {
start_pc = input.readUnsignedShort();
length = input.readUnsignedShort();
name_index = input.readUnsignedShort();
descriptor_index = input.readUnsignedShort();
index = input.readUnsignedShort();
this.position = position;
}
/**
* Get the index in the local variable table.
* Get the index in the local variable table (memory location/slot).
*
* @return the index.
*/
public int getIndex() {
return index;
}
/**
* Get the position in the local variable table.
*
* @return the position
*/
public int getPosition() {
return position;
}
/**
* Get the name of the variable
* @param constantPool ConstantPool of the current class

View File

@ -47,8 +47,10 @@ public class LocalVariableTable {
*
* @param input
* the stream of the class
* @param withPositions a hack if we find a better solution to map the positions LocalVariableTypeTable
* @param withPositions
* a hack if we find a better solution to map the positions LocalVariableTypeTable
* @throws IOException
* if any I/O error occurs.
*/
void read( DataInputStream input, boolean withPositions ) throws IOException {
count = input.readUnsignedShort();
@ -57,7 +59,7 @@ public class LocalVariableTable {
tablePosition = new LocalVariable[count];
}
for( int i = 0; i < count; i++ ) {
LocalVariable var = new LocalVariable( input );
LocalVariable var = new LocalVariable( input, i );
int idx = var.getIndex();
if( withPositions ) {
tablePosition[i] = var;
@ -95,7 +97,7 @@ public class LocalVariableTable {
}
/**
* Get the LocalVariable with its memory location. The index has empty places with double and long variables.
* Get the LocalVariable with its memory location (slot). The index has empty places with double and long variables.
*
* @param idx
* the index in the memory