@Override public void visitCode(Code obj) { code = obj; super.visitCode(obj); CodeException[] exceptions = obj.getExceptionTable(); for (CodeException exception : exceptions) { exception.accept(this); } Attribute[] attributes = obj.getAttributes(); for (Attribute attribute : attributes) { attribute.accept(this); } visitAfter(obj); code = null; }
if (a.getTag() == org.apache.bcel.Const.ATTR_CODE) { for (Attribute ca : ((Code) a).getAttributes()) { if (ca.getTag() == org.apache.bcel.Const.ATTR_LOCAL_VARIABLE_TABLE) { for (LocalVariable l : ((LocalVariableTable) ca).getLocalVariableTable()) { printLocal(out, fout, l, v, defs, refs); } else if (a.getTag() == org.apache.bcel.Const.ATTR_BOOTSTRAP_METHODS ) { } else if (a.getTag() == org.apache.bcel.Const.ATTR_SOURCE_FILE) { v[a.getNameIndex()] = 1; break; ArrayList<LocalVariable[]> locals = new ArrayList<>(); for (Attribute a : m.getAttributes()) { if (a.getTag() == org.apache.bcel.Const.ATTR_EXCEPTIONS) { for (int i : ((ExceptionTable) a).getExceptionIndexTable()) { v[i] = 1; } else if (a.getTag() == org.apache.bcel.Const.ATTR_CODE) { for (Attribute ca : ((Code) a).getAttributes()) { if (ca.getTag() == org.apache.bcel.Const.ATTR_LOCAL_VARIABLE_TABLE) { locals.add(((LocalVariableTable) ca).getLocalVariableTable());
/** * Dump constant value attribute to file stream on binary format. * * @param file Output file stream * @throws IOException */ @Override public final void dump( final DataOutputStream file ) throws IOException { super.dump(file); file.writeShort(constantvalue_index); }
protected Attribute findAttribute(final String name, final Attribute[] all) { final List<Attribute> chosenAttrsList= new ArrayList<>(); for (final Attribute element : all) { if (element.getName().equals(name)) { chosenAttrsList.add(element); } } return chosenAttrsList.isEmpty() ? null : chosenAttrsList.get(0); }
/** * @return constant value associated with this field (may be null) */ public final ConstantValue getConstantValue() { for(int i=0; i < attributes_count; i++) if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) return (ConstantValue)attributes[i]; return null; }
/** * Dump source file attribute to file stream in binary format. * * @param file Output file stream * @throws IOException */ @Override public final void dump( final DataOutputStream file ) throws IOException { super.dump(file); if (super.getLength() > 0) { file.write(bytes, 0, super.getLength()); } }
/** * @return String representation. */ @Override public final String toString() { final StringBuilder buf = new StringBuilder("Synthetic"); if (super.getLength() > 0) { buf.append(" ").append(Utility.toHexString(bytes)); } return buf.toString(); }
/** * @return deep copy of this field */ protected FieldOrMethod copy_(ConstantPool constant_pool) { FieldOrMethod c = null; try { c = (FieldOrMethod)clone(); } catch(CloneNotSupportedException e) {} c.constant_pool = constant_pool; c.attributes = new Attribute[attributes_count]; for(int i=0; i < attributes_count; i++) c.attributes[i] = attributes[i].copy(constant_pool); return c; } }
final int attributeNameIndex = attr.getNameIndex(); final int length = attr.getLength(); UTF8Entry utf8Entry = constantPool.getUTF8Entry(attributeNameIndex); if (utf8Entry == null) {
/** * Class method reads one attribute from the input data stream. This method * must not be accessible from the outside. It is called by the Field and * Method constructor methods. * * @see Field * @see Method * * @param file Input stream * @param constant_pool Array of constants * @return Attribute * @throws IOException * @throws ClassFormatException */ public static Attribute readAttribute(final DataInputStream file, final ConstantPool constant_pool) throws IOException, ClassFormatException { return readAttribute((DataInput) file, constant_pool); }
/** * @return String representation of code chunk. */ public final String toString(boolean verbose) { StringBuffer buf; buf = new StringBuffer("Code(max_stack = " + max_stack + ", max_locals = " + max_locals + ", code_length = " + code_length + ")\n" + Utility.codeToString(code, constant_pool, 0, -1, verbose)); if(exception_table_length > 0) { buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n"); for(int i=0; i < exception_table_length; i++) buf.append(exception_table[i].toString(constant_pool, verbose) + "\n"); } if(attributes_count > 0) { buf.append("\nAttribute(s) = \n"); for(int i=0; i < attributes_count; i++) buf.append(attributes[i].toString() + "\n"); } return buf.toString(); }
attributes = new Attribute[attributes_count]; for (int i = 0; i < attributes_count; i++) { attributes[i] = Attribute.readAttribute(file, constant_pool); super.setLength(length);
/** * Dump constant value attribute to file stream on binary format. * * @param file Output file stream * @throws IOException */ public final void dump(DataOutputStream file) throws IOException { super.dump(file); file.writeShort(constantvalue_index); } /**
@Nullable private Attribute getBootstrapAttribute(JavaClass clz) { for (Attribute att : clz.getAttributes()) { if ("BootstrapMethods".equals(att.getName())) { return att; } } return null; }
/** * @return constant value associated with this field (may be null) */ public final ConstantValue getConstantValue() { for (final Attribute attribute : super.getAttributes()) { if (attribute.getTag() == Const.ATTR_CONSTANT_VALUE) { return (ConstantValue) attribute; } } return null; }
/** * @return the full size of this code attribute, minus its first 6 bytes, * including the size of all its contained attributes */ private int calculateLength() { int len = 0; if (attributes != null) { for (final Attribute attribute : attributes) { len += attribute.getLength() + 6 /*attribute header size*/; } } return len + getInternalLength(); }
/** * @return deep copy of this field */ protected FieldOrMethod copy_( final ConstantPool _constant_pool ) { FieldOrMethod c = null; try { c = (FieldOrMethod)clone(); } catch(final CloneNotSupportedException e) { // ignored, but will cause NPE ... } c.constant_pool = constant_pool; c.attributes = new Attribute[attributes.length]; c.attributes_count = attributes_count; // init deprecated field for (int i = 0; i < attributes.length; i++) { c.attributes[i] = attributes[i].copy(constant_pool); } return c; }
/** * Read information about the attributes of the class. * @throws IOException * @throws ClassFormatException */ private final void readAttributes() throws IOException, ClassFormatException { int attributes_count; attributes_count = file.readUnsignedShort(); attributes = new Attribute[attributes_count]; for(int i=0; i < attributes_count; i++) attributes[i] = Attribute.readAttribute(file, constant_pool); }