Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 InterfaceType futureType = typeProvider.futureType; | 1005 InterfaceType futureType = typeProvider.futureType; |
| 1006 // | 1006 // |
| 1007 // Check whether the type needs to be replaced. | 1007 // Check whether the type needs to be replaced. |
| 1008 // | 1008 // |
| 1009 DartType type = typeAnnotation?.type; | 1009 DartType type = typeAnnotation?.type; |
| 1010 if (type == null || | 1010 if (type == null || |
| 1011 type.isDynamic || | 1011 type.isDynamic || |
| 1012 type is InterfaceType && type.element == futureType.element) { | 1012 type is InterfaceType && type.element == futureType.element) { |
| 1013 return; | 1013 return; |
| 1014 } | 1014 } |
| 1015 futureType = futureType.instantiate(<DartType>[type]); | 1015 // TODO(brianwilkerson) Unconditionally execute the body of the 'if' when |
| 1016 // Future<void> is fully supported. | |
| 1017 if (!type.isVoid) { | |
|
scheglov
2017/05/26 16:30:04
Use Future<Null> instead of Future<void> for now?
Brian Wilkerson
2017/05/30 13:15:12
If this is important, I can fix it in a follow-up
| |
| 1018 futureType = futureType.instantiate(<DartType>[type]); | |
| 1019 } | |
| 1016 // prepare code for the types | 1020 // prepare code for the types |
| 1017 addReplacement(range.node(typeAnnotation), (EditBuilder builder) { | 1021 addReplacement(range.node(typeAnnotation), (EditBuilder builder) { |
| 1018 if (!(builder as DartEditBuilder).writeType(futureType)) { | 1022 if (!(builder as DartEditBuilder).writeType(futureType)) { |
| 1019 builder.write('void'); | 1023 builder.write('void'); |
| 1020 } | 1024 } |
| 1021 }); | 1025 }); |
| 1022 } | 1026 } |
| 1023 | 1027 |
| 1024 /** | 1028 /** |
| 1025 * Adds edits to the given [change] that ensure that all the [libraries] are | 1029 * Adds edits to the given [change] that ensure that all the [libraries] are |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 builder.write(importUri); | 1120 builder.write(importUri); |
| 1117 builder.writeln("';"); | 1121 builder.writeln("';"); |
| 1118 if (i == uriList.length - 1 && desc.insertEmptyLineAfter) { | 1122 if (i == uriList.length - 1 && desc.insertEmptyLineAfter) { |
| 1119 builder.writeln(); | 1123 builder.writeln(); |
| 1120 } | 1124 } |
| 1121 }); | 1125 }); |
| 1122 } | 1126 } |
| 1123 } | 1127 } |
| 1124 | 1128 |
| 1125 /** | 1129 /** |
| 1126 * Returns a [InsertDesc] describing where to insert a new directive or a | 1130 * Returns an insertion description describing where to insert a new directive |
| 1127 * top-level declaration at the top of the file. | 1131 * or a top-level declaration at the top of the file. |
| 1128 */ | 1132 */ |
| 1129 _InsertionDescription _getInsertDescTop() { | 1133 _InsertionDescription _getInsertDescTop() { |
| 1130 // skip leading line comments | 1134 // skip leading line comments |
| 1131 int offset = 0; | 1135 int offset = 0; |
| 1132 bool insertEmptyLineBefore = false; | 1136 bool insertEmptyLineBefore = false; |
| 1133 bool insertEmptyLineAfter = false; | 1137 bool insertEmptyLineAfter = false; |
| 1134 String source = unit.element.context.getContents(unit.element.source).data; | 1138 String source = unit.element.context.getContents(unit.element.source).data; |
| 1135 var lineInfo = unit.lineInfo; | 1139 var lineInfo = unit.lineInfo; |
| 1136 // skip hash-bang | 1140 // skip hash-bang |
| 1137 if (offset < source.length - 2) { | 1141 if (offset < source.length - 2) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1161 String linePrefix = _getText(source, offset, 2); | 1165 String linePrefix = _getText(source, offset, 2); |
| 1162 if (linePrefix == "//") { | 1166 if (linePrefix == "//") { |
| 1163 insertEmptyLineBefore = true; | 1167 insertEmptyLineBefore = true; |
| 1164 offset = lineInfo.getOffsetOfLineAfter(offset); | 1168 offset = lineInfo.getOffsetOfLineAfter(offset); |
| 1165 } else { | 1169 } else { |
| 1166 break; | 1170 break; |
| 1167 } | 1171 } |
| 1168 } | 1172 } |
| 1169 // determine if empty line is required after | 1173 // determine if empty line is required after |
| 1170 int currentLine = lineInfo.getLocation(offset).lineNumber; | 1174 int currentLine = lineInfo.getLocation(offset).lineNumber; |
| 1171 if (currentLine < lineInfo.lineCount) { | 1175 if (currentLine + 1 < lineInfo.lineCount) { |
| 1172 int nextLineOffset = lineInfo.getOffsetOfLine(currentLine + 1); | 1176 int nextLineOffset = lineInfo.getOffsetOfLine(currentLine + 1); |
| 1173 String insertLine = source.substring(offset, nextLineOffset); | 1177 String insertLine = source.substring(offset, nextLineOffset); |
| 1174 if (!insertLine.trim().isEmpty) { | 1178 if (!insertLine.trim().isEmpty) { |
| 1175 insertEmptyLineAfter = true; | 1179 insertEmptyLineAfter = true; |
| 1176 } | 1180 } |
| 1177 } | 1181 } |
| 1178 return new _InsertionDescription( | 1182 return new _InsertionDescription( |
| 1179 offset, insertEmptyLineBefore, insertEmptyLineAfter); | 1183 offset, insertEmptyLineBefore, insertEmptyLineAfter); |
| 1180 } | 1184 } |
| 1181 | 1185 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 } | 1311 } |
| 1308 } | 1312 } |
| 1309 | 1313 |
| 1310 class _InsertionDescription { | 1314 class _InsertionDescription { |
| 1311 final int offset; | 1315 final int offset; |
| 1312 final bool insertEmptyLineBefore; | 1316 final bool insertEmptyLineBefore; |
| 1313 final bool insertEmptyLineAfter; | 1317 final bool insertEmptyLineAfter; |
| 1314 _InsertionDescription( | 1318 _InsertionDescription( |
| 1315 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter); | 1319 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter); |
| 1316 } | 1320 } |
| OLD | NEW |