/** * Read a single element_value structure. * * @param data * @param cp */ private static Object readElementValue(ByteBuffer data, VmCP cp) { final int tag = data.get() & 0xFF; switch (tag) { case 'B': return (byte) cp.getInt(data.getChar()); case 'C': return (char) cp.getInt(data.getChar()); case 'D': return cp.getDouble(data.getChar()); case 'F': return cp.getFloat(data.getChar()); case 'I': return cp.getInt(data.getChar()); case 'J': return cp.getLong(data.getChar()); case 'S': return (short) cp.getInt(data.getChar()); case 'Z': return cp.getInt(data.getChar()) != 0; case 's': return cp.getAny(data.getChar()); case 'e': // enum { final String typeDescr = cp.getUTF8(data.getChar()); final String constName = cp.getUTF8(data.getChar()); return new VmAnnotation.EnumValue(typeDescr, constName); } case 'c': // class { final String classDescr = cp.getUTF8(data.getChar()); return new VmAnnotation.ClassInfo(classDescr); } case '@': // annotation return readAnnotation(data, cp, true); case '[': // array { final int numValues = data.getChar(); final Object[] arr = new Object[numValues]; for (int i = 0; i < numValues; i++) { arr[i] = readElementValue(data, cp); } return arr; } default: throw new ClassFormatError("Unknown element_value tag '" + (char) tag + '\''); } }
/** * Read the fields table * * @param data * @param cp * @param slotSize * @param loader */ private static FieldData[] readFields( ByteBuffer data, VmCP cp, int slotSize, VmClassLoader loader) { final int fcount = data.getChar(); if (fcount > 0) { final FieldData[] ftable = new FieldData[fcount]; for (int i = 0; i < fcount; i++) { int modifiers = data.getChar(); final String name = cp.getUTF8(data.getChar()); final String signature = cp.getUTF8(data.getChar()); final boolean isstatic = ((modifiers & Modifier.ACC_STATIC) != 0); // Read field attributes final int acount = data.getChar(); VmAnnotation[] rVisAnn = null; byte[] rawAnnotations = null; Object constantValue = null; for (int a = 0; a < acount; a++) { final String attrName = cp.getUTF8(data.getChar()); final int length = data.getInt(); if (isstatic && VmArray.equals(ConstantValueAttrName, attrName)) { constantValue = cp.getAny(data.getChar()); } else if (VmArray.equals(RuntimeVisibleAnnotationsAttrName, attrName)) { rawAnnotations = new byte[length]; data.slice().get(rawAnnotations); rVisAnn = readRuntimeAnnotations(data, cp, true, loader); } else if (VmArray.equals(RuntimeInvisibleAnnotationsAttrName, attrName)) { readRuntimeAnnotations(data, cp, false, loader); } else { skip(data, length); } } ftable[i] = new FieldData(name, signature, modifiers, constantValue, rVisAnn, rawAnnotations); } return ftable; } else { return null; } }