langtools/src/share/classes/com/sun/tools/classfile/Attributes.java
changeset 22163 3651128c74eb
parent 22159 682da512ec17
equal deleted inserted replaced
22162:3b3e23e67329 22163:3651128c74eb
    36  *  If you write code that depends on this, you do so at your own risk.
    36  *  If you write code that depends on this, you do so at your own risk.
    37  *  This code and its internal interfaces are subject to change or
    37  *  This code and its internal interfaces are subject to change or
    38  *  deletion without notice.</b>
    38  *  deletion without notice.</b>
    39  */
    39  */
    40 public class Attributes implements Iterable<Attribute> {
    40 public class Attributes implements Iterable<Attribute> {
       
    41 
       
    42     public final Attribute[] attrs;
       
    43     public final Map<String, Attribute> map;
       
    44 
    41     Attributes(ClassReader cr) throws IOException {
    45     Attributes(ClassReader cr) throws IOException {
    42         map = new HashMap<String,Attribute>();
    46         map = new HashMap<>();
    43         int attrs_count = cr.readUnsignedShort();
    47         int attrs_count = cr.readUnsignedShort();
    44         attrs = new Attribute[attrs_count];
    48         attrs = new Attribute[attrs_count];
    45         for (int i = 0; i < attrs_count; i++) {
    49         for (int i = 0; i < attrs_count; i++) {
    46             Attribute attr = Attribute.read(cr);
    50             Attribute attr = Attribute.read(cr);
    47             attrs[i] = attr;
    51             attrs[i] = attr;
    53         }
    57         }
    54     }
    58     }
    55 
    59 
    56     public Attributes(ConstantPool constant_pool, Attribute[] attrs) {
    60     public Attributes(ConstantPool constant_pool, Attribute[] attrs) {
    57         this.attrs = attrs;
    61         this.attrs = attrs;
    58         map = new HashMap<String,Attribute>();
    62         map = new HashMap<>();
    59         for (Attribute attr : attrs) {
    63         for (Attribute attr : attrs) {
    60             try {
    64             try {
    61                 map.put(attr.getName(constant_pool), attr);
    65                 map.put(attr.getName(constant_pool), attr);
    62             } catch (ConstantPoolException e) {
    66             } catch (ConstantPoolException e) {
    63                 // don't enter invalid names in map
    67                 // don't enter invalid names in map
    98         int length = 2;
   102         int length = 2;
    99         for (Attribute a: attrs)
   103         for (Attribute a: attrs)
   100             length += a.byteLength();
   104             length += a.byteLength();
   101         return length;
   105         return length;
   102     }
   106     }
   103 
       
   104     public final Attribute[] attrs;
       
   105     public final Map<String, Attribute> map;
       
   106 }
   107 }