@@ -14,7 +14,7 @@ use crate::bind::parse::{
1414 BindDefinition , BindField , BindFieldMethod , BindFieldProperty , BindInput , BindPackage ,
1515 BindVariant ,
1616} ;
17- use crate :: java_class :: get_attribute;
17+ use crate :: utils :: get_attribute;
1818
1919pub fn bind ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
2020 let BindInput { package, defs } = syn:: parse_macro_input!( input as BindInput ) ;
@@ -195,7 +195,9 @@ fn bind_def_class(
195195 . map ( |prop| {
196196 let name = prop. ident ;
197197 let ty = prop. ty ;
198- quote_spanned ! { name. span( ) => pub const #name: :: rosttasse:: prelude:: Field <#ty> }
198+ quote_spanned ! { name. span( ) =>
199+ pub const #name: :: rosttasse:: prelude:: StaticField <#class, #ty> = :: rosttasse:: prelude:: StaticField :: new( stringify!( #name) ) ;
200+ }
199201 } )
200202 . collect_vec ( ) ;
201203
@@ -226,7 +228,7 @@ fn bind_def_class(
226228 } )
227229 . collect :: < Vec < _ > > ( ) ;
228230
229- let instance_impl = crate :: java_class :: struct_ :: generate_instance_field_common (
231+ let instance_impl = generate_instance_field_common (
230232 & class,
231233 quote_spanned ! { class. span( ) => self . raw} ,
232234 quote_spanned ! { class. span( ) => Self {
@@ -419,3 +421,60 @@ fn prepare_method(method: &BindFieldMethod) -> MethodInfo {
419421 ret,
420422 }
421423}
424+
425+ fn generate_instance_field_common (
426+ struct_name : & Ident ,
427+ self_ident : proc_macro2:: TokenStream ,
428+ from_raw : proc_macro2:: TokenStream ,
429+ ) -> proc_macro2:: TokenStream {
430+ quote_spanned ! { self_ident. span( ) =>
431+ impl From <:: rosttasse:: prelude:: Instance > for #struct_name {
432+ fn from( value: :: rosttasse:: prelude:: Instance ) -> Self {
433+ <#struct_name as :: rosttasse:: prelude:: JavaClass >:: from_raw( value)
434+ }
435+ }
436+
437+ impl Into <:: rosttasse:: prelude:: Instance > for #struct_name {
438+ fn into( self ) -> :: rosttasse:: prelude:: Instance {
439+ #self_ident
440+ }
441+ }
442+
443+ impl :: core:: ops:: Deref for #struct_name {
444+ type Target = :: rosttasse:: prelude:: Instance ;
445+
446+ fn deref( & self ) -> & Self :: Target {
447+ & #self_ident
448+ }
449+ }
450+
451+ impl :: rosttasse:: prelude:: IntoJValue for #struct_name {
452+ fn into_jvalue<' local>( self , env: & mut :: jni:: JNIEnv <' local>) -> :: jni:: objects:: JValueOwned <' local> {
453+ #self_ident. into_jvalue( env)
454+ }
455+ }
456+
457+ impl :: rosttasse:: prelude:: FromJValue for #struct_name {
458+ fn from_jvalue<' local>( value: :: jni:: objects:: JValueOwned <' local>) -> Self {
459+ <:: rosttasse:: prelude:: Instance as :: rosttasse:: prelude:: FromJValue >:: from_jvalue( value) . into( )
460+ }
461+ }
462+
463+ impl :: rosttasse:: prelude:: JavaClass for #struct_name {
464+ fn get_raw( & self ) -> :: rosttasse:: prelude:: Instance {
465+ #self_ident. clone( )
466+ }
467+
468+ fn from_raw( raw: :: rosttasse:: prelude:: Instance ) -> Self {
469+ #from_raw
470+ }
471+ }
472+
473+ impl #struct_name {
474+ #[ allow( dead_code) ]
475+ pub fn cast_unchecked<T : From <:: rosttasse:: prelude:: Instance >>( & self ) -> T {
476+ T :: from( #self_ident)
477+ }
478+ }
479+ }
480+ }
0 commit comments