/
attribute_info.go
93 lines (87 loc) · 2.37 KB
/
attribute_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package classfile
var (
_attrDeprecated = &DeprecatedAttribute{}
_attrSynthetic = &SyntheticAttribute{}
)
/*
attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
*/
type AttributeInfo interface {
readInfo(reader *ContentReader) error
}
func readAttributes(reader *ContentReader, pool *ConstantPool) ([]AttributeInfo, error) {
var err error
attributesCount, err := reader.readUint16()
attributes := make([]AttributeInfo, attributesCount)
for i := range attributes {
attributes[i], err = readAttribute(reader, pool)
if err != nil {
break
}
}
return attributes, err
}
func readAttribute(reader *ContentReader, pool *ConstantPool) (AttributeInfo, error) {
var err error
var attrNameIndex uint16
var attrLen uint32
var attrName string
attrNameIndex, err = reader.readUint16()
attrLen, err = reader.readUint32()
attrName, err = pool.getUtf8(attrNameIndex)
attrInfo := newAttributeInfo(attrName, pool)
if attrInfo == nil {
attrInfo = &UnparsedAttribute{
name: attrName,
length: attrLen,
}
}
err = attrInfo.readInfo(reader)
return attrInfo, err
}
func newAttributeInfo(attrName string, pool *ConstantPool) AttributeInfo {
switch attrName {
// case "AnnotationDefault":
case "BootstrapMethods":
return &BootstrapMethodsAttribute{}
case "Code":
return &CodeAttribute{pool: pool}
case "ConstantValue":
return &ConstantValueAttribute{}
case "Deprecated":
return _attrDeprecated
case "EnclosingMethod":
return &EnclosingMethodAttribute{pool: pool}
case "Exceptions":
return &ExceptionsAttribute{}
case "InnerClasses":
return &InnerClassesAttribute{}
case "LineNumberTable":
return &LineNumberTableAttribute{}
case "LocalVariableTable":
return &LocalVariableTableAttribute{}
case "LocalVariableTypeTable":
return &LocalVariableTypeTableAttribute{}
// case "MethodParameters":
// case "RuntimeInvisibleAnnotations":
// case "RuntimeInvisibleParameterAnnotations":
// case "RuntimeInvisibleTypeAnnotations":
// case "RuntimeVisibleAnnotations":
// case "RuntimeVisibleParameterAnnotations":
// case "RuntimeVisibleTypeAnnotations":
case "Signature":
return &SignatureAttribute{pool: pool}
case "SourceFile":
return &SourceFileAttribute{pool: pool}
// case "SourceDebugExtension":
// case "StackMapTable":
case "Synthetic":
return _attrSynthetic
default:
return nil // undefined attr
}
}