| 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 analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 return problemReported; | 510 return problemReported; |
| 511 } | 511 } |
| 512 | 512 |
| 513 /** | 513 /** |
| 514 * Produce a hint if the given [target] could have a value of `null`. | 514 * Produce a hint if the given [target] could have a value of `null`. |
| 515 */ | 515 */ |
| 516 void _checkForCanBeNullAfterNullAware(Expression target, Token operator) { | 516 void _checkForCanBeNullAfterNullAware(Expression target, Token operator) { |
| 517 if (operator?.type == TokenType.QUESTION_PERIOD) { | 517 if (operator?.type == TokenType.QUESTION_PERIOD) { |
| 518 return; | 518 return; |
| 519 } | 519 } |
| 520 while (target is ParenthesizedExpression) { | 520 target = target?.unParenthesized; |
| 521 target = (target as ParenthesizedExpression).expression; | |
| 522 } | |
| 523 if (target is MethodInvocation) { | 521 if (target is MethodInvocation) { |
| 524 if (target.operator?.type == TokenType.QUESTION_PERIOD) { | 522 if (target.operator?.type == TokenType.QUESTION_PERIOD) { |
| 525 _errorReporter.reportErrorForNode( | 523 _errorReporter.reportErrorForNode( |
| 526 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, target); | 524 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, target); |
| 527 } | 525 } |
| 528 } else if (target is PropertyAccess) { | 526 } else if (target is PropertyAccess) { |
| 529 if (target.operator.type == TokenType.QUESTION_PERIOD) { | 527 if (target.operator.type == TokenType.QUESTION_PERIOD) { |
| 530 _errorReporter.reportErrorForNode( | 528 _errorReporter.reportErrorForNode( |
| 531 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, target); | 529 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, target); |
| 532 } | 530 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 _errorReporter.reportErrorForNode( | 809 _errorReporter.reportErrorForNode( |
| 812 HintCode.MISSING_RETURN, returnType, [returnTypeType.displayName]); | 810 HintCode.MISSING_RETURN, returnType, [returnTypeType.displayName]); |
| 813 } | 811 } |
| 814 } | 812 } |
| 815 } | 813 } |
| 816 | 814 |
| 817 /** | 815 /** |
| 818 * Produce a hint if the given [condition] could have a value of `null`. | 816 * Produce a hint if the given [condition] could have a value of `null`. |
| 819 */ | 817 */ |
| 820 void _checkForPossibleNullCondition(Expression condition) { | 818 void _checkForPossibleNullCondition(Expression condition) { |
| 821 while (condition is ParenthesizedExpression) { | 819 condition = condition?.unParenthesized; |
| 822 condition = (condition as ParenthesizedExpression).expression; | |
| 823 } | |
| 824 if (condition is BinaryExpression) { | 820 if (condition is BinaryExpression) { |
| 825 _checkForPossibleNullConditionInBinaryExpression(condition); | 821 _checkForPossibleNullConditionInBinaryExpression(condition); |
| 826 } else if (condition is PrefixExpression) { | 822 } else if (condition is PrefixExpression) { |
| 827 _checkForPossibleNullConditionInPrefixExpression(condition); | 823 _checkForPossibleNullConditionInPrefixExpression(condition); |
| 828 } else { | 824 } else { |
| 829 _checkForPossibleNullConditionInSimpleExpression(condition); | 825 _checkForPossibleNullConditionInSimpleExpression(condition); |
| 830 } | 826 } |
| 831 } | 827 } |
| 832 | 828 |
| 833 /** | 829 /** |
| (...skipping 4789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5623 } else if (expression is PropertyAccess) { | 5619 } else if (expression is PropertyAccess) { |
| 5624 element = expression.propertyName.staticElement; | 5620 element = expression.propertyName.staticElement; |
| 5625 } | 5621 } |
| 5626 if (element is VariableElement) { | 5622 if (element is VariableElement) { |
| 5627 return element; | 5623 return element; |
| 5628 } | 5624 } |
| 5629 return null; | 5625 return null; |
| 5630 } | 5626 } |
| 5631 | 5627 |
| 5632 /** | 5628 /** |
| 5633 * Return the static element associated with the given expression whose type c
an be promoted, or | 5629 * Return the static element associated with the given expression whose type |
| 5634 * `null` if there is no element whose type can be promoted. | 5630 * can be promoted, or `null` if there is no element whose type can be |
| 5635 * | 5631 * promoted. |
| 5636 * @param expression the expression with which the element is associated | |
| 5637 * @return the element associated with the given expression | |
| 5638 */ | 5632 */ |
| 5639 VariableElement getPromotionStaticElement(Expression expression) { | 5633 VariableElement getPromotionStaticElement(Expression expression) { |
| 5640 while (expression is ParenthesizedExpression) { | 5634 expression = expression?.unParenthesized; |
| 5641 expression = (expression as ParenthesizedExpression).expression; | |
| 5642 } | |
| 5643 if (expression is SimpleIdentifier) { | 5635 if (expression is SimpleIdentifier) { |
| 5644 Element element = expression.staticElement; | 5636 Element element = expression.staticElement; |
| 5645 if (element is VariableElement) { | 5637 if (element is VariableElement) { |
| 5646 ElementKind kind = element.kind; | 5638 ElementKind kind = element.kind; |
| 5647 if (kind == ElementKind.LOCAL_VARIABLE || | 5639 if (kind == ElementKind.LOCAL_VARIABLE || |
| 5648 kind == ElementKind.PARAMETER) { | 5640 kind == ElementKind.PARAMETER) { |
| 5649 return element; | 5641 return element; |
| 5650 } | 5642 } |
| 5651 } | 5643 } |
| 5652 } | 5644 } |
| (...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7170 * following the given expression will not be reached). | 7162 * following the given expression will not be reached). |
| 7171 * | 7163 * |
| 7172 * @param expression the expression being tested | 7164 * @param expression the expression being tested |
| 7173 * @return `true` if the given expression terminates abruptly | 7165 * @return `true` if the given expression terminates abruptly |
| 7174 */ | 7166 */ |
| 7175 bool _isAbruptTerminationExpression(Expression expression) { | 7167 bool _isAbruptTerminationExpression(Expression expression) { |
| 7176 // TODO(brianwilkerson) This needs to be significantly improved. Ideally we | 7168 // TODO(brianwilkerson) This needs to be significantly improved. Ideally we |
| 7177 // would eventually turn this into a method on Expression that returns a | 7169 // would eventually turn this into a method on Expression that returns a |
| 7178 // termination indication (normal, abrupt with no exception, abrupt with an | 7170 // termination indication (normal, abrupt with no exception, abrupt with an |
| 7179 // exception). | 7171 // exception). |
| 7180 while (expression is ParenthesizedExpression) { | 7172 expression = expression?.unParenthesized; |
| 7181 expression = (expression as ParenthesizedExpression).expression; | |
| 7182 } | |
| 7183 return expression is ThrowExpression || expression is RethrowExpression; | 7173 return expression is ThrowExpression || expression is RethrowExpression; |
| 7184 } | 7174 } |
| 7185 | 7175 |
| 7186 /** | 7176 /** |
| 7187 * Return `true` if the given statement terminates abruptly (that is, if any s
tatement | 7177 * Return `true` if the given statement terminates abruptly (that is, if any s
tatement |
| 7188 * following the given statement will not be reached). | 7178 * following the given statement will not be reached). |
| 7189 * | 7179 * |
| 7190 * @param statement the statement being tested | 7180 * @param statement the statement being tested |
| 7191 * @return `true` if the given statement terminates abruptly | 7181 * @return `true` if the given statement terminates abruptly |
| 7192 */ | 7182 */ |
| (...skipping 3702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10895 return null; | 10885 return null; |
| 10896 } | 10886 } |
| 10897 if (identical(node.staticElement, variable)) { | 10887 if (identical(node.staticElement, variable)) { |
| 10898 if (node.inSetterContext()) { | 10888 if (node.inSetterContext()) { |
| 10899 result = true; | 10889 result = true; |
| 10900 } | 10890 } |
| 10901 } | 10891 } |
| 10902 return null; | 10892 return null; |
| 10903 } | 10893 } |
| 10904 } | 10894 } |
| OLD | NEW |