* @return a map of element offsets in class file data.
*/
public Map<Object, Range> getOffsetMap() {
Map<Object, Range> map = new HashMap<Object, Range>();
int offset = 0;
map.put(OffsetTag.MAGIC, new Range(offset, 4));
offset += 4;
map.put(OffsetTag.VERSION, new Range(offset, 4));
map.put(OffsetTag.MINOR_VERSION, new Range(offset, 2));
offset += 2;
map.put(OffsetTag.MAJOR_VERSION, new Range(offset, 2));
offset += 2;
int poolSize = this.pool.getData().length;
map.put(OffsetTag.CONSTANT_POOL, new Range(offset, poolSize));
// TODO: offsets for each pool item?
offset += poolSize;
map.put(OffsetTag.ACCESS_FLAGS, new Range(offset, 2));
offset += 2;
map.put(OffsetTag.THIS_CLASS, new Range(offset, 2));
offset += 2;
map.put(OffsetTag.SUPER_CLASS, new Range(offset, 2));
offset += 2;
map.put(OffsetTag.INTERFACE_COUNT, new Range(offset, 2));
offset += 2;
map.put(OffsetTag.INTERFACE_DATA, new Range(offset, this.interfaces.size()*2));
{
for (Interface anInterface : this.interfaces) {
map.put(anInterface, new Range(offset, 2));
offset += 2;
}
}
map.put(OffsetTag.FIELD_COUNT, new Range(offset, 2));
offset += 2;
int fieldDataTotalSize = 0;
Range fieldDataOffset = new Range(offset, 0);
map.put(OffsetTag.FIELD_DATA, fieldDataOffset);
for (Field field : this.fields) {
int fieldSize = field.getData().length;
map.put(field, new Range(offset, fieldSize));
offset += fieldSize;
fieldDataTotalSize += fieldSize;
}
fieldDataOffset.setSize(fieldDataTotalSize);
map.put(OffsetTag.METHOD_COUNT, new Range(offset, 2));
offset += 2;
int methodDataTotalSize = 0;
Range methodDataOffset = new Range(offset, 0);
map.put(OffsetTag.METHOD_DATA, methodDataOffset);
for (Method method : this.methods) {
int methodSize = method.getData().length;
map.put(method, new Range(offset, methodSize));
offset += methodSize;
methodDataTotalSize += methodSize;
}
methodDataOffset.setSize(methodDataTotalSize);
map.put(OffsetTag.ATTRIBUTES, new Range(offset, this.attributes.getData().length));
return map;
}