@@ -9,221 +9,13 @@ use crate::{
99 SyntaxKind :: { ATTR , COMMENT , WHITESPACE } ,
1010 SyntaxNode , SyntaxToken ,
1111 algo:: { self , neighbor} ,
12- ast:: { self , HasGenericParams , edit:: IndentLevel , make, syntax_factory:: SyntaxFactory } ,
12+ ast:: { self , edit:: IndentLevel , make, syntax_factory:: SyntaxFactory } ,
1313 syntax_editor:: { Position , SyntaxEditor } ,
1414 ted,
1515} ;
1616
1717use super :: { GenericParam , HasName } ;
1818
19- pub trait GenericParamsOwnerEdit : ast:: HasGenericParams {
20- fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList ;
21- fn get_or_create_where_clause ( & self ) -> ast:: WhereClause ;
22- }
23-
24- impl GenericParamsOwnerEdit for ast:: Fn {
25- fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList {
26- match self . generic_param_list ( ) {
27- Some ( it) => it,
28- None => {
29- let position = if let Some ( name) = self . name ( ) {
30- ted:: Position :: after ( name. syntax )
31- } else if let Some ( fn_token) = self . fn_token ( ) {
32- ted:: Position :: after ( fn_token)
33- } else if let Some ( param_list) = self . param_list ( ) {
34- ted:: Position :: before ( param_list. syntax )
35- } else {
36- ted:: Position :: last_child_of ( self . syntax ( ) )
37- } ;
38- create_generic_param_list ( position)
39- }
40- }
41- }
42-
43- fn get_or_create_where_clause ( & self ) -> ast:: WhereClause {
44- if self . where_clause ( ) . is_none ( ) {
45- let position = if let Some ( ty) = self . ret_type ( ) {
46- ted:: Position :: after ( ty. syntax ( ) )
47- } else if let Some ( param_list) = self . param_list ( ) {
48- ted:: Position :: after ( param_list. syntax ( ) )
49- } else {
50- ted:: Position :: last_child_of ( self . syntax ( ) )
51- } ;
52- create_where_clause ( position) ;
53- }
54- self . where_clause ( ) . unwrap ( )
55- }
56- }
57-
58- impl GenericParamsOwnerEdit for ast:: Impl {
59- fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList {
60- match self . generic_param_list ( ) {
61- Some ( it) => it,
62- None => {
63- let position = match self . impl_token ( ) {
64- Some ( imp_token) => ted:: Position :: after ( imp_token) ,
65- None => ted:: Position :: last_child_of ( self . syntax ( ) ) ,
66- } ;
67- create_generic_param_list ( position)
68- }
69- }
70- }
71-
72- fn get_or_create_where_clause ( & self ) -> ast:: WhereClause {
73- if self . where_clause ( ) . is_none ( ) {
74- let position = match self . assoc_item_list ( ) {
75- Some ( items) => ted:: Position :: before ( items. syntax ( ) ) ,
76- None => ted:: Position :: last_child_of ( self . syntax ( ) ) ,
77- } ;
78- create_where_clause ( position) ;
79- }
80- self . where_clause ( ) . unwrap ( )
81- }
82- }
83-
84- impl GenericParamsOwnerEdit for ast:: Trait {
85- fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList {
86- match self . generic_param_list ( ) {
87- Some ( it) => it,
88- None => {
89- let position = if let Some ( name) = self . name ( ) {
90- ted:: Position :: after ( name. syntax )
91- } else if let Some ( trait_token) = self . trait_token ( ) {
92- ted:: Position :: after ( trait_token)
93- } else {
94- ted:: Position :: last_child_of ( self . syntax ( ) )
95- } ;
96- create_generic_param_list ( position)
97- }
98- }
99- }
100-
101- fn get_or_create_where_clause ( & self ) -> ast:: WhereClause {
102- if self . where_clause ( ) . is_none ( ) {
103- let position = match ( self . assoc_item_list ( ) , self . semicolon_token ( ) ) {
104- ( Some ( items) , _) => ted:: Position :: before ( items. syntax ( ) ) ,
105- ( _, Some ( tok) ) => ted:: Position :: before ( tok) ,
106- ( None , None ) => ted:: Position :: last_child_of ( self . syntax ( ) ) ,
107- } ;
108- create_where_clause ( position) ;
109- }
110- self . where_clause ( ) . unwrap ( )
111- }
112- }
113-
114- impl GenericParamsOwnerEdit for ast:: TypeAlias {
115- fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList {
116- match self . generic_param_list ( ) {
117- Some ( it) => it,
118- None => {
119- let position = if let Some ( name) = self . name ( ) {
120- ted:: Position :: after ( name. syntax )
121- } else if let Some ( trait_token) = self . type_token ( ) {
122- ted:: Position :: after ( trait_token)
123- } else {
124- ted:: Position :: last_child_of ( self . syntax ( ) )
125- } ;
126- create_generic_param_list ( position)
127- }
128- }
129- }
130-
131- fn get_or_create_where_clause ( & self ) -> ast:: WhereClause {
132- if self . where_clause ( ) . is_none ( ) {
133- let position = match self . eq_token ( ) {
134- Some ( tok) => ted:: Position :: before ( tok) ,
135- None => match self . semicolon_token ( ) {
136- Some ( tok) => ted:: Position :: before ( tok) ,
137- None => ted:: Position :: last_child_of ( self . syntax ( ) ) ,
138- } ,
139- } ;
140- create_where_clause ( position) ;
141- }
142- self . where_clause ( ) . unwrap ( )
143- }
144- }
145-
146- impl GenericParamsOwnerEdit for ast:: Struct {
147- fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList {
148- match self . generic_param_list ( ) {
149- Some ( it) => it,
150- None => {
151- let position = if let Some ( name) = self . name ( ) {
152- ted:: Position :: after ( name. syntax )
153- } else if let Some ( struct_token) = self . struct_token ( ) {
154- ted:: Position :: after ( struct_token)
155- } else {
156- ted:: Position :: last_child_of ( self . syntax ( ) )
157- } ;
158- create_generic_param_list ( position)
159- }
160- }
161- }
162-
163- fn get_or_create_where_clause ( & self ) -> ast:: WhereClause {
164- if self . where_clause ( ) . is_none ( ) {
165- let tfl = self . field_list ( ) . and_then ( |fl| match fl {
166- ast:: FieldList :: RecordFieldList ( _) => None ,
167- ast:: FieldList :: TupleFieldList ( it) => Some ( it) ,
168- } ) ;
169- let position = if let Some ( tfl) = tfl {
170- ted:: Position :: after ( tfl. syntax ( ) )
171- } else if let Some ( gpl) = self . generic_param_list ( ) {
172- ted:: Position :: after ( gpl. syntax ( ) )
173- } else if let Some ( name) = self . name ( ) {
174- ted:: Position :: after ( name. syntax ( ) )
175- } else {
176- ted:: Position :: last_child_of ( self . syntax ( ) )
177- } ;
178- create_where_clause ( position) ;
179- }
180- self . where_clause ( ) . unwrap ( )
181- }
182- }
183-
184- impl GenericParamsOwnerEdit for ast:: Enum {
185- fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList {
186- match self . generic_param_list ( ) {
187- Some ( it) => it,
188- None => {
189- let position = if let Some ( name) = self . name ( ) {
190- ted:: Position :: after ( name. syntax )
191- } else if let Some ( enum_token) = self . enum_token ( ) {
192- ted:: Position :: after ( enum_token)
193- } else {
194- ted:: Position :: last_child_of ( self . syntax ( ) )
195- } ;
196- create_generic_param_list ( position)
197- }
198- }
199- }
200-
201- fn get_or_create_where_clause ( & self ) -> ast:: WhereClause {
202- if self . where_clause ( ) . is_none ( ) {
203- let position = if let Some ( gpl) = self . generic_param_list ( ) {
204- ted:: Position :: after ( gpl. syntax ( ) )
205- } else if let Some ( name) = self . name ( ) {
206- ted:: Position :: after ( name. syntax ( ) )
207- } else {
208- ted:: Position :: last_child_of ( self . syntax ( ) )
209- } ;
210- create_where_clause ( position) ;
211- }
212- self . where_clause ( ) . unwrap ( )
213- }
214- }
215-
216- fn create_where_clause ( position : ted:: Position ) {
217- let where_clause = make:: where_clause ( empty ( ) ) . clone_for_update ( ) ;
218- ted:: insert ( position, where_clause. syntax ( ) ) ;
219- }
220-
221- fn create_generic_param_list ( position : ted:: Position ) -> ast:: GenericParamList {
222- let gpl = make:: generic_param_list ( empty ( ) ) . clone_for_update ( ) ;
223- ted:: insert_raw ( position, gpl. syntax ( ) ) ;
224- gpl
225- }
226-
22719pub trait AttrsOwnerEdit : ast:: HasAttrs {
22820 fn remove_attrs_and_docs ( & self ) {
22921 remove_attrs_and_docs ( self . syntax ( ) ) ;
@@ -879,8 +671,6 @@ impl<N: AstNode + Clone> Indent for N {}
879671
880672#[ cfg( test) ]
881673mod tests {
882- use std:: fmt;
883-
884674 use parser:: Edition ;
885675
886676 use crate :: SourceFile ;
@@ -892,33 +682,6 @@ mod tests {
892682 parse. tree ( ) . syntax ( ) . descendants ( ) . find_map ( N :: cast) . unwrap ( ) . clone_for_update ( )
893683 }
894684
895- #[ test]
896- fn test_create_generic_param_list ( ) {
897- fn check_create_gpl < N : GenericParamsOwnerEdit + fmt:: Display > ( before : & str , after : & str ) {
898- let gpl_owner = ast_mut_from_text :: < N > ( before) ;
899- gpl_owner. get_or_create_generic_param_list ( ) ;
900- assert_eq ! ( gpl_owner. to_string( ) , after) ;
901- }
902-
903- check_create_gpl :: < ast:: Fn > ( "fn foo" , "fn foo<>" ) ;
904- check_create_gpl :: < ast:: Fn > ( "fn foo() {}" , "fn foo<>() {}" ) ;
905-
906- check_create_gpl :: < ast:: Impl > ( "impl" , "impl<>" ) ;
907- check_create_gpl :: < ast:: Impl > ( "impl Struct {}" , "impl<> Struct {}" ) ;
908- check_create_gpl :: < ast:: Impl > ( "impl Trait for Struct {}" , "impl<> Trait for Struct {}" ) ;
909-
910- check_create_gpl :: < ast:: Trait > ( "trait Trait<>" , "trait Trait<>" ) ;
911- check_create_gpl :: < ast:: Trait > ( "trait Trait<> {}" , "trait Trait<> {}" ) ;
912-
913- check_create_gpl :: < ast:: Struct > ( "struct A" , "struct A<>" ) ;
914- check_create_gpl :: < ast:: Struct > ( "struct A;" , "struct A<>;" ) ;
915- check_create_gpl :: < ast:: Struct > ( "struct A();" , "struct A<>();" ) ;
916- check_create_gpl :: < ast:: Struct > ( "struct A {}" , "struct A<> {}" ) ;
917-
918- check_create_gpl :: < ast:: Enum > ( "enum E" , "enum E<>" ) ;
919- check_create_gpl :: < ast:: Enum > ( "enum E {" , "enum E<> {" ) ;
920- }
921-
922685 #[ test]
923686 fn test_increase_indent ( ) {
924687 let arm_list = ast_mut_from_text :: < ast:: Fn > (
0 commit comments