| 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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 692 |
| 693 class CorrectionUtils { | 693 class CorrectionUtils { |
| 694 final CompilationUnit unit; | 694 final CompilationUnit unit; |
| 695 | 695 |
| 696 /** | 696 /** |
| 697 * The [ClassElement] the generated code is inserted to, so we can decide if | 697 * The [ClassElement] the generated code is inserted to, so we can decide if |
| 698 * a type parameter may or may not be used. | 698 * a type parameter may or may not be used. |
| 699 */ | 699 */ |
| 700 ClassElement targetClassElement; | 700 ClassElement targetClassElement; |
| 701 | 701 |
| 702 ExecutableElement targetExecutableElement; |
| 703 |
| 702 LibraryElement _library; | 704 LibraryElement _library; |
| 703 String _buffer; | 705 String _buffer; |
| 704 String _endOfLine; | 706 String _endOfLine; |
| 705 | 707 |
| 706 CorrectionUtils(this.unit) { | 708 CorrectionUtils(this.unit) { |
| 707 CompilationUnitElement unitElement = unit.element; | 709 CompilationUnitElement unitElement = unit.element; |
| 708 AnalysisContext context = unitElement.context; | 710 AnalysisContext context = unitElement.context; |
| 709 if (context == null) { | 711 if (context == null) { |
| 710 throw new CancelCorrectionException(); | 712 throw new CancelCorrectionException(); |
| 711 } | 713 } |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 return _invertCondition0(expression.unParenthesized); | 1495 return _invertCondition0(expression.unParenthesized); |
| 1494 } | 1496 } |
| 1495 DartType type = expression.bestType; | 1497 DartType type = expression.bestType; |
| 1496 if (type.displayName == "bool") { | 1498 if (type.displayName == "bool") { |
| 1497 return _InvertedCondition._simple("!${getNodeText(expression)}"); | 1499 return _InvertedCondition._simple("!${getNodeText(expression)}"); |
| 1498 } | 1500 } |
| 1499 return _InvertedCondition._simple(getNodeText(expression)); | 1501 return _InvertedCondition._simple(getNodeText(expression)); |
| 1500 } | 1502 } |
| 1501 | 1503 |
| 1502 /** | 1504 /** |
| 1503 * Checks if [type] is visible at [targetOffset]. | 1505 * Checks if [type] is visible in [targetExecutableElement] or |
| 1506 * [targetClassElement]. |
| 1504 */ | 1507 */ |
| 1505 bool _isTypeVisible(DartType type) { | 1508 bool _isTypeVisible(DartType type) { |
| 1506 if (type is TypeParameterType) { | 1509 if (type is TypeParameterType) { |
| 1507 TypeParameterElement parameterElement = type.element; | 1510 TypeParameterElement parameterElement = type.element; |
| 1508 Element parameterClassElement = parameterElement.enclosingElement; | 1511 Element parameterClassElement = parameterElement.enclosingElement; |
| 1509 return identical(parameterClassElement, targetClassElement); | 1512 return identical(parameterClassElement, targetExecutableElement) || |
| 1513 identical(parameterClassElement, targetClassElement); |
| 1510 } | 1514 } |
| 1511 return true; | 1515 return true; |
| 1512 } | 1516 } |
| 1513 | 1517 |
| 1514 /** | 1518 /** |
| 1515 * @return <code>true</code> if "selection" covers "range" and there are any n
on-whitespace tokens | 1519 * @return <code>true</code> if "selection" covers "range" and there are any n
on-whitespace tokens |
| 1516 * between "selection" and "range" start/end. | 1520 * between "selection" and "range" start/end. |
| 1517 */ | 1521 */ |
| 1518 bool _selectionIncludesNonWhitespaceOutsideRange( | 1522 bool _selectionIncludesNonWhitespaceOutsideRange( |
| 1519 SourceRange selection, SourceRange range) { | 1523 SourceRange selection, SourceRange range) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 _InvertedCondition expr, int newOperatorPrecedence) { | 1665 _InvertedCondition expr, int newOperatorPrecedence) { |
| 1662 if (expr._precedence < newOperatorPrecedence) { | 1666 if (expr._precedence < newOperatorPrecedence) { |
| 1663 return "(${expr._source})"; | 1667 return "(${expr._source})"; |
| 1664 } | 1668 } |
| 1665 return expr._source; | 1669 return expr._source; |
| 1666 } | 1670 } |
| 1667 | 1671 |
| 1668 static _InvertedCondition _simple(String source) => | 1672 static _InvertedCondition _simple(String source) => |
| 1669 new _InvertedCondition(2147483647, source); | 1673 new _InvertedCondition(2147483647, source); |
| 1670 } | 1674 } |
| OLD | NEW |