Not sure if it's a bug in the compiler or the ksy. Very cool project idea :)
//This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
import io.kaitai.struct.KaitaiStruct;
import io.kaitai.struct.KaitaiStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class JavaClass extends KaitaiStruct {
public static JavaClass fromFile(String fileName) throws IOException {
return new JavaClass(new KaitaiStream(fileName));
}
public JavaClass(KaitaiStream _io) throws IOException {
super(_io);
this._root = this;
_parse();
}
public JavaClass(KaitaiStream _io, KaitaiStruct _parent) throws IOException {
super(_io);
this._parent = _parent;
this._root = this;
_parse();
}
public JavaClass(KaitaiStream _io, KaitaiStruct _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.magic = _io.ensureFixedContents(4, new byte[] { -54, -2, -70, -66 });
this.versionMinor = _io.readU2be();
this.versionMajor = _io.readU2be();
this.constantPoolCount = _io.readU2be();
constantPool = new ArrayList<ConstantPoolEntry>((int) ((constantPoolCount() - 1)));
for (int i = 0; i < (constantPoolCount() - 1); i++) {
this.constantPool.add(new ConstantPoolEntry(_io, this, _root));
}
this.accessFlags = _io.readU2be();
this.thisClass = _io.readU2be();
this.superClass = _io.readU2be();
this.interfacesCount = _io.readU2be();
interfaces = new ArrayList<Integer>((int) (interfacesCount()));
for (int i = 0; i < interfacesCount(); i++) {
this.interfaces.add(_io.readU2be());
}
this.fieldsCount = _io.readU2be();
fields = new ArrayList<FieldInfo>((int) (fieldsCount()));
for (int i = 0; i < fieldsCount(); i++) {
this.fields.add(new FieldInfo(_io, this, _root));
}
this.methodsCount = _io.readU2be();
methods = new ArrayList<MethodInfo>((int) (methodsCount()));
for (int i = 0; i < methodsCount(); i++) {
this.methods.add(new MethodInfo(_io, this, _root));
}
}
public static class MethodRefCpInfo extends KaitaiStruct {
public static MethodRefCpInfo fromFile(String fileName) throws IOException {
return new MethodRefCpInfo(new KaitaiStream(fileName));
}
public MethodRefCpInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public MethodRefCpInfo(KaitaiStream _io, ConstantPoolEntry _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public MethodRefCpInfo(KaitaiStream _io, ConstantPoolEntry _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.classIndex = _io.readU2be();
this.nameAndTypeIndex = _io.readU2be();
}
private int classIndex;
private int nameAndTypeIndex;
private JavaClass _root;
private JavaClass.ConstantPoolEntry _parent;
public int classIndex() { return classIndex; }
public int nameAndTypeIndex() { return nameAndTypeIndex; }
public JavaClass _root() { return _root; }
public JavaClass.ConstantPoolEntry _parent() { return _parent; }
}
public static class FieldInfo extends KaitaiStruct {
public static FieldInfo fromFile(String fileName) throws IOException {
return new FieldInfo(new KaitaiStream(fileName));
}
public FieldInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public FieldInfo(KaitaiStream _io, JavaClass _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public FieldInfo(KaitaiStream _io, JavaClass _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.accessFlags = _io.readU2be();
this.nameIndex = _io.readU2be();
this.descriptorIndex = _io.readU2be();
this.attributesCount = _io.readU2be();
attributes = new ArrayList<Attribute>((int) (attributesCount()));
for (int i = 0; i < attributesCount(); i++) {
this.attributes.add(new Attribute(_io, this, _root));
}
}
private int accessFlags;
private int nameIndex;
private int descriptorIndex;
private int attributesCount;
private ArrayList<Attribute> attributes;
private JavaClass _root;
private JavaClass _parent;
public int accessFlags() { return accessFlags; }
public int nameIndex() { return nameIndex; }
public int descriptorIndex() { return descriptorIndex; }
public int attributesCount() { return attributesCount; }
public ArrayList<Attribute> attributes() { return attributes; }
public JavaClass _root() { return _root; }
public JavaClass _parent() { return _parent; }
}
public static class NameAndTypeCpInfo extends KaitaiStruct {
public static NameAndTypeCpInfo fromFile(String fileName) throws IOException {
return new NameAndTypeCpInfo(new KaitaiStream(fileName));
}
public NameAndTypeCpInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public NameAndTypeCpInfo(KaitaiStream _io, ConstantPoolEntry _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public NameAndTypeCpInfo(KaitaiStream _io, ConstantPoolEntry _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.nameIndex = _io.readU2be();
this.descriptorIndex = _io.readU2be();
}
private int nameIndex;
private int descriptorIndex;
private JavaClass _root;
private JavaClass.ConstantPoolEntry _parent;
public int nameIndex() { return nameIndex; }
public int descriptorIndex() { return descriptorIndex; }
public JavaClass _root() { return _root; }
public JavaClass.ConstantPoolEntry _parent() { return _parent; }
}
public static class Utf8CpInfo extends KaitaiStruct {
public static Utf8CpInfo fromFile(String fileName) throws IOException {
return new Utf8CpInfo(new KaitaiStream(fileName));
}
public Utf8CpInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public Utf8CpInfo(KaitaiStream _io, ConstantPoolEntry _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public Utf8CpInfo(KaitaiStream _io, ConstantPoolEntry _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.strLen = _io.readU2be();
this.value = _io.readStrByteLimit(strLen(), "UTF-8");
}
private int strLen;
private String value;
private JavaClass _root;
private JavaClass.ConstantPoolEntry _parent;
public int strLen() { return strLen; }
public String value() { return value; }
public JavaClass _root() { return _root; }
public JavaClass.ConstantPoolEntry _parent() { return _parent; }
}
public static class InterfaceMethodRefCpInfo extends KaitaiStruct {
public static InterfaceMethodRefCpInfo fromFile(String fileName) throws IOException {
return new InterfaceMethodRefCpInfo(new KaitaiStream(fileName));
}
public InterfaceMethodRefCpInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public InterfaceMethodRefCpInfo(KaitaiStream _io, ConstantPoolEntry _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public InterfaceMethodRefCpInfo(KaitaiStream _io, ConstantPoolEntry _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.classIndex = _io.readU2be();
this.nameAndTypeIndex = _io.readU2be();
}
private int classIndex;
private int nameAndTypeIndex;
private JavaClass _root;
private JavaClass.ConstantPoolEntry _parent;
public int classIndex() { return classIndex; }
public int nameAndTypeIndex() { return nameAndTypeIndex; }
public JavaClass _root() { return _root; }
public JavaClass.ConstantPoolEntry _parent() { return _parent; }
}
public static class Attribute extends KaitaiStruct {
public static Attribute fromFile(String fileName) throws IOException {
return new Attribute(new KaitaiStream(fileName));
}
public Attribute(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public Attribute(KaitaiStream _io, FieldInfo _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public Attribute(KaitaiStream _io, FieldInfo _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.attributeNameIndex = _io.readU2be();
this.attributeLength = _io.readU4be();
this.info = _io.readBytes(attributeLength());
}
private int attributeNameIndex;
private long attributeLength;
private byte[] info;
private JavaClass _root;
private JavaClass.FieldInfo _parent;
public int attributeNameIndex() { return attributeNameIndex; }
public long attributeLength() { return attributeLength; }
public byte[] info() { return info; }
public JavaClass _root() { return _root; }
public JavaClass.FieldInfo _parent() { return _parent; }
}
public static class ClassCpInfo extends KaitaiStruct {
public static ClassCpInfo fromFile(String fileName) throws IOException {
return new ClassCpInfo(new KaitaiStream(fileName));
}
public ClassCpInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public ClassCpInfo(KaitaiStream _io, ConstantPoolEntry _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public ClassCpInfo(KaitaiStream _io, ConstantPoolEntry _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.nameIndex = _io.readU2be();
}
private ConstantPoolEntry name;
public ConstantPoolEntry name() throws IOException {
if (name != null)
return name;
name = _root.constantPool().get((nameIndex() - 1));
return name;
}
private int nameIndex;
private JavaClass _root;
private JavaClass.ConstantPoolEntry _parent;
public int nameIndex() { return nameIndex; }
public JavaClass _root() { return _root; }
public JavaClass.ConstantPoolEntry _parent() { return _parent; }
}
public static class ConstantPoolEntry extends KaitaiStruct {
public static ConstantPoolEntry fromFile(String fileName) throws IOException {
return new ConstantPoolEntry(new KaitaiStream(fileName));
}
public ConstantPoolEntry(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public ConstantPoolEntry(KaitaiStream _io, JavaClass _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public ConstantPoolEntry(KaitaiStream _io, JavaClass _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.tag = Tag.byId(_io.readU1());
if (tag() == Tag.UTF8) {
this.utf8CpInfo = new Utf8CpInfo(_io, this, _root);
}
if (tag() == Tag.CLASS) {
this.classCpInfo = new ClassCpInfo(_io, this, _root);
}
if (tag() == Tag.NAME_AND_TYPE) {
this.nameAndTypeCpInfo = new NameAndTypeCpInfo(_io, this, _root);
}
if (tag() == Tag.FIELD_REF) {
this.fieldRefCpInfo = new FieldRefCpInfo(_io, this, _root);
}
if (tag() == Tag.METHOD_REF) {
this.methodRefCpInfo = new MethodRefCpInfo(_io, this, _root);
}
if (tag() == Tag.INTERFACE_METHOD_REF) {
this.interfaceMethodRefCpInfo = new InterfaceMethodRefCpInfo(_io, this, _root);
}
}
private Tag tag;
private Utf8CpInfo utf8CpInfo;
private ClassCpInfo classCpInfo;
private NameAndTypeCpInfo nameAndTypeCpInfo;
private FieldRefCpInfo fieldRefCpInfo;
private MethodRefCpInfo methodRefCpInfo;
private InterfaceMethodRefCpInfo interfaceMethodRefCpInfo;
private JavaClass _root;
private JavaClass _parent;
public Tag tag() { return tag; }
public Utf8CpInfo utf8CpInfo() { return utf8CpInfo; }
public ClassCpInfo classCpInfo() { return classCpInfo; }
public NameAndTypeCpInfo nameAndTypeCpInfo() { return nameAndTypeCpInfo; }
public FieldRefCpInfo fieldRefCpInfo() { return fieldRefCpInfo; }
public MethodRefCpInfo methodRefCpInfo() { return methodRefCpInfo; }
public InterfaceMethodRefCpInfo interfaceMethodRefCpInfo() { return interfaceMethodRefCpInfo; }
public JavaClass _root() { return _root; }
public JavaClass _parent() { return _parent; }
public enum Tag {
LONG(5),
METHOD_REF(10),
UTF8(1),
DOUBLE(6),
FIELD_REF(9),
NAME_AND_TYPE(12),
CLASS(7),
INTEGER(3),
INVOKE_DYNAMIC(18),
METHOD_TYPE(16),
INTERFACE_METHOD_REF(11),
STRING(8),
FLOAT(4),
METHOD_HANDLE(15);
private final long id;
Tag(long id) { this.id = id; }
public long id() { return id; }
private static final Map<Long, Tag> byId = new HashMap<Long, Tag>(14);
static {
for (Tag e : Tag.values())
byId.put(e.id(), e);
}
public static Tag byId(long id) { return byId.get(id); }
}
}
public static class MethodInfo extends KaitaiStruct {
public static MethodInfo fromFile(String fileName) throws IOException {
return new MethodInfo(new KaitaiStream(fileName));
}
public MethodInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public MethodInfo(KaitaiStream _io, JavaClass _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public MethodInfo(KaitaiStream _io, JavaClass _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.accessFlags = _io.readU2be();
this.nameIndex = _io.readU2be();
this.descriptorIndex = _io.readU2be();
this.attributesCount = _io.readU2be();
attributes = new ArrayList<Attribute>((int) (attributesCount()));
for (int i = 0; i < attributesCount(); i++) {
this.attributes.add(new Attribute(_io, this, _root));
}
}
private int accessFlags;
private int nameIndex;
private int descriptorIndex;
private int attributesCount;
private ArrayList<Attribute> attributes;
private JavaClass _root;
private JavaClass _parent;
public int accessFlags() { return accessFlags; }
public int nameIndex() { return nameIndex; }
public int descriptorIndex() { return descriptorIndex; }
public int attributesCount() { return attributesCount; }
public ArrayList<Attribute> attributes() { return attributes; }
public JavaClass _root() { return _root; }
public JavaClass _parent() { return _parent; }
}
public static class FieldRefCpInfo extends KaitaiStruct {
public static FieldRefCpInfo fromFile(String fileName) throws IOException {
return new FieldRefCpInfo(new KaitaiStream(fileName));
}
public FieldRefCpInfo(KaitaiStream _io) throws IOException {
super(_io);
_parse();
}
public FieldRefCpInfo(KaitaiStream _io, ConstantPoolEntry _parent) throws IOException {
super(_io);
this._parent = _parent;
_parse();
}
public FieldRefCpInfo(KaitaiStream _io, ConstantPoolEntry _parent, JavaClass _root) throws IOException {
super(_io);
this._parent = _parent;
this._root = _root;
_parse();
}
private void _parse() throws IOException {
this.classIndex = _io.readU2be();
this.nameAndTypeIndex = _io.readU2be();
}
private int classIndex;
private int nameAndTypeIndex;
private JavaClass _root;
private JavaClass.ConstantPoolEntry _parent;
public int classIndex() { return classIndex; }
public int nameAndTypeIndex() { return nameAndTypeIndex; }
public JavaClass _root() { return _root; }
public JavaClass.ConstantPoolEntry _parent() { return _parent; }
}
private byte[] magic;
private int versionMinor;
private int versionMajor;
private int constantPoolCount;
private ArrayList<ConstantPoolEntry> constantPool;
private int accessFlags;
private int thisClass;
private int superClass;
private int interfacesCount;
private ArrayList<Integer> interfaces;
private int fieldsCount;
private ArrayList<FieldInfo> fields;
private int methodsCount;
private ArrayList<MethodInfo> methods;
private JavaClass _root;
private KaitaiStruct _parent;
public byte[] magic() { return magic; }
public int versionMinor() { return versionMinor; }
public int versionMajor() { return versionMajor; }
public int constantPoolCount() { return constantPoolCount; }
public ArrayList<ConstantPoolEntry> constantPool() { return constantPool; }
public int accessFlags() { return accessFlags; }
public int thisClass() { return thisClass; }
public int superClass() { return superClass; }
public int interfacesCount() { return interfacesCount; }
public ArrayList<Integer> interfaces() { return interfaces; }
public int fieldsCount() { return fieldsCount; }
public ArrayList<FieldInfo> fields() { return fields; }
public int methodsCount() { return methodsCount; }
public ArrayList<MethodInfo> methods() { return methods; }
public JavaClass _root() { return _root; }
public KaitaiStruct _parent() { return _parent; }
}