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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 InterfaceType futureType = typeProvider.futureType; | 1024 InterfaceType futureType = typeProvider.futureType; |
1025 // | 1025 // |
1026 // Check whether the type needs to be replaced. | 1026 // Check whether the type needs to be replaced. |
1027 // | 1027 // |
1028 DartType type = typeAnnotation?.type; | 1028 DartType type = typeAnnotation?.type; |
1029 if (type == null || | 1029 if (type == null || |
1030 type.isDynamic || | 1030 type.isDynamic || |
1031 type is InterfaceType && type.element == futureType.element) { | 1031 type is InterfaceType && type.element == futureType.element) { |
1032 return; | 1032 return; |
1033 } | 1033 } |
1034 futureType = futureType.instantiate(<DartType>[type]); | 1034 // TODO(brianwilkerson) Unconditionally execute the body of the 'if' when |
| 1035 // Future<void> is fully supported. |
| 1036 if (!type.isVoid) { |
| 1037 futureType = futureType.instantiate(<DartType>[type]); |
| 1038 } |
1035 // prepare code for the types | 1039 // prepare code for the types |
1036 addReplacement(range.node(typeAnnotation), (EditBuilder builder) { | 1040 addReplacement(range.node(typeAnnotation), (EditBuilder builder) { |
1037 if (!(builder as DartEditBuilder).writeType(futureType)) { | 1041 if (!(builder as DartEditBuilder).writeType(futureType)) { |
1038 builder.write('void'); | 1042 builder.write('void'); |
1039 } | 1043 } |
1040 }); | 1044 }); |
1041 } | 1045 } |
1042 | 1046 |
1043 /** | 1047 /** |
1044 * Adds edits to the given [change] that ensure that all the [libraries] are | 1048 * 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... |
1135 builder.write(importUri); | 1139 builder.write(importUri); |
1136 builder.writeln("';"); | 1140 builder.writeln("';"); |
1137 if (i == uriList.length - 1 && desc.insertEmptyLineAfter) { | 1141 if (i == uriList.length - 1 && desc.insertEmptyLineAfter) { |
1138 builder.writeln(); | 1142 builder.writeln(); |
1139 } | 1143 } |
1140 }); | 1144 }); |
1141 } | 1145 } |
1142 } | 1146 } |
1143 | 1147 |
1144 /** | 1148 /** |
1145 * Returns a [InsertDesc] describing where to insert a new directive or a | 1149 * Returns an insertion description describing where to insert a new directive |
1146 * top-level declaration at the top of the file. | 1150 * or a top-level declaration at the top of the file. |
1147 */ | 1151 */ |
1148 _InsertionDescription _getInsertDescTop() { | 1152 _InsertionDescription _getInsertDescTop() { |
1149 // skip leading line comments | 1153 // skip leading line comments |
1150 int offset = 0; | 1154 int offset = 0; |
1151 bool insertEmptyLineBefore = false; | 1155 bool insertEmptyLineBefore = false; |
1152 bool insertEmptyLineAfter = false; | 1156 bool insertEmptyLineAfter = false; |
1153 String source = unit.element.context.getContents(unit.element.source).data; | 1157 String source = unit.element.context.getContents(unit.element.source).data; |
1154 var lineInfo = unit.lineInfo; | 1158 var lineInfo = unit.lineInfo; |
1155 // skip hash-bang | 1159 // skip hash-bang |
1156 if (offset < source.length - 2) { | 1160 if (offset < source.length - 2) { |
(...skipping 23 matching lines...) Expand all Loading... |
1180 String linePrefix = _getText(source, offset, 2); | 1184 String linePrefix = _getText(source, offset, 2); |
1181 if (linePrefix == "//") { | 1185 if (linePrefix == "//") { |
1182 insertEmptyLineBefore = true; | 1186 insertEmptyLineBefore = true; |
1183 offset = lineInfo.getOffsetOfLineAfter(offset); | 1187 offset = lineInfo.getOffsetOfLineAfter(offset); |
1184 } else { | 1188 } else { |
1185 break; | 1189 break; |
1186 } | 1190 } |
1187 } | 1191 } |
1188 // determine if empty line is required after | 1192 // determine if empty line is required after |
1189 int currentLine = lineInfo.getLocation(offset).lineNumber; | 1193 int currentLine = lineInfo.getLocation(offset).lineNumber; |
1190 if (currentLine < lineInfo.lineCount) { | 1194 if (currentLine + 1 < lineInfo.lineCount) { |
1191 int nextLineOffset = lineInfo.getOffsetOfLine(currentLine + 1); | 1195 int nextLineOffset = lineInfo.getOffsetOfLine(currentLine + 1); |
1192 String insertLine = source.substring(offset, nextLineOffset); | 1196 String insertLine = source.substring(offset, nextLineOffset); |
1193 if (!insertLine.trim().isEmpty) { | 1197 if (!insertLine.trim().isEmpty) { |
1194 insertEmptyLineAfter = true; | 1198 insertEmptyLineAfter = true; |
1195 } | 1199 } |
1196 } | 1200 } |
1197 return new _InsertionDescription( | 1201 return new _InsertionDescription( |
1198 offset, insertEmptyLineBefore, insertEmptyLineAfter); | 1202 offset, insertEmptyLineBefore, insertEmptyLineAfter); |
1199 } | 1203 } |
1200 | 1204 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 } | 1330 } |
1327 } | 1331 } |
1328 | 1332 |
1329 class _InsertionDescription { | 1333 class _InsertionDescription { |
1330 final int offset; | 1334 final int offset; |
1331 final bool insertEmptyLineBefore; | 1335 final bool insertEmptyLineBefore; |
1332 final bool insertEmptyLineAfter; | 1336 final bool insertEmptyLineAfter; |
1333 _InsertionDescription( | 1337 _InsertionDescription( |
1334 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter); | 1338 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter); |
1335 } | 1339 } |
OLD | NEW |