pub struct ConstantPoolBuilder { /* private fields */ }Expand description
A builder for the constant pool of a class.
This struct manages the deduplication of constant pool entries, ensuring that strings, classes, and member references are stored efficiently.
Implementations§
Source§impl ConstantPoolBuilder
impl ConstantPoolBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty ConstantPoolBuilder.
The constant pool starts with a dummy entry at index 0, as per JVM spec.
Sourcepub fn into_pool(self) -> Vec<CpInfo>
pub fn into_pool(self) -> Vec<CpInfo>
Consumes the builder and returns the raw vector of CpInfo entries.
Sourcepub fn utf8(&mut self, value: &str) -> u16
pub fn utf8(&mut self, value: &str) -> u16
Adds a UTF-8 string to the constant pool if it doesn’t exist.
Returns the index of the entry.
Sourcepub fn class(&mut self, name: &str) -> u16
pub fn class(&mut self, name: &str) -> u16
Adds a Class constant to the pool.
This will recursively add the UTF-8 name of the class.
Sourcepub fn string(&mut self, value: &str) -> u16
pub fn string(&mut self, value: &str) -> u16
Adds a String constant to the pool.
This is for string literals (e.g., ldc "foo").
pub fn integer(&mut self, value: i32) -> u16
pub fn float(&mut self, value: f32) -> u16
pub fn long(&mut self, value: i64) -> u16
pub fn double(&mut self, value: f64) -> u16
Sourcepub fn name_and_type(&mut self, name: &str, descriptor: &str) -> u16
pub fn name_and_type(&mut self, name: &str, descriptor: &str) -> u16
Adds a NameAndType constant to the pool.
Used for field and method descriptors.
Sourcepub fn field_ref(&mut self, owner: &str, name: &str, descriptor: &str) -> u16
pub fn field_ref(&mut self, owner: &str, name: &str, descriptor: &str) -> u16
Adds a Fieldref constant to the pool.
Sourcepub fn method_ref(&mut self, owner: &str, name: &str, descriptor: &str) -> u16
pub fn method_ref(&mut self, owner: &str, name: &str, descriptor: &str) -> u16
Adds a Methodref constant to the pool.