1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use proc_macro2::{Span as Span2, TokenStream as TokenStream2};
use quote::{quote, quote_spanned};
use syn::{spanned::Spanned, Generics, Ident};
use crate::widgets::gen::PropertyName;
impl PropertyName {
pub fn assign_fn_stream(&self, p_generics: &Option<Generics>, w_name: &Ident) -> TokenStream2 {
let mut tokens = match self {
PropertyName::Ident(ident) => {
quote! { #w_name.#ident }
}
PropertyName::Path(path) => quote! { #path },
};
if let Some(generics) = p_generics {
tokens.extend(quote! { :: #generics });
}
tokens
}
pub fn assign_args_stream(&self, w_name: &Ident) -> Option<TokenStream2> {
match self {
PropertyName::Ident(_) => None,
PropertyName::Path(_) => Some(quote_spanned! { w_name.span() => & #w_name, }),
}
}
pub fn self_assign_fn_stream(
&self,
p_generics: &Option<Generics>,
w_name: &Ident,
widgets_as_self: bool,
) -> TokenStream2 {
let self_token = if widgets_as_self {
quote! { widgets }
} else {
quote! { self }
};
let mut tokens = match self {
PropertyName::Ident(ident) => {
quote! { #self_token.#w_name.#ident }
}
PropertyName::Path(path) => quote! { #path },
};
if let Some(generics) = p_generics {
tokens.extend(quote! { :: #generics });
}
tokens
}
pub fn self_assign_args_stream(
&self,
w_name: &Ident,
widgets_as_self: bool,
) -> Option<TokenStream2> {
let self_token = if widgets_as_self {
quote! { widgets }
} else {
quote! { self }
};
match self {
PropertyName::Ident(_) => None,
PropertyName::Path(_) => {
Some(quote_spanned! { w_name.span() => & #self_token.#w_name, })
}
}
}
}
impl Spanned for PropertyName {
fn span(&self) -> Span2 {
match self {
PropertyName::Ident(ident) => ident.span(),
PropertyName::Path(path) => path.span(),
}
}
}