Index: pkg/analysis_server/lib/src/provisional/edit/utilities/change_builder_dart.dart |
diff --git a/pkg/analysis_server/lib/src/provisional/edit/utilities/change_builder_dart.dart b/pkg/analysis_server/lib/src/provisional/edit/utilities/change_builder_dart.dart |
index 557b1503959ddef24ec3038055191b4c538c0085..35ab956774b7cb8850d4c1ef6a180f0783916684 100644 |
--- a/pkg/analysis_server/lib/src/provisional/edit/utilities/change_builder_dart.dart |
+++ b/pkg/analysis_server/lib/src/provisional/edit/utilities/change_builder_dart.dart |
@@ -8,6 +8,7 @@ import 'package:analyzer/dart/ast/ast.dart'; |
import 'package:analyzer/dart/element/element.dart'; |
import 'package:analyzer/dart/element/type.dart'; |
import 'package:analyzer/src/dart/analysis/driver.dart'; |
+import 'package:analyzer/src/generated/resolver.dart'; |
/** |
* A [ChangeBuilder] used to build changes in Dart files. |
@@ -47,7 +48,7 @@ abstract class DartEditBuilder extends EditBuilder { |
* list of [interfaces] is provided, then the class will implement those |
* interfaces. If [isAbstract] is `true`, then the class will be abstract. If |
* a [memberWriter] is provided, then it will be invoked to allow members to |
- * be generated. (The members will automatically be preceeded and followed by |
+ * be generated. (The members will automatically be preceded and followed by |
* end-of-line markers.) If a list of [mixins] is provided, then the class |
* will mix in those classes. If a [nameGroupName] is provided, then the name |
* of the class will be included in the linked edit group with that name. If a |
@@ -61,18 +62,19 @@ abstract class DartEditBuilder extends EditBuilder { |
void memberWriter(), |
Iterable<DartType> mixins, |
String nameGroupName, |
- DartType superclass}); |
+ DartType superclass, |
+ String superclassGroupName}); |
/** |
* Write the code for a declaration of a field with the given [name]. If an |
* [initializerWriter] is provided, it will be invoked to write the content of |
* the initializer. (The equal sign separating the field name from the |
* initializer expression will automatically be written.) If [isConst] is |
- * `true`, then the declaration will be preceeded by the `const` keyword. If |
- * [isFinal] is `true`, then the declaration will be preceeded by the `final` |
+ * `true`, then the declaration will be preceded by the `const` keyword. If |
+ * [isFinal] is `true`, then the declaration will be preceded by the `final` |
* keyword. (If both [isConst] and [isFinal] are `true`, then only the `const` |
* keyword will be written.) If [isStatic] is `true`, then the declaration |
- * will be preceeded by the `static` keyword. If a [nameGroupName] is |
+ * will be preceded by the `static` keyword. If a [nameGroupName] is |
* provided, the name of the field will be included in the linked edit group |
* with that name. If a [type] is provided, then it will be used as the type |
* of the field. (The keyword `var` will be provided automatically when |
@@ -89,10 +91,32 @@ abstract class DartEditBuilder extends EditBuilder { |
String typeGroupName}); |
/** |
+ * Write the code for a declaration of a function with the given [name]. If a |
+ * [bodyWriter] is provided, it will be invoked to write the body of the |
+ * function. (The space between the name and the body will automatically be |
+ * written.) If [isStatic] is `true`, then the declaration will be preceded |
+ * by the `static` keyword. If a [nameGroupName] is provided, the name of the |
+ * function will be included in the linked edit group with that name. If a |
+ * [returnType] is provided, then it will be used as the return type of the |
+ * function. If a [returnTypeGroupName] is provided, then if a return type was |
+ * written it will be in the linked edit group with that name. If a |
+ * [parameterWriter] is provided, then it will be invoked to write the |
+ * declarations of the parameters to the function. (The parentheses around the |
+ * parameters will automatically be written.) |
+ */ |
+ void writeFunctionDeclaration(String name, |
+ {void bodyWriter(), |
+ bool isStatic: false, |
+ String nameGroupName, |
+ void parameterWriter(), |
+ DartType returnType, |
+ String returnTypeGroupName}); |
+ |
+ /** |
* Write the code for a declaration of a getter with the given [name]. If a |
* [bodyWriter] is provided, it will be invoked to write the body of the |
* getter. (The space between the name and the body will automatically be |
- * written.) If [isStatic] is `true`, then the declaration will be preceeded |
+ * written.) If [isStatic] is `true`, then the declaration will be preceded |
* by the `static` keyword. If a [nameGroupName] is provided, the name of the |
* getter will be included in the linked edit group with that name. If a |
* [returnType] is provided, then it will be used as the return type of the |
@@ -107,11 +131,44 @@ abstract class DartEditBuilder extends EditBuilder { |
String returnTypeGroupName}); |
/** |
+ * Write the code for a declaration of a local variable with the given [name]. |
+ * If an [initializerWriter] is provided, it will be invoked to write the |
+ * content of the initializer. (The equal sign separating the variable name |
+ * from the initializer expression will automatically be written.) If |
+ * [isConst] is `true`, then the declaration will be preceded by the `const` |
+ * keyword. If [isFinal] is `true`, then the declaration will be preceded by |
+ * the `final` keyword. (If both [isConst] and [isFinal] are `true`, then only |
+ * the `const` keyword will be written.) If a [nameGroupName] is provided, the |
+ * name of the variable will be included in the linked edit group with that |
+ * name. If a [type] is provided, then it will be used as the type of the |
+ * variable. (The keyword `var` will be provided automatically when required.) |
+ * If a [typeGroupName] is provided, then if a type was written it will be in |
+ * the linked edit group with that name. |
+ */ |
+ void writeLocalVariableDeclaration(String name, |
+ {void initializerWriter(), |
+ bool isConst: false, |
+ bool isFinal: false, |
+ String nameGroupName, |
+ DartType type, |
+ String typeGroupName}); |
+ |
+ /** |
* Append a placeholder for an override of the specified inherited [member]. |
*/ |
void writeOverrideOfInheritedMember(ExecutableElement member); |
/** |
+ * Write the code for a parameter that would match the given [argument]. The |
+ * name of the parameter will be generated based on the type of the argument, |
+ * but if the argument type is not known the [index] will be used to compose |
+ * a name. In any case, the set of [usedNames] will be used to ensure that the |
+ * name is unique (and the chosen name will be added to the set). |
+ */ |
+ void writeParameterMatchingArgument( |
+ Expression argument, int index, Set<String> usedNames); |
+ |
+ /** |
* Write the code for a list of [parameters], including the surrounding |
* parentheses. |
*/ |
@@ -119,7 +176,7 @@ abstract class DartEditBuilder extends EditBuilder { |
/** |
* Write the code for a list of parameters that would match the given list of |
- * [arguments], including the surrounding parentheses. |
+ * [arguments]. The surrounding parentheses are *not* written. |
*/ |
void writeParametersMatchingArguments(ArgumentList arguments); |
@@ -152,4 +209,41 @@ abstract class DartEditBuilder extends EditBuilder { |
* |
* Clients may not extend, implement or mix-in this class. |
*/ |
-abstract class DartFileEditBuilder extends FileEditBuilder {} |
+abstract class DartFileEditBuilder extends FileEditBuilder { |
+ /** |
+ * Create one or more edits that will convert the given function [body] from |
+ * being synchronous to be asynchronous. This includes adding the `async` |
+ * modifier to the body as well as potentially replacing the return type of |
+ * the function to `Future`. |
+ * |
+ * There is currently a limitation in that the function body must not be a |
+ * generator. |
+ * |
+ * Throws an [ArgumentError] if the function body is not both synchronous and |
+ * a non-generator. |
+ */ |
+ void convertFunctionFromSyncToAsync( |
+ FunctionBody body, TypeProvider typeProvider); |
+ |
+ /** |
+ * Optionally create an edit to replace the given [typeAnnotation] with the |
+ * type `Future` (with the given type annotation as the type argument). The |
+ * [typeProvider] is used to check the current type, because if it is already |
+ * `Future` no edit will be added. |
+ */ |
+ void replaceTypeWithFuture( |
+ TypeAnnotation typeAnnotation, TypeProvider typeProvider); |
+} |
+ |
+/** |
+ * A [LinkedEditBuilder] used to build linked edits for Dart files. |
+ * |
+ * Clients may not extend, implement or mix-in this class. |
+ */ |
+abstract class DartLinkedEditBuilder extends LinkedEditBuilder { |
+ /** |
+ * Add the given [type] and all of its supertypes (other than mixins) as |
+ * suggestions for the current linked edit group. |
+ */ |
+ void addSuperTypesAsSuggestions(DartType type); |
+} |