Skip to main content

ClassWriter

Struct ClassWriter 

Source
pub struct ClassWriter<W: Write> { /* private fields */ }
Expand description

JVM Class file writer

Implementations§

Source§

impl<W: Write> ClassWriter<W>

Source

pub fn collect_attribute_constants(&mut self, attribute: &JvmAttribute)

Collects constants from an attribute and adds them to the constant pool

Source

pub fn collect_annotation_constants(&mut self, annotations: &[JvmAnnotation])

Collects constants from annotations

Source

pub fn collect_annotation_value_constants(&mut self, value: &JvmAnnotationValue)

Collects constants from annotation values

Source

pub fn collect_verification_type_constants(&mut self, vt: &JvmVerificationType)

Collects constants from a verification type and adds them to the constant pool

Source

pub fn write_attribute(&mut self, attribute: &JvmAttribute) -> Result<()>

Writes an attribute to the class file

Source

pub fn write_verification_type_to_buf( &mut self, vt: &JvmVerificationType, buf: &mut Vec<u8>, ) -> Result<()>

Writes a verification type to a buffer

Source

pub fn write_stack_map_frame_to_buf( &mut self, frame: &JvmStackMapFrame, buf: &mut Vec<u8>, ) -> Result<()>

Writes a stack map frame to a buffer

Source

pub fn write_annotation_to_buf( &mut self, annotation: &JvmAnnotation, buf: &mut Vec<u8>, ) -> Result<()>

Writes an annotation to a buffer

Source

pub fn write_annotation_element_to_buf( &mut self, element: &JvmAnnotationElement, buf: &mut Vec<u8>, ) -> Result<()>

Writes an annotation element to a buffer

Source

pub fn write_annotation_value_to_buf( &mut self, value: &JvmAnnotationValue, buf: &mut Vec<u8>, ) -> Result<()>

Writes an annotation value to a buffer

Source

pub fn write_code_attribute( &mut self, program: &JvmProgram, method: &JvmMethod, code_utf8_idx: u16, ) -> Result<()>

Writes a Code attribute to the class file

Source§

impl<W: Write> ClassWriter<W>

Source

pub fn write_fields(&mut self, program: &JvmProgram) -> Result<()>

写入字段

Source

pub fn write_methods( &mut self, program: &JvmProgram, code_utf8_idx: u16, ) -> Result<()>

写入方法

Source§

impl<W: Write> ClassWriter<W>

Source

pub fn generate_method_bytecode( &mut self, method: &JvmMethod, ) -> (Vec<u8>, HashMap<String, i32>)

生成方法的字节码及标签位置

Source

pub fn emit_instruction( &mut self, instruction: &JvmInstruction, bytecode: &mut Vec<u8>, jump_patches: &mut Vec<(usize, usize, String, bool)>, pos: usize, )

发射单条指令的字节码

Source§

impl<W: Write> ClassWriter<W>

Source

pub fn add_utf8(&mut self, s: String) -> u16

Adds a Utf8 constant to the constant pool

Source

pub fn add_class(&mut self, name: String) -> u16

Adds a Class constant to the constant pool

Source

pub fn add_string(&mut self, value: String) -> u16

Adds a String constant to the constant pool

Source

pub fn add_name_and_type(&mut self, name: String, descriptor: String) -> u16

Adds a NameAndType constant to the constant pool

Source

pub fn add_field_ref( &mut self, class_name: String, name: String, descriptor: String, ) -> u16

Adds a Fieldref constant to the constant pool

Source

pub fn add_method_ref( &mut self, class_name: String, name: String, descriptor: String, ) -> u16

Adds a Methodref constant to the constant pool

Source

pub fn add_interface_method_ref( &mut self, class_name: String, name: String, descriptor: String, ) -> u16

Adds an InterfaceMethodref constant to the constant pool

Source

pub fn add_int(&mut self, val: i32) -> u16

Adds an Integer constant to the constant pool

Source

pub fn add_float(&mut self, val: f32) -> u16

Adds a Float constant to the constant pool

Source

pub fn add_long(&mut self, val: i64) -> u16

Adds a Long constant to the constant pool

Source

pub fn add_double(&mut self, val: f64) -> u16

Adds a Double constant to the constant pool

Source

pub fn add_method_handle(&mut self, kind: u8, ref_idx: u16) -> u16

Adds a MethodHandle constant to the constant pool

Source

pub fn add_method_type(&mut self, descriptor: String) -> u16

Adds a MethodType constant to the constant pool

Source

pub fn add_dynamic( &mut self, bootstrap_method_attr_idx: u16, name: String, descriptor: String, ) -> u16

Adds a Dynamic constant to the constant pool

Source

pub fn add_invoke_dynamic( &mut self, bootstrap_method_attr_idx: u16, name: String, descriptor: String, ) -> u16

Adds an InvokeDynamic constant to the constant pool

Source

pub fn add_module(&mut self, name: String) -> u16

Adds a Module constant to the constant pool

Source

pub fn add_package(&mut self, name: String) -> u16

Adds a Package constant to the constant pool

Source

pub fn add_cp_entry(&mut self, entry: CpEntry) -> u16

Adds a constant pool entry and returns its index

Source

pub fn write_constant_pool(&mut self) -> Result<()>

Writes the constant pool to the class file

Source§

impl<W: Write> ClassWriter<W>

Source

pub fn new(writer: W) -> Self

Create a new Class writer

Source

pub fn finish(self) -> W

Finish writing and return the underlying writer

Source

pub fn write(self, program: &JvmProgram) -> GaiaDiagnostics<W>

Write ClassView as binary Class format

Auto Trait Implementations§

§

impl<W> Freeze for ClassWriter<W>
where W: Freeze,

§

impl<W> !RefUnwindSafe for ClassWriter<W>

§

impl<W> Send for ClassWriter<W>
where W: Send,

§

impl<W> Sync for ClassWriter<W>
where W: Sync,

§

impl<W> Unpin for ClassWriter<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for ClassWriter<W>
where W: UnsafeUnpin,

§

impl<W> !UnwindSafe for ClassWriter<W>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more