java_asm/jvms/attr/
annotation.rs

1use java_asm_macro::{ReadFrom, WriteInto};
2
3// annotation {
4//     u2 type_index;
5//     u2 num_element_value_pairs;
6//     {   u2            element_name_index;
7//         element_value value;
8//     } element_value_pairs[num_element_value_pairs];
9// }
10#[derive(Clone, Debug, ReadFrom, WriteInto)]
11pub struct AnnotationInfo {
12    pub type_index: u16,
13    pub num_element_value_pairs: u16,
14    #[index(num_element_value_pairs)]
15    pub element_value_pairs: Vec<AnnotationElement>,
16}
17
18// {
19//     u2            element_name_index; // CONSTANT_Utf8_info
20//     element_value value;
21// }
22#[derive(Clone, Debug, ReadFrom, WriteInto)]
23pub struct AnnotationElement {
24    pub element_name_index: u16,
25    pub value: AnnotationElementValueInfo,
26}
27
28// element_value {
29//     u1 tag;
30//     union {
31//         u2 const_value_index;
32//
33//         {   u2 type_name_index;
34//             u2 const_name_index;
35//         } enum_const_value;
36//
37//         u2 class_info_index;
38//
39//         annotation annotation_value;
40//
41//         {   u2            num_values;
42//             element_value values[num_values];
43//         } array_value;
44//     } value;
45// }
46#[derive(Clone, Debug, WriteInto)]
47pub struct AnnotationElementValueInfo {
48    pub tag: u8,
49    pub value: AnnotationElementValue,
50}
51
52// union {
53//     u2 const_value_index;
54//
55//     {   u2 type_name_index; // CONSTANT_Utf8_info
56//         u2 const_name_index; // CONSTANT_Utf8_info
57//     } enum_const_value;
58//
59//     u2 class_info_index; // CONSTANT_Utf8_info
60//
61//     annotation annotation_value;
62//
63//     {   u2            num_values;
64//         element_value values[num_values];
65//     } array_value;
66// } value;
67#[derive(Clone, Debug, WriteInto)]
68pub enum AnnotationElementValue {
69    Const { const_value_index: u16 },
70    EnumConst { type_name_index: u16, const_name_index: u16 },
71    Class { class_info_index: u16 },
72    Annotation { annotation_value: AnnotationInfo },
73    Array { num_values: u16, values: Vec<AnnotationElementValueInfo> },
74}
75
76// {
77//     u2         num_annotations;
78//     annotation annotations[num_annotations];
79// }
80#[derive(Clone, Debug, ReadFrom, WriteInto)]
81pub struct ParameterAnnotationInfo {
82    pub num_annotations: u16,
83    #[index(num_annotations)]
84    pub annotations: Vec<AnnotationInfo>,
85}