rustjava_runtime/classes/java/util/
illegal_format_width_exception.rs1use alloc::{string::ToString, vec};
2
3use jvm::{ClassInstanceRef, Jvm, Result, runtime::JavaLangString};
4use jvm_class_proto::{JavaFieldProto, JavaMethodProto};
5use jvm_types::{ClassAccessFlags, FieldAccessFlags, MethodAccessFlags};
6
7use crate::{RuntimeClassProto, RuntimeContext, classes::java::lang::String};
8
9pub struct IllegalFormatWidthException;
11
12impl IllegalFormatWidthException {
13 pub fn as_proto() -> RuntimeClassProto {
14 RuntimeClassProto {
15 name: "java/util/IllegalFormatWidthException",
16 parent_class: Some("java/util/IllegalFormatException"),
17 interfaces: vec![],
18 methods: vec![
19 JavaMethodProto::new("<init>", "(I)V", Self::init, MethodAccessFlags::PUBLIC),
20 JavaMethodProto::new("getWidth", "()I", Self::get_width, MethodAccessFlags::PUBLIC),
21 JavaMethodProto::new("getMessage", "()Ljava/lang/String;", Self::get_message, MethodAccessFlags::PUBLIC),
22 ],
23 fields: vec![JavaFieldProto::new("width", "I", FieldAccessFlags::PRIVATE)],
24 access_flags: ClassAccessFlags::PUBLIC,
25 }
26 }
27
28 async fn init(jvm: &Jvm, _: &mut RuntimeContext, mut this: ClassInstanceRef<Self>, width: i32) -> Result<()> {
29 let _: () = jvm.invoke_special(&this, "java/util/IllegalFormatException", "<init>", "()V", ()).await?;
30 jvm.put_field(&mut this, "java/util/IllegalFormatWidthException", "width", "I", width)
31 .await
32 }
33
34 async fn get_width(jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>) -> Result<i32> {
35 jvm.get_field(&this, "java/util/IllegalFormatWidthException", "width", "I").await
36 }
37
38 async fn get_message(jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>) -> Result<ClassInstanceRef<String>> {
39 let width: i32 = jvm.get_field(&this, "java/util/IllegalFormatWidthException", "width", "I").await?;
40 Ok(JavaLangString::from_rust_string(jvm, &width.to_string()).await?.into())
41 }
42}