| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.106 crate/::{Spanrust-analyzer cargo proc-macro2 1.0.106 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#}; |
| 4 | use quoterust-analyzer cargo quote 1.0.44 crate/::quoterust-analyzer cargo quote 1.0.44 quote!; |
| 5 | |
| 6 | pub const WRONG_PLACE_MSGrust-analyzer cargo glib-macros 0.22.6 derived_properties_attribute/WRONG_PLACE_MSG.: &str = |
| 7 | "This macro should be used on `impl` block for `glib::ObjectImpl` trait"; |
| 8 | |
| 9 | pub fn impl_derived_propertiesrust-analyzer cargo glib-macros 0.22.6 derived_properties_attribute/impl_derived_properties().(input: &synrust-analyzer cargo syn 2.0.117 crate/::ItemImplrust-analyzer cargo syn 2.0.117 item/ItemImpl#) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#> { |
| 10 | let synrust-analyzer cargo syn 2.0.117 crate/::ItemImplrust-analyzer cargo syn 2.0.117 item/ItemImpl# { |
| 11 | attrsrust-analyzer cargo syn 2.0.117 item/ItemImpl#attrs., |
| 12 | genericsrust-analyzer cargo syn 2.0.117 item/ItemImpl#generics., |
| 13 | trait_rust-analyzer cargo syn 2.0.117 item/ItemImpl#trait_., |
| 14 | self_tyrust-analyzer cargo syn 2.0.117 item/ItemImpl#self_ty., |
| 15 | itemsrust-analyzer cargo syn 2.0.117 item/ItemImpl#items., |
| 16 | .. |
| 17 | } = input; |
| 18 | |
| 19 | let trait_path = &trait_ |
| 20 | .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 21 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::newrust-analyzer cargo syn 2.0.117 error/impl#[Error]new().(Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().(), WRONG_PLACE_MSGrust-analyzer cargo glib-macros 0.22.6 derived_properties_attribute/WRONG_PLACE_MSG.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 22 | .1; |
| 23 | |
| 24 | let mut has_property = false; |
| 25 | let mut has_properties = false; |
| 26 | let mut has_set_property = false; |
| 27 | |
| 28 | for item in items { |
| 29 | if let synrust-analyzer cargo syn 2.0.117 crate/::ImplItemrust-analyzer cargo syn 2.0.117 item/ImplItem#::Fnrust-analyzer cargo syn 2.0.117 item/ImplItem#Fn#(method) = item { |
| 30 | let ident = &method.sigrust-analyzer cargo syn 2.0.117 item/ImplItemFn#sig..identrust-analyzer cargo syn 2.0.117 item/Signature#ident.; |
| 31 | |
| 32 | if ident rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."properties" { |
| 33 | has_properties = true; |
| 34 | } else if ident rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."set_property" { |
| 35 | has_set_property = true; |
| 36 | } else if ident rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."property" { |
| 37 | has_property = true; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | let crate_ident = craterust-analyzer cargo glib-macros 0.22.6 crate/::utilsrust-analyzer cargo glib-macros 0.22.6 utils/::crate_ident_newrust-analyzer cargo glib-macros 0.22.6 utils/crate_ident_new().(); |
| 43 | |
| 44 | let properties = quoterust-analyzer cargo quote 1.0.44 quote!!( |
| 45 | fn properties() -> &'static [#crate_ident::ParamSpec] { |
| 46 | Self::derived_properties() |
| 47 | } |
| 48 | ); |
| 49 | |
| 50 | let set_property = quoterust-analyzer cargo quote 1.0.44 quote!!( |
| 51 | fn set_property(&self, id: usize, value: &#crate_ident::Value, pspec: &#crate_ident::ParamSpec) { |
| 52 | Self::derived_set_property(self, id, value, pspec) |
| 53 | } |
| 54 | ); |
| 55 | |
| 56 | let property = quoterust-analyzer cargo quote 1.0.44 quote!!( |
| 57 | fn property(&self, id: usize, pspec: &#crate_ident::ParamSpec) -> #crate_ident::Value { |
| 58 | Self::derived_property(self, id, pspec) |
| 59 | } |
| 60 | ); |
| 61 | |
| 62 | let generated = [ |
| 63 | (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_properties).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(properties), |
| 64 | (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_set_property).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(set_property), |
| 65 | (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_property).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(property), |
| 66 | ]; |
| 67 | |
| 68 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo quote 1.0.44 quote!!( |
| 69 | #(#attrs)* |
| 70 | impl #generics #trait_path for #self_ty { |
| 71 | #(#items)* |
| 72 | #(#generated)* |
| 73 | } |
| 74 | )) |
| 75 | } |