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/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 } | 1020 } |
1021 } | 1021 } |
1022 // Check the block for a return statement, if not, create the hint | 1022 // Check the block for a return statement, if not, create the hint |
1023 if (!ExitDetector.exits(body)) { | 1023 if (!ExitDetector.exits(body)) { |
1024 _errorReporter.reportErrorForNode( | 1024 _errorReporter.reportErrorForNode( |
1025 HintCode.MISSING_RETURN, returnType, [returnTypeType.displayName]); | 1025 HintCode.MISSING_RETURN, returnType, [returnTypeType.displayName]); |
1026 } | 1026 } |
1027 } | 1027 } |
1028 } | 1028 } |
1029 | 1029 |
1030 void _checkRequiredParameter(FormalParameterList node) { | |
1031 final requiredParameters = | |
1032 node.parameters.where((p) => p.element?.isRequired == true); | |
1033 final nonNamedParamsWithRequired = | |
1034 requiredParameters.where((p) => p.kind != ParameterKind.NAMED); | |
1035 final namedParamsWithRequiredAndDefault = requiredParameters | |
1036 .where((p) => p.kind == ParameterKind.NAMED) | |
1037 .where((p) => p.element.defaultValueCode != null); | |
1038 final paramsToHint = [ | |
1039 nonNamedParamsWithRequired, | |
1040 namedParamsWithRequiredAndDefault | |
1041 ].expand((e) => e); | |
1042 for (final param in paramsToHint) { | |
1043 _errorReporter.reportErrorForNode( | |
1044 HintCode.INVALID_REQUIRED_PARAM, param, [param.identifier.name]); | |
1045 } | |
1046 } | |
1047 | |
1048 /** | 1030 /** |
1049 * Produce a hint if the given [condition] could have a value of `null`. | 1031 * Produce a hint if the given [condition] could have a value of `null`. |
1050 */ | 1032 */ |
1051 void _checkForPossibleNullCondition(Expression condition) { | 1033 void _checkForPossibleNullCondition(Expression condition) { |
1052 condition = condition?.unParenthesized; | 1034 condition = condition?.unParenthesized; |
1053 if (condition is BinaryExpression) { | 1035 if (condition is BinaryExpression) { |
1054 _checkForPossibleNullConditionInBinaryExpression(condition); | 1036 _checkForPossibleNullConditionInBinaryExpression(condition); |
1055 } else if (condition is PrefixExpression) { | 1037 } else if (condition is PrefixExpression) { |
1056 _checkForPossibleNullConditionInPrefixExpression(condition); | 1038 _checkForPossibleNullConditionInPrefixExpression(condition); |
1057 } else { | 1039 } else { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 // such as m().x, m()[k], a + m(), f(m()), return m(). | 1192 // such as m().x, m()[k], a + m(), f(m()), return m(). |
1211 if (expression is MethodInvocation) { | 1193 if (expression is MethodInvocation) { |
1212 if (identical(expression.staticType, VoidTypeImpl.instance)) { | 1194 if (identical(expression.staticType, VoidTypeImpl.instance)) { |
1213 SimpleIdentifier methodName = expression.methodName; | 1195 SimpleIdentifier methodName = expression.methodName; |
1214 _errorReporter.reportErrorForNode( | 1196 _errorReporter.reportErrorForNode( |
1215 HintCode.USE_OF_VOID_RESULT, methodName, [methodName.name]); | 1197 HintCode.USE_OF_VOID_RESULT, methodName, [methodName.name]); |
1216 } | 1198 } |
1217 } | 1199 } |
1218 } | 1200 } |
1219 | 1201 |
| 1202 void _checkRequiredParameter(FormalParameterList node) { |
| 1203 final requiredParameters = |
| 1204 node.parameters.where((p) => p.element?.isRequired == true); |
| 1205 final nonNamedParamsWithRequired = |
| 1206 requiredParameters.where((p) => p.kind != ParameterKind.NAMED); |
| 1207 final namedParamsWithRequiredAndDefault = requiredParameters |
| 1208 .where((p) => p.kind == ParameterKind.NAMED) |
| 1209 .where((p) => p.element.defaultValueCode != null); |
| 1210 final paramsToHint = [ |
| 1211 nonNamedParamsWithRequired, |
| 1212 namedParamsWithRequiredAndDefault |
| 1213 ].expand((e) => e); |
| 1214 for (final param in paramsToHint) { |
| 1215 _errorReporter.reportErrorForNode( |
| 1216 HintCode.INVALID_REQUIRED_PARAM, param, [param.identifier.name]); |
| 1217 } |
| 1218 } |
| 1219 |
1220 /** | 1220 /** |
1221 * Check for the passed class declaration for the | 1221 * Check for the passed class declaration for the |
1222 * [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. | 1222 * [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. |
1223 * | 1223 * |
1224 * @param node the class declaration to check | 1224 * @param node the class declaration to check |
1225 * @return `true` if and only if a hint code is generated on the passed node | 1225 * @return `true` if and only if a hint code is generated on the passed node |
1226 * See [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]. | 1226 * See [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]. |
1227 */ | 1227 */ |
1228 // bool _checkForOverrideEqualsButNotHashCode(ClassDeclaration node) { | 1228 // bool _checkForOverrideEqualsButNotHashCode(ClassDeclaration node) { |
1229 // ClassElement classElement = node.element; | 1229 // ClassElement classElement = node.element; |
(...skipping 9706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10936 return null; | 10936 return null; |
10937 } | 10937 } |
10938 if (identical(node.staticElement, variable)) { | 10938 if (identical(node.staticElement, variable)) { |
10939 if (node.inSetterContext()) { | 10939 if (node.inSetterContext()) { |
10940 result = true; | 10940 result = true; |
10941 } | 10941 } |
10942 } | 10942 } |
10943 return null; | 10943 return null; |
10944 } | 10944 } |
10945 } | 10945 } |
OLD | NEW |