75 this.compat = compat; |
75 this.compat = compat; |
76 } |
76 } |
77 |
77 |
78 public Attribute createAttribute(ClassReader cr, int name_index, byte[] data) |
78 public Attribute createAttribute(ClassReader cr, int name_index, byte[] data) |
79 throws IOException { |
79 throws IOException { |
80 if (standardAttributes == null) |
80 if (standardAttributes == null) { |
81 init(); |
81 init(); |
|
82 } |
82 |
83 |
83 ConstantPool cp = cr.getConstantPool(); |
84 ConstantPool cp = cr.getConstantPool(); |
|
85 String reasonForDefaultAttr; |
84 try { |
86 try { |
85 String name = cp.getUTF8Value(name_index); |
87 String name = cp.getUTF8Value(name_index); |
86 Class<? extends Attribute> attrClass = standardAttributes.get(name); |
88 Class<? extends Attribute> attrClass = standardAttributes.get(name); |
87 if (attrClass != null) { |
89 if (attrClass != null) { |
88 try { |
90 try { |
89 Class<?>[] constrArgTypes = {ClassReader.class, int.class, int.class}; |
91 Class<?>[] constrArgTypes = {ClassReader.class, int.class, int.class}; |
90 Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes); |
92 Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes); |
91 return constr.newInstance(new Object[] { cr, name_index, data.length }); |
93 return constr.newInstance(new Object[] { cr, name_index, data.length }); |
92 } catch (Throwable t) { |
94 } catch (Throwable t) { |
|
95 reasonForDefaultAttr = t.toString(); |
93 // fall through and use DefaultAttribute |
96 // fall through and use DefaultAttribute |
94 // t.printStackTrace(); |
97 // t.printStackTrace(); |
95 } |
98 } |
|
99 } else { |
|
100 reasonForDefaultAttr = "unknown attribute"; |
96 } |
101 } |
97 } catch (ConstantPoolException e) { |
102 } catch (ConstantPoolException e) { |
|
103 reasonForDefaultAttr = e.toString(); |
98 // fall through and use DefaultAttribute |
104 // fall through and use DefaultAttribute |
99 } |
105 } |
100 return new DefaultAttribute(cr, name_index, data); |
106 return new DefaultAttribute(cr, name_index, data, reasonForDefaultAttr); |
101 } |
107 } |
102 |
108 |
103 protected void init() { |
109 protected void init() { |
104 standardAttributes = new HashMap<String,Class<? extends Attribute>>(); |
110 standardAttributes = new HashMap<String,Class<? extends Attribute>>(); |
105 standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class); |
111 standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class); |