| 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/plugin/protocol/protocol.dart' | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 10 show SourceChange, SourceEdit; | 10 show SourceChange, SourceEdit; |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 String getText(int offset, int length) { | 1026 String getText(int offset, int length) { |
| 1027 return _buffer.substring(offset, offset + length); | 1027 return _buffer.substring(offset, offset + length); |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 /** | 1030 /** |
| 1031 * Returns the source to reference [type] in this [CompilationUnit]. | 1031 * Returns the source to reference [type] in this [CompilationUnit]. |
| 1032 * | 1032 * |
| 1033 * Fills [librariesToImport] with [LibraryElement]s whose elements are | 1033 * Fills [librariesToImport] with [LibraryElement]s whose elements are |
| 1034 * used by the generated source, but not imported. | 1034 * used by the generated source, but not imported. |
| 1035 */ | 1035 */ |
| 1036 String getTypeSource(DartType type, Set<LibraryElement> librariesToImport) { | 1036 String getTypeSource(DartType type, Set<LibraryElement> librariesToImport, |
| 1037 {StringBuffer parametersBuffer}) { |
| 1037 StringBuffer sb = new StringBuffer(); | 1038 StringBuffer sb = new StringBuffer(); |
| 1038 // type parameter | 1039 // type parameter |
| 1039 if (!_isTypeVisible(type)) { | 1040 if (!_isTypeVisible(type)) { |
| 1040 return 'dynamic'; | 1041 return 'dynamic'; |
| 1041 } | 1042 } |
| 1042 // just a Function, not FunctionTypeAliasElement | 1043 // just a Function, not FunctionTypeAliasElement |
| 1043 if (type is FunctionType && type.element is! FunctionTypeAliasElement) { | 1044 if (type is FunctionType && type.element is! FunctionTypeAliasElement) { |
| 1044 return "Function"; | 1045 if (parametersBuffer == null) { |
| 1046 return "Function"; |
| 1047 } |
| 1048 parametersBuffer.write('('); |
| 1049 for (ParameterElement parameter in type.parameters) { |
| 1050 String parameterType = getTypeSource(parameter.type, librariesToImport); |
| 1051 if (parametersBuffer.length != 1) { |
| 1052 parametersBuffer.write(', '); |
| 1053 } |
| 1054 parametersBuffer.write(parameterType); |
| 1055 parametersBuffer.write(' '); |
| 1056 parametersBuffer.write(parameter.name); |
| 1057 } |
| 1058 parametersBuffer.write(')'); |
| 1059 return getTypeSource(type.returnType, librariesToImport); |
| 1045 } | 1060 } |
| 1046 // BottomType | 1061 // BottomType |
| 1047 if (type.isBottom) { | 1062 if (type.isBottom) { |
| 1048 return 'dynamic'; | 1063 return 'dynamic'; |
| 1049 } | 1064 } |
| 1050 // prepare element | 1065 // prepare element |
| 1051 Element element = type.element; | 1066 Element element = type.element; |
| 1052 if (element == null) { | 1067 if (element == null) { |
| 1053 String source = type.toString(); | 1068 String source = type.toString(); |
| 1054 source = source.replaceAll('<dynamic>', ''); | 1069 source = source.replaceAll('<dynamic>', ''); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 _InvertedCondition expr, int newOperatorPrecedence) { | 1516 _InvertedCondition expr, int newOperatorPrecedence) { |
| 1502 if (expr._precedence < newOperatorPrecedence) { | 1517 if (expr._precedence < newOperatorPrecedence) { |
| 1503 return "(${expr._source})"; | 1518 return "(${expr._source})"; |
| 1504 } | 1519 } |
| 1505 return expr._source; | 1520 return expr._source; |
| 1506 } | 1521 } |
| 1507 | 1522 |
| 1508 static _InvertedCondition _simple(String source) => | 1523 static _InvertedCondition _simple(String source) => |
| 1509 new _InvertedCondition(2147483647, source); | 1524 new _InvertedCondition(2147483647, source); |
| 1510 } | 1525 } |
| OLD | NEW |