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

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

Issue 2860383002: Move ChangeBuilder to analyzer_plugin (Closed)
Patch Set: Created 3 years, 7 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
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';
7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart';
11 import 'package:analyzer/src/generated/resolver.dart';
12 import 'package:analyzer/src/generated/source.dart';
13
14 /**
15 * A [ChangeBuilder] used to build changes in Dart files.
16 *
17 * Clients may not extend, implement or mix-in this class.
18 */
19 abstract class DartChangeBuilder extends ChangeBuilder {
20 /**
21 * Initialize a newly created change builder.
22 */
23 factory DartChangeBuilder(AnalysisDriver driver) = DartChangeBuilderImpl;
24 }
25
26 /**
27 * An [EditBuilder] used to build edits in Dart files.
28 *
29 * Clients may not extend, implement or mix-in this class.
30 */
31 abstract class DartEditBuilder extends EditBuilder {
32 /**
33 * Write the code for a declaration of a class with the given [name]. If a
34 * list of [interfaces] is provided, then the class will implement those
35 * interfaces. If [isAbstract] is `true`, then the class will be abstract. If
36 * a [memberWriter] is provided, then it will be invoked to allow members to
37 * be generated. (The members will automatically be preceded and followed by
38 * end-of-line markers.) If a list of [mixins] is provided, then the class
39 * will mix in those classes. If a [nameGroupName] is provided, then the name
40 * of the class will be included in the linked edit group with that name. If a
41 * [superclass] is given then it will be the superclass of the class. (If a
42 * list of [mixins] is provided but no [superclass] is given then the class
43 * will extend `Object`.)
44 */
45 void writeClassDeclaration(String name,
46 {Iterable<DartType> interfaces,
47 bool isAbstract: false,
48 void memberWriter(),
49 Iterable<DartType> mixins,
50 String nameGroupName,
51 DartType superclass,
52 String superclassGroupName});
53
54 /**
55 * Write the code for a constructor declaration in the class with the given
56 * [className]. If [isConst] is `true`, then the constructor will be marked
57 * as being a `const` constructor. If a [constructorName] is provided, then
58 * the constructor will have the given name. If both a constructor name and a
59 * [constructorNameGroupName] is provided, then the name of the constructor
60 * will be included in the linked edit group with that name. If an
61 * [argumentList] is provided then the constructor will have parameters that
62 * match the given arguments. If no argument list is given, but a list of
63 * [fieldNames] is provided, then field formal parameters will be created for
64 * each of the field names.
65 */
66 void writeConstructorDeclaration(String className,
67 {ArgumentList argumentList,
68 SimpleIdentifier constructorName,
69 String constructorNameGroupName,
70 List<String> fieldNames,
71 bool isConst: false});
72
73 /**
74 * Write the code for a declaration of a field with the given [name]. If an
75 * [initializerWriter] is provided, it will be invoked to write the content of
76 * the initializer. (The equal sign separating the field name from the
77 * initializer expression will automatically be written.) If [isConst] is
78 * `true`, then the declaration will be preceded by the `const` keyword. If
79 * [isFinal] is `true`, then the declaration will be preceded by the `final`
80 * keyword. (If both [isConst] and [isFinal] are `true`, then only the `const`
81 * keyword will be written.) If [isStatic] is `true`, then the declaration
82 * will be preceded by the `static` keyword. If a [nameGroupName] is
83 * provided, the name of the field will be included in the linked edit group
84 * with that name. If a [type] is provided, then it will be used as the type
85 * of the field. (The keyword `var` will be provided automatically when
86 * required.) If a [typeGroupName] is provided, then if a type was written
87 * it will be in the linked edit group with that name.
88 */
89 void writeFieldDeclaration(String name,
90 {void initializerWriter(),
91 bool isConst: false,
92 bool isFinal: false,
93 bool isStatic: false,
94 String nameGroupName,
95 DartType type,
96 String typeGroupName});
97
98 /**
99 * Write the code for a declaration of a function with the given [name]. If a
100 * [bodyWriter] is provided, it will be invoked to write the body of the
101 * function. (The space between the name and the body will automatically be
102 * written.) If [isStatic] is `true`, then the declaration will be preceded
103 * by the `static` keyword. If a [nameGroupName] is provided, the name of the
104 * function will be included in the linked edit group with that name. If a
105 * [returnType] is provided, then it will be used as the return type of the
106 * function. If a [returnTypeGroupName] is provided, then if a return type was
107 * written it will be in the linked edit group with that name. If a
108 * [parameterWriter] is provided, then it will be invoked to write the
109 * declarations of the parameters to the function. (The parentheses around the
110 * parameters will automatically be written.)
111 */
112 void writeFunctionDeclaration(String name,
113 {void bodyWriter(),
114 bool isStatic: false,
115 String nameGroupName,
116 void parameterWriter(),
117 DartType returnType,
118 String returnTypeGroupName});
119
120 /**
121 * Write the code for a declaration of a getter with the given [name]. If a
122 * [bodyWriter] is provided, it will be invoked to write the body of the
123 * getter. (The space between the name and the body will automatically be
124 * written.) If [isStatic] is `true`, then the declaration will be preceded
125 * by the `static` keyword. If a [nameGroupName] is provided, the name of the
126 * getter will be included in the linked edit group with that name. If a
127 * [returnType] is provided, then it will be used as the return type of the
128 * getter. If a [returnTypeGroupName] is provided, then if a return type was
129 * written it will be in the linked edit group with that name.
130 */
131 void writeGetterDeclaration(String name,
132 {void bodyWriter(),
133 bool isStatic: false,
134 String nameGroupName,
135 DartType returnType,
136 String returnTypeGroupName});
137
138 /**
139 * Write the code for a declaration of a local variable with the given [name].
140 * If an [initializerWriter] is provided, it will be invoked to write the
141 * content of the initializer. (The equal sign separating the variable name
142 * from the initializer expression will automatically be written.) If
143 * [isConst] is `true`, then the declaration will be preceded by the `const`
144 * keyword. If [isFinal] is `true`, then the declaration will be preceded by
145 * the `final` keyword. (If both [isConst] and [isFinal] are `true`, then only
146 * the `const` keyword will be written.) If a [nameGroupName] is provided, the
147 * name of the variable will be included in the linked edit group with that
148 * name. If a [type] is provided, then it will be used as the type of the
149 * variable. (The keyword `var` will be provided automatically when required.)
150 * If a [typeGroupName] is provided, then if a type was written it will be in
151 * the linked edit group with that name.
152 */
153 void writeLocalVariableDeclaration(String name,
154 {void initializerWriter(),
155 bool isConst: false,
156 bool isFinal: false,
157 String nameGroupName,
158 DartType type,
159 String typeGroupName});
160
161 /**
162 * Append a placeholder for an override of the specified inherited [member].
163 */
164 void writeOverrideOfInheritedMember(ExecutableElement member);
165
166 /**
167 * Write the code for a parameter that would match the given [argument]. The
168 * name of the parameter will be generated based on the type of the argument,
169 * but if the argument type is not known the [index] will be used to compose
170 * a name. In any case, the set of [usedNames] will be used to ensure that the
171 * name is unique (and the chosen name will be added to the set).
172 */
173 void writeParameterMatchingArgument(
174 Expression argument, int index, Set<String> usedNames);
175
176 /**
177 * Write the code for a list of [parameters], including the surrounding
178 * parentheses.
179 */
180 void writeParameters(Iterable<ParameterElement> parameters);
181
182 /**
183 * Write the code for a list of parameters that would match the given list of
184 * [arguments]. The surrounding parentheses are *not* written.
185 */
186 void writeParametersMatchingArguments(ArgumentList arguments);
187
188 /**
189 * Write the code for a single parameter with the given [type] and [name].
190 * The [type] can be `null` if no type is to be specified for the parameter.
191 */
192 void writeParameterSource(DartType type, String name);
193
194 /**
195 * Write the code for a type annotation for the given [type]. If the [type] is
196 * either `null` or represents the type 'dynamic', then the behavior depends
197 * on whether a type is [required]. If [required] is `true`, then 'var' will
198 * be written; otherwise, nothing is written.
199 *
200 * If the [groupName] is not `null`, then the name of the type (including type
201 * parameters) will be included as a region in the linked edit group with that
202 * name. If the [groupName] is not `null` and [addSupertypeProposals] is
203 * `true`, then all of the supertypes of the [type] will be added as
204 * suggestions for alternatives to the type name.
205 */
206 bool writeType(DartType type,
207 {bool addSupertypeProposals: false,
208 String groupName,
209 bool required: false});
210
211 /**
212 * Write the code to declare the given [typeParameter]. The enclosing angle
213 * brackets are not automatically written.
214 */
215 void writeTypeParameter(TypeParameterElement typeParameter);
216
217 /**
218 * Write the code to declare the given list of [typeParameters]. The enclosing
219 * angle brackets are automatically written.
220 */
221 void writeTypeParameters(List<TypeParameterElement> typeParameters);
222 }
223
224 /**
225 * A [FileEditBuilder] used to build edits for Dart files.
226 *
227 * Clients may not extend, implement or mix-in this class.
228 */
229 abstract class DartFileEditBuilder extends FileEditBuilder {
230 /**
231 * Create one or more edits that will convert the given function [body] from
232 * being synchronous to be asynchronous. This includes adding the `async`
233 * modifier to the body as well as potentially replacing the return type of
234 * the function to `Future`.
235 *
236 * There is currently a limitation in that the function body must not be a
237 * generator.
238 *
239 * Throws an [ArgumentError] if the function body is not both synchronous and
240 * a non-generator.
241 */
242 void convertFunctionFromSyncToAsync(
243 FunctionBody body, TypeProvider typeProvider);
244
245 /**
246 * Arrange to have imports added for each of the given [libraries].
247 */
248 void importLibraries(Iterable<Source> libraries);
249
250 /**
251 * Optionally create an edit to replace the given [typeAnnotation] with the
252 * type `Future` (with the given type annotation as the type argument). The
253 * [typeProvider] is used to check the current type, because if it is already
254 * `Future` no edit will be added.
255 */
256 void replaceTypeWithFuture(
257 TypeAnnotation typeAnnotation, TypeProvider typeProvider);
258 }
259
260 /**
261 * A [LinkedEditBuilder] used to build linked edits for Dart files.
262 *
263 * Clients may not extend, implement or mix-in this class.
264 */
265 abstract class DartLinkedEditBuilder extends LinkedEditBuilder {
266 /**
267 * Add the given [type] and all of its supertypes (other than mixins) as
268 * suggestions for the current linked edit group.
269 */
270 void addSuperTypesAsSuggestions(DartType type);
271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698