| OLD | NEW |
| 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 | 12 |
| 12 /** | 13 /** |
| 13 * A [ChangeBuilder] used to build changes in Dart files. | 14 * A [ChangeBuilder] used to build changes in Dart files. |
| 14 * | 15 * |
| 15 * Clients may not extend, implement or mix-in this class. | 16 * Clients may not extend, implement or mix-in this class. |
| 16 */ | 17 */ |
| 17 abstract class DartChangeBuilder extends ChangeBuilder { | 18 abstract class DartChangeBuilder extends ChangeBuilder { |
| 18 /** | 19 /** |
| 19 * Initialize a newly created change builder. | 20 * Initialize a newly created change builder. |
| 20 */ | 21 */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 40 /** | 41 /** |
| 41 * The group-id used for the name of the superclass in a class declaration. | 42 * The group-id used for the name of the superclass in a class declaration. |
| 42 */ | 43 */ |
| 43 static const String SUPERCLASS_GROUP_ID = 'SUPERCLASS'; | 44 static const String SUPERCLASS_GROUP_ID = 'SUPERCLASS'; |
| 44 | 45 |
| 45 /** | 46 /** |
| 46 * Write the code for a declaration of a class with the given [name]. If a | 47 * Write the code for a declaration of a class with the given [name]. If a |
| 47 * list of [interfaces] is provided, then the class will implement those | 48 * list of [interfaces] is provided, then the class will implement those |
| 48 * interfaces. If [isAbstract] is `true`, then the class will be abstract. If | 49 * interfaces. If [isAbstract] is `true`, then the class will be abstract. If |
| 49 * a [memberWriter] is provided, then it will be invoked to allow members to | 50 * a [memberWriter] is provided, then it will be invoked to allow members to |
| 50 * be generated. (The members will automatically be preceeded and followed by | 51 * be generated. (The members will automatically be preceded and followed by |
| 51 * end-of-line markers.) If a list of [mixins] is provided, then the class | 52 * end-of-line markers.) If a list of [mixins] is provided, then the class |
| 52 * will mix in those classes. If a [nameGroupName] is provided, then the name | 53 * will mix in those classes. If a [nameGroupName] is provided, then the name |
| 53 * of the class will be included in the linked edit group with that name. If a | 54 * of the class will be included in the linked edit group with that name. If a |
| 54 * [superclass] is given then it will be the superclass of the class. (If a | 55 * [superclass] is given then it will be the superclass of the class. (If a |
| 55 * list of [mixins] is provided but no [superclass] is given then the class | 56 * list of [mixins] is provided but no [superclass] is given then the class |
| 56 * will extend `Object`.) | 57 * will extend `Object`.) |
| 57 */ | 58 */ |
| 58 void writeClassDeclaration(String name, | 59 void writeClassDeclaration(String name, |
| 59 {Iterable<DartType> interfaces, | 60 {Iterable<DartType> interfaces, |
| 60 bool isAbstract: false, | 61 bool isAbstract: false, |
| 61 void memberWriter(), | 62 void memberWriter(), |
| 62 Iterable<DartType> mixins, | 63 Iterable<DartType> mixins, |
| 63 String nameGroupName, | 64 String nameGroupName, |
| 64 DartType superclass}); | 65 DartType superclass, |
| 66 String superclassGroupName}); |
| 65 | 67 |
| 66 /** | 68 /** |
| 67 * Write the code for a declaration of a field with the given [name]. If an | 69 * Write the code for a declaration of a field with the given [name]. If an |
| 68 * [initializerWriter] is provided, it will be invoked to write the content of | 70 * [initializerWriter] is provided, it will be invoked to write the content of |
| 69 * the initializer. (The equal sign separating the field name from the | 71 * the initializer. (The equal sign separating the field name from the |
| 70 * initializer expression will automatically be written.) If [isConst] is | 72 * initializer expression will automatically be written.) If [isConst] is |
| 71 * `true`, then the declaration will be preceeded by the `const` keyword. If | 73 * `true`, then the declaration will be preceded by the `const` keyword. If |
| 72 * [isFinal] is `true`, then the declaration will be preceeded by the `final` | 74 * [isFinal] is `true`, then the declaration will be preceded by the `final` |
| 73 * keyword. (If both [isConst] and [isFinal] are `true`, then only the `const` | 75 * keyword. (If both [isConst] and [isFinal] are `true`, then only the `const` |
| 74 * keyword will be written.) If [isStatic] is `true`, then the declaration | 76 * keyword will be written.) If [isStatic] is `true`, then the declaration |
| 75 * will be preceeded by the `static` keyword. If a [nameGroupName] is | 77 * will be preceded by the `static` keyword. If a [nameGroupName] is |
| 76 * provided, the name of the field will be included in the linked edit group | 78 * provided, the name of the field will be included in the linked edit group |
| 77 * with that name. If a [type] is provided, then it will be used as the type | 79 * with that name. If a [type] is provided, then it will be used as the type |
| 78 * of the field. (The keyword `var` will be provided automatically when | 80 * of the field. (The keyword `var` will be provided automatically when |
| 79 * required.) If a [typeGroupName] is provided, then if a type was written | 81 * required.) If a [typeGroupName] is provided, then if a type was written |
| 80 * it will be in the linked edit group with that name. | 82 * it will be in the linked edit group with that name. |
| 81 */ | 83 */ |
| 82 void writeFieldDeclaration(String name, | 84 void writeFieldDeclaration(String name, |
| 83 {void initializerWriter(), | 85 {void initializerWriter(), |
| 84 bool isConst: false, | 86 bool isConst: false, |
| 85 bool isFinal: false, | 87 bool isFinal: false, |
| 86 bool isStatic: false, | 88 bool isStatic: false, |
| 87 String nameGroupName, | 89 String nameGroupName, |
| 88 DartType type, | 90 DartType type, |
| 89 String typeGroupName}); | 91 String typeGroupName}); |
| 90 | 92 |
| 91 /** | 93 /** |
| 94 * Write the code for a declaration of a function with the given [name]. If a |
| 95 * [bodyWriter] is provided, it will be invoked to write the body of the |
| 96 * function. (The space between the name and the body will automatically be |
| 97 * written.) If [isStatic] is `true`, then the declaration will be preceded |
| 98 * by the `static` keyword. If a [nameGroupName] is provided, the name of the |
| 99 * function will be included in the linked edit group with that name. If a |
| 100 * [returnType] is provided, then it will be used as the return type of the |
| 101 * function. If a [returnTypeGroupName] is provided, then if a return type was |
| 102 * written it will be in the linked edit group with that name. If a |
| 103 * [parameterWriter] is provided, then it will be invoked to write the |
| 104 * declarations of the parameters to the function. (The parentheses around the |
| 105 * parameters will automatically be written.) |
| 106 */ |
| 107 void writeFunctionDeclaration(String name, |
| 108 {void bodyWriter(), |
| 109 bool isStatic: false, |
| 110 String nameGroupName, |
| 111 void parameterWriter(), |
| 112 DartType returnType, |
| 113 String returnTypeGroupName}); |
| 114 |
| 115 /** |
| 92 * Write the code for a declaration of a getter with the given [name]. If a | 116 * Write the code for a declaration of a getter with the given [name]. If a |
| 93 * [bodyWriter] is provided, it will be invoked to write the body of the | 117 * [bodyWriter] is provided, it will be invoked to write the body of the |
| 94 * getter. (The space between the name and the body will automatically be | 118 * getter. (The space between the name and the body will automatically be |
| 95 * written.) If [isStatic] is `true`, then the declaration will be preceeded | 119 * written.) If [isStatic] is `true`, then the declaration will be preceded |
| 96 * by the `static` keyword. If a [nameGroupName] is provided, the name of the | 120 * by the `static` keyword. If a [nameGroupName] is provided, the name of the |
| 97 * getter will be included in the linked edit group with that name. If a | 121 * getter will be included in the linked edit group with that name. If a |
| 98 * [returnType] is provided, then it will be used as the return type of the | 122 * [returnType] is provided, then it will be used as the return type of the |
| 99 * getter. If a [returnTypeGroupName] is provided, then if a return type was | 123 * getter. If a [returnTypeGroupName] is provided, then if a return type was |
| 100 * written it will be in the linked edit group with that name. | 124 * written it will be in the linked edit group with that name. |
| 101 */ | 125 */ |
| 102 void writeGetterDeclaration(String name, | 126 void writeGetterDeclaration(String name, |
| 103 {void bodyWriter(), | 127 {void bodyWriter(), |
| 104 bool isStatic: false, | 128 bool isStatic: false, |
| 105 String nameGroupName, | 129 String nameGroupName, |
| 106 DartType returnType, | 130 DartType returnType, |
| 107 String returnTypeGroupName}); | 131 String returnTypeGroupName}); |
| 108 | 132 |
| 109 /** | 133 /** |
| 134 * Write the code for a declaration of a local variable with the given [name]. |
| 135 * If an [initializerWriter] is provided, it will be invoked to write the |
| 136 * content of the initializer. (The equal sign separating the variable name |
| 137 * from the initializer expression will automatically be written.) If |
| 138 * [isConst] is `true`, then the declaration will be preceded by the `const` |
| 139 * keyword. If [isFinal] is `true`, then the declaration will be preceded by |
| 140 * the `final` keyword. (If both [isConst] and [isFinal] are `true`, then only |
| 141 * the `const` keyword will be written.) If a [nameGroupName] is provided, the |
| 142 * name of the variable will be included in the linked edit group with that |
| 143 * name. If a [type] is provided, then it will be used as the type of the |
| 144 * variable. (The keyword `var` will be provided automatically when required.) |
| 145 * If a [typeGroupName] is provided, then if a type was written it will be in |
| 146 * the linked edit group with that name. |
| 147 */ |
| 148 void writeLocalVariableDeclaration(String name, |
| 149 {void initializerWriter(), |
| 150 bool isConst: false, |
| 151 bool isFinal: false, |
| 152 String nameGroupName, |
| 153 DartType type, |
| 154 String typeGroupName}); |
| 155 |
| 156 /** |
| 110 * Append a placeholder for an override of the specified inherited [member]. | 157 * Append a placeholder for an override of the specified inherited [member]. |
| 111 */ | 158 */ |
| 112 void writeOverrideOfInheritedMember(ExecutableElement member); | 159 void writeOverrideOfInheritedMember(ExecutableElement member); |
| 113 | 160 |
| 114 /** | 161 /** |
| 162 * Write the code for a parameter that would match the given [argument]. The |
| 163 * name of the parameter will be generated based on the type of the argument, |
| 164 * but if the argument type is not known the [index] will be used to compose |
| 165 * a name. In any case, the set of [usedNames] will be used to ensure that the |
| 166 * name is unique (and the chosen name will be added to the set). |
| 167 */ |
| 168 void writeParameterMatchingArgument( |
| 169 Expression argument, int index, Set<String> usedNames); |
| 170 |
| 171 /** |
| 115 * Write the code for a list of [parameters], including the surrounding | 172 * Write the code for a list of [parameters], including the surrounding |
| 116 * parentheses. | 173 * parentheses. |
| 117 */ | 174 */ |
| 118 void writeParameters(Iterable<ParameterElement> parameters); | 175 void writeParameters(Iterable<ParameterElement> parameters); |
| 119 | 176 |
| 120 /** | 177 /** |
| 121 * Write the code for a list of parameters that would match the given list of | 178 * Write the code for a list of parameters that would match the given list of |
| 122 * [arguments], including the surrounding parentheses. | 179 * [arguments]. The surrounding parentheses are *not* written. |
| 123 */ | 180 */ |
| 124 void writeParametersMatchingArguments(ArgumentList arguments); | 181 void writeParametersMatchingArguments(ArgumentList arguments); |
| 125 | 182 |
| 126 /** | 183 /** |
| 127 * Write the code for a single parameter with the given [type] and [name]. | 184 * Write the code for a single parameter with the given [type] and [name]. |
| 128 * The [type] can be `null` if no type is to be specified for the parameter. | 185 * The [type] can be `null` if no type is to be specified for the parameter. |
| 129 */ | 186 */ |
| 130 void writeParameterSource(DartType type, String name); | 187 void writeParameterSource(DartType type, String name); |
| 131 | 188 |
| 132 /** | 189 /** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 145 {bool addSupertypeProposals: false, | 202 {bool addSupertypeProposals: false, |
| 146 String groupName, | 203 String groupName, |
| 147 bool required: false}); | 204 bool required: false}); |
| 148 } | 205 } |
| 149 | 206 |
| 150 /** | 207 /** |
| 151 * A [FileEditBuilder] used to build edits for Dart files. | 208 * A [FileEditBuilder] used to build edits for Dart files. |
| 152 * | 209 * |
| 153 * Clients may not extend, implement or mix-in this class. | 210 * Clients may not extend, implement or mix-in this class. |
| 154 */ | 211 */ |
| 155 abstract class DartFileEditBuilder extends FileEditBuilder {} | 212 abstract class DartFileEditBuilder extends FileEditBuilder { |
| 213 /** |
| 214 * Create one or more edits that will convert the given function [body] from |
| 215 * being synchronous to be asynchronous. This includes adding the `async` |
| 216 * modifier to the body as well as potentially replacing the return type of |
| 217 * the function to `Future`. |
| 218 * |
| 219 * There is currently a limitation in that the function body must not be a |
| 220 * generator. |
| 221 * |
| 222 * Throws an [ArgumentError] if the function body is not both synchronous and |
| 223 * a non-generator. |
| 224 */ |
| 225 void convertFunctionFromSyncToAsync( |
| 226 FunctionBody body, TypeProvider typeProvider); |
| 227 |
| 228 /** |
| 229 * Optionally create an edit to replace the given [typeAnnotation] with the |
| 230 * 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 |
| 232 * `Future` no edit will be added. |
| 233 */ |
| 234 void replaceTypeWithFuture( |
| 235 TypeAnnotation typeAnnotation, TypeProvider typeProvider); |
| 236 } |
| 237 |
| 238 /** |
| 239 * A [LinkedEditBuilder] used to build linked edits for Dart files. |
| 240 * |
| 241 * Clients may not extend, implement or mix-in this class. |
| 242 */ |
| 243 abstract class DartLinkedEditBuilder extends LinkedEditBuilder { |
| 244 /** |
| 245 * Add the given [type] and all of its supertypes (other than mixins) as |
| 246 * suggestions for the current linked edit group. |
| 247 */ |
| 248 void addSuperTypesAsSuggestions(DartType type); |
| 249 } |
| OLD | NEW |