Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Side by Side Diff: pkg/analysis_server/lib/src/provisional/edit/utilities/change_builder_dart.dart

Issue 2790173003: Bug fixes and added support for creating source edits (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_co re.dart'; 5 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_co re.dart';
6 import 'package:analysis_server/src/utilities/change_builder_dart.dart'; 6 import 'package:analysis_server/src/utilities/change_builder_dart.dart';
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart'; 10 import 'package:analyzer/src/dart/analysis/driver.dart';
11 import 'package:analyzer/src/generated/resolver.dart'; 11 import 'package:analyzer/src/generated/resolver.dart';
12 import 'package:analyzer/src/generated/source.dart';
12 13
13 /** 14 /**
14 * A [ChangeBuilder] used to build changes in Dart files. 15 * A [ChangeBuilder] used to build changes in Dart files.
15 * 16 *
16 * Clients may not extend, implement or mix-in this class. 17 * Clients may not extend, implement or mix-in this class.
17 */ 18 */
18 abstract class DartChangeBuilder extends ChangeBuilder { 19 abstract class DartChangeBuilder extends ChangeBuilder {
19 /** 20 /**
20 * Initialize a newly created change builder. 21 * Initialize a newly created change builder.
21 */ 22 */
22 factory DartChangeBuilder(AnalysisDriver driver) = DartChangeBuilderImpl; 23 factory DartChangeBuilder(AnalysisDriver driver) = DartChangeBuilderImpl;
23 } 24 }
24 25
25 /** 26 /**
26 * An [EditBuilder] used to build edits in Dart files. 27 * An [EditBuilder] used to build edits in Dart files.
27 * 28 *
28 * Clients may not extend, implement or mix-in this class. 29 * Clients may not extend, implement or mix-in this class.
29 */ 30 */
30 abstract class DartEditBuilder extends EditBuilder { 31 abstract class DartEditBuilder extends EditBuilder {
31 /** 32 /**
32 * The group-id used for the name of a declaration. 33 * The edits in this builder will be inside the class with the given
34 * [element].
35 *
36 * TODO(brianwilkerson) Remove this method.
33 */ 37 */
34 static const String NAME_GROUP_ID = 'NAME'; 38 void set targetClassElement(ClassElement element);
35
36 /**
37 * The group-id used for the return type of a function, getter or method.
38 */
39 static const String RETURN_TYPE_GROUP_ID = 'RETURN_TYPE';
40
41 /**
42 * The group-id used for the name of the superclass in a class declaration.
43 */
44 static const String SUPERCLASS_GROUP_ID = 'SUPERCLASS';
45 39
46 /** 40 /**
47 * Write the code for a declaration of a class with the given [name]. If a 41 * Write the code for a declaration of a class with the given [name]. If a
48 * list of [interfaces] is provided, then the class will implement those 42 * list of [interfaces] is provided, then the class will implement those
49 * interfaces. If [isAbstract] is `true`, then the class will be abstract. If 43 * interfaces. If [isAbstract] is `true`, then the class will be abstract. If
50 * a [memberWriter] is provided, then it will be invoked to allow members to 44 * a [memberWriter] is provided, then it will be invoked to allow members to
51 * be generated. (The members will automatically be preceded and followed by 45 * be generated. (The members will automatically be preceded and followed by
52 * end-of-line markers.) If a list of [mixins] is provided, then the class 46 * end-of-line markers.) If a list of [mixins] is provided, then the class
53 * will mix in those classes. If a [nameGroupName] is provided, then the name 47 * will mix in those classes. If a [nameGroupName] is provided, then the name
54 * of the class will be included in the linked edit group with that name. If a 48 * of the class will be included in the linked edit group with that name. If a
55 * [superclass] is given then it will be the superclass of the class. (If a 49 * [superclass] is given then it will be the superclass of the class. (If a
56 * list of [mixins] is provided but no [superclass] is given then the class 50 * list of [mixins] is provided but no [superclass] is given then the class
57 * will extend `Object`.) 51 * will extend `Object`.)
58 */ 52 */
59 void writeClassDeclaration(String name, 53 void writeClassDeclaration(String name,
60 {Iterable<DartType> interfaces, 54 {Iterable<DartType> interfaces,
61 bool isAbstract: false, 55 bool isAbstract: false,
62 void memberWriter(), 56 void memberWriter(),
63 Iterable<DartType> mixins, 57 Iterable<DartType> mixins,
64 String nameGroupName, 58 String nameGroupName,
65 DartType superclass, 59 DartType superclass,
66 String superclassGroupName}); 60 String superclassGroupName});
67 61
68 /** 62 /**
63 * Write the code for a constructor declaration in the class with the given
64 * [className]. If [isConst] is `true`, then the constructor will be marked
65 * as being a `const` constructor. If a [constructorName] is provided, then
66 * the constructor will have the given name. If both a constructor name and a
67 * [constructorNameGroupName] is provided, then the name of the constructor
68 * will be included in the linked edit group with that name. If an
69 * [argumentList] is provided then the constructor will have parameters that
70 * match the given arguments. If no argument list is given, but a list of
71 * [fieldNames] is provided, then field formal parameters will be created for
72 * each of the field names.
73 */
74 void writeConstructorDeclaration(String className,
75 {ArgumentList argumentList,
76 SimpleIdentifier constructorName,
77 String constructorNameGroupName,
78 List<String> fieldNames,
79 bool isConst: false});
80
81 /**
69 * Write the code for a declaration of a field with the given [name]. If an 82 * Write the code for a declaration of a field with the given [name]. If an
70 * [initializerWriter] is provided, it will be invoked to write the content of 83 * [initializerWriter] is provided, it will be invoked to write the content of
71 * the initializer. (The equal sign separating the field name from the 84 * the initializer. (The equal sign separating the field name from the
72 * initializer expression will automatically be written.) If [isConst] is 85 * initializer expression will automatically be written.) If [isConst] is
73 * `true`, then the declaration will be preceded by the `const` keyword. If 86 * `true`, then the declaration will be preceded by the `const` keyword. If
74 * [isFinal] is `true`, then the declaration will be preceded by the `final` 87 * [isFinal] is `true`, then the declaration will be preceded by the `final`
75 * keyword. (If both [isConst] and [isFinal] are `true`, then only the `const` 88 * keyword. (If both [isConst] and [isFinal] are `true`, then only the `const`
76 * keyword will be written.) If [isStatic] is `true`, then the declaration 89 * keyword will be written.) If [isStatic] is `true`, then the declaration
77 * will be preceded by the `static` keyword. If a [nameGroupName] is 90 * will be preceded by the `static` keyword. If a [nameGroupName] is
78 * provided, the name of the field will be included in the linked edit group 91 * provided, the name of the field will be included in the linked edit group
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 * If the [groupName] is not `null`, then the name of the type (including type 208 * If the [groupName] is not `null`, then the name of the type (including type
196 * parameters) will be included as a region in the linked edit group with that 209 * parameters) will be included as a region in the linked edit group with that
197 * name. If the [groupName] is not `null` and [addSupertypeProposals] is 210 * name. If the [groupName] is not `null` and [addSupertypeProposals] is
198 * `true`, then all of the supertypes of the [type] will be added as 211 * `true`, then all of the supertypes of the [type] will be added as
199 * suggestions for alternatives to the type name. 212 * suggestions for alternatives to the type name.
200 */ 213 */
201 bool writeType(DartType type, 214 bool writeType(DartType type,
202 {bool addSupertypeProposals: false, 215 {bool addSupertypeProposals: false,
203 String groupName, 216 String groupName,
204 bool required: false}); 217 bool required: false});
218
219 /**
220 * Write the code to declare the given [typeParameter]. The enclosing angle
221 * brackets are not automatically written.
222 */
223 void writeTypeParameter(TypeParameterElement typeParameter);
224
225 /**
226 * Write the code to declare the given list of [typeParameters]. The enclosing
227 * angle brackets are automatically written.
228 */
229 void writeTypeParameters(List<TypeParameterElement> typeParameters);
205 } 230 }
206 231
207 /** 232 /**
208 * A [FileEditBuilder] used to build edits for Dart files. 233 * A [FileEditBuilder] used to build edits for Dart files.
209 * 234 *
210 * Clients may not extend, implement or mix-in this class. 235 * Clients may not extend, implement or mix-in this class.
211 */ 236 */
212 abstract class DartFileEditBuilder extends FileEditBuilder { 237 abstract class DartFileEditBuilder extends FileEditBuilder {
213 /** 238 /**
214 * Create one or more edits that will convert the given function [body] from 239 * Create one or more edits that will convert the given function [body] from
215 * being synchronous to be asynchronous. This includes adding the `async` 240 * being synchronous to be asynchronous. This includes adding the `async`
216 * modifier to the body as well as potentially replacing the return type of 241 * modifier to the body as well as potentially replacing the return type of
217 * the function to `Future`. 242 * the function to `Future`.
218 * 243 *
219 * There is currently a limitation in that the function body must not be a 244 * There is currently a limitation in that the function body must not be a
220 * generator. 245 * generator.
221 * 246 *
222 * Throws an [ArgumentError] if the function body is not both synchronous and 247 * Throws an [ArgumentError] if the function body is not both synchronous and
223 * a non-generator. 248 * a non-generator.
224 */ 249 */
225 void convertFunctionFromSyncToAsync( 250 void convertFunctionFromSyncToAsync(
226 FunctionBody body, TypeProvider typeProvider); 251 FunctionBody body, TypeProvider typeProvider);
227 252
228 /** 253 /**
254 * Arrange to have imports added for each of the given [libraries].
255 */
256 void importLibraries(Iterable<Source> libraries);
257
258 /**
229 * Optionally create an edit to replace the given [typeAnnotation] with the 259 * Optionally create an edit to replace the given [typeAnnotation] with the
230 * type `Future` (with the given type annotation as the type argument). The 260 * type `Future` (with the given type annotation as the type argument). The
231 * [typeProvider] is used to check the current type, because if it is already 261 * [typeProvider] is used to check the current type, because if it is already
232 * `Future` no edit will be added. 262 * `Future` no edit will be added.
233 */ 263 */
234 void replaceTypeWithFuture( 264 void replaceTypeWithFuture(
235 TypeAnnotation typeAnnotation, TypeProvider typeProvider); 265 TypeAnnotation typeAnnotation, TypeProvider typeProvider);
236 } 266 }
237 267
238 /** 268 /**
239 * A [LinkedEditBuilder] used to build linked edits for Dart files. 269 * A [LinkedEditBuilder] used to build linked edits for Dart files.
240 * 270 *
241 * Clients may not extend, implement or mix-in this class. 271 * Clients may not extend, implement or mix-in this class.
242 */ 272 */
243 abstract class DartLinkedEditBuilder extends LinkedEditBuilder { 273 abstract class DartLinkedEditBuilder extends LinkedEditBuilder {
244 /** 274 /**
245 * Add the given [type] and all of its supertypes (other than mixins) as 275 * Add the given [type] and all of its supertypes (other than mixins) as
246 * suggestions for the current linked edit group. 276 * suggestions for the current linked edit group.
247 */ 277 */
248 void addSuperTypesAsSuggestions(DartType type); 278 void addSuperTypesAsSuggestions(DartType type);
249 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698