bindgen-jni 0.0.1

Renamed to jni-bindgen. Code generator for binding to JVM APIs from Rust
Documentation
//! [Java SE 7 § 4.6](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.6):  Parsing APIs and structures for class methods.

use super::*;



bitflags! {
    #[derive(Default)]
    /// [Java SE 7 § 4.6](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.6):  method_info::access_flags values.
    pub struct MethodAccessFlags : u16 {
        /// Declared `public`; may be accessed from outside its package.
        const PUBLIC        = 0x0001;
        /// Declared `private`; usable only with the defining class.
        const PRIVATE       = 0x0002;
        /// Declared `protectdd`; may be accessed within subclasses.
        const PROTECTED     = 0x0004;
        /// Declared `static`.
        const STATIC        = 0x0008;
        /// Declared `final`; no subclasses allowed.
        const FINAL         = 0x0010;
        /// Declared `syncronized`; invocation is wrapped by a monitor use.
        const SYNCRONIZED   = 0x0020;
        /// A bridge method, generated by the compiler.
        const BRIDGE        = 0x0040;
        /// Declared with variable number of arguments.
        const VARARGS       = 0x0080;
        /// Declared `native`; implemented in a langauge other than Java.
        const NATIVE        = 0x0100;
        /// Declared `abstract`; must not be instantiated.
        const ABSTRACT      = 0x0400;
        /// Declared `strictfp`; floating-point mode is FP-strict.
        const STRICT        = 0x0800;
        /// Declared synthetic; not present in the source code.
        const SYNTHETIC     = 0x1000;
    }
}

impl MethodAccessFlags {
    pub fn read(r: &mut impl Read) -> io::Result<Self> {
        Ok(Self::from_bits_truncate(read_u2(r)?))
    }
}



/// [Java SE 7 &sect; 4.6](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.6):  method_info, minus the trailing attributes
#[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(())
    }
}



/// [Java SE 7 &sect; 4.6](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.6):  Visit a method_info
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) {}
}