/
attribute.go
405 lines (321 loc) · 7.61 KB
/
attribute.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
package parser
var (
deprecated = &AttributeDeprecated{}
synthetic = &AttributeSynthetic{}
)
type Attribute interface {
Name() string
}
type AttributeConstantValue struct {
ConstantValueIndex uint16
}
func (a *AttributeConstantValue) Name() string {
return "ConstantValue"
}
type AttributeCode struct {
MaxStack uint16
MaxLocals uint16
Codes []uint8
ExceptionTable []*Exception
Attributes []Attribute
}
func (a *AttributeCode) Name() string {
return "Code"
}
func (a *AttributeCode) LineNumberTable() *AttributeLineNumberTable {
for _, e := range a.Attributes {
if attr, ok := e.(*AttributeLineNumberTable); ok {
return attr
}
}
return nil
}
func (a *AttributeCode) LocalVariableTable() *AttributeLocalVariableTable {
for _, e := range a.Attributes {
if attr, ok := e.(*AttributeLocalVariableTable); ok {
return attr
}
}
return nil
}
func (a *AttributeCode) LocalVariableTypeTable() *AttributeLocalVariableTypeTable {
for _, e := range a.Attributes {
if attr, ok := e.(*AttributeLocalVariableTypeTable); ok {
return attr
}
}
return nil
}
func (a *AttributeCode) StackMapTable() *AttributeStackMapTable {
for _, e := range a.Attributes {
if attr, ok := e.(*AttributeStackMapTable); ok {
return attr
}
}
return nil
}
func (a *AttributeCode) RuntimeVisibleTypeAnnotations() *AttributeRuntimeVisibleTypeAnnotations {
for _, e := range a.Attributes {
if attr, ok := e.(*AttributeRuntimeVisibleTypeAnnotations); ok {
return attr
}
}
return nil
}
func (a *AttributeCode) RuntimeInvisibleTypeAnnotations() *AttributeRuntimeInvisibleTypeAnnotations {
for _, e := range a.Attributes {
if attr, ok := e.(*AttributeRuntimeInvisibleTypeAnnotations); ok {
return attr
}
}
return nil
}
type Exception struct {
StartPc uint16
EndPc uint16
HandlerPc uint16
CatchType uint16
}
type AttributeExceptions struct {
ExceptionIndexes []uint16
}
func (a *AttributeExceptions) Name() string {
return "Exceptions"
}
type AttributeInnerClasses struct {
InnerClasses []*InnerClass
}
func (a *AttributeInnerClasses) Name() string {
return "InnerClasses"
}
type InnerClass struct {
InnerClassInfoIndex uint16
OuterClassInfoIndex uint16
InnerNameIndex uint16
InnerClassAccessFlags uint16
}
type AttributeEnclosingMethod struct {
ClassIndex uint16
MethodIndex uint16
}
func (a *AttributeEnclosingMethod) Name() string {
return "EnclosingMethod"
}
type AttributeSynthetic struct {
Signature uint16
}
func (a *AttributeSynthetic) Name() string {
return "Synthetic"
}
type AttributeSignature struct {
Signature uint16
}
func (a *AttributeSignature) Name() string {
return "Signature"
}
type AttributeSourceFile struct {
SourcefileIndex uint16
}
func (a *AttributeSourceFile) Name() string {
return "SourceFile"
}
type AttributeSourceDebugExtension struct {
DebugExtension []byte
}
func (a *AttributeSourceDebugExtension) Name() string {
return "SourceDebugExtension"
}
type AttributeLineNumberTable struct {
LineNumberTable []*LineNumber
}
func (a *AttributeLineNumberTable) Name() string {
return "LineNumberTable"
}
type LineNumber struct {
StartPc uint16
LineNumber uint16
}
type AttributeLocalVariableTable struct {
LocalVaribleTable []*LocalVariable
}
func (a *AttributeLocalVariableTable) Name() string {
return "LocalVariableTable"
}
type LocalVariable struct {
StartPc uint16
Length uint16
NameIndex uint16
DescriptorInedx uint16
Index uint16
}
type AttributeLocalVariableTypeTable struct {
LocalVaribleTypeTable []*LocalVariableType
}
func (a *AttributeLocalVariableTypeTable) Name() string {
return "LocalVariableTypeTable"
}
type LocalVariableType struct {
StartPc uint16
Length uint16
NameIndex uint16
SignatureInedx uint16
Index uint16
}
type AttributeDeprecated struct{}
func (a *AttributeDeprecated) Name() string {
return "Deprecated"
}
type AttributeRuntimeVisibleAnnotations struct {
Annotations []*Annotation
}
func (a *AttributeRuntimeVisibleAnnotations) Name() string {
return "RuntimeVisibleAnnotations"
}
type AttributeRuntimeInvisibleAnnotations struct {
Annotations []*Annotation
}
func (a *AttributeRuntimeInvisibleAnnotations) Name() string {
return "RuntimeInvisibleAnnotations"
}
type AttributeRuntimeVisibleParameterAnnotations struct {
ParameterAnnotations []*ParameterAnnotation
}
func (a *AttributeRuntimeVisibleParameterAnnotations) Name() string {
return "RuntimeVisibleParameterAnnotations"
}
type AttributeRuntimeInvisibleParameterAnnotations struct {
ParameterAnnotations []*ParameterAnnotation
}
func (a *AttributeRuntimeInvisibleParameterAnnotations) Name() string {
return "RuntimeInvisibleParameterAnnotations"
}
type ParameterAnnotation struct {
Annotations []*Annotation
}
type AttributeRuntimeVisibleTypeAnnotations struct {
TypeAnnotations []*TypeAnnotation
}
func (a *AttributeRuntimeVisibleTypeAnnotations) Name() string {
return "RuntimeVisibleTypeAnnotations"
}
type AttributeRuntimeInvisibleTypeAnnotations struct {
TypeAnnotations []*TypeAnnotation
}
func (a *AttributeRuntimeInvisibleTypeAnnotations) Name() string {
return "RuntimeInvisibleTypeAnnotations"
}
type TypeAnnotation struct {
TargetType uint8
TargetInfo TargetInfo
TargetPath *TypePath
TypeIndex uint16
ElementValuePairs []*ElementValuePair
}
type TargetInfo interface{}
type TypeParameterTarget struct {
TypeParameterIndex uint8
}
type SuperTypeTarget struct {
SuperTypeIndex uint16
}
type TypeParameterBoundTarget struct {
TypeParameterIndex uint8
BoundIndex uint8
}
type EmptyTarget struct{}
type FormalParameterTarget struct {
FormalParameterIndex uint8
}
type ThrowsTarget struct {
ThrowsTypeIndex uint16
}
type LocalVarTarget struct {
LocalVarTargetTables []*LocalVarTargetTable
}
type CatchTarget struct {
ExceptionTableIndex uint16
}
type OffsetTarget struct {
Offset uint16
}
type TypeArgumentTarget struct {
Offset uint16
TypeArgumentIndex uint8
}
type LocalVarTargetTable struct {
StartPc uint16
Length uint16
Index uint16
}
type TypePath struct {
Paths []*Path
}
type Path struct {
TypePathKind uint8
TypeArgumentIndex uint8
}
type Annotation struct {
elementValue
TypeIndex uint16
ElementValuePairs []*ElementValuePair
}
func (a *Annotation) Type(c *ConstantPool) (string, error) {
typ, err := c.GetConstantUtf8(a.TypeIndex)
if err != nil {
return "", err
}
return typ.String(), nil
}
type ElementValuePair struct {
ElementNameIndex uint16
ElementValue ElementValue
}
type AttributeAnnotationDefault struct {
DefaultValue ElementValue
}
func (a *AttributeAnnotationDefault) Name() string {
return "AnnotationDefault"
}
type AttributeBootstrapMethods struct {
BootstrapMethods []*BootstrapMethod
}
func (a *AttributeBootstrapMethods) Name() string {
return "BootstrapMethods"
}
type BootstrapMethod struct {
BootstrapMethodRef uint16
BootstrapArguments []uint16
}
type AttributeMethodParameters struct {
Parameters []*MethodParameter
}
func (a *AttributeMethodParameters) Name() string {
return "MethodParameters"
}
type MethodParameter struct {
NameIndex uint16
AccessFlags uint16
}
type AttributeNestHost struct {
HostClassIndex uint16
}
func (a *AttributeNestHost) Name() string {
return "NestHost"
}
type AttributeNestMembers struct {
Classes []uint16
}
func (a *AttributeNestMembers) Name() string {
return "NestHost"
}
type AttributeRecord struct {
Components []RecordComponentInfo
}
func (a *AttributeRecord) Name() string {
return "Record"
}
type RecordComponentInfo struct {
NameIndex uint16
DescriptorIndex uint16
Attributes []Attribute
}