[−][src]Struct jvm_class_file_parser::ClassFile
A representation of a JVM class file.
For details on the format and structure of a JVM class file, see the corresponding section of the Java Virtual Machine Specification.
https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html
Fields
minor_version: u16
major_version: u16
constant_pool: Vec<Box<ConstantPoolEntry>>
access_flags: HashSet<ClassAccess>
this_class: u16
super_class: u16
interfaces: Vec<u16>
fields: Vec<Field>
methods: Vec<Method>
attributes: Vec<Attribute>
Methods
impl ClassFile
[src][−]
pub fn from_file<R: Read>(file: &mut R) -> Result<ClassFile>
[src][−]
Parses the given class file. Fails if the given file is not a valid class file.
let mut file = File::open("classes/Dummy.class").unwrap(); let class_file = ClassFile::from_file(&mut file).unwrap();
pub fn to_file<W: Write>(&self, file: &mut W) -> Result<()>
[src]
pub fn get_class_name(&self) -> &str
[src][−]
Returns the name of the class file.
let mut file = File::open("classes/Dummy.class").unwrap(); let class_file = ClassFile::from_file(&mut file).unwrap(); assert_eq!("Dummy", class_file.get_class_name());
pub fn get_source_file_name(&self) -> Option<&str>
[src][−]
Returns the name of the source file that the class file was compiled from.
If the class file does not have a SourceFile
attribute, then a None
option is returned.
let mut file = File::open("classes/Dummy.class").unwrap(); let class_file = ClassFile::from_file(&mut file).unwrap(); assert_eq!(Some("Dummy.java"), class_file.get_source_file_name());
pub fn get_constant_utf8(&self, index: usize) -> &str
[src][−]
Returns a string representation of the specified Utf8 constant.
let mut file = File::open("classes/Dummy.class").unwrap(); let class_file = ClassFile::from_file(&mut file).unwrap(); assert_eq!("<init>", class_file.get_constant_utf8(4));
pub fn get_constant_class_str(&self, index: usize) -> &str
[src][−]
Returns a string representation of the specified class constant.
let mut file = File::open("classes/Dummy.class").unwrap(); let class_file = ClassFile::from_file(&mut file).unwrap(); assert_eq!("java/lang/Object", class_file.get_constant_class_str(3));
pub fn get_constant_name_and_type_str(&self, index: usize) -> String
[src][−]
Returns a string representation of the specified name and type constant.
let mut file = File::open("classes/Dummy.class").unwrap(); let class_file = ClassFile::from_file(&mut file).unwrap(); assert_eq!( "\"<init>\":()V", class_file.get_constant_name_and_type_str(10) );
pub fn get_constant(&self, index: usize) -> &Box<ConstantPoolEntry>
[src][−]
Returns the specified constant from the constant pool.
This method exists in order to encapsulate the fact that the constant pool indexes start at 1 rather than 0.
let mut file = File::open("classes/Dummy.class").unwrap(); let class_file = ClassFile::from_file(&mut file).unwrap(); assert_eq!( ConstantClass { name_index: 11, }, *class_file.get_constant(2).deref() );
Trait Implementations
impl Eq for ClassFile
[src]
impl PartialEq<ClassFile> for ClassFile
[src][+]
impl Debug for ClassFile
[src][+]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src][−]
impl<T, U> Into for T where
U: From<T>,
[src][−]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src][−]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src][−]
impl<T> Borrow for T where
T: ?Sized,
[src][−]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src][−]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src][−]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src][−]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src][−]
U: TryFrom<T>,