@Override
public void parse(ClassNameAndSuperclassInfo.Builder builder) throws InvalidClassFileFormatException {
try {
int magic = in.readInt();
if (magic != 0xcafebabe) {
throw new InvalidClassFileFormatException("Classfile header isn't 0xCAFEBABE", expectedClassDescriptor,
codeBaseEntry);
}
int major_version = in.readUnsignedShort();
int minor_version = in.readUnsignedShort();
int constant_pool_count = in.readUnsignedShort();
constantPool = new Constant[constant_pool_count];
for (int i = 1; i < constantPool.length; i++) {
constantPool[i] = readConstant();
if (constantPool[i].tag == IClassConstants.CONSTANT_Double
|| constantPool[i].tag == IClassConstants.CONSTANT_Long) {
// Double and Long constants take up two constant pool
// entries
++i;
}
}
int access_flags = in.readUnsignedShort();
int this_class = in.readUnsignedShort();
ClassDescriptor thisClassDescriptor = getClassDescriptor(this_class);
int super_class = in.readUnsignedShort();
ClassDescriptor superClassDescriptor = getClassDescriptor(super_class);
int interfaces_count = in.readUnsignedShort();
if (interfaces_count < 0) {
throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry);
}
ClassDescriptor[] interfaceDescriptorList;
if (interfaces_count == 0) {
interfaceDescriptorList = ClassDescriptor.EMPTY_ARRAY;
} else {
interfaceDescriptorList = new ClassDescriptor[interfaces_count];
for (int i = 0; i < interfaceDescriptorList.length; i++) {
interfaceDescriptorList[i] = getClassDescriptor(in.readUnsignedShort());
}
}
// Extract all references to other classes,
// both CONSTANT_Class entries and also referenced method
// signatures.
Collection<ClassDescriptor> referencedClassDescriptorList = extractReferencedClasses();
builder.setClassDescriptor(thisClassDescriptor);
builder.setSuperclassDescriptor(superClassDescriptor);
builder.setInterfaceDescriptorList(interfaceDescriptorList);
builder.setCodeBaseEntry(codeBaseEntry);
builder.setAccessFlags(access_flags);
builder.setReferencedClassDescriptors(referencedClassDescriptorList);
builder.setClassfileVersion(major_version, minor_version);
} catch (IOException e) {
throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry, e);
}
}