bindgen_jni/class_file_visitor/
method.rs1use super::*;
4
5
6
7bitflags! {
8 #[derive(Default)]
9 pub struct MethodAccessFlags : u16 {
11 const PUBLIC = 0x0001;
13 const PRIVATE = 0x0002;
15 const PROTECTED = 0x0004;
17 const STATIC = 0x0008;
19 const FINAL = 0x0010;
21 const SYNCRONIZED = 0x0020;
23 const BRIDGE = 0x0040;
25 const VARARGS = 0x0080;
27 const NATIVE = 0x0100;
29 const ABSTRACT = 0x0400;
31 const STRICT = 0x0800;
33 const SYNTHETIC = 0x1000;
35 }
36}
37
38impl MethodAccessFlags {
39 pub fn read(r: &mut impl Read) -> io::Result<Self> {
40 Ok(Self::from_bits_truncate(read_u2(r)?))
41 }
42}
43
44
45
46#[derive(Clone, Copy, Debug)]
48pub struct Method {
49 pub access_flags: MethodAccessFlags,
50 pub name_index: u16,
51 pub descriptor_index: u16,
52 pub attributes_count: u16,
53}
54
55impl Method {
56 pub(crate) fn read_except_attributes(read: &mut impl Read) -> io::Result<Self> {
57 Ok(Self{
58 access_flags: MethodAccessFlags::read(read)?,
59 name_index: read_u2(read)?,
60 descriptor_index: read_u2(read)?,
61 attributes_count: read_u2(read)?,
62 })
63 }
64
65 pub(crate) fn read_list_visitor(read: &mut impl Read, visitor: &mut impl Visitor) -> io::Result<()> {
66 let method_count = read_u2(read)?;
67 for method_index in 0..method_count {
68 let method = Method::read_except_attributes(read)?;
69 visitor.on_method(method_index, method);
70 Attribute::read_list_callback(read, method.attributes_count, |attribute_index, attribute| visitor.on_method_attribute(method_index, attribute_index, attribute))?;
71 }
72 Ok(())
73 }
74}
75
76
77
78pub trait Visitor {
80 fn on_method(&mut self, _index: u16, _method: Method) {}
81 fn on_method_attribute(&mut self, _method_index: u16, _attribute_index: u16, _attribute: Attribute) {}
82}
83