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

Unified Diff: pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Issue 1051733003: Fix removing type annotations for const/final variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/assist_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 63287c4eb0fd4e96a9aa3b93a488db21167e9ab1..d213c4725c3572d0329a8c32eab736c3d9da3874 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -1126,50 +1126,48 @@ class AssistProcessor {
}
void _addProposal_removeTypeAnnotation() {
- AstNode typeStart = null;
- AstNode typeEnd = null;
+ VariableDeclarationList variableList;
// try top-level variable
{
TopLevelVariableDeclaration declaration =
node.getAncestor((node) => node is TopLevelVariableDeclaration);
if (declaration != null) {
- TypeName typeNode = declaration.variables.type;
- if (typeNode != null) {
- VariableDeclaration field = declaration.variables.variables[0];
- typeStart = declaration;
- typeEnd = field;
- }
+ variableList = declaration.variables;
}
}
// try class field
- {
+ if (variableList == null) {
FieldDeclaration fieldDeclaration =
node.getAncestor((node) => node is FieldDeclaration);
if (fieldDeclaration != null) {
- TypeName typeNode = fieldDeclaration.fields.type;
- if (typeNode != null) {
- VariableDeclaration field = fieldDeclaration.fields.variables[0];
- typeStart = fieldDeclaration;
- typeEnd = field;
- }
+ variableList = fieldDeclaration.fields;
}
}
// try local variable
- {
+ if (variableList == null) {
VariableDeclarationStatement statement =
node.getAncestor((node) => node is VariableDeclarationStatement);
if (statement != null) {
- TypeName typeNode = statement.variables.type;
- if (typeNode != null) {
- VariableDeclaration variable = statement.variables.variables[0];
- typeStart = typeNode;
- typeEnd = variable;
- }
+ variableList = statement.variables;
}
}
+ if (variableList == null) {
+ _coverageMarker();
+ return;
+ }
+ // we need a type
+ TypeName typeNode = variableList.type;
+ if (typeNode == null) {
+ _coverageMarker();
+ return;
+ }
// add edit
- if (typeStart != null && typeEnd != null) {
- SourceRange typeRange = rangeStartStart(typeStart, typeEnd);
+ Token keyword = variableList.keyword;
+ VariableDeclaration firstVariable = variableList.variables[0];
+ SourceRange typeRange = rangeStartStart(typeNode, firstVariable);
+ if (keyword != null && keyword.lexeme != 'var') {
+ _addReplaceEdit(typeRange, '');
+ } else {
_addReplaceEdit(typeRange, 'var ');
}
// add proposal
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/assist_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698