OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library services.src.correction.util; | 5 library services.src.correction.util; |
6 | 6 |
7 import 'dart:math'; | 7 import 'dart:math'; |
8 | 8 |
9 import 'package:analysis_server/src/protocol.dart' show SourceChange, | 9 import 'package:analysis_server/src/protocol.dart' show SourceChange, |
10 SourceEdit; | 10 SourceEdit; |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 | 927 |
928 /** | 928 /** |
929 * Returns the text of the given range in the unit. | 929 * Returns the text of the given range in the unit. |
930 */ | 930 */ |
931 String getText(int offset, int length) { | 931 String getText(int offset, int length) { |
932 return _buffer.substring(offset, offset + length); | 932 return _buffer.substring(offset, offset + length); |
933 } | 933 } |
934 | 934 |
935 /** | 935 /** |
936 * Returns the source to reference [type] in this [CompilationUnit]. | 936 * Returns the source to reference [type] in this [CompilationUnit]. |
| 937 * May return `null` if [type] does not have a source. |
937 * | 938 * |
938 * Fills [librariesToImport] with [LibraryElement]s whose elements are | 939 * Fills [librariesToImport] with [LibraryElement]s whose elements are |
939 * used by the generated source, but not imported. | 940 * used by the generated source, but not imported. |
940 */ | 941 */ |
941 String getTypeSource(DartType type, Set<LibraryElement> librariesToImport) { | 942 String getTypeSource(DartType type, Set<LibraryElement> librariesToImport) { |
942 StringBuffer sb = new StringBuffer(); | 943 StringBuffer sb = new StringBuffer(); |
943 // just a Function, not FunctionTypeAliasElement | 944 // just a Function, not FunctionTypeAliasElement |
944 if (type is FunctionType && type.element is! FunctionTypeAliasElement) { | 945 if (type is FunctionType && type.element is! FunctionTypeAliasElement) { |
945 return "Function"; | 946 return "Function"; |
946 } | 947 } |
| 948 // dynamic or BottomType |
| 949 if (type.isDynamic || type.isBottom) { |
| 950 return null; |
| 951 } |
947 // prepare element | 952 // prepare element |
948 Element element = type.element; | 953 Element element = type.element; |
949 if (element == null) { | 954 if (element == null) { |
950 String source = type.toString(); | 955 String source = type.toString(); |
951 source = source.replaceAll('<dynamic>', ''); | 956 source = source.replaceAll('<dynamic>', ''); |
952 source = source.replaceAll('<dynamic, dynamic>', ''); | 957 source = source.replaceAll('<dynamic, dynamic>', ''); |
953 return source; | 958 return source; |
954 } | 959 } |
955 // check if imported | 960 // check if imported |
956 if (element.library != _library) { | 961 if (element.library != _library) { |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 | 1473 |
1469 @override | 1474 @override |
1470 Object visitExpression(Expression node) { | 1475 Object visitExpression(Expression node) { |
1471 if (node is BinaryExpression && node.operator.type == groupOperatorType) { | 1476 if (node is BinaryExpression && node.operator.type == groupOperatorType) { |
1472 return super.visitNode(node); | 1477 return super.visitNode(node); |
1473 } | 1478 } |
1474 operands.add(node); | 1479 operands.add(node); |
1475 return null; | 1480 return null; |
1476 } | 1481 } |
1477 } | 1482 } |
OLD | NEW |