| Index: pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| index be95ec110e997d1078a2285df34f7db6c05f51b3..a35eeb82b9880b9a8524f12a2cf6ff0a4a30a65c 100644
|
| --- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| +++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
|
| @@ -287,10 +287,6 @@ class AssistProcessor {
|
|
|
| void _addProposal_addTypeAnnotation_VariableDeclaration() {
|
| AstNode node = this.node;
|
| - // check if "var v = 42;^"
|
| - if (node is VariableDeclarationStatement) {
|
| - node = (node as VariableDeclarationStatement).variables;
|
| - }
|
| // prepare VariableDeclarationList
|
| VariableDeclarationList declarationList =
|
| node.getAncestor((node) => node is VariableDeclarationList);
|
| @@ -310,6 +306,11 @@ class AssistProcessor {
|
| return;
|
| }
|
| VariableDeclaration variable = variables[0];
|
| + // must be not after the name of the variable
|
| + if (selectionOffset > variable.name.end) {
|
| + _coverageMarker();
|
| + return;
|
| + }
|
| // we need an initializer to get the type from
|
| Expression initializer = variable.initializer;
|
| if (initializer == null) {
|
| @@ -1431,44 +1432,26 @@ class AssistProcessor {
|
| }
|
|
|
| void _addProposal_removeTypeAnnotation() {
|
| - VariableDeclarationList variableList;
|
| - // try top-level variable
|
| - {
|
| - TopLevelVariableDeclaration declaration =
|
| - node.getAncestor((node) => node is TopLevelVariableDeclaration);
|
| - if (declaration != null) {
|
| - variableList = declaration.variables;
|
| - }
|
| - }
|
| - // try class field
|
| - if (variableList == null) {
|
| - FieldDeclaration fieldDeclaration =
|
| - node.getAncestor((node) => node is FieldDeclaration);
|
| - if (fieldDeclaration != null) {
|
| - variableList = fieldDeclaration.fields;
|
| - }
|
| - }
|
| - // try local variable
|
| - if (variableList == null) {
|
| - VariableDeclarationStatement statement =
|
| - node.getAncestor((node) => node is VariableDeclarationStatement);
|
| - if (statement != null) {
|
| - variableList = statement.variables;
|
| - }
|
| - }
|
| - if (variableList == null) {
|
| + VariableDeclarationList declarationList =
|
| + node.getAncestor((n) => n is VariableDeclarationList);
|
| + if (declarationList == null) {
|
| _coverageMarker();
|
| return;
|
| }
|
| // we need a type
|
| - TypeName typeNode = variableList.type;
|
| + TypeName typeNode = declarationList.type;
|
| if (typeNode == null) {
|
| _coverageMarker();
|
| return;
|
| }
|
| + // must be not after the name of the variable
|
| + VariableDeclaration firstVariable = declarationList.variables[0];
|
| + if (selectionOffset > firstVariable.name.end) {
|
| + _coverageMarker();
|
| + return;
|
| + }
|
| // add edit
|
| - Token keyword = variableList.keyword;
|
| - VariableDeclaration firstVariable = variableList.variables[0];
|
| + Token keyword = declarationList.keyword;
|
| SourceRange typeRange = rangeStartStart(typeNode, firstVariable);
|
| if (keyword != null && keyword.lexeme != 'var') {
|
| _addReplaceEdit(typeRange, '');
|
|
|