@@ -71,6 +71,189 @@ impl SyntaxFactory {
7171 ast
7272 }
7373
74+
75+ pub fn path_from_text ( & self , text : & str ) -> ast:: Path {
76+ make:: path_from_text ( text) . clone_for_update ( )
77+ }
78+
79+ pub fn expr_field ( & self , receiver : ast:: Expr , field : & str ) -> ast:: FieldExpr {
80+ let ast:: Expr :: FieldExpr ( ast) =
81+ make:: expr_field ( receiver. clone ( ) , field) . clone_for_update ( )
82+ else {
83+ unreachable ! ( )
84+ } ;
85+
86+ if let Some ( mut mapping) = self . mappings ( ) {
87+ let mut builder = SyntaxMappingBuilder :: new ( ast. syntax ( ) . clone ( ) ) ;
88+ builder. map_node ( receiver. syntax ( ) . clone ( ) , ast. expr ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
89+ builder. finish ( & mut mapping) ;
90+ }
91+
92+ ast
93+ }
94+
95+ pub fn impl_trait (
96+ & self ,
97+ attrs : impl IntoIterator < Item = ast:: Attr > ,
98+ is_unsafe : bool ,
99+ trait_gen_params : Option < ast:: GenericParamList > ,
100+ trait_gen_args : Option < ast:: GenericArgList > ,
101+ type_gen_params : Option < ast:: GenericParamList > ,
102+ type_gen_args : Option < ast:: GenericArgList > ,
103+ is_negative : bool ,
104+ path_type : ast:: Type ,
105+ ty : ast:: Type ,
106+ trait_where_clause : Option < ast:: WhereClause > ,
107+ ty_where_clause : Option < ast:: WhereClause > ,
108+ body : Option < ast:: AssocItemList > ,
109+ ) -> ast:: Impl {
110+ let ( attrs, attrs_input) = iterator_input ( attrs) ;
111+ let ast = make:: impl_trait (
112+ attrs,
113+ is_unsafe,
114+ trait_gen_params. clone ( ) ,
115+ trait_gen_args. clone ( ) ,
116+ type_gen_params. clone ( ) ,
117+ type_gen_args. clone ( ) ,
118+ is_negative,
119+ path_type. clone ( ) ,
120+ ty. clone ( ) ,
121+ trait_where_clause. clone ( ) ,
122+ ty_where_clause. clone ( ) ,
123+ body. clone ( ) ,
124+ )
125+ . clone_for_update ( ) ;
126+
127+ if let Some ( mut mapping) = self . mappings ( ) {
128+ let mut builder = SyntaxMappingBuilder :: new ( ast. syntax ( ) . clone ( ) ) ;
129+ builder. map_children ( attrs_input, ast. attrs ( ) . map ( |attr| attr. syntax ( ) . clone ( ) ) ) ;
130+ if let Some ( trait_gen_params) = trait_gen_params {
131+ builder. map_node (
132+ trait_gen_params. syntax ( ) . clone ( ) ,
133+ ast. generic_param_list ( ) . unwrap ( ) . syntax ( ) . clone ( ) ,
134+ ) ;
135+ }
136+ builder. map_node ( path_type. syntax ( ) . clone ( ) , ast. trait_ ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
137+ builder. map_node ( ty. syntax ( ) . clone ( ) , ast. self_ty ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
138+ if let Some ( ty_where_clause) = ty_where_clause {
139+ builder. map_node (
140+ ty_where_clause. syntax ( ) . clone ( ) ,
141+ ast. where_clause ( ) . unwrap ( ) . syntax ( ) . clone ( ) ,
142+ ) ;
143+ }
144+ if let Some ( body) = body {
145+ builder. map_node (
146+ body. syntax ( ) . clone ( ) ,
147+ ast. assoc_item_list ( ) . unwrap ( ) . syntax ( ) . clone ( ) ,
148+ ) ;
149+ }
150+ builder. finish ( & mut mapping) ;
151+ }
152+
153+ ast
154+ }
155+
156+ pub fn ty_alias (
157+ & self ,
158+ attrs : impl IntoIterator < Item = ast:: Attr > ,
159+ ident : & str ,
160+ generic_param_list : Option < ast:: GenericParamList > ,
161+ type_param_bounds : Option < ast:: TypeParam > ,
162+ where_clause : Option < ast:: WhereClause > ,
163+ assignment : Option < ( ast:: Type , Option < ast:: WhereClause > ) > ,
164+ ) -> ast:: TypeAlias {
165+ let ( attrs, attrs_input) = iterator_input ( attrs) ;
166+ let ast = make:: ty_alias (
167+ attrs,
168+ ident,
169+ generic_param_list. clone ( ) ,
170+ type_param_bounds. clone ( ) ,
171+ where_clause. clone ( ) ,
172+ assignment. clone ( ) ,
173+ )
174+ . clone_for_update ( ) ;
175+
176+ if let Some ( mut mapping) = self . mappings ( ) {
177+ let mut builder = SyntaxMappingBuilder :: new ( ast. syntax ( ) . clone ( ) ) ;
178+ builder. map_children ( attrs_input, ast. attrs ( ) . map ( |attr| attr. syntax ( ) . clone ( ) ) ) ;
179+ if let Some ( generic_param_list) = generic_param_list {
180+ builder. map_node (
181+ generic_param_list. syntax ( ) . clone ( ) ,
182+ ast. generic_param_list ( ) . unwrap ( ) . syntax ( ) . clone ( ) ,
183+ ) ;
184+ }
185+ if let Some ( type_param_bounds) = type_param_bounds {
186+ builder. map_node (
187+ type_param_bounds. syntax ( ) . clone ( ) ,
188+ ast. type_bound_list ( ) . unwrap ( ) . syntax ( ) . clone ( ) ,
189+ ) ;
190+ }
191+ if let Some ( where_clause) = where_clause {
192+ builder. map_node (
193+ where_clause. syntax ( ) . clone ( ) ,
194+ ast. where_clause ( ) . unwrap ( ) . syntax ( ) . clone ( ) ,
195+ ) ;
196+ }
197+ if let Some ( ( ty, _) ) = assignment {
198+ builder. map_node ( ty. syntax ( ) . clone ( ) , ast. ty ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
199+ }
200+ builder. finish ( & mut mapping) ;
201+ }
202+
203+ ast
204+ }
205+
206+ pub fn param_list (
207+ & self ,
208+ self_param : Option < ast:: SelfParam > ,
209+ params : impl IntoIterator < Item = ast:: Param > ,
210+ ) -> ast:: ParamList {
211+ let ( params, input) = iterator_input ( params) ;
212+ let ast = make:: param_list ( self_param. clone ( ) , params) . clone_for_update ( ) ;
213+
214+ if let Some ( mut mapping) = self . mappings ( ) {
215+ let mut builder = SyntaxMappingBuilder :: new ( ast. syntax ( ) . clone ( ) ) ;
216+ if let Some ( self_param) = self_param {
217+ if let Some ( new_self_param) = ast. self_param ( ) {
218+ builder. map_node ( self_param. syntax ( ) . clone ( ) , new_self_param. syntax ( ) . clone ( ) ) ;
219+ }
220+ }
221+ builder. map_children ( input, ast. params ( ) . map ( |p| p. syntax ( ) . clone ( ) ) ) ;
222+ builder. finish ( & mut mapping) ;
223+ }
224+
225+ ast
226+ }
227+
228+ pub fn const_param ( & self , name : ast:: Name , ty : ast:: Type ) -> ast:: ConstParam {
229+ let ast = make:: const_param ( name. clone ( ) , ty. clone ( ) ) . clone_for_update ( ) ;
230+
231+ if let Some ( mut mapping) = self . mappings ( ) {
232+ let mut builder = SyntaxMappingBuilder :: new ( ast. syntax ( ) . clone ( ) ) ;
233+ builder. map_node ( name. syntax ( ) . clone ( ) , ast. name ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
234+ builder. map_node ( ty. syntax ( ) . clone ( ) , ast. ty ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
235+ builder. finish ( & mut mapping) ;
236+ }
237+
238+ ast
239+ }
240+
241+ pub fn generic_param_list (
242+ & self ,
243+ params : impl IntoIterator < Item = ast:: GenericParam > ,
244+ ) -> ast:: GenericParamList {
245+ let ( params, input) = iterator_input ( params) ;
246+ let ast = make:: generic_param_list ( params) . clone_for_update ( ) ;
247+
248+ if let Some ( mut mapping) = self . mappings ( ) {
249+ let mut builder = SyntaxMappingBuilder :: new ( ast. syntax ( ) . clone ( ) ) ;
250+ builder. map_children ( input, ast. generic_params ( ) . map ( |p| p. syntax ( ) . clone ( ) ) ) ;
251+ builder. finish ( & mut mapping) ;
252+ }
253+
254+ ast
255+ }
256+
74257 pub fn path_segment ( & self , name_ref : ast:: NameRef ) -> ast:: PathSegment {
75258 let ast = make:: path_segment ( name_ref. clone ( ) ) . clone_for_update ( ) ;
76259
0 commit comments