public <T extends StructGeneralAttribute> T getAttribute(StructGeneralAttribute.Key<T> attribute) { //noinspection unchecked return (T)attributes.get(attribute.getName()); }
public boolean hasAttribute(StructGeneralAttribute.Key<?> attribute) { return attributes.containsKey(attribute.getName()); }
protected Map<String, StructGeneralAttribute> readAttributes(DataInputFullStream in, ConstantPool pool) throws IOException { int length = in.readUnsignedShort(); Map<String, StructGeneralAttribute> attributes = new HashMap<>(length); for (int i = 0; i < length; i++) { int nameIndex = in.readUnsignedShort(); String name = pool.getPrimitiveConstant(nameIndex).getString(); StructGeneralAttribute attribute = readAttribute(in, pool, name); if (attribute != null) { if (StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE.getName().equals(name) && attributes.containsKey(name)) { // merge all variable tables StructLocalVariableTableAttribute table = (StructLocalVariableTableAttribute)attributes.get(name); table.add((StructLocalVariableTableAttribute)attribute); } else if (StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TYPE_TABLE.getName().equals(name) && attributes.containsKey(name)) { // merge all variable tables StructLocalVariableTypeTableAttribute table = (StructLocalVariableTypeTableAttribute)attributes.get(name); table.add((StructLocalVariableTypeTableAttribute)attribute); } else { attributes.put(attribute.getName(), attribute); } } } return attributes; }
int attrNameIndex = in.readUnsignedShort(); String attrName = pool.getPrimitiveConstant(attrNameIndex).getString(); if (!StructGeneralAttribute.ATTRIBUTE_CODE.getName().equals(attrName)) { in.discard(in.readInt()); continue;
if (ATTRIBUTE_INNER_CLASSES.getName().equals(name)) { attr = new StructInnerClassesAttribute(); else if (ATTRIBUTE_CONSTANT_VALUE.getName().equals(name)) { attr = new StructConstantValueAttribute(); else if (ATTRIBUTE_SIGNATURE.getName().equals(name)) { attr = new StructGenericSignatureAttribute(); else if (ATTRIBUTE_ANNOTATION_DEFAULT.getName().equals(name)) { attr = new StructAnnDefaultAttribute(); else if (ATTRIBUTE_EXCEPTIONS.getName().equals(name)) { attr = new StructExceptionsAttribute(); else if (ATTRIBUTE_ENCLOSING_METHOD.getName().equals(name)) { attr = new StructEnclosingMethodAttribute(); else if (ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS.getName().equals(name) || ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS.getName().equals(name)) { attr = new StructAnnotationAttribute(); else if (ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS.getName().equals(name) || ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS.getName().equals(name)) { attr = new StructAnnotationParameterAttribute(); else if (ATTRIBUTE_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.getName().equals(name) || ATTRIBUTE_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS.getName().equals(name)) { attr = new StructTypeAnnotationAttribute(); else if (ATTRIBUTE_LOCAL_VARIABLE_TABLE.getName().equals(name)) { attr = new StructLocalVariableTableAttribute();
@Override protected StructGeneralAttribute readAttribute(DataInputFullStream in, ConstantPool pool, String name) throws IOException { if (StructGeneralAttribute.ATTRIBUTE_CODE.getName().equals(name)) { if (!classStruct.isOwn()) { // skip code in foreign classes in.discard(8); in.discard(in.readInt()); in.discard(8 * in.readUnsignedShort()); } else { containsCode = true; in.discard(6); localVariables = in.readUnsignedShort(); codeLength = in.readInt(); in.discard(codeLength); int excLength = in.readUnsignedShort(); in.discard(excLength * 8); codeFullLength = codeLength + excLength * 8 + 2; } codeAttributes = readAttributes(in, pool); return null; } return super.readAttribute(in, pool, name); }