use super::*;
bitflags! {
#[derive(Default)]
pub struct MethodAccessFlags : u16 {
const PUBLIC = 0x0001;
const PRIVATE = 0x0002;
const PROTECTED = 0x0004;
const STATIC = 0x0008;
const FINAL = 0x0010;
const SYNCRONIZED = 0x0020;
const BRIDGE = 0x0040;
const VARARGS = 0x0080;
const NATIVE = 0x0100;
const ABSTRACT = 0x0400;
const STRICT = 0x0800;
const SYNTHETIC = 0x1000;
}
}
impl MethodAccessFlags {
pub fn read(r: &mut impl Read) -> io::Result<Self> {
Ok(Self::from_bits_truncate(read_u2(r)?))
}
}
#[derive(Clone, Copy, Debug)]
pub struct Method {
pub access_flags: MethodAccessFlags,
pub name_index: u16,
pub descriptor_index: u16,
pub attributes_count: u16,
}
impl Method {
pub(crate) fn read_except_attributes(read: &mut impl Read) -> io::Result<Self> {
Ok(Self{
access_flags: MethodAccessFlags::read(read)?,
name_index: read_u2(read)?,
descriptor_index: read_u2(read)?,
attributes_count: read_u2(read)?,
})
}
pub(crate) fn read_list_visitor(read: &mut impl Read, visitor: &mut impl Visitor) -> io::Result<()> {
let method_count = read_u2(read)?;
for method_index in 0..method_count {
let method = Method::read_except_attributes(read)?;
visitor.on_method(method_index, method);
Attribute::read_list_callback(read, method.attributes_count, |attribute_index, attribute| visitor.on_method_attribute(method_index, attribute_index, attribute))?;
}
Ok(())
}
}
pub trait Visitor {
fn on_method(&mut self, _index: u16, _method: Method) {}
fn on_method_attribute(&mut self, _method_index: u16, _attribute_index: u16, _attribute: Attribute) {}
}