@@ -28,7 +28,7 @@ pub fn generate_cpp_methods(
2828 let mut generated = GeneratedCppQObjectBlocks :: default ( ) ;
2929 let qobject_ident = qobject_idents. name . cxx_unqualified ( ) ;
3030 for invokable in invokables {
31- let idents = QMethodName :: from ( invokable) ;
31+ let idents = QMethodName :: try_from ( invokable) ? ;
3232 let return_cxx_ty = syn_type_to_cpp_return_type ( & invokable. method . sig . output , type_names) ?;
3333
3434 let parameters: Vec < CppNamedType > = invokable
@@ -63,7 +63,7 @@ pub fn generate_cpp_methods(
6363
6464 let body = format ! (
6565 "{ident}({parameter_names})" ,
66- ident = idents. wrapper. cpp ,
66+ ident = idents. wrapper. cxx_unqualified ( ) ,
6767 parameter_names = parameters
6868 . iter( )
6969 . map( |parameter| parameter. ident. as_str( ) )
@@ -85,7 +85,7 @@ pub fn generate_cpp_methods(
8585 } else {
8686 "void"
8787 } ,
88- ident = idents. name. cpp ,
88+ ident = idents. name. cxx_unqualified ( ) ,
8989 parameter_types = parameter_types,
9090 is_qinvokable = if invokable. is_qinvokable {
9191 "Q_INVOKABLE "
@@ -122,7 +122,7 @@ pub fn generate_cpp_methods(
122122 } else {
123123 "void"
124124 } ,
125- ident = idents. name. cpp ,
125+ ident = idents. name. cxx_unqualified ( ) ,
126126 body = if return_cxx_ty. is_some( ) {
127127 format!( "return {body}" , body = body)
128128 } else {
@@ -143,7 +143,7 @@ pub fn generate_cpp_methods(
143143 } else {
144144 "void"
145145 } ,
146- ident = idents. wrapper. cpp ,
146+ ident = idents. wrapper. cxx_unqualified ( ) ,
147147 ) ) ) ;
148148 }
149149
@@ -155,27 +155,42 @@ mod tests {
155155 use super :: * ;
156156
157157 use crate :: generator:: naming:: qobject:: tests:: create_qobjectname;
158+ use crate :: naming:: Name ;
158159 use crate :: parser:: parameter:: ParsedFunctionParameter ;
159160 use indoc:: indoc;
160161 use pretty_assertions:: assert_str_eq;
161162 use quote:: format_ident;
162163 use std:: collections:: HashSet ;
163- use syn:: parse_quote;
164+ use syn:: { parse_quote, ForeignItemFn } ;
164165
165166 #[ test]
166167 fn test_generate_cpp_invokables ( ) {
168+ let method1: ForeignItemFn = parse_quote ! { fn void_invokable( self : & MyObject ) ; } ;
169+ let method2: ForeignItemFn =
170+ parse_quote ! { fn trivial_invokable( self : & MyObject , param: i32 ) -> i32 ; } ;
171+ let method3: ForeignItemFn = parse_quote ! { fn opaque_invokable( self : Pin <& mut MyObject >, param: & QColor ) -> UniquePtr <QColor >; } ;
172+ let method4: ForeignItemFn =
173+ parse_quote ! { fn specifiers_invokable( self : & MyObject , param: i32 ) -> i32 ; } ;
174+ let method5: ForeignItemFn = parse_quote ! { fn cpp_method( self : & MyObject ) ; } ;
167175 let invokables = vec ! [
168176 ParsedMethod {
169- method: parse_quote! { fn void_invokable ( self : & MyObject ) ; } ,
177+ method: method1 . clone ( ) ,
170178 qobject_ident: format_ident!( "MyObject" ) ,
171179 mutable: false ,
172180 safe: true ,
173181 parameters: vec![ ] ,
174182 specifiers: HashSet :: new( ) ,
175183 is_qinvokable: true ,
184+ name: Name :: from_rust_ident_and_attrs(
185+ & method1. sig. ident,
186+ & method1. attrs,
187+ None ,
188+ None ,
189+ )
190+ . unwrap( ) ,
176191 } ,
177192 ParsedMethod {
178- method: parse_quote! { fn trivial_invokable ( self : & MyObject , param : i32 ) -> i32 ; } ,
193+ method: method2 . clone ( ) ,
179194 qobject_ident: format_ident!( "MyObject" ) ,
180195 mutable: false ,
181196 safe: true ,
@@ -185,9 +200,16 @@ mod tests {
185200 } ] ,
186201 specifiers: HashSet :: new( ) ,
187202 is_qinvokable: true ,
203+ name: Name :: from_rust_ident_and_attrs(
204+ & method2. sig. ident,
205+ & method2. attrs,
206+ None ,
207+ None ,
208+ )
209+ . unwrap( ) ,
188210 } ,
189211 ParsedMethod {
190- method: parse_quote! { fn opaque_invokable ( self : Pin < & mut MyObject > , param : & QColor ) -> UniquePtr < QColor > ; } ,
212+ method: method3 . clone ( ) ,
191213 qobject_ident: format_ident!( "MyObject" ) ,
192214 mutable: true ,
193215 safe: true ,
@@ -197,9 +219,16 @@ mod tests {
197219 } ] ,
198220 specifiers: HashSet :: new( ) ,
199221 is_qinvokable: true ,
222+ name: Name :: from_rust_ident_and_attrs(
223+ & method3. sig. ident,
224+ & method3. attrs,
225+ None ,
226+ None ,
227+ )
228+ . unwrap( ) ,
200229 } ,
201230 ParsedMethod {
202- method: parse_quote! { fn specifiers_invokable ( self : & MyObject , param : i32 ) -> i32 ; } ,
231+ method: method4 . clone ( ) ,
203232 qobject_ident: format_ident!( "MyObject" ) ,
204233 mutable: false ,
205234 safe: true ,
@@ -215,15 +244,29 @@ mod tests {
215244 specifiers
216245 } ,
217246 is_qinvokable: true ,
247+ name: Name :: from_rust_ident_and_attrs(
248+ & method4. sig. ident,
249+ & method4. attrs,
250+ None ,
251+ None ,
252+ )
253+ . unwrap( ) ,
218254 } ,
219255 ParsedMethod {
220- method: parse_quote! { fn cpp_method ( self : & MyObject ) ; } ,
256+ method: method5 . clone ( ) ,
221257 qobject_ident: format_ident!( "MyObject" ) ,
222258 mutable: false ,
223259 safe: true ,
224260 parameters: vec![ ] ,
225261 specifiers: HashSet :: new( ) ,
226262 is_qinvokable: false ,
263+ name: Name :: from_rust_ident_and_attrs(
264+ & method5. sig. ident,
265+ & method5. attrs,
266+ None ,
267+ None ,
268+ )
269+ . unwrap( ) ,
227270 } ,
228271 ] ;
229272 let qobject_idents = create_qobjectname ( ) ;
@@ -385,8 +428,10 @@ mod tests {
385428
386429 #[ test]
387430 fn test_generate_cpp_invokables_mapped_cxx_name ( ) {
431+ let method: ForeignItemFn =
432+ parse_quote ! { fn trivial_invokable( self : & MyObject , param: A ) -> B ; } ;
388433 let invokables = vec ! [ ParsedMethod {
389- method: parse_quote! { fn trivial_invokable ( self : & MyObject , param : A ) -> B ; } ,
434+ method: method . clone ( ) ,
390435 qobject_ident: format_ident!( "MyObject" ) ,
391436 mutable: false ,
392437 safe: true ,
@@ -396,6 +441,8 @@ mod tests {
396441 } ] ,
397442 specifiers: HashSet :: new( ) ,
398443 is_qinvokable: true ,
444+ name: Name :: from_rust_ident_and_attrs( & method. sig. ident, & method. attrs, None , None )
445+ . unwrap( ) ,
399446 } ] ;
400447 let qobject_idents = create_qobjectname ( ) ;
401448
0 commit comments