Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 708263002: Clean up references in comments (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/lib/src/generated/html.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 engine.resolver.error_verifier; 5 library engine.resolver.error_verifier;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'java_engine.dart'; 10 import 'java_engine.dart';
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 /** 84 /**
85 * The manager for the inheritance mappings. 85 * The manager for the inheritance mappings.
86 */ 86 */
87 final InheritanceManager _inheritanceManager; 87 final InheritanceManager _inheritanceManager;
88 88
89 /** 89 /**
90 * This is set to `true` iff the visitor is currently visiting children nodes of a 90 * This is set to `true` iff the visitor is currently visiting children nodes of a
91 * [ConstructorDeclaration] and the constructor is 'const'. 91 * [ConstructorDeclaration] and the constructor is 'const'.
92 * 92 *
93 * @see #visitConstructorDeclaration(ConstructorDeclaration) 93 * See [visitConstructorDeclaration].
94 */ 94 */
95 bool _isEnclosingConstructorConst = false; 95 bool _isEnclosingConstructorConst = false;
96 96
97 /** 97 /**
98 * A flag indicating whether we are currently within a function body marked as being asynchronous. 98 * A flag indicating whether we are currently within a function body marked as being asynchronous.
99 */ 99 */
100 bool _inAsync = false; 100 bool _inAsync = false;
101 101
102 /** 102 /**
103 * A flag indicating whether we are currently within a function body marked as being a generator. 103 * A flag indicating whether we are currently within a function body marked as being a generator.
104 */ 104 */
105 bool _inGenerator = false; 105 bool _inGenerator = false;
106 106
107 /** 107 /**
108 * This is set to `true` iff the visitor is currently visiting children nodes of a 108 * This is set to `true` iff the visitor is currently visiting children nodes of a
109 * [CatchClause]. 109 * [CatchClause].
110 * 110 *
111 * @see #visitCatchClause(CatchClause) 111 * See [visitCatchClause].
112 */ 112 */
113 bool _isInCatchClause = false; 113 bool _isInCatchClause = false;
114 114
115 /** 115 /**
116 * This is set to `true` iff the visitor is currently visiting children nodes of an 116 * This is set to `true` iff the visitor is currently visiting children nodes of an
117 * [Comment]. 117 * [Comment].
118 */ 118 */
119 bool _isInComment = false; 119 bool _isInComment = false;
120 120
121 /** 121 /**
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 /** 180 /**
181 * A flag indicating whether the current library contains at least one import directive with a URI 181 * A flag indicating whether the current library contains at least one import directive with a URI
182 * that uses the "dart-ext" scheme. 182 * that uses the "dart-ext" scheme.
183 */ 183 */
184 bool _hasExtUri = false; 184 bool _hasExtUri = false;
185 185
186 /** 186 /**
187 * This is set to `false` on the entry of every [BlockFunctionBody], and is re stored 187 * This is set to `false` on the entry of every [BlockFunctionBody], and is re stored
188 * to the enclosing value on exit. The value is used in 188 * to the enclosing value on exit. The value is used in
189 * [checkForMixedReturns] to prevent both 189 * [checkForMixedReturns] to prevent both
190 * [StaticWarningCode#MIXED_RETURN_TYPES] and [StaticWarningCode#RETURN_WITHOU T_VALUE] 190 * [StaticWarningCode.MIXED_RETURN_TYPES] and [StaticWarningCode.RETURN_WITHOU T_VALUE]
191 * from being generated in the same function body. 191 * from being generated in the same function body.
192 */ 192 */
193 bool _hasReturnWithoutValue = false; 193 bool _hasReturnWithoutValue = false;
194 194
195 /** 195 /**
196 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of 196 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of
197 * a class. 197 * a class.
198 */ 198 */
199 ClassElement _enclosingClass; 199 ClassElement _enclosingClass;
200 200
(...skipping 13 matching lines...) Expand all
214 * The return statements found in the method or function that we are currently visiting that do 214 * The return statements found in the method or function that we are currently visiting that do
215 * not have a return value. 215 * not have a return value.
216 */ 216 */
217 List<ReturnStatement> _returnsWithout = new List<ReturnStatement>(); 217 List<ReturnStatement> _returnsWithout = new List<ReturnStatement>();
218 218
219 /** 219 /**
220 * This map is initialized when visiting the contents of a class declaration. If the visitor is 220 * This map is initialized when visiting the contents of a class declaration. If the visitor is
221 * not in an enclosing class declaration, then the map is set to `null`. 221 * not in an enclosing class declaration, then the map is set to `null`.
222 * 222 *
223 * When set the map maps the set of [FieldElement]s in the class to an 223 * When set the map maps the set of [FieldElement]s in the class to an
224 * [INIT_STATE#NOT_INIT] or [INIT_STATE#INIT_IN_DECLARATION]. <code>checkFor*< /code> 224 * [INIT_STATE.NOT_INIT] or [INIT_STATE.INIT_IN_DECLARATION]. <code>checkFor*< /code>
225 * methods, specifically [checkForAllFinalInitializedErrorCodes], 225 * methods, specifically [checkForAllFinalInitializedErrorCodes],
226 * can make a copy of the map to compute error code states. <code>checkFor*</c ode> methods should 226 * can make a copy of the map to compute error code states. <code>checkFor*</c ode> methods should
227 * only ever make a copy, or read from this map after it has been set in 227 * only ever make a copy, or read from this map after it has been set in
228 * [visitClassDeclaration]. 228 * [visitClassDeclaration].
229 * 229 *
230 * @see #visitClassDeclaration(ClassDeclaration) 230 * See [visitClassDeclaration], and [_checkForAllFinalInitializedErrorCodes].
231 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration)
232 */ 231 */
233 HashMap<FieldElement, INIT_STATE> _initialFieldElementsMap; 232 HashMap<FieldElement, INIT_STATE> _initialFieldElementsMap;
234 233
235 /** 234 /**
236 * A table mapping name of the library to the export directive which export th is library. 235 * A table mapping name of the library to the export directive which export th is library.
237 */ 236 */
238 HashMap<String, LibraryElement> _nameToExportElement = new HashMap<String, Lib raryElement>(); 237 HashMap<String, LibraryElement> _nameToExportElement = new HashMap<String, Lib raryElement>();
239 238
240 /** 239 /**
241 * A table mapping name of the library to the import directive which import th is library. 240 * A table mapping name of the library to the import directive which import th is library.
242 */ 241 */
243 HashMap<String, LibraryElement> _nameToImportElement = new HashMap<String, Lib raryElement>(); 242 HashMap<String, LibraryElement> _nameToImportElement = new HashMap<String, Lib raryElement>();
244 243
245 /** 244 /**
246 * A table mapping names to the exported elements. 245 * A table mapping names to the exported elements.
247 */ 246 */
248 HashMap<String, Element> _exportedElements = new HashMap<String, Element>(); 247 HashMap<String, Element> _exportedElements = new HashMap<String, Element>();
249 248
250 /** 249 /**
251 * A set of the names of the variable initializers we are visiting now. 250 * A set of the names of the variable initializers we are visiting now.
252 */ 251 */
253 HashSet<String> _namesForReferenceToDeclaredVariableInInitializer = new HashSe t<String>(); 252 HashSet<String> _namesForReferenceToDeclaredVariableInInitializer = new HashSe t<String>();
254 253
255 /** 254 /**
256 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS] and 255 * A list of types used by the [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS] and
257 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. 256 * [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS] error codes.
258 */ 257 */
259 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; 258 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT;
260 259
261 /** 260 /**
262 * Static final string with value `"getter "` used in the construction of the 261 * Static final string with value `"getter "` used in the construction of the
263 * [StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], and si milar, error 262 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], and si milar, error
264 * code messages. 263 * code messages.
265 * 264 *
266 * @see #checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration) 265 * See [_checkForNonAbstractClassInheritsAbstractMember].
267 */ 266 */
268 static String _GETTER_SPACE = "getter "; 267 static String _GETTER_SPACE = "getter ";
269 268
270 /** 269 /**
271 * Static final string with value `"setter "` used in the construction of the 270 * Static final string with value `"setter "` used in the construction of the
272 * [StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], and si milar, error 271 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], and si milar, error
273 * code messages. 272 * code messages.
274 * 273 *
275 * @see #checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration) 274 * See [_checkForNonAbstractClassInheritsAbstractMember].
276 */ 275 */
277 static String _SETTER_SPACE = "setter "; 276 static String _SETTER_SPACE = "setter ";
278 277
279 /** 278 /**
280 * Initialize the [ErrorVerifier] visitor. 279 * Initialize the [ErrorVerifier] visitor.
281 */ 280 */
282 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, t his._inheritanceManager) { 281 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, t his._inheritanceManager) {
283 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; 282 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary;
284 this._hasExtUri = _currentLibrary.hasExtUri; 283 this._hasExtUri = _currentLibrary.hasExtUri;
285 _isEnclosingConstructorConst = false; 284 _isEnclosingConstructorConst = false;
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 _errorReporter.reportErrorForNode(errorCode, node, []); 1061 _errorReporter.reportErrorForNode(errorCode, node, []);
1063 } 1062 }
1064 return super.visitYieldStatement(node); 1063 return super.visitYieldStatement(node);
1065 } 1064 }
1066 1065
1067 /** 1066 /**
1068 * This verifies if the passed map literal has type arguments then there is ex actly two. 1067 * This verifies if the passed map literal has type arguments then there is ex actly two.
1069 * 1068 *
1070 * @param typeArguments the type arguments, always non-`null` 1069 * @param typeArguments the type arguments, always non-`null`
1071 * @return `true` if and only if an error code is generated on the passed node 1070 * @return `true` if and only if an error code is generated on the passed node
1072 * @see StaticTypeWarningCode#EXPECTED_TWO_MAP_TYPE_ARGUMENTS 1071 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS].
1073 */ 1072 */
1074 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { 1073 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) {
1075 // check number of type arguments 1074 // check number of type arguments
1076 int num = typeArguments.arguments.length; 1075 int num = typeArguments.arguments.length;
1077 if (num == 2) { 1076 if (num == 2) {
1078 return false; 1077 return false;
1079 } 1078 }
1080 // report problem 1079 // report problem
1081 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYP E_ARGUMENTS, typeArguments, [num]); 1080 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYP E_ARGUMENTS, typeArguments, [num]);
1082 return true; 1081 return true;
1083 } 1082 }
1084 1083
1085 /** 1084 /**
1086 * This verifies that the passed constructor declaration does not violate any of the error codes 1085 * This verifies that the passed constructor declaration does not violate any of the error codes
1087 * relating to the initialization of fields in the enclosing class. 1086 * relating to the initialization of fields in the enclosing class.
1088 * 1087 *
1089 * @param node the [ConstructorDeclaration] to evaluate 1088 * @param node the [ConstructorDeclaration] to evaluate
1090 * @return `true` if and only if an error code is generated on the passed node 1089 * @return `true` if and only if an error code is generated on the passed node
1091 * @see #initialFieldElementsMap 1090 * See [_initialFieldElementsMap],
1092 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR 1091 * [StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR],
1093 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES 1092 * and [CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES].
1094 */ 1093 */
1095 bool _checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { 1094 bool _checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) {
1096 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod e.externalKeyword != null) { 1095 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod e.externalKeyword != null) {
1097 return false; 1096 return false;
1098 } 1097 }
1099 // Ignore if native class. 1098 // Ignore if native class.
1100 if (_isInNativeClass) { 1099 if (_isInNativeClass) {
1101 return false; 1100 return false;
1102 } 1101 }
1103 bool foundError = false; 1102 bool foundError = false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 } 1179 }
1181 1180
1182 /** 1181 /**
1183 * This checks the passed executable element against override-error codes. 1182 * This checks the passed executable element against override-error codes.
1184 * 1183 *
1185 * @param executableElement a non-null [ExecutableElement] to evaluate 1184 * @param executableElement a non-null [ExecutableElement] to evaluate
1186 * @param overriddenExecutable the element that the executableElement is overr iding 1185 * @param overriddenExecutable the element that the executableElement is overr iding
1187 * @param parameters the parameters of the executable element 1186 * @param parameters the parameters of the executable element
1188 * @param errorNameTarget the node to report problems on 1187 * @param errorNameTarget the node to report problems on
1189 * @return `true` if and only if an error code is generated on the passed node 1188 * @return `true` if and only if an error code is generated on the passed node
1190 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1189 * See [StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC ],
1191 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED 1190 * [CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED],
1192 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL 1191 * [CompileTimeErrorCode.INVALID_OVERRIDE_POSITIONAL],
1193 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED 1192 * [CompileTimeErrorCode.INVALID_OVERRIDE_NAMED],
1194 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE 1193 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE],
1195 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE 1194 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE],
1196 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE 1195 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE],
1197 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE 1196 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE],
1198 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE 1197 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE],
1199 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE 1198 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and
1200 * @see StaticWarningCode#INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES 1199 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES].
1201 */ 1200 */
1202 bool _checkForAllInvalidOverrideErrorCodes(ExecutableElement executableElement , ExecutableElement overriddenExecutable, List<ParameterElement> parameters, Lis t<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { 1201 bool _checkForAllInvalidOverrideErrorCodes(ExecutableElement executableElement , ExecutableElement overriddenExecutable, List<ParameterElement> parameters, Lis t<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) {
1203 bool isGetter = false; 1202 bool isGetter = false;
1204 bool isSetter = false; 1203 bool isSetter = false;
1205 if (executableElement is PropertyAccessorElement) { 1204 if (executableElement is PropertyAccessorElement) {
1206 PropertyAccessorElement accessorElement = executableElement; 1205 PropertyAccessorElement accessorElement = executableElement;
1207 isGetter = accessorElement.isGetter; 1206 isGetter = accessorElement.isGetter;
1208 isSetter = accessorElement.isSetter; 1207 isSetter = accessorElement.isSetter;
1209 } 1208 }
1210 String executableElementName = executableElement.name; 1209 String executableElementName = executableElement.name;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 } 1437 }
1439 } 1438 }
1440 return false; 1439 return false;
1441 } 1440 }
1442 1441
1443 /** 1442 /**
1444 * This checks the passed field declaration against override-error codes. 1443 * This checks the passed field declaration against override-error codes.
1445 * 1444 *
1446 * @param node the [MethodDeclaration] to evaluate 1445 * @param node the [MethodDeclaration] to evaluate
1447 * @return `true` if and only if an error code is generated on the passed node 1446 * @return `true` if and only if an error code is generated on the passed node
1448 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement) 1447 * See [_checkForAllInvalidOverrideErrorCodes].
1449 */ 1448 */
1450 bool _checkForAllInvalidOverrideErrorCodesForField(FieldDeclaration node) { 1449 bool _checkForAllInvalidOverrideErrorCodesForField(FieldDeclaration node) {
1451 if (_enclosingClass == null || node.isStatic) { 1450 if (_enclosingClass == null || node.isStatic) {
1452 return false; 1451 return false;
1453 } 1452 }
1454 bool hasProblems = false; 1453 bool hasProblems = false;
1455 VariableDeclarationList fields = node.fields; 1454 VariableDeclarationList fields = node.fields;
1456 for (VariableDeclaration field in fields.variables) { 1455 for (VariableDeclaration field in fields.variables) {
1457 FieldElement element = field.element as FieldElement; 1456 FieldElement element = field.element as FieldElement;
1458 if (element == null) { 1457 if (element == null) {
(...skipping 22 matching lines...) Expand all
1481 } 1480 }
1482 } 1481 }
1483 return hasProblems; 1482 return hasProblems;
1484 } 1483 }
1485 1484
1486 /** 1485 /**
1487 * This checks the passed method declaration against override-error codes. 1486 * This checks the passed method declaration against override-error codes.
1488 * 1487 *
1489 * @param node the [MethodDeclaration] to evaluate 1488 * @param node the [MethodDeclaration] to evaluate
1490 * @return `true` if and only if an error code is generated on the passed node 1489 * @return `true` if and only if an error code is generated on the passed node
1491 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement) 1490 * See [_checkForAllInvalidOverrideErrorCodes].
1492 */ 1491 */
1493 bool _checkForAllInvalidOverrideErrorCodesForMethod(MethodDeclaration node) { 1492 bool _checkForAllInvalidOverrideErrorCodesForMethod(MethodDeclaration node) {
1494 if (_enclosingClass == null || node.isStatic || node.body is NativeFunctionB ody) { 1493 if (_enclosingClass == null || node.isStatic || node.body is NativeFunctionB ody) {
1495 return false; 1494 return false;
1496 } 1495 }
1497 ExecutableElement executableElement = node.element; 1496 ExecutableElement executableElement = node.element;
1498 if (executableElement == null) { 1497 if (executableElement == null) {
1499 return false; 1498 return false;
1500 } 1499 }
1501 SimpleIdentifier methodName = node.name; 1500 SimpleIdentifier methodName = node.name;
1502 if (methodName.isSynthetic) { 1501 if (methodName.isSynthetic) {
1503 return false; 1502 return false;
1504 } 1503 }
1505 FormalParameterList formalParameterList = node.parameters; 1504 FormalParameterList formalParameterList = node.parameters;
1506 NodeList<FormalParameter> parameterList = formalParameterList != null ? form alParameterList.parameters : null; 1505 NodeList<FormalParameter> parameterList = formalParameterList != null ? form alParameterList.parameters : null;
1507 List<AstNode> parameters = parameterList != null ? new List.from(parameterLi st) : null; 1506 List<AstNode> parameters = parameterList != null ? new List.from(parameterLi st) : null;
1508 return _checkForAllInvalidOverrideErrorCodesForExecutable(executableElement, executableElement.parameters, parameters, methodName); 1507 return _checkForAllInvalidOverrideErrorCodesForExecutable(executableElement, executableElement.parameters, parameters, methodName);
1509 } 1508 }
1510 1509
1511 /** 1510 /**
1512 * This verifies that all classes of the passed 'with' clause are valid. 1511 * This verifies that all classes of the passed 'with' clause are valid.
1513 * 1512 *
1514 * @param node the 'with' clause to evaluate 1513 * @param node the 'with' clause to evaluate
1515 * @return `true` if and only if an error code is generated on the passed node 1514 * @return `true` if and only if an error code is generated on the passed node
1516 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR 1515 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR],
1517 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT 1516 * [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT], and
1518 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER 1517 * [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER].
1519 */ 1518 */
1520 bool _checkForAllMixinErrorCodes(WithClause withClause) { 1519 bool _checkForAllMixinErrorCodes(WithClause withClause) {
1521 if (withClause == null) { 1520 if (withClause == null) {
1522 return false; 1521 return false;
1523 } 1522 }
1524 bool problemReported = false; 1523 bool problemReported = false;
1525 for (TypeName mixinName in withClause.mixinTypes) { 1524 for (TypeName mixinName in withClause.mixinTypes) {
1526 DartType mixinType = mixinName.type; 1525 DartType mixinType = mixinName.type;
1527 if (mixinType is! InterfaceType) { 1526 if (mixinType is! InterfaceType) {
1528 continue; 1527 continue;
(...skipping 21 matching lines...) Expand all
1550 } 1549 }
1551 } 1550 }
1552 return problemReported; 1551 return problemReported;
1553 } 1552 }
1554 1553
1555 /** 1554 /**
1556 * This checks error related to the redirected constructors. 1555 * This checks error related to the redirected constructors.
1557 * 1556 *
1558 * @param node the constructor declaration to evaluate 1557 * @param node the constructor declaration to evaluate
1559 * @return `true` if and only if an error code is generated on the passed node 1558 * @return `true` if and only if an error code is generated on the passed node
1560 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE 1559 * See [StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE],
1561 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE 1560 * [StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE], and
1562 * @see StaticWarningCode#REDIRECT_TO_MISSING_CONSTRUCTOR 1561 * [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR].
1563 */ 1562 */
1564 bool _checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) { 1563 bool _checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) {
1565 // 1564 //
1566 // Prepare redirected constructor node 1565 // Prepare redirected constructor node
1567 // 1566 //
1568 ConstructorName redirectedConstructor = node.redirectedConstructor; 1567 ConstructorName redirectedConstructor = node.redirectedConstructor;
1569 if (redirectedConstructor == null) { 1568 if (redirectedConstructor == null) {
1570 return false; 1569 return false;
1571 } 1570 }
1572 // 1571 //
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 * 1619 *
1621 * This checks that return statements without expressions are not in a generat ive constructor and 1620 * This checks that return statements without expressions are not in a generat ive constructor and
1622 * the return type is not assignable to `null`; that is, we don't have `return ;` if 1621 * the return type is not assignable to `null`; that is, we don't have `return ;` if
1623 * the enclosing method has a return type. 1622 * the enclosing method has a return type.
1624 * 1623 *
1625 * This checks that the return type matches the type of the declared return ty pe in the enclosing 1624 * This checks that the return type matches the type of the declared return ty pe in the enclosing
1626 * method or function. 1625 * method or function.
1627 * 1626 *
1628 * @param node the return statement to evaluate 1627 * @param node the return statement to evaluate
1629 * @return `true` if and only if an error code is generated on the passed node 1628 * @return `true` if and only if an error code is generated on the passed node
1630 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR 1629 * See [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR],
1631 * @see StaticWarningCode#RETURN_WITHOUT_VALUE 1630 * [StaticWarningCode.RETURN_WITHOUT_VALUE], and
1632 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE 1631 * [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE].
1633 */ 1632 */
1634 bool _checkForAllReturnStatementErrorCodes(ReturnStatement node) { 1633 bool _checkForAllReturnStatementErrorCodes(ReturnStatement node) {
1635 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type; 1634 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
1636 DartType expectedReturnType = functionType == null ? DynamicTypeImpl.instanc e : functionType.returnType; 1635 DartType expectedReturnType = functionType == null ? DynamicTypeImpl.instanc e : functionType.returnType;
1637 Expression returnExpression = node.expression; 1636 Expression returnExpression = node.expression;
1638 // RETURN_IN_GENERATIVE_CONSTRUCTOR 1637 // RETURN_IN_GENERATIVE_CONSTRUCTOR
1639 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && ! (_enclosingFunction as ConstructorElement).isFactory; 1638 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && ! (_enclosingFunction as ConstructorElement).isFactory;
1640 if (isGenerativeConstructor) { 1639 if (isGenerativeConstructor) {
1641 if (returnExpression == null) { 1640 if (returnExpression == null) {
1642 return false; 1641 return false;
(...skipping 19 matching lines...) Expand all
1662 1661
1663 /** 1662 /**
1664 * This verifies that the export namespace of the passed export directive does not export any name 1663 * This verifies that the export namespace of the passed export directive does not export any name
1665 * already exported by other export directive. 1664 * already exported by other export directive.
1666 * 1665 *
1667 * @param node the export directive node to report problem on 1666 * @param node the export directive node to report problem on
1668 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the 1667 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the
1669 * node was `null`, then this method is not called 1668 * node was `null`, then this method is not called
1670 * @param exportedLibrary the library element containing the exported element 1669 * @param exportedLibrary the library element containing the exported element
1671 * @return `true` if and only if an error code is generated on the passed node 1670 * @return `true` if and only if an error code is generated on the passed node
1672 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT 1671 * See [CompileTimeErrorCode.AMBIGUOUS_EXPORT].
1673 */ 1672 */
1674 bool _checkForAmbiguousExport(ExportDirective node, ExportElement exportElemen t, LibraryElement exportedLibrary) { 1673 bool _checkForAmbiguousExport(ExportDirective node, ExportElement exportElemen t, LibraryElement exportedLibrary) {
1675 if (exportedLibrary == null) { 1674 if (exportedLibrary == null) {
1676 return false; 1675 return false;
1677 } 1676 }
1678 // check exported names 1677 // check exported names
1679 Namespace namespace = new NamespaceBuilder().createExportNamespaceForDirecti ve(exportElement); 1678 Namespace namespace = new NamespaceBuilder().createExportNamespaceForDirecti ve(exportElement);
1680 Map<String, Element> definedNames = namespace.definedNames; 1679 Map<String, Element> definedNames = namespace.definedNames;
1681 for (String name in definedNames.keys) { 1680 for (String name in definedNames.keys) {
1682 Element element = definedNames[name]; 1681 Element element = definedNames[name];
(...skipping 16 matching lines...) Expand all
1699 * 1698 *
1700 * This method corresponds to BestPracticesVerifier.checkForArgumentTypeNotAss ignable. 1699 * This method corresponds to BestPracticesVerifier.checkForArgumentTypeNotAss ignable.
1701 * 1700 *
1702 * @param expression the expression to evaluate 1701 * @param expression the expression to evaluate
1703 * @param expectedStaticType the expected static type of the parameter 1702 * @param expectedStaticType the expected static type of the parameter
1704 * @param actualStaticType the actual static type of the argument 1703 * @param actualStaticType the actual static type of the argument
1705 * @param expectedPropagatedType the expected propagated type of the parameter , may be 1704 * @param expectedPropagatedType the expected propagated type of the parameter , may be
1706 * `null` 1705 * `null`
1707 * @param actualPropagatedType the expected propagated type of the parameter, may be `null` 1706 * @param actualPropagatedType the expected propagated type of the parameter, may be `null`
1708 * @return `true` if and only if an error code is generated on the passed node 1707 * @return `true` if and only if an error code is generated on the passed node
1709 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 1708 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE],
1710 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 1709 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1711 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 1710 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1712 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 1711 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE],
1713 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 1712 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE],
1714 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 1713 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and
1715 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 1714 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE].
1716 */ 1715 */
1717 bool _checkForArgumentTypeNotAssignable(Expression expression, DartType expect edStaticType, DartType actualStaticType, ErrorCode errorCode) { 1716 bool _checkForArgumentTypeNotAssignable(Expression expression, DartType expect edStaticType, DartType actualStaticType, ErrorCode errorCode) {
1718 // 1717 //
1719 // Warning case: test static type information 1718 // Warning case: test static type information
1720 // 1719 //
1721 if (actualStaticType != null && expectedStaticType != null) { 1720 if (actualStaticType != null && expectedStaticType != null) {
1722 if (!actualStaticType.isAssignableTo(expectedStaticType)) { 1721 if (!actualStaticType.isAssignableTo(expectedStaticType)) {
1723 _errorReporter.reportTypeErrorForNode(errorCode, expression, [actualStat icType, expectedStaticType]); 1722 _errorReporter.reportTypeErrorForNode(errorCode, expression, [actualStat icType, expectedStaticType]);
1724 return true; 1723 return true;
1725 } 1724 }
1726 } 1725 }
1727 return false; 1726 return false;
1728 } 1727 }
1729 1728
1730 /** 1729 /**
1731 * This verifies that the passed argument can be assigned to its corresponding parameter. 1730 * This verifies that the passed argument can be assigned to its corresponding parameter.
1732 * 1731 *
1733 * This method corresponds to BestPracticesVerifier.checkForArgumentTypeNotAss ignableForArgument. 1732 * This method corresponds to BestPracticesVerifier.checkForArgumentTypeNotAss ignableForArgument.
1734 * 1733 *
1735 * @param argument the argument to evaluate 1734 * @param argument the argument to evaluate
1736 * @return `true` if and only if an error code is generated on the passed node 1735 * @return `true` if and only if an error code is generated on the passed node
1737 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 1736 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE].
1738 */ 1737 */
1739 bool _checkForArgumentTypeNotAssignableForArgument(Expression argument) { 1738 bool _checkForArgumentTypeNotAssignableForArgument(Expression argument) {
1740 if (argument == null) { 1739 if (argument == null) {
1741 return false; 1740 return false;
1742 } 1741 }
1743 ParameterElement staticParameterElement = argument.staticParameterElement; 1742 ParameterElement staticParameterElement = argument.staticParameterElement;
1744 DartType staticParameterType = staticParameterElement == null ? null : stati cParameterElement.type; 1743 DartType staticParameterType = staticParameterElement == null ? null : stati cParameterElement.type;
1745 return _checkForArgumentTypeNotAssignableWithExpectedTypes(argument, staticP arameterType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); 1744 return _checkForArgumentTypeNotAssignableWithExpectedTypes(argument, staticP arameterType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE);
1746 } 1745 }
1747 1746
1748 /** 1747 /**
1749 * This verifies that the passed expression can be assigned to its correspondi ng parameters. 1748 * This verifies that the passed expression can be assigned to its correspondi ng parameters.
1750 * 1749 *
1751 * This method corresponds to 1750 * This method corresponds to
1752 * BestPracticesVerifier.checkForArgumentTypeNotAssignableWithExpectedTypes. 1751 * BestPracticesVerifier.checkForArgumentTypeNotAssignableWithExpectedTypes.
1753 * 1752 *
1754 * @param expression the expression to evaluate 1753 * @param expression the expression to evaluate
1755 * @param expectedStaticType the expected static type 1754 * @param expectedStaticType the expected static type
1756 * @param expectedPropagatedType the expected propagated type, may be `null` 1755 * @param expectedPropagatedType the expected propagated type, may be `null`
1757 * @return `true` if and only if an error code is generated on the passed node 1756 * @return `true` if and only if an error code is generated on the passed node
1758 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 1757 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE],
1759 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 1758 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1760 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 1759 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1761 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 1760 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE],
1762 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 1761 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE],
1763 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 1762 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and
1764 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 1763 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE].
1765 */ 1764 */
1766 bool _checkForArgumentTypeNotAssignableWithExpectedTypes(Expression expression , DartType expectedStaticType, ErrorCode errorCode) => _checkForArgumentTypeNotA ssignable(expression, expectedStaticType, getStaticType(expression), errorCode); 1765 bool _checkForArgumentTypeNotAssignableWithExpectedTypes(Expression expression , DartType expectedStaticType, ErrorCode errorCode) => _checkForArgumentTypeNotA ssignable(expression, expectedStaticType, getStaticType(expression), errorCode);
1767 1766
1768 /** 1767 /**
1769 * This verifies that the passed arguments can be assigned to their correspond ing parameters. 1768 * This verifies that the passed arguments can be assigned to their correspond ing parameters.
1770 * 1769 *
1771 * This method corresponds to BestPracticesVerifier.checkForArgumentTypesNotAs signableInList. 1770 * This method corresponds to BestPracticesVerifier.checkForArgumentTypesNotAs signableInList.
1772 * 1771 *
1773 * @param node the arguments to evaluate 1772 * @param node the arguments to evaluate
1774 * @return `true` if and only if an error code is generated on the passed node 1773 * @return `true` if and only if an error code is generated on the passed node
1775 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 1774 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE].
1776 */ 1775 */
1777 bool _checkForArgumentTypesNotAssignableInList(ArgumentList argumentList) { 1776 bool _checkForArgumentTypesNotAssignableInList(ArgumentList argumentList) {
1778 if (argumentList == null) { 1777 if (argumentList == null) {
1779 return false; 1778 return false;
1780 } 1779 }
1781 bool problemReported = false; 1780 bool problemReported = false;
1782 for (Expression argument in argumentList.arguments) { 1781 for (Expression argument in argumentList.arguments) {
1783 if (_checkForArgumentTypeNotAssignableForArgument(argument)) { 1782 if (_checkForArgumentTypeNotAssignableForArgument(argument)) {
1784 problemReported = true; 1783 problemReported = true;
1785 } 1784 }
(...skipping 24 matching lines...) Expand all
1810 } 1809 }
1811 _errorReporter.reportErrorForNode(errorCode, expression, arguments); 1810 _errorReporter.reportErrorForNode(errorCode, expression, arguments);
1812 return true; 1811 return true;
1813 } 1812 }
1814 1813
1815 /** 1814 /**
1816 * This verifies that the passed expression is not final. 1815 * This verifies that the passed expression is not final.
1817 * 1816 *
1818 * @param node the expression to evaluate 1817 * @param node the expression to evaluate
1819 * @return `true` if and only if an error code is generated on the passed node 1818 * @return `true` if and only if an error code is generated on the passed node
1820 * @see StaticWarningCode#ASSIGNMENT_TO_CONST 1819 * See [StaticWarningCode.ASSIGNMENT_TO_CONST],
1821 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL 1820 * [StaticWarningCode.ASSIGNMENT_TO_FINAL], and
1822 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD 1821 * [StaticWarningCode.ASSIGNMENT_TO_METHOD].
1823 */ 1822 */
1824 bool _checkForAssignmentToFinal(Expression expression) { 1823 bool _checkForAssignmentToFinal(Expression expression) {
1825 // prepare element 1824 // prepare element
1826 Element element = null; 1825 Element element = null;
1827 AstNode highlightedNode = expression; 1826 AstNode highlightedNode = expression;
1828 if (expression is Identifier) { 1827 if (expression is Identifier) {
1829 element = expression.staticElement; 1828 element = expression.staticElement;
1830 if (expression is PrefixedIdentifier) { 1829 if (expression is PrefixedIdentifier) {
1831 highlightedNode = expression.identifier; 1830 highlightedNode = expression.identifier;
1832 } 1831 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 return false; 1866 return false;
1868 } 1867 }
1869 1868
1870 /** 1869 /**
1871 * This verifies that the passed identifier is not a keyword, and generates th e passed error code 1870 * This verifies that the passed identifier is not a keyword, and generates th e passed error code
1872 * on the identifier if it is a keyword. 1871 * on the identifier if it is a keyword.
1873 * 1872 *
1874 * @param identifier the identifier to check to ensure that it is not a keywor d 1873 * @param identifier the identifier to check to ensure that it is not a keywor d
1875 * @param errorCode if the passed identifier is a keyword then this error code is created on the 1874 * @param errorCode if the passed identifier is a keyword then this error code is created on the
1876 * identifier, the error code will be one of 1875 * identifier, the error code will be one of
1877 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME], 1876 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME],
1878 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME] or 1877 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME] or
1879 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] 1878 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]
1880 * @return `true` if and only if an error code is generated on the passed node 1879 * @return `true` if and only if an error code is generated on the passed node
1881 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME 1880 * See [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME],
1882 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME 1881 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME], and
1883 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME 1882 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME].
1884 */ 1883 */
1885 bool _checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode e rrorCode) { 1884 bool _checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode e rrorCode) {
1886 sc.Token token = identifier.token; 1885 sc.Token token = identifier.token;
1887 if (token.type == sc.TokenType.KEYWORD) { 1886 if (token.type == sc.TokenType.KEYWORD) {
1888 _errorReporter.reportErrorForNode(errorCode, identifier, [identifier.name] ); 1887 _errorReporter.reportErrorForNode(errorCode, identifier, [identifier.name] );
1889 return true; 1888 return true;
1890 } 1889 }
1891 return false; 1890 return false;
1892 } 1891 }
1893 1892
1894 /** 1893 /**
1895 * This verifies that the given switch case is terminated with 'break', 'conti nue', 'return' or 1894 * This verifies that the given switch case is terminated with 'break', 'conti nue', 'return' or
1896 * 'throw'. 1895 * 'throw'.
1897 * 1896 *
1898 * @param node the switch case to evaluate 1897 * @param node the switch case to evaluate
1899 * @return `true` if and only if an error code is generated on the passed node 1898 * @return `true` if and only if an error code is generated on the passed node
1900 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED 1899 * see [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED].
1901 */ 1900 */
1902 bool _checkForCaseBlockNotTerminated(SwitchCase node) { 1901 bool _checkForCaseBlockNotTerminated(SwitchCase node) {
1903 NodeList<Statement> statements = node.statements; 1902 NodeList<Statement> statements = node.statements;
1904 if (statements.isEmpty) { 1903 if (statements.isEmpty) {
1905 // fall-through without statements at all 1904 // fall-through without statements at all
1906 AstNode parent = node.parent; 1905 AstNode parent = node.parent;
1907 if (parent is SwitchStatement) { 1906 if (parent is SwitchStatement) {
1908 SwitchStatement switchStatement = parent; 1907 SwitchStatement switchStatement = parent;
1909 NodeList<SwitchMember> members = switchStatement.members; 1908 NodeList<SwitchMember> members = switchStatement.members;
1910 int index = members.indexOf(node); 1909 int index = members.indexOf(node);
(...skipping 20 matching lines...) Expand all
1931 _errorReporter.reportErrorForToken(StaticWarningCode.CASE_BLOCK_NOT_TERMINAT ED, node.keyword, []); 1930 _errorReporter.reportErrorForToken(StaticWarningCode.CASE_BLOCK_NOT_TERMINAT ED, node.keyword, []);
1932 return true; 1931 return true;
1933 } 1932 }
1934 1933
1935 /** 1934 /**
1936 * This verifies that the switch cases in the given switch statement is termin ated with 'break', 1935 * This verifies that the switch cases in the given switch statement is termin ated with 'break',
1937 * 'continue', 'return' or 'throw'. 1936 * 'continue', 'return' or 'throw'.
1938 * 1937 *
1939 * @param node the switch statement containing the cases to be checked 1938 * @param node the switch statement containing the cases to be checked
1940 * @return `true` if and only if an error code is generated on the passed node 1939 * @return `true` if and only if an error code is generated on the passed node
1941 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED 1940 * See [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED].
1942 */ 1941 */
1943 bool _checkForCaseBlocksNotTerminated(SwitchStatement node) { 1942 bool _checkForCaseBlocksNotTerminated(SwitchStatement node) {
1944 bool foundError = false; 1943 bool foundError = false;
1945 NodeList<SwitchMember> members = node.members; 1944 NodeList<SwitchMember> members = node.members;
1946 int lastMember = members.length - 1; 1945 int lastMember = members.length - 1;
1947 for (int i = 0; i < lastMember; i++) { 1946 for (int i = 0; i < lastMember; i++) {
1948 SwitchMember member = members[i]; 1947 SwitchMember member = members[i];
1949 if (member is SwitchCase && _checkForCaseBlockNotTerminated(member)) { 1948 if (member is SwitchCase && _checkForCaseBlockNotTerminated(member)) {
1950 foundError = true; 1949 foundError = true;
1951 } 1950 }
1952 } 1951 }
1953 return foundError; 1952 return foundError;
1954 } 1953 }
1955 1954
1956 /** 1955 /**
1957 * This verifies that the passed method declaration is abstract only if the en closing class is 1956 * This verifies that the passed method declaration is abstract only if the en closing class is
1958 * also abstract. 1957 * also abstract.
1959 * 1958 *
1960 * @param node the method declaration to evaluate 1959 * @param node the method declaration to evaluate
1961 * @return `true` if and only if an error code is generated on the passed node 1960 * @return `true` if and only if an error code is generated on the passed node
1962 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER 1961 * See [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER].
1963 */ 1962 */
1964 bool _checkForConcreteClassWithAbstractMember(MethodDeclaration node) { 1963 bool _checkForConcreteClassWithAbstractMember(MethodDeclaration node) {
1965 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac t) { 1964 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac t) {
1966 SimpleIdentifier nameNode = node.name; 1965 SimpleIdentifier nameNode = node.name;
1967 String memberName = nameNode.name; 1966 String memberName = nameNode.name;
1968 ExecutableElement overriddenMember; 1967 ExecutableElement overriddenMember;
1969 if (node.isGetter) { 1968 if (node.isGetter) {
1970 overriddenMember = _enclosingClass.lookUpInheritedConcreteGetter(memberN ame, _currentLibrary); 1969 overriddenMember = _enclosingClass.lookUpInheritedConcreteGetter(memberN ame, _currentLibrary);
1971 } else if (node.isSetter) { 1970 } else if (node.isSetter) {
1972 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter(memberN ame, _currentLibrary); 1971 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter(memberN ame, _currentLibrary);
1973 } else { 1972 } else {
1974 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod(memberN ame, _currentLibrary); 1973 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod(memberN ame, _currentLibrary);
1975 } 1974 }
1976 if (overriddenMember == null) { 1975 if (overriddenMember == null) {
1977 _errorReporter.reportErrorForNode(StaticWarningCode.CONCRETE_CLASS_WITH_ ABSTRACT_MEMBER, nameNode, [memberName, _enclosingClass.displayName]); 1976 _errorReporter.reportErrorForNode(StaticWarningCode.CONCRETE_CLASS_WITH_ ABSTRACT_MEMBER, nameNode, [memberName, _enclosingClass.displayName]);
1978 return true; 1977 return true;
1979 } 1978 }
1980 } 1979 }
1981 return false; 1980 return false;
1982 } 1981 }
1983 1982
1984 /** 1983 /**
1985 * This verifies all possible conflicts of the constructor name with other con structors and 1984 * This verifies all possible conflicts of the constructor name with other con structors and
1986 * members of the same class. 1985 * members of the same class.
1987 * 1986 *
1988 * @param node the constructor declaration to evaluate 1987 * @param node the constructor declaration to evaluate
1989 * @param constructorElement the constructor element 1988 * @param constructorElement the constructor element
1990 * @return `true` if and only if an error code is generated on the passed node 1989 * @return `true` if and only if an error code is generated on the passed node
1991 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT 1990 * See [CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT],
1992 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME 1991 * [CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME],
1993 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD 1992 * [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD], and
1994 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD 1993 * [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD].
1995 */ 1994 */
1996 bool _checkForConflictingConstructorNameAndMember(ConstructorDeclaration node, ConstructorElement constructorElement) { 1995 bool _checkForConflictingConstructorNameAndMember(ConstructorDeclaration node, ConstructorElement constructorElement) {
1997 SimpleIdentifier constructorName = node.name; 1996 SimpleIdentifier constructorName = node.name;
1998 String name = constructorElement.name; 1997 String name = constructorElement.name;
1999 ClassElement classElement = constructorElement.enclosingElement; 1998 ClassElement classElement = constructorElement.enclosingElement;
2000 // constructors 1999 // constructors
2001 List<ConstructorElement> constructors = classElement.constructors; 2000 List<ConstructorElement> constructors = classElement.constructors;
2002 for (ConstructorElement otherConstructor in constructors) { 2001 for (ConstructorElement otherConstructor in constructors) {
2003 if (identical(otherConstructor, constructorElement)) { 2002 if (identical(otherConstructor, constructorElement)) {
2004 continue; 2003 continue;
(...skipping 23 matching lines...) Expand all
2028 } 2027 }
2029 } 2028 }
2030 return false; 2029 return false;
2031 } 2030 }
2032 2031
2033 /** 2032 /**
2034 * This verifies that the [enclosingClass] does not have a method and getter p air with the 2033 * This verifies that the [enclosingClass] does not have a method and getter p air with the
2035 * same name on, via inheritance. 2034 * same name on, via inheritance.
2036 * 2035 *
2037 * @return `true` if and only if an error code is generated on the passed node 2036 * @return `true` if and only if an error code is generated on the passed node
2038 * @see CompileTimeErrorCode#CONFLICTING_GETTER_AND_METHOD 2037 * See [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD], and
2039 * @see CompileTimeErrorCode#CONFLICTING_METHOD_AND_GETTER 2038 * [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER].
2040 */ 2039 */
2041 bool _checkForConflictingGetterAndMethod() { 2040 bool _checkForConflictingGetterAndMethod() {
2042 if (_enclosingClass == null) { 2041 if (_enclosingClass == null) {
2043 return false; 2042 return false;
2044 } 2043 }
2045 bool hasProblem = false; 2044 bool hasProblem = false;
2046 // method declared in the enclosing class vs. inherited getter 2045 // method declared in the enclosing class vs. inherited getter
2047 for (MethodElement method in _enclosingClass.methods) { 2046 for (MethodElement method in _enclosingClass.methods) {
2048 String name = method.name; 2047 String name = method.name;
2049 // find inherited property accessor (and can be only getter) 2048 // find inherited property accessor (and can be only getter)
(...skipping 30 matching lines...) Expand all
2080 return hasProblem; 2079 return hasProblem;
2081 } 2080 }
2082 2081
2083 /** 2082 /**
2084 * This verifies that the superclass of the [enclosingClass] does not declare accessible 2083 * This verifies that the superclass of the [enclosingClass] does not declare accessible
2085 * static members with the same name as the instance getters/setters declared in 2084 * static members with the same name as the instance getters/setters declared in
2086 * [enclosingClass]. 2085 * [enclosingClass].
2087 * 2086 *
2088 * @param node the method declaration to evaluate 2087 * @param node the method declaration to evaluate
2089 * @return `true` if and only if an error code is generated on the passed node 2088 * @return `true` if and only if an error code is generated on the passed node
2090 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER 2089 * See [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER], and
2091 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER 2090 * [StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER].
2092 */ 2091 */
2093 bool _checkForConflictingInstanceGetterAndSuperclassMember() { 2092 bool _checkForConflictingInstanceGetterAndSuperclassMember() {
2094 if (_enclosingClass == null) { 2093 if (_enclosingClass == null) {
2095 return false; 2094 return false;
2096 } 2095 }
2097 InterfaceType enclosingType = _enclosingClass.type; 2096 InterfaceType enclosingType = _enclosingClass.type;
2098 // check every accessor 2097 // check every accessor
2099 bool hasProblem = false; 2098 bool hasProblem = false;
2100 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 2099 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
2101 // we analyze instance accessors here 2100 // we analyze instance accessors here
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 } 2140 }
2142 2141
2143 /** 2142 /**
2144 * This verifies that the enclosing class does not have a setter with the same name as the passed 2143 * This verifies that the enclosing class does not have a setter with the same name as the passed
2145 * instance method declaration. 2144 * instance method declaration.
2146 * 2145 *
2147 * TODO(jwren) add other "conflicting" error codes into algorithm/ data struct ure 2146 * TODO(jwren) add other "conflicting" error codes into algorithm/ data struct ure
2148 * 2147 *
2149 * @param node the method declaration to evaluate 2148 * @param node the method declaration to evaluate
2150 * @return `true` if and only if an error code is generated on the passed node 2149 * @return `true` if and only if an error code is generated on the passed node
2151 * @see StaticWarningCode#CONFLICTING_INSTANCE_METHOD_SETTER 2150 * See [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER].
2152 */ 2151 */
2153 bool _checkForConflictingInstanceMethodSetter(ClassDeclaration node) { 2152 bool _checkForConflictingInstanceMethodSetter(ClassDeclaration node) {
2154 // Reference all of the class members in this class. 2153 // Reference all of the class members in this class.
2155 NodeList<ClassMember> classMembers = node.members; 2154 NodeList<ClassMember> classMembers = node.members;
2156 if (classMembers.isEmpty) { 2155 if (classMembers.isEmpty) {
2157 return false; 2156 return false;
2158 } 2157 }
2159 // Create a HashMap to track conflicting members, and then loop through memb ers in the class to 2158 // Create a HashMap to track conflicting members, and then loop through memb ers in the class to
2160 // construct the HashMap, at the same time, look for violations. Don't add members if they are 2159 // construct the HashMap, at the same time, look for violations. Don't add members if they are
2161 // part of a conflict, this prevents multiple warnings for one issue. 2160 // part of a conflict, this prevents multiple warnings for one issue.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 } 2221 }
2223 return foundError; 2222 return foundError;
2224 } 2223 }
2225 2224
2226 /** 2225 /**
2227 * This verifies that the enclosing class does not have an instance member wit h the same name as 2226 * This verifies that the enclosing class does not have an instance member wit h the same name as
2228 * the passed static getter method declaration. 2227 * the passed static getter method declaration.
2229 * 2228 *
2230 * @param node the method declaration to evaluate 2229 * @param node the method declaration to evaluate
2231 * @return `true` if and only if an error code is generated on the passed node 2230 * @return `true` if and only if an error code is generated on the passed node
2232 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER 2231 * See [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER].
2233 */ 2232 */
2234 bool _checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node) { 2233 bool _checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node) {
2235 if (!node.isStatic) { 2234 if (!node.isStatic) {
2236 return false; 2235 return false;
2237 } 2236 }
2238 // prepare name 2237 // prepare name
2239 SimpleIdentifier nameNode = node.name; 2238 SimpleIdentifier nameNode = node.name;
2240 if (nameNode == null) { 2239 if (nameNode == null) {
2241 return false; 2240 return false;
2242 } 2241 }
(...skipping 19 matching lines...) Expand all
2262 _errorReporter.reportErrorForNode(StaticWarningCode.CONFLICTING_STATIC_GETTE R_AND_INSTANCE_SETTER, nameNode, [setterType.displayName]); 2261 _errorReporter.reportErrorForNode(StaticWarningCode.CONFLICTING_STATIC_GETTE R_AND_INSTANCE_SETTER, nameNode, [setterType.displayName]);
2263 return true; 2262 return true;
2264 } 2263 }
2265 2264
2266 /** 2265 /**
2267 * This verifies that the enclosing class does not have an instance member wit h the same name as 2266 * This verifies that the enclosing class does not have an instance member wit h the same name as
2268 * the passed static getter method declaration. 2267 * the passed static getter method declaration.
2269 * 2268 *
2270 * @param node the method declaration to evaluate 2269 * @param node the method declaration to evaluate
2271 * @return `true` if and only if an error code is generated on the passed node 2270 * @return `true` if and only if an error code is generated on the passed node
2272 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER 2271 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER].
2273 */ 2272 */
2274 bool _checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node) { 2273 bool _checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node) {
2275 if (!node.isStatic) { 2274 if (!node.isStatic) {
2276 return false; 2275 return false;
2277 } 2276 }
2278 // prepare name 2277 // prepare name
2279 SimpleIdentifier nameNode = node.name; 2278 SimpleIdentifier nameNode = node.name;
2280 if (nameNode == null) { 2279 if (nameNode == null) {
2281 return false; 2280 return false;
2282 } 2281 }
(...skipping 25 matching lines...) Expand all
2308 // report problem 2307 // report problem
2309 _errorReporter.reportErrorForNode(StaticWarningCode.CONFLICTING_STATIC_SETTE R_AND_INSTANCE_MEMBER, nameNode, [memberType.displayName]); 2308 _errorReporter.reportErrorForNode(StaticWarningCode.CONFLICTING_STATIC_SETTE R_AND_INSTANCE_MEMBER, nameNode, [memberType.displayName]);
2310 return true; 2309 return true;
2311 } 2310 }
2312 2311
2313 /** 2312 /**
2314 * This verifies all conflicts between type variable and enclosing class. TODO (scheglov) 2313 * This verifies all conflicts between type variable and enclosing class. TODO (scheglov)
2315 * 2314 *
2316 * @param node the class declaration to evaluate 2315 * @param node the class declaration to evaluate
2317 * @return `true` if and only if an error code is generated on the passed node 2316 * @return `true` if and only if an error code is generated on the passed node
2318 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_CLASS 2317 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and
2319 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_MEMBER 2318 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER].
2320 */ 2319 */
2321 bool _checkForConflictingTypeVariableErrorCodes(ClassDeclaration node) { 2320 bool _checkForConflictingTypeVariableErrorCodes(ClassDeclaration node) {
2322 bool problemReported = false; 2321 bool problemReported = false;
2323 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { 2322 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) {
2324 String name = typeParameter.name; 2323 String name = typeParameter.name;
2325 // name is same as the name of the enclosing class 2324 // name is same as the name of the enclosing class
2326 if (_enclosingClass.name == name) { 2325 if (_enclosingClass.name == name) {
2327 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.CONFLICTING_TYP E_VARIABLE_AND_CLASS, typeParameter.nameOffset, name.length, [name]); 2326 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.CONFLICTING_TYP E_VARIABLE_AND_CLASS, typeParameter.nameOffset, name.length, [name]);
2328 problemReported = true; 2327 problemReported = true;
2329 } 2328 }
2330 // check members 2329 // check members
2331 if (_enclosingClass.getMethod(name) != null || _enclosingClass.getGetter(n ame) != null || _enclosingClass.getSetter(name) != null) { 2330 if (_enclosingClass.getMethod(name) != null || _enclosingClass.getGetter(n ame) != null || _enclosingClass.getSetter(name) != null) {
2332 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.CONFLICTING_TYP E_VARIABLE_AND_MEMBER, typeParameter.nameOffset, name.length, [name]); 2331 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.CONFLICTING_TYP E_VARIABLE_AND_MEMBER, typeParameter.nameOffset, name.length, [name]);
2333 problemReported = true; 2332 problemReported = true;
2334 } 2333 }
2335 } 2334 }
2336 return problemReported; 2335 return problemReported;
2337 } 2336 }
2338 2337
2339 /** 2338 /**
2340 * This verifies that if the passed constructor declaration is 'const' then th ere are no 2339 * This verifies that if the passed constructor declaration is 'const' then th ere are no
2341 * invocations of non-'const' super constructors. 2340 * invocations of non-'const' super constructors.
2342 * 2341 *
2343 * @param node the constructor declaration to evaluate 2342 * @param node the constructor declaration to evaluate
2344 * @return `true` if and only if an error code is generated on the passed node 2343 * @return `true` if and only if an error code is generated on the passed node
2345 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER 2344 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER].
2346 */ 2345 */
2347 bool _checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) { 2346 bool _checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) {
2348 if (!_isEnclosingConstructorConst) { 2347 if (!_isEnclosingConstructorConst) {
2349 return false; 2348 return false;
2350 } 2349 }
2351 // OK, const factory, checked elsewhere 2350 // OK, const factory, checked elsewhere
2352 if (node.factoryKeyword != null) { 2351 if (node.factoryKeyword != null) {
2353 return false; 2352 return false;
2354 } 2353 }
2355 // check for mixins 2354 // check for mixins
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 return true; 2388 return true;
2390 } 2389 }
2391 2390
2392 /** 2391 /**
2393 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final 2392 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final
2394 * instance variable. 2393 * instance variable.
2395 * 2394 *
2396 * @param node the constructor declaration to evaluate 2395 * @param node the constructor declaration to evaluate
2397 * @param constructorElement the constructor element 2396 * @param constructorElement the constructor element
2398 * @return `true` if and only if an error code is generated on the passed node 2397 * @return `true` if and only if an error code is generated on the passed node
2399 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD 2398 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD].
2400 */ 2399 */
2401 bool _checkForConstConstructorWithNonFinalField(ConstructorDeclaration node, C onstructorElement constructorElement) { 2400 bool _checkForConstConstructorWithNonFinalField(ConstructorDeclaration node, C onstructorElement constructorElement) {
2402 if (!_isEnclosingConstructorConst) { 2401 if (!_isEnclosingConstructorConst) {
2403 return false; 2402 return false;
2404 } 2403 }
2405 // check if there is non-final field 2404 // check if there is non-final field
2406 ClassElement classElement = constructorElement.enclosingElement; 2405 ClassElement classElement = constructorElement.enclosingElement;
2407 if (!classElement.hasNonFinalField) { 2406 if (!classElement.hasNonFinalField) {
2408 return false; 2407 return false;
2409 } 2408 }
2410 // report problem 2409 // report problem
2411 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_FINAL_FIELD, node, []); 2410 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_FINAL_FIELD, node, []);
2412 return true; 2411 return true;
2413 } 2412 }
2414 2413
2415 /** 2414 /**
2416 * This verifies that the passed 'const' instance creation expression is not c reating a deferred 2415 * This verifies that the passed 'const' instance creation expression is not c reating a deferred
2417 * type. 2416 * type.
2418 * 2417 *
2419 * @param node the instance creation expression to evaluate 2418 * @param node the instance creation expression to evaluate
2420 * @param constructorName the constructor name, always non-`null` 2419 * @param constructorName the constructor name, always non-`null`
2421 * @param typeName the name of the type defining the constructor, always non-` null` 2420 * @param typeName the name of the type defining the constructor, always non-` null`
2422 * @return `true` if and only if an error code is generated on the passed node 2421 * @return `true` if and only if an error code is generated on the passed node
2423 * @see CompileTimeErrorCode#CONST_DEFERRED_CLASS 2422 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS].
2424 */ 2423 */
2425 bool _checkForConstDeferredClass(InstanceCreationExpression node, ConstructorN ame constructorName, TypeName typeName) { 2424 bool _checkForConstDeferredClass(InstanceCreationExpression node, ConstructorN ame constructorName, TypeName typeName) {
2426 if (typeName.isDeferred) { 2425 if (typeName.isDeferred) {
2427 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_DEFERRED_CLAS S, constructorName, [typeName.name.name]); 2426 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_DEFERRED_CLAS S, constructorName, [typeName.name.name]);
2428 return true; 2427 return true;
2429 } 2428 }
2430 return false; 2429 return false;
2431 } 2430 }
2432 2431
2433 /** 2432 /**
2434 * This verifies that the passed throw expression is not enclosed in a 'const' constructor 2433 * This verifies that the passed throw expression is not enclosed in a 'const' constructor
2435 * declaration. 2434 * declaration.
2436 * 2435 *
2437 * @param node the throw expression expression to evaluate 2436 * @param node the throw expression expression to evaluate
2438 * @return `true` if and only if an error code is generated on the passed node 2437 * @return `true` if and only if an error code is generated on the passed node
2439 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION 2438 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION].
2440 */ 2439 */
2441 bool _checkForConstEvalThrowsException(ThrowExpression node) { 2440 bool _checkForConstEvalThrowsException(ThrowExpression node) {
2442 if (_isEnclosingConstructorConst) { 2441 if (_isEnclosingConstructorConst) {
2443 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_T HROWS_EXCEPTION, node, []); 2442 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_T HROWS_EXCEPTION, node, []);
2444 return true; 2443 return true;
2445 } 2444 }
2446 return false; 2445 return false;
2447 } 2446 }
2448 2447
2449 /** 2448 /**
2450 * This verifies that the passed normal formal parameter is not 'const'. 2449 * This verifies that the passed normal formal parameter is not 'const'.
2451 * 2450 *
2452 * @param node the normal formal parameter to evaluate 2451 * @param node the normal formal parameter to evaluate
2453 * @return `true` if and only if an error code is generated on the passed node 2452 * @return `true` if and only if an error code is generated on the passed node
2454 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER 2453 * See [CompileTimeErrorCode.CONST_FORMAL_PARAMETER].
2455 */ 2454 */
2456 bool _checkForConstFormalParameter(NormalFormalParameter node) { 2455 bool _checkForConstFormalParameter(NormalFormalParameter node) {
2457 if (node.isConst) { 2456 if (node.isConst) {
2458 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FORMAL_PARAME TER, node, []); 2457 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FORMAL_PARAME TER, node, []);
2459 return true; 2458 return true;
2460 } 2459 }
2461 return false; 2460 return false;
2462 } 2461 }
2463 2462
2464 /** 2463 /**
2465 * This verifies that the passed instance creation expression is not being inv oked on an abstract 2464 * This verifies that the passed instance creation expression is not being inv oked on an abstract
2466 * class. 2465 * class.
2467 * 2466 *
2468 * @param node the instance creation expression to evaluate 2467 * @param node the instance creation expression to evaluate
2469 * @param typeName the [TypeName] of the [ConstructorName] from the 2468 * @param typeName the [TypeName] of the [ConstructorName] from the
2470 * [InstanceCreationExpression], this is the AST node that the error is attached to 2469 * [InstanceCreationExpression], this is the AST node that the error is attached to
2471 * @param type the type being constructed with this [InstanceCreationExpressio n] 2470 * @param type the type being constructed with this [InstanceCreationExpressio n]
2472 * @return `true` if and only if an error code is generated on the passed node 2471 * @return `true` if and only if an error code is generated on the passed node
2473 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS 2472 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and
2474 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS 2473 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS].
2475 */ 2474 */
2476 bool _checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Typ eName typeName, InterfaceType type) { 2475 bool _checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Typ eName typeName, InterfaceType type) {
2477 if (type.element.isAbstract) { 2476 if (type.element.isAbstract) {
2478 ConstructorElement element = node.staticElement; 2477 ConstructorElement element = node.staticElement;
2479 if (element != null && !element.isFactory) { 2478 if (element != null && !element.isFactory) {
2480 if ((node.keyword as sc.KeywordToken).keyword == sc.Keyword.CONST) { 2479 if ((node.keyword as sc.KeywordToken).keyword == sc.Keyword.CONST) {
2481 _errorReporter.reportErrorForNode(StaticWarningCode.CONST_WITH_ABSTRAC T_CLASS, typeName, []); 2480 _errorReporter.reportErrorForNode(StaticWarningCode.CONST_WITH_ABSTRAC T_CLASS, typeName, []);
2482 } else { 2481 } else {
2483 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_ABSTRACT_ CLASS, typeName, []); 2482 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_ABSTRACT_ CLASS, typeName, []);
2484 } 2483 }
2485 return true; 2484 return true;
2486 } 2485 }
2487 } 2486 }
2488 return false; 2487 return false;
2489 } 2488 }
2490 2489
2491 /** 2490 /**
2492 * This verifies that the passed instance creation expression is not being inv oked on an enum. 2491 * This verifies that the passed instance creation expression is not being inv oked on an enum.
2493 * 2492 *
2494 * @param node the instance creation expression to verify 2493 * @param node the instance creation expression to verify
2495 * @param typeName the [TypeName] of the [ConstructorName] from the 2494 * @param typeName the [TypeName] of the [ConstructorName] from the
2496 * [InstanceCreationExpression], this is the AST node that the error is attached to 2495 * [InstanceCreationExpression], this is the AST node that the error is attached to
2497 * @param type the type being constructed with this [InstanceCreationExpressio n] 2496 * @param type the type being constructed with this [InstanceCreationExpressio n]
2498 * @return `true` if and only if an error code is generated on the passed node 2497 * @return `true` if and only if an error code is generated on the passed node
2499 * @see CompileTimeErrorCode#INSTANTIATE_ENUM 2498 * See [CompileTimeErrorCode.INSTANTIATE_ENUM].
2500 */ 2499 */
2501 bool _checkForConstOrNewWithEnum(InstanceCreationExpression node, TypeName typ eName, InterfaceType type) { 2500 bool _checkForConstOrNewWithEnum(InstanceCreationExpression node, TypeName typ eName, InterfaceType type) {
2502 if (type.element.isEnum) { 2501 if (type.element.isEnum) {
2503 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANTIATE_ENUM, t ypeName, []); 2502 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANTIATE_ENUM, t ypeName, []);
2504 return true; 2503 return true;
2505 } 2504 }
2506 return false; 2505 return false;
2507 } 2506 }
2508 2507
2509 /** 2508 /**
2510 * This verifies that the passed 'const' instance creation expression is not b eing invoked on a 2509 * This verifies that the passed 'const' instance creation expression is not b eing invoked on a
2511 * constructor that is not 'const'. 2510 * constructor that is not 'const'.
2512 * 2511 *
2513 * This method assumes that the instance creation was tested to be 'const' bef ore being called. 2512 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
2514 * 2513 *
2515 * @param node the instance creation expression to verify 2514 * @param node the instance creation expression to verify
2516 * @return `true` if and only if an error code is generated on the passed node 2515 * @return `true` if and only if an error code is generated on the passed node
2517 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST 2516 * See [CompileTimeErrorCode.CONST_WITH_NON_CONST].
2518 */ 2517 */
2519 bool _checkForConstWithNonConst(InstanceCreationExpression node) { 2518 bool _checkForConstWithNonConst(InstanceCreationExpression node) {
2520 ConstructorElement constructorElement = node.staticElement; 2519 ConstructorElement constructorElement = node.staticElement;
2521 if (constructorElement != null && !constructorElement.isConst) { 2520 if (constructorElement != null && !constructorElement.isConst) {
2522 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_CONS T, node, []); 2521 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_CONS T, node, []);
2523 return true; 2522 return true;
2524 } 2523 }
2525 return false; 2524 return false;
2526 } 2525 }
2527 2526
2528 /** 2527 /**
2529 * This verifies that the passed type name does not reference any type paramet ers. 2528 * This verifies that the passed type name does not reference any type paramet ers.
2530 * 2529 *
2531 * @param typeName the type name to evaluate 2530 * @param typeName the type name to evaluate
2532 * @return `true` if and only if an error code is generated on the passed node 2531 * @return `true` if and only if an error code is generated on the passed node
2533 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS 2532 * See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS].
2534 */ 2533 */
2535 bool _checkForConstWithTypeParameters(TypeName typeName) { 2534 bool _checkForConstWithTypeParameters(TypeName typeName) {
2536 // something wrong with AST 2535 // something wrong with AST
2537 if (typeName == null) { 2536 if (typeName == null) {
2538 return false; 2537 return false;
2539 } 2538 }
2540 Identifier name = typeName.name; 2539 Identifier name = typeName.name;
2541 if (name == null) { 2540 if (name == null) {
2542 return false; 2541 return false;
2543 } 2542 }
(...skipping 19 matching lines...) Expand all
2563 /** 2562 /**
2564 * This verifies that if the passed 'const' instance creation expression is be ing invoked on the 2563 * This verifies that if the passed 'const' instance creation expression is be ing invoked on the
2565 * resolved constructor. 2564 * resolved constructor.
2566 * 2565 *
2567 * This method assumes that the instance creation was tested to be 'const' bef ore being called. 2566 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
2568 * 2567 *
2569 * @param node the instance creation expression to evaluate 2568 * @param node the instance creation expression to evaluate
2570 * @param constructorName the constructor name, always non-`null` 2569 * @param constructorName the constructor name, always non-`null`
2571 * @param typeName the name of the type defining the constructor, always non-` null` 2570 * @param typeName the name of the type defining the constructor, always non-` null`
2572 * @return `true` if and only if an error code is generated on the passed node 2571 * @return `true` if and only if an error code is generated on the passed node
2573 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR 2572 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and
2574 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT 2573 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT].
2575 */ 2574 */
2576 bool _checkForConstWithUndefinedConstructor(InstanceCreationExpression node, C onstructorName constructorName, TypeName typeName) { 2575 bool _checkForConstWithUndefinedConstructor(InstanceCreationExpression node, C onstructorName constructorName, TypeName typeName) {
2577 // OK if resolved 2576 // OK if resolved
2578 if (node.staticElement != null) { 2577 if (node.staticElement != null) {
2579 return false; 2578 return false;
2580 } 2579 }
2581 DartType type = typeName.type; 2580 DartType type = typeName.type;
2582 if (type is InterfaceType) { 2581 if (type is InterfaceType) {
2583 ClassElement element = type.element; 2582 ClassElement element = type.element;
2584 if (element != null && element.isEnum) { 2583 if (element != null && element.isEnum) {
(...skipping 10 matching lines...) Expand all
2595 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_UNDEFINE D_CONSTRUCTOR_DEFAULT, constructorName, [className]); 2594 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_UNDEFINE D_CONSTRUCTOR_DEFAULT, constructorName, [className]);
2596 } 2595 }
2597 return true; 2596 return true;
2598 } 2597 }
2599 2598
2600 /** 2599 /**
2601 * This verifies that there are no default parameters in the passed function t ype alias. 2600 * This verifies that there are no default parameters in the passed function t ype alias.
2602 * 2601 *
2603 * @param node the function type alias to evaluate 2602 * @param node the function type alias to evaluate
2604 * @return `true` if and only if an error code is generated on the passed node 2603 * @return `true` if and only if an error code is generated on the passed node
2605 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS 2604 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS].
2606 */ 2605 */
2607 bool _checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { 2606 bool _checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) {
2608 bool result = false; 2607 bool result = false;
2609 FormalParameterList formalParameterList = node.parameters; 2608 FormalParameterList formalParameterList = node.parameters;
2610 NodeList<FormalParameter> parameters = formalParameterList.parameters; 2609 NodeList<FormalParameter> parameters = formalParameterList.parameters;
2611 for (FormalParameter formalParameter in parameters) { 2610 for (FormalParameter formalParameter in parameters) {
2612 if (formalParameter is DefaultFormalParameter) { 2611 if (formalParameter is DefaultFormalParameter) {
2613 DefaultFormalParameter defaultFormalParameter = formalParameter; 2612 DefaultFormalParameter defaultFormalParameter = formalParameter;
2614 if (defaultFormalParameter.defaultValue != null) { 2613 if (defaultFormalParameter.defaultValue != null) {
2615 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I N_FUNCTION_TYPE_ALIAS, node, []); 2614 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I N_FUNCTION_TYPE_ALIAS, node, []);
2616 result = true; 2615 result = true;
2617 } 2616 }
2618 } 2617 }
2619 } 2618 }
2620 return result; 2619 return result;
2621 } 2620 }
2622 2621
2623 /** 2622 /**
2624 * This verifies that the given default formal parameter is not part of a func tion typed 2623 * This verifies that the given default formal parameter is not part of a func tion typed
2625 * parameter. 2624 * parameter.
2626 * 2625 *
2627 * @param node the default formal parameter to evaluate 2626 * @param node the default formal parameter to evaluate
2628 * @return `true` if and only if an error code is generated on the passed node 2627 * @return `true` if and only if an error code is generated on the passed node
2629 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER 2628 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER].
2630 */ 2629 */
2631 bool _checkForDefaultValueInFunctionTypedParameter(DefaultFormalParameter node ) { 2630 bool _checkForDefaultValueInFunctionTypedParameter(DefaultFormalParameter node ) {
2632 // OK, not in a function typed parameter. 2631 // OK, not in a function typed parameter.
2633 if (!_isInFunctionTypedFormalParameter) { 2632 if (!_isInFunctionTypedFormalParameter) {
2634 return false; 2633 return false;
2635 } 2634 }
2636 // OK, no default value. 2635 // OK, no default value.
2637 if (node.defaultValue == null) { 2636 if (node.defaultValue == null) {
2638 return false; 2637 return false;
2639 } 2638 }
2640 // Report problem. 2639 // Report problem.
2641 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPED_PARAMETER, node, []); 2640 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPED_PARAMETER, node, []);
2642 return true; 2641 return true;
2643 } 2642 }
2644 2643
2645 /** 2644 /**
2646 * This verifies that any deferred imports in the given compilation unit have a unique prefix. 2645 * This verifies that any deferred imports in the given compilation unit have a unique prefix.
2647 * 2646 *
2648 * @param node the compilation unit containing the imports to be checked 2647 * @param node the compilation unit containing the imports to be checked
2649 * @return `true` if an error was generated 2648 * @return `true` if an error was generated
2650 * @see CompileTimeErrorCode#SHARED_DEFERRED_PREFIX 2649 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX].
2651 */ 2650 */
2652 bool _checkForDeferredPrefixCollisions(CompilationUnit node) { 2651 bool _checkForDeferredPrefixCollisions(CompilationUnit node) {
2653 bool foundError = false; 2652 bool foundError = false;
2654 NodeList<Directive> directives = node.directives; 2653 NodeList<Directive> directives = node.directives;
2655 int count = directives.length; 2654 int count = directives.length;
2656 if (count > 0) { 2655 if (count > 0) {
2657 HashMap<PrefixElement, List<ImportDirective>> prefixToDirectivesMap = new HashMap<PrefixElement, List<ImportDirective>>(); 2656 HashMap<PrefixElement, List<ImportDirective>> prefixToDirectivesMap = new HashMap<PrefixElement, List<ImportDirective>>();
2658 for (int i = 0; i < count; i++) { 2657 for (int i = 0; i < count; i++) {
2659 Directive directive = directives[i]; 2658 Directive directive = directives[i];
2660 if (directive is ImportDirective) { 2659 if (directive is ImportDirective) {
(...skipping 20 matching lines...) Expand all
2681 } 2680 }
2682 } 2681 }
2683 return foundError; 2682 return foundError;
2684 } 2683 }
2685 2684
2686 /** 2685 /**
2687 * This verifies that the enclosing class does not have an instance member wit h the given name of 2686 * This verifies that the enclosing class does not have an instance member wit h the given name of
2688 * the static member. 2687 * the static member.
2689 * 2688 *
2690 * @return `true` if and only if an error code is generated on the passed node 2689 * @return `true` if and only if an error code is generated on the passed node
2691 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE 2690 * See [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE].
2692 */ 2691 */
2693 bool _checkForDuplicateDefinitionInheritance() { 2692 bool _checkForDuplicateDefinitionInheritance() {
2694 if (_enclosingClass == null) { 2693 if (_enclosingClass == null) {
2695 return false; 2694 return false;
2696 } 2695 }
2697 bool hasProblem = false; 2696 bool hasProblem = false;
2698 for (ExecutableElement member in _enclosingClass.methods) { 2697 for (ExecutableElement member in _enclosingClass.methods) {
2699 if (member.isStatic && _checkForDuplicateDefinitionOfMember(member)) { 2698 if (member.isStatic && _checkForDuplicateDefinitionOfMember(member)) {
2700 hasProblem = true; 2699 hasProblem = true;
2701 } 2700 }
2702 } 2701 }
2703 for (ExecutableElement member in _enclosingClass.accessors) { 2702 for (ExecutableElement member in _enclosingClass.accessors) {
2704 if (member.isStatic && _checkForDuplicateDefinitionOfMember(member)) { 2703 if (member.isStatic && _checkForDuplicateDefinitionOfMember(member)) {
2705 hasProblem = true; 2704 hasProblem = true;
2706 } 2705 }
2707 } 2706 }
2708 return hasProblem; 2707 return hasProblem;
2709 } 2708 }
2710 2709
2711 /** 2710 /**
2712 * This verifies that the enclosing class does not have an instance member wit h the given name of 2711 * This verifies that the enclosing class does not have an instance member wit h the given name of
2713 * the static member. 2712 * the static member.
2714 * 2713 *
2715 * @param staticMember the static member to check conflict for 2714 * @param staticMember the static member to check conflict for
2716 * @return `true` if and only if an error code is generated on the passed node 2715 * @return `true` if and only if an error code is generated on the passed node
2717 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE 2716 * See [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE].
2718 */ 2717 */
2719 bool _checkForDuplicateDefinitionOfMember(ExecutableElement staticMember) { 2718 bool _checkForDuplicateDefinitionOfMember(ExecutableElement staticMember) {
2720 // prepare name 2719 // prepare name
2721 String name = staticMember.name; 2720 String name = staticMember.name;
2722 if (name == null) { 2721 if (name == null) {
2723 return false; 2722 return false;
2724 } 2723 }
2725 // try to find member 2724 // try to find member
2726 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name); 2725 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name);
2727 if (inheritedMember == null) { 2726 if (inheritedMember == null) {
(...skipping 16 matching lines...) Expand all
2744 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.DUPLICATE_DEFINITIO N_INHERITANCE, staticMember.nameOffset, name.length, [name, displayName]); 2743 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.DUPLICATE_DEFINITIO N_INHERITANCE, staticMember.nameOffset, name.length, [name, displayName]);
2745 return true; 2744 return true;
2746 } 2745 }
2747 2746
2748 /** 2747 /**
2749 * This verifies if the passed list literal has type arguments then there is e xactly one. 2748 * This verifies if the passed list literal has type arguments then there is e xactly one.
2750 * 2749 *
2751 * @param node the list literal to evaluate 2750 * @param node the list literal to evaluate
2752 * @param typeArguments the type arguments, always non-`null` 2751 * @param typeArguments the type arguments, always non-`null`
2753 * @return `true` if and only if an error code is generated on the passed node 2752 * @return `true` if and only if an error code is generated on the passed node
2754 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS 2753 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS].
2755 */ 2754 */
2756 bool _checkForExpectedOneListTypeArgument(ListLiteral node, TypeArgumentList t ypeArguments) { 2755 bool _checkForExpectedOneListTypeArgument(ListLiteral node, TypeArgumentList t ypeArguments) {
2757 // check number of type arguments 2756 // check number of type arguments
2758 int num = typeArguments.arguments.length; 2757 int num = typeArguments.arguments.length;
2759 if (num == 1) { 2758 if (num == 1) {
2760 return false; 2759 return false;
2761 } 2760 }
2762 // report problem 2761 // report problem
2763 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_ONE_LIST_TY PE_ARGUMENTS, typeArguments, [num]); 2762 _errorReporter.reportErrorForNode(StaticTypeWarningCode.EXPECTED_ONE_LIST_TY PE_ARGUMENTS, typeArguments, [num]);
2764 return true; 2763 return true;
2765 } 2764 }
2766 2765
2767 /** 2766 /**
2768 * This verifies the passed import has unique name among other exported librar ies. 2767 * This verifies the passed import has unique name among other exported librar ies.
2769 * 2768 *
2770 * @param node the export directive to evaluate 2769 * @param node the export directive to evaluate
2771 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the 2770 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the
2772 * node was `null`, then this method is not called 2771 * node was `null`, then this method is not called
2773 * @param exportedLibrary the library element containing the exported element 2772 * @param exportedLibrary the library element containing the exported element
2774 * @return `true` if and only if an error code is generated on the passed node 2773 * @return `true` if and only if an error code is generated on the passed node
2775 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME 2774 * See [CompileTimeErrorCode.EXPORT_DUPLICATED_LIBRARY_NAME].
2776 */ 2775 */
2777 bool _checkForExportDuplicateLibraryName(ExportDirective node, ExportElement e xportElement, LibraryElement exportedLibrary) { 2776 bool _checkForExportDuplicateLibraryName(ExportDirective node, ExportElement e xportElement, LibraryElement exportedLibrary) {
2778 if (exportedLibrary == null) { 2777 if (exportedLibrary == null) {
2779 return false; 2778 return false;
2780 } 2779 }
2781 String name = exportedLibrary.name; 2780 String name = exportedLibrary.name;
2782 // check if there is other exported library with the same name 2781 // check if there is other exported library with the same name
2783 LibraryElement prevLibrary = _nameToExportElement[name]; 2782 LibraryElement prevLibrary = _nameToExportElement[name];
2784 if (prevLibrary != null) { 2783 if (prevLibrary != null) {
2785 if (prevLibrary != exportedLibrary) { 2784 if (prevLibrary != exportedLibrary) {
(...skipping 21 matching lines...) Expand all
2807 } 2806 }
2808 2807
2809 /** 2808 /**
2810 * Check that if the visiting library is not system, then any passed library s hould not be SDK 2809 * Check that if the visiting library is not system, then any passed library s hould not be SDK
2811 * internal library. 2810 * internal library.
2812 * 2811 *
2813 * @param node the export directive to evaluate 2812 * @param node the export directive to evaluate
2814 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the 2813 * @param exportElement the [ExportElement] retrieved from the node, if the el ement in the
2815 * node was `null`, then this method is not called 2814 * node was `null`, then this method is not called
2816 * @return `true` if and only if an error code is generated on the passed node 2815 * @return `true` if and only if an error code is generated on the passed node
2817 * @see CompileTimeErrorCode#EXPORT_INTERNAL_LIBRARY 2816 * See [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY].
2818 */ 2817 */
2819 bool _checkForExportInternalLibrary(ExportDirective node, ExportElement export Element) { 2818 bool _checkForExportInternalLibrary(ExportDirective node, ExportElement export Element) {
2820 if (_isInSystemLibrary) { 2819 if (_isInSystemLibrary) {
2821 return false; 2820 return false;
2822 } 2821 }
2823 // should be private 2822 // should be private
2824 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; 2823 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk;
2825 String uri = exportElement.uri; 2824 String uri = exportElement.uri;
2826 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); 2825 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
2827 if (sdkLibrary == null) { 2826 if (sdkLibrary == null) {
2828 return false; 2827 return false;
2829 } 2828 }
2830 if (!sdkLibrary.isInternal) { 2829 if (!sdkLibrary.isInternal) {
2831 return false; 2830 return false;
2832 } 2831 }
2833 // report problem 2832 // report problem
2834 _errorReporter.reportErrorForNode(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRA RY, node, [node.uri]); 2833 _errorReporter.reportErrorForNode(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRA RY, node, [node.uri]);
2835 return true; 2834 return true;
2836 } 2835 }
2837 2836
2838 /** 2837 /**
2839 * This verifies that the passed extends clause does not extend a deferred cla ss. 2838 * This verifies that the passed extends clause does not extend a deferred cla ss.
2840 * 2839 *
2841 * @param node the extends clause to test 2840 * @param node the extends clause to test
2842 * @return `true` if and only if an error code is generated on the passed node 2841 * @return `true` if and only if an error code is generated on the passed node
2843 * @see CompileTimeErrorCode#EXTENDS_DEFERRED_CLASS 2842 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS].
2844 */ 2843 */
2845 bool _checkForExtendsDeferredClass(ExtendsClause node) { 2844 bool _checkForExtendsDeferredClass(ExtendsClause node) {
2846 if (node == null) { 2845 if (node == null) {
2847 return false; 2846 return false;
2848 } 2847 }
2849 return _checkForExtendsOrImplementsDeferredClass(node.superclass, CompileTim eErrorCode.EXTENDS_DEFERRED_CLASS); 2848 return _checkForExtendsOrImplementsDeferredClass(node.superclass, CompileTim eErrorCode.EXTENDS_DEFERRED_CLASS);
2850 } 2849 }
2851 2850
2852 /** 2851 /**
2853 * This verifies that the passed type alias does not extend a deferred class. 2852 * This verifies that the passed type alias does not extend a deferred class.
2854 * 2853 *
2855 * @param node the extends clause to test 2854 * @param node the extends clause to test
2856 * @return `true` if and only if an error code is generated on the passed node 2855 * @return `true` if and only if an error code is generated on the passed node
2857 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 2856 * See [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS].
2858 */ 2857 */
2859 bool _checkForExtendsDeferredClassInTypeAlias(ClassTypeAlias node) { 2858 bool _checkForExtendsDeferredClassInTypeAlias(ClassTypeAlias node) {
2860 if (node == null) { 2859 if (node == null) {
2861 return false; 2860 return false;
2862 } 2861 }
2863 return _checkForExtendsOrImplementsDeferredClass(node.superclass, CompileTim eErrorCode.EXTENDS_DEFERRED_CLASS); 2862 return _checkForExtendsOrImplementsDeferredClass(node.superclass, CompileTim eErrorCode.EXTENDS_DEFERRED_CLASS);
2864 } 2863 }
2865 2864
2866 /** 2865 /**
2867 * This verifies that the passed extends clause does not extend classes such a s num or String. 2866 * This verifies that the passed extends clause does not extend classes such a s num or String.
2868 * 2867 *
2869 * @param node the extends clause to test 2868 * @param node the extends clause to test
2870 * @return `true` if and only if an error code is generated on the passed node 2869 * @return `true` if and only if an error code is generated on the passed node
2871 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 2870 * See [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS].
2872 */ 2871 */
2873 bool _checkForExtendsDisallowedClass(ExtendsClause node) { 2872 bool _checkForExtendsDisallowedClass(ExtendsClause node) {
2874 if (node == null) { 2873 if (node == null) {
2875 return false; 2874 return false;
2876 } 2875 }
2877 return _checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileT imeErrorCode.EXTENDS_DISALLOWED_CLASS); 2876 return _checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileT imeErrorCode.EXTENDS_DISALLOWED_CLASS);
2878 } 2877 }
2879 2878
2880 /** 2879 /**
2881 * This verifies that the passed type alias does not extend classes such as nu m or String. 2880 * This verifies that the passed type alias does not extend classes such as nu m or String.
2882 * 2881 *
2883 * @param node the extends clause to test 2882 * @param node the extends clause to test
2884 * @return `true` if and only if an error code is generated on the passed node 2883 * @return `true` if and only if an error code is generated on the passed node
2885 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 2884 * See [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS].
2886 */ 2885 */
2887 bool _checkForExtendsDisallowedClassInTypeAlias(ClassTypeAlias node) { 2886 bool _checkForExtendsDisallowedClassInTypeAlias(ClassTypeAlias node) {
2888 if (node == null) { 2887 if (node == null) {
2889 return false; 2888 return false;
2890 } 2889 }
2891 return _checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileT imeErrorCode.EXTENDS_DISALLOWED_CLASS); 2890 return _checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileT imeErrorCode.EXTENDS_DISALLOWED_CLASS);
2892 } 2891 }
2893 2892
2894 /** 2893 /**
2895 * This verifies that the passed type name does not extend, implement or mixin classes that are 2894 * This verifies that the passed type name does not extend, implement or mixin classes that are
2896 * deferred. 2895 * deferred.
2897 * 2896 *
2898 * @param node the type name to test 2897 * @param node the type name to test
2899 * @return `true` if and only if an error code is generated on the passed node 2898 * @return `true` if and only if an error code is generated on the passed node
2900 * @see #checkForExtendsDeferredClass(ExtendsClause) 2899 * See [_checkForExtendsDeferredClass],
2901 * @see #checkForExtendsDeferredClassInTypeAlias(ClassTypeAlias) 2900 * [_checkForExtendsDeferredClassInTypeAlias],
2902 * @see #checkForImplementsDeferredClass(ImplementsClause) 2901 * [_checkForImplementsDeferredClass],
2903 * @see #checkForAllMixinErrorCodes(WithClause) 2902 * [_checkForAllMixinErrorCodes],
2904 * @see CompileTimeErrorCode#EXTENDS_DEFERRED_CLASS 2903 * [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS],
2905 * @see CompileTimeErrorCode#IMPLEMENTS_DEFERRED_CLASS 2904 * [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS], and
2906 * @see CompileTimeErrorCode#MIXIN_DEFERRED_CLASS 2905 * [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS].
2907 */ 2906 */
2908 bool _checkForExtendsOrImplementsDeferredClass(TypeName typeName, ErrorCode er rorCode) { 2907 bool _checkForExtendsOrImplementsDeferredClass(TypeName typeName, ErrorCode er rorCode) {
2909 if (typeName.isSynthetic) { 2908 if (typeName.isSynthetic) {
2910 return false; 2909 return false;
2911 } 2910 }
2912 if (typeName.isDeferred) { 2911 if (typeName.isDeferred) {
2913 _errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name.name ]); 2912 _errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name.name ]);
2914 return true; 2913 return true;
2915 } 2914 }
2916 return false; 2915 return false;
2917 } 2916 }
2918 2917
2919 /** 2918 /**
2920 * This verifies that the passed type name does not extend, implement or mixin classes such as 2919 * This verifies that the passed type name does not extend, implement or mixin classes such as
2921 * 'num' or 'String'. 2920 * 'num' or 'String'.
2922 * 2921 *
2923 * @param node the type name to test 2922 * @param node the type name to test
2924 * @return `true` if and only if an error code is generated on the passed node 2923 * @return `true` if and only if an error code is generated on the passed node
2925 * @see #checkForExtendsDisallowedClass(ExtendsClause) 2924 * See [_checkForExtendsDisallowedClass],
2926 * @see #checkForExtendsDisallowedClassInTypeAlias(ClassTypeAlias) 2925 * [_checkForExtendsDisallowedClassInTypeAlias],
2927 * @see #checkForImplementsDisallowedClass(ImplementsClause) 2926 * [_checkForImplementsDisallowedClass],
2928 * @see #checkForAllMixinErrorCodes(WithClause) 2927 * [_checkForAllMixinErrorCodes],
2929 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 2928 * [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS],
2930 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS 2929 * [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS], and
2931 * @see CompileTimeErrorCode#MIXIN_OF_DISALLOWED_CLASS 2930 * [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS].
2932 */ 2931 */
2933 bool _checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode errorCode) { 2932 bool _checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode errorCode) {
2934 if (typeName.isSynthetic) { 2933 if (typeName.isSynthetic) {
2935 return false; 2934 return false;
2936 } 2935 }
2937 DartType superType = typeName.type; 2936 DartType superType = typeName.type;
2938 for (InterfaceType disallowedType in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMEN T) { 2937 for (InterfaceType disallowedType in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMEN T) {
2939 if (superType != null && superType == disallowedType) { 2938 if (superType != null && superType == disallowedType) {
2940 // if the violating type happens to be 'num', we need to rule out the ca se where the 2939 // if the violating type happens to be 'num', we need to rule out the ca se where the
2941 // enclosing class is 'int' or 'double' 2940 // enclosing class is 'int' or 'double'
(...skipping 20 matching lines...) Expand all
2962 } 2961 }
2963 2962
2964 /** 2963 /**
2965 * This verifies that the passed constructor field initializer has compatible field and 2964 * This verifies that the passed constructor field initializer has compatible field and
2966 * initializer expression types. 2965 * initializer expression types.
2967 * 2966 *
2968 * @param node the constructor field initializer to test 2967 * @param node the constructor field initializer to test
2969 * @param staticElement the static element from the name in the 2968 * @param staticElement the static element from the name in the
2970 * [ConstructorFieldInitializer] 2969 * [ConstructorFieldInitializer]
2971 * @return `true` if and only if an error code is generated on the passed node 2970 * @return `true` if and only if an error code is generated on the passed node
2972 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE 2971 * See [CompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE], and
2973 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE 2972 * [StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE].
2974 */ 2973 */
2975 bool _checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node, Element staticElement) { 2974 bool _checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node, Element staticElement) {
2976 // prepare field element 2975 // prepare field element
2977 if (staticElement is! FieldElement) { 2976 if (staticElement is! FieldElement) {
2978 return false; 2977 return false;
2979 } 2978 }
2980 FieldElement fieldElement = staticElement as FieldElement; 2979 FieldElement fieldElement = staticElement as FieldElement;
2981 // prepare field type 2980 // prepare field type
2982 DartType fieldType = fieldElement.type; 2981 DartType fieldType = fieldElement.type;
2983 // prepare expression type 2982 // prepare expression type
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3022 // fieldType); 3021 // fieldType);
3023 // } 3022 // }
3024 // return true; 3023 // return true;
3025 } 3024 }
3026 3025
3027 /** 3026 /**
3028 * This verifies that the passed field formal parameter is in a constructor de claration. 3027 * This verifies that the passed field formal parameter is in a constructor de claration.
3029 * 3028 *
3030 * @param node the field formal parameter to test 3029 * @param node the field formal parameter to test
3031 * @return `true` if and only if an error code is generated on the passed node 3030 * @return `true` if and only if an error code is generated on the passed node
3032 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR 3031 * See [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR].
3033 */ 3032 */
3034 bool _checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamet er node) { 3033 bool _checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamet er node) {
3035 ConstructorDeclaration constructor = node.getAncestor((node) => node is Cons tructorDeclaration); 3034 ConstructorDeclaration constructor = node.getAncestor((node) => node is Cons tructorDeclaration);
3036 if (constructor == null) { 3035 if (constructor == null) {
3037 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_O UTSIDE_CONSTRUCTOR, node, []); 3036 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_O UTSIDE_CONSTRUCTOR, node, []);
3038 return true; 3037 return true;
3039 } 3038 }
3040 // constructor cannot be a factory 3039 // constructor cannot be a factory
3041 if (constructor.factoryKeyword != null) { 3040 if (constructor.factoryKeyword != null) {
3042 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_F ACTORY_CONSTRUCTOR, node, []); 3041 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_F ACTORY_CONSTRUCTOR, node, []);
(...skipping 12 matching lines...) Expand all
3055 3054
3056 /** 3055 /**
3057 * This verifies that the passed variable declaration list has only initialize d variables if the 3056 * This verifies that the passed variable declaration list has only initialize d variables if the
3058 * list is final or const. This method is called by 3057 * list is final or const. This method is called by
3059 * [checkForFinalNotInitializedInClass], 3058 * [checkForFinalNotInitializedInClass],
3060 * [visitTopLevelVariableDeclaration] and 3059 * [visitTopLevelVariableDeclaration] and
3061 * [visitVariableDeclarationStatement]. 3060 * [visitVariableDeclarationStatement].
3062 * 3061 *
3063 * @param node the class declaration to test 3062 * @param node the class declaration to test
3064 * @return `true` if and only if an error code is generated on the passed node 3063 * @return `true` if and only if an error code is generated on the passed node
3065 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED 3064 * See [CompileTimeErrorCode.CONST_NOT_INITIALIZED], and
3066 * @see StaticWarningCode#FINAL_NOT_INITIALIZED 3065 * [StaticWarningCode.FINAL_NOT_INITIALIZED].
3067 */ 3066 */
3068 bool _checkForFinalNotInitialized(VariableDeclarationList node) { 3067 bool _checkForFinalNotInitialized(VariableDeclarationList node) {
3069 if (_isInNativeClass) { 3068 if (_isInNativeClass) {
3070 return false; 3069 return false;
3071 } 3070 }
3072 bool foundError = false; 3071 bool foundError = false;
3073 if (!node.isSynthetic) { 3072 if (!node.isSynthetic) {
3074 NodeList<VariableDeclaration> variables = node.variables; 3073 NodeList<VariableDeclaration> variables = node.variables;
3075 for (VariableDeclaration variable in variables) { 3074 for (VariableDeclaration variable in variables) {
3076 if (variable.initializer == null) { 3075 if (variable.initializer == null) {
3077 if (node.isConst) { 3076 if (node.isConst) {
3078 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_NOT_INI TIALIZED, variable.name, [variable.name.name]); 3077 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_NOT_INI TIALIZED, variable.name, [variable.name.name]);
3079 } else if (node.isFinal) { 3078 } else if (node.isFinal) {
3080 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_NOT_INITIA LIZED, variable.name, [variable.name.name]); 3079 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_NOT_INITIA LIZED, variable.name, [variable.name.name]);
3081 } 3080 }
3082 foundError = true; 3081 foundError = true;
3083 } 3082 }
3084 } 3083 }
3085 } 3084 }
3086 return foundError; 3085 return foundError;
3087 } 3086 }
3088 3087
3089 /** 3088 /**
3090 * This verifies that final fields that are declared, without any constructors in the enclosing 3089 * This verifies that final fields that are declared, without any constructors in the enclosing
3091 * class, are initialized. Cases in which there is at least one constructor ar e handled at the end 3090 * class, are initialized. Cases in which there is at least one constructor ar e handled at the end
3092 * of [checkForAllFinalInitializedErrorCodes]. 3091 * of [checkForAllFinalInitializedErrorCodes].
3093 * 3092 *
3094 * @param node the class declaration to test 3093 * @param node the class declaration to test
3095 * @return `true` if and only if an error code is generated on the passed node 3094 * @return `true` if and only if an error code is generated on the passed node
3096 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED 3095 * See [CompileTimeErrorCode.CONST_NOT_INITIALIZED], and
3097 * @see StaticWarningCode#FINAL_NOT_INITIALIZED 3096 * [StaticWarningCode.FINAL_NOT_INITIALIZED].
3098 */ 3097 */
3099 bool _checkForFinalNotInitializedInClass(ClassDeclaration node) { 3098 bool _checkForFinalNotInitializedInClass(ClassDeclaration node) {
3100 NodeList<ClassMember> classMembers = node.members; 3099 NodeList<ClassMember> classMembers = node.members;
3101 for (ClassMember classMember in classMembers) { 3100 for (ClassMember classMember in classMembers) {
3102 if (classMember is ConstructorDeclaration) { 3101 if (classMember is ConstructorDeclaration) {
3103 return false; 3102 return false;
3104 } 3103 }
3105 } 3104 }
3106 bool foundError = false; 3105 bool foundError = false;
3107 for (ClassMember classMember in classMembers) { 3106 for (ClassMember classMember in classMembers) {
3108 if (classMember is FieldDeclaration 3107 if (classMember is FieldDeclaration
3109 && _checkForFinalNotInitialized(classMember.fields)) { 3108 && _checkForFinalNotInitialized(classMember.fields)) {
3110 foundError = true; 3109 foundError = true;
3111 } 3110 }
3112 } 3111 }
3113 return foundError; 3112 return foundError;
3114 } 3113 }
3115 3114
3116 /** 3115 /**
3117 * This verifies that the passed implements clause does not implement classes that are deferred. 3116 * This verifies that the passed implements clause does not implement classes that are deferred.
3118 * 3117 *
3119 * @param node the implements clause to test 3118 * @param node the implements clause to test
3120 * @return `true` if and only if an error code is generated on the passed node 3119 * @return `true` if and only if an error code is generated on the passed node
3121 * @see CompileTimeErrorCode#IMPLEMENTS_DEFERRED_CLASS 3120 * See [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS].
3122 */ 3121 */
3123 bool _checkForImplementsDeferredClass(ImplementsClause node) { 3122 bool _checkForImplementsDeferredClass(ImplementsClause node) {
3124 if (node == null) { 3123 if (node == null) {
3125 return false; 3124 return false;
3126 } 3125 }
3127 bool foundError = false; 3126 bool foundError = false;
3128 for (TypeName type in node.interfaces) { 3127 for (TypeName type in node.interfaces) {
3129 if (_checkForExtendsOrImplementsDeferredClass( 3128 if (_checkForExtendsOrImplementsDeferredClass(
3130 type, 3129 type,
3131 CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS)) { 3130 CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS)) {
3132 foundError = true; 3131 foundError = true;
3133 } 3132 }
3134 } 3133 }
3135 return foundError; 3134 return foundError;
3136 } 3135 }
3137 3136
3138 /** 3137 /**
3139 * This verifies that the passed implements clause does not implement classes such as 'num' or 3138 * This verifies that the passed implements clause does not implement classes such as 'num' or
3140 * 'String'. 3139 * 'String'.
3141 * 3140 *
3142 * @param node the implements clause to test 3141 * @param node the implements clause to test
3143 * @return `true` if and only if an error code is generated on the passed node 3142 * @return `true` if and only if an error code is generated on the passed node
3144 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS 3143 * See [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS].
3145 */ 3144 */
3146 bool _checkForImplementsDisallowedClass(ImplementsClause node) { 3145 bool _checkForImplementsDisallowedClass(ImplementsClause node) {
3147 if (node == null) { 3146 if (node == null) {
3148 return false; 3147 return false;
3149 } 3148 }
3150 bool foundError = false; 3149 bool foundError = false;
3151 for (TypeName type in node.interfaces) { 3150 for (TypeName type in node.interfaces) {
3152 if (_checkForExtendsOrImplementsDisallowedClass( 3151 if (_checkForExtendsOrImplementsDisallowedClass(
3153 type, 3152 type,
3154 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)) { 3153 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)) {
3155 foundError = true; 3154 foundError = true;
3156 } 3155 }
3157 } 3156 }
3158 return foundError; 3157 return foundError;
3159 } 3158 }
3160 3159
3161 /** 3160 /**
3162 * This verifies that if the passed identifier is part of constructor initiali zer, then it does 3161 * This verifies that if the passed identifier is part of constructor initiali zer, then it does
3163 * not reference implicitly 'this' expression. 3162 * not reference implicitly 'this' expression.
3164 * 3163 *
3165 * @param node the simple identifier to test 3164 * @param node the simple identifier to test
3166 * @return `true` if and only if an error code is generated on the passed node 3165 * @return `true` if and only if an error code is generated on the passed node
3167 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER 3166 * See [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER], and
3168 * @see CompileTimeErrorCode#INSTANCE_MEMBER_ACCESS_FROM_STATIC TODO(scheglov) rename thid method 3167 * [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC].
3168 * TODO(scheglov) rename thid method
3169 */ 3169 */
3170 bool _checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { 3170 bool _checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) {
3171 if (!_isInConstructorInitializer && !_isInStaticMethod && !_isInFactory && ! _isInInstanceVariableInitializer && !_isInStaticVariableDeclaration) { 3171 if (!_isInConstructorInitializer && !_isInStaticMethod && !_isInFactory && ! _isInInstanceVariableInitializer && !_isInStaticVariableDeclaration) {
3172 return false; 3172 return false;
3173 } 3173 }
3174 // prepare element 3174 // prepare element
3175 Element element = node.staticElement; 3175 Element element = node.staticElement;
3176 if (!(element is MethodElement || element is PropertyAccessorElement)) { 3176 if (!(element is MethodElement || element is PropertyAccessorElement)) {
3177 return false; 3177 return false;
3178 } 3178 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3222 return true; 3222 return true;
3223 } 3223 }
3224 3224
3225 /** 3225 /**
3226 * This verifies the passed import has unique name among other imported librar ies. 3226 * This verifies the passed import has unique name among other imported librar ies.
3227 * 3227 *
3228 * @param node the import directive to evaluate 3228 * @param node the import directive to evaluate
3229 * @param importElement the [ImportElement] retrieved from the node, if the el ement in the 3229 * @param importElement the [ImportElement] retrieved from the node, if the el ement in the
3230 * node was `null`, then this method is not called 3230 * node was `null`, then this method is not called
3231 * @return `true` if and only if an error code is generated on the passed node 3231 * @return `true` if and only if an error code is generated on the passed node
3232 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME 3232 * See [CompileTimeErrorCode.IMPORT_DUPLICATED_LIBRARY_NAME].
3233 */ 3233 */
3234 bool _checkForImportDuplicateLibraryName(ImportDirective node, ImportElement i mportElement) { 3234 bool _checkForImportDuplicateLibraryName(ImportDirective node, ImportElement i mportElement) {
3235 // prepare imported library 3235 // prepare imported library
3236 LibraryElement nodeLibrary = importElement.importedLibrary; 3236 LibraryElement nodeLibrary = importElement.importedLibrary;
3237 if (nodeLibrary == null) { 3237 if (nodeLibrary == null) {
3238 return false; 3238 return false;
3239 } 3239 }
3240 String name = nodeLibrary.name; 3240 String name = nodeLibrary.name;
3241 // check if there is another imported library with the same name 3241 // check if there is another imported library with the same name
3242 LibraryElement prevLibrary = _nameToImportElement[name]; 3242 LibraryElement prevLibrary = _nameToImportElement[name];
(...skipping 23 matching lines...) Expand all
3266 } 3266 }
3267 3267
3268 /** 3268 /**
3269 * Check that if the visiting library is not system, then any passed library s hould not be SDK 3269 * Check that if the visiting library is not system, then any passed library s hould not be SDK
3270 * internal library. 3270 * internal library.
3271 * 3271 *
3272 * @param node the import directive to evaluate 3272 * @param node the import directive to evaluate
3273 * @param importElement the [ImportElement] retrieved from the node, if the el ement in the 3273 * @param importElement the [ImportElement] retrieved from the node, if the el ement in the
3274 * node was `null`, then this method is not called 3274 * node was `null`, then this method is not called
3275 * @return `true` if and only if an error code is generated on the passed node 3275 * @return `true` if and only if an error code is generated on the passed node
3276 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY 3276 * See [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY].
3277 */ 3277 */
3278 bool _checkForImportInternalLibrary(ImportDirective node, ImportElement import Element) { 3278 bool _checkForImportInternalLibrary(ImportDirective node, ImportElement import Element) {
3279 if (_isInSystemLibrary) { 3279 if (_isInSystemLibrary) {
3280 return false; 3280 return false;
3281 } 3281 }
3282 // should be private 3282 // should be private
3283 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; 3283 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk;
3284 String uri = importElement.uri; 3284 String uri = importElement.uri;
3285 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); 3285 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
3286 if (sdkLibrary == null) { 3286 if (sdkLibrary == null) {
3287 return false; 3287 return false;
3288 } 3288 }
3289 if (!sdkLibrary.isInternal) { 3289 if (!sdkLibrary.isInternal) {
3290 return false; 3290 return false;
3291 } 3291 }
3292 // report problem 3292 // report problem
3293 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRA RY, node, [node.uri]); 3293 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRA RY, node, [node.uri]);
3294 return true; 3294 return true;
3295 } 3295 }
3296 3296
3297 /** 3297 /**
3298 * For each class declaration, this method is called which verifies that all i nherited members are 3298 * For each class declaration, this method is called which verifies that all i nherited members are
3299 * inherited consistently. 3299 * inherited consistently.
3300 * 3300 *
3301 * @return `true` if and only if an error code is generated on the passed node 3301 * @return `true` if and only if an error code is generated on the passed node
3302 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE 3302 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE].
3303 */ 3303 */
3304 bool _checkForInconsistentMethodInheritance() { 3304 bool _checkForInconsistentMethodInheritance() {
3305 // Ensure that the inheritance manager has a chance to generate all errors w e may care about, 3305 // Ensure that the inheritance manager has a chance to generate all errors w e may care about,
3306 // note that we ensure that the interfaces data since there are no errors. 3306 // note that we ensure that the interfaces data since there are no errors.
3307 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); 3307 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass);
3308 HashSet<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClas s); 3308 HashSet<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClas s);
3309 if (errors == null || errors.isEmpty) { 3309 if (errors == null || errors.isEmpty) {
3310 return false; 3310 return false;
3311 } 3311 }
3312 for (AnalysisError error in errors) { 3312 for (AnalysisError error in errors) {
3313 _errorReporter.reportError(error); 3313 _errorReporter.reportError(error);
3314 } 3314 }
3315 return true; 3315 return true;
3316 } 3316 }
3317 3317
3318 /** 3318 /**
3319 * This checks the given "typeReference" is not a type reference and that then the "name" is 3319 * This checks the given "typeReference" is not a type reference and that then the "name" is
3320 * reference to an instance member. 3320 * reference to an instance member.
3321 * 3321 *
3322 * @param typeReference the resolved [ClassElement] of the left hand side of t he expression, 3322 * @param typeReference the resolved [ClassElement] of the left hand side of t he expression,
3323 * or `null`, aka, the class element of 'C' in 'C.x', see 3323 * or `null`, aka, the class element of 'C' in 'C.x', see
3324 * [getTypeReference] 3324 * [getTypeReference]
3325 * @param name the accessed name to evaluate 3325 * @param name the accessed name to evaluate
3326 * @return `true` if and only if an error code is generated on the passed node 3326 * @return `true` if and only if an error code is generated on the passed node
3327 * @see StaticTypeWarningCode#INSTANCE_ACCESS_TO_STATIC_MEMBER 3327 * See [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER].
3328 */ 3328 */
3329 bool _checkForInstanceAccessToStaticMember(ClassElement typeReference, SimpleI dentifier name) { 3329 bool _checkForInstanceAccessToStaticMember(ClassElement typeReference, SimpleI dentifier name) {
3330 // OK, in comment 3330 // OK, in comment
3331 if (_isInComment) { 3331 if (_isInComment) {
3332 return false; 3332 return false;
3333 } 3333 }
3334 // OK, target is a type 3334 // OK, target is a type
3335 if (typeReference != null) { 3335 if (typeReference != null) {
3336 return false; 3336 return false;
3337 } 3337 }
(...skipping 16 matching lines...) Expand all
3354 return true; 3354 return true;
3355 } 3355 }
3356 3356
3357 /** 3357 /**
3358 * This checks whether the given [executableElement] collides with the name of a static 3358 * This checks whether the given [executableElement] collides with the name of a static
3359 * method in one of its superclasses, and reports the appropriate warning if i t does. 3359 * method in one of its superclasses, and reports the appropriate warning if i t does.
3360 * 3360 *
3361 * @param executableElement the method to check. 3361 * @param executableElement the method to check.
3362 * @param errorNameTarget the node to report problems on. 3362 * @param errorNameTarget the node to report problems on.
3363 * @return `true` if and only if a warning was generated. 3363 * @return `true` if and only if a warning was generated.
3364 * @see StaticTypeWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_ST ATIC 3364 * See [StaticTypeWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_ST ATIC].
3365 */ 3365 */
3366 bool _checkForInstanceMethodNameCollidesWithSuperclassStatic(ExecutableElement executableElement, SimpleIdentifier errorNameTarget) { 3366 bool _checkForInstanceMethodNameCollidesWithSuperclassStatic(ExecutableElement executableElement, SimpleIdentifier errorNameTarget) {
3367 String executableElementName = executableElement.name; 3367 String executableElementName = executableElement.name;
3368 if (executableElement is! PropertyAccessorElement && !executableElement.isOp erator) { 3368 if (executableElement is! PropertyAccessorElement && !executableElement.isOp erator) {
3369 HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>(); 3369 HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>();
3370 InterfaceType superclassType = _enclosingClass.supertype; 3370 InterfaceType superclassType = _enclosingClass.supertype;
3371 ClassElement superclassElement = superclassType == null ? null : superclas sType.element; 3371 ClassElement superclassElement = superclassType == null ? null : superclas sType.element;
3372 bool executableElementPrivate = Identifier.isPrivateName(executableElement Name); 3372 bool executableElementPrivate = Identifier.isPrivateName(executableElement Name);
3373 while (superclassElement != null && !visitedClasses.contains(superclassEle ment)) { 3373 while (superclassElement != null && !visitedClasses.contains(superclassEle ment)) {
3374 visitedClasses.add(superclassElement); 3374 visitedClasses.add(superclassElement);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3418 return false; 3418 return false;
3419 } 3419 }
3420 3420
3421 /** 3421 /**
3422 * This verifies that an 'int' can be assigned to the parameter corresponding to the given 3422 * This verifies that an 'int' can be assigned to the parameter corresponding to the given
3423 * expression. This is used for prefix and postfix expressions where the argum ent value is 3423 * expression. This is used for prefix and postfix expressions where the argum ent value is
3424 * implicit. 3424 * implicit.
3425 * 3425 *
3426 * @param argument the expression to which the operator is being applied 3426 * @param argument the expression to which the operator is being applied
3427 * @return `true` if and only if an error code is generated on the passed node 3427 * @return `true` if and only if an error code is generated on the passed node
3428 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 3428 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE].
3429 */ 3429 */
3430 bool _checkForIntNotAssignable(Expression argument) { 3430 bool _checkForIntNotAssignable(Expression argument) {
3431 if (argument == null) { 3431 if (argument == null) {
3432 return false; 3432 return false;
3433 } 3433 }
3434 ParameterElement staticParameterElement = argument.staticParameterElement; 3434 ParameterElement staticParameterElement = argument.staticParameterElement;
3435 DartType staticParameterType = staticParameterElement == null ? null : stati cParameterElement.type; 3435 DartType staticParameterType = staticParameterElement == null ? null : stati cParameterElement.type;
3436 return _checkForArgumentTypeNotAssignable(argument, staticParameterType, _in tType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); 3436 return _checkForArgumentTypeNotAssignable(argument, staticParameterType, _in tType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE);
3437 } 3437 }
3438 3438
3439 /** 3439 /**
3440 * This verifies that the passed [Annotation] isn't defined in a deferred libr ary. 3440 * This verifies that the passed [Annotation] isn't defined in a deferred libr ary.
3441 * 3441 *
3442 * @param node the [Annotation] 3442 * @param node the [Annotation]
3443 * @return `true` if and only if an error code is generated on the passed node 3443 * @return `true` if and only if an error code is generated on the passed node
3444 * @see CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY 3444 * See [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY].
3445 */ 3445 */
3446 bool _checkForInvalidAnnotationFromDeferredLibrary(Annotation node) { 3446 bool _checkForInvalidAnnotationFromDeferredLibrary(Annotation node) {
3447 Identifier nameIdentifier = node.name; 3447 Identifier nameIdentifier = node.name;
3448 if (nameIdentifier is PrefixedIdentifier) { 3448 if (nameIdentifier is PrefixedIdentifier) {
3449 if (nameIdentifier.isDeferred) { 3449 if (nameIdentifier.isDeferred) {
3450 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATIO N_FROM_DEFERRED_LIBRARY, node.name, []); 3450 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATIO N_FROM_DEFERRED_LIBRARY, node.name, []);
3451 return true; 3451 return true;
3452 } 3452 }
3453 } 3453 }
3454 return false; 3454 return false;
3455 } 3455 }
3456 3456
3457 /** 3457 /**
3458 * This verifies that the passed left hand side and right hand side represent a valid assignment. 3458 * This verifies that the passed left hand side and right hand side represent a valid assignment.
3459 * 3459 *
3460 * @param lhs the left hand side expression 3460 * @param lhs the left hand side expression
3461 * @param rhs the right hand side expression 3461 * @param rhs the right hand side expression
3462 * @return `true` if and only if an error code is generated on the passed node 3462 * @return `true` if and only if an error code is generated on the passed node
3463 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 3463 * See [StaticTypeWarningCode.INVALID_ASSIGNMENT].
3464 */ 3464 */
3465 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { 3465 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) {
3466 if (lhs == null || rhs == null) { 3466 if (lhs == null || rhs == null) {
3467 return false; 3467 return false;
3468 } 3468 }
3469 VariableElement leftVariableElement = getVariableElement(lhs); 3469 VariableElement leftVariableElement = getVariableElement(lhs);
3470 DartType leftType = (leftVariableElement == null) ? getStaticType(lhs) : lef tVariableElement.type; 3470 DartType leftType = (leftVariableElement == null) ? getStaticType(lhs) : lef tVariableElement.type;
3471 DartType staticRightType = getStaticType(rhs); 3471 DartType staticRightType = getStaticType(rhs);
3472 if (!staticRightType.isAssignableTo(leftType)) { 3472 if (!staticRightType.isAssignableTo(leftType)) {
3473 _errorReporter.reportTypeErrorForNode(StaticTypeWarningCode.INVALID_ASSIGN MENT, rhs, [staticRightType, leftType]); 3473 _errorReporter.reportTypeErrorForNode(StaticTypeWarningCode.INVALID_ASSIGN MENT, rhs, [staticRightType, leftType]);
3474 return true; 3474 return true;
3475 } 3475 }
3476 return false; 3476 return false;
3477 } 3477 }
3478 3478
3479 /** 3479 /**
3480 * Given an assignment using a compound assignment operator, this verifies tha t the given 3480 * Given an assignment using a compound assignment operator, this verifies tha t the given
3481 * assignment is valid. 3481 * assignment is valid.
3482 * 3482 *
3483 * @param node the assignment expression being tested 3483 * @param node the assignment expression being tested
3484 * @param lhs the left hand side expression 3484 * @param lhs the left hand side expression
3485 * @param rhs the right hand side expression 3485 * @param rhs the right hand side expression
3486 * @return `true` if and only if an error code is generated on the passed node 3486 * @return `true` if and only if an error code is generated on the passed node
3487 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 3487 * See [StaticTypeWarningCode.INVALID_ASSIGNMENT].
3488 */ 3488 */
3489 bool _checkForInvalidCompoundAssignment(AssignmentExpression node, Expression lhs, Expression rhs) { 3489 bool _checkForInvalidCompoundAssignment(AssignmentExpression node, Expression lhs, Expression rhs) {
3490 if (lhs == null) { 3490 if (lhs == null) {
3491 return false; 3491 return false;
3492 } 3492 }
3493 VariableElement leftVariableElement = getVariableElement(lhs); 3493 VariableElement leftVariableElement = getVariableElement(lhs);
3494 DartType leftType = (leftVariableElement == null) ? getStaticType(lhs) : lef tVariableElement.type; 3494 DartType leftType = (leftVariableElement == null) ? getStaticType(lhs) : lef tVariableElement.type;
3495 MethodElement invokedMethod = node.staticElement; 3495 MethodElement invokedMethod = node.staticElement;
3496 if (invokedMethod == null) { 3496 if (invokedMethod == null) {
3497 return false; 3497 return false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3544 return true; 3544 return true;
3545 } 3545 }
3546 return false; 3546 return false;
3547 } 3547 }
3548 3548
3549 /** 3549 /**
3550 * This verifies that the usage of the passed 'this' is valid. 3550 * This verifies that the usage of the passed 'this' is valid.
3551 * 3551 *
3552 * @param node the 'this' expression to evaluate 3552 * @param node the 'this' expression to evaluate
3553 * @return `true` if and only if an error code is generated on the passed node 3553 * @return `true` if and only if an error code is generated on the passed node
3554 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS 3554 * See [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS].
3555 */ 3555 */
3556 bool _checkForInvalidReferenceToThis(ThisExpression node) { 3556 bool _checkForInvalidReferenceToThis(ThisExpression node) {
3557 if (!_isThisInValidContext(node)) { 3557 if (!_isThisInValidContext(node)) {
3558 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_REFERENCE_T O_THIS, node, []); 3558 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_REFERENCE_T O_THIS, node, []);
3559 return true; 3559 return true;
3560 } 3560 }
3561 return false; 3561 return false;
3562 } 3562 }
3563 3563
3564 /** 3564 /**
3565 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav e a type 3565 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav e a type
3566 * parameter as a type argument. 3566 * parameter as a type argument.
3567 * 3567 *
3568 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp ective 3568 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp ective
3569 * [ListLiteral] or [MapLiteral] 3569 * [ListLiteral] or [MapLiteral]
3570 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS T_LIST] or 3570 * @param errorCode either [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONS T_LIST] or
3571 * [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP] 3571 * [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]
3572 * @return `true` if and only if an error code is generated on the passed node 3572 * @return `true` if and only if an error code is generated on the passed node
3573 */ 3573 */
3574 bool _checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argume nts, ErrorCode errorCode) { 3574 bool _checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argume nts, ErrorCode errorCode) {
3575 bool foundError = false; 3575 bool foundError = false;
3576 for (TypeName typeName in arguments) { 3576 for (TypeName typeName in arguments) {
3577 if (typeName.type is TypeParameterType) { 3577 if (typeName.type is TypeParameterType) {
3578 _errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name]); 3578 _errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name]);
3579 foundError = true; 3579 foundError = true;
3580 } 3580 }
3581 } 3581 }
3582 return foundError; 3582 return foundError;
3583 } 3583 }
3584 3584
3585 /** 3585 /**
3586 * This verifies that the elements given [ListLiteral] are subtypes of the spe cified element 3586 * This verifies that the elements given [ListLiteral] are subtypes of the spe cified element
3587 * type. 3587 * type.
3588 * 3588 *
3589 * @param node the list literal to evaluate 3589 * @param node the list literal to evaluate
3590 * @param typeArguments the type arguments, always non-`null` 3590 * @param typeArguments the type arguments, always non-`null`
3591 * @return `true` if and only if an error code is generated on the passed node 3591 * @return `true` if and only if an error code is generated on the passed node
3592 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 3592 * See [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], and
3593 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 3593 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE].
3594 */ 3594 */
3595 bool _checkForListElementTypeNotAssignable(ListLiteral node, TypeArgumentList typeArguments) { 3595 bool _checkForListElementTypeNotAssignable(ListLiteral node, TypeArgumentList typeArguments) {
3596 NodeList<TypeName> typeNames = typeArguments.arguments; 3596 NodeList<TypeName> typeNames = typeArguments.arguments;
3597 if (typeNames.length < 1) { 3597 if (typeNames.length < 1) {
3598 return false; 3598 return false;
3599 } 3599 }
3600 DartType listElementType = typeNames[0].type; 3600 DartType listElementType = typeNames[0].type;
3601 // Check every list element. 3601 // Check every list element.
3602 bool hasProblems = false; 3602 bool hasProblems = false;
3603 for (Expression element in node.elements) { 3603 for (Expression element in node.elements) {
(...skipping 17 matching lines...) Expand all
3621 return hasProblems; 3621 return hasProblems;
3622 } 3622 }
3623 3623
3624 /** 3624 /**
3625 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the 3625 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the
3626 * key/value types specified in the type arguments. 3626 * key/value types specified in the type arguments.
3627 * 3627 *
3628 * @param node the map literal to evaluate 3628 * @param node the map literal to evaluate
3629 * @param typeArguments the type arguments, always non-`null` 3629 * @param typeArguments the type arguments, always non-`null`
3630 * @return `true` if and only if an error code is generated on the passed node 3630 * @return `true` if and only if an error code is generated on the passed node
3631 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 3631 * See [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE],
3632 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 3632 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE],
3633 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 3633 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and
3634 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 3634 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE].
3635 */ 3635 */
3636 bool _checkForMapTypeNotAssignable(MapLiteral node, TypeArgumentList typeArgum ents) { 3636 bool _checkForMapTypeNotAssignable(MapLiteral node, TypeArgumentList typeArgum ents) {
3637 // Prepare maps key/value types. 3637 // Prepare maps key/value types.
3638 NodeList<TypeName> typeNames = typeArguments.arguments; 3638 NodeList<TypeName> typeNames = typeArguments.arguments;
3639 if (typeNames.length < 2) { 3639 if (typeNames.length < 2) {
3640 return false; 3640 return false;
3641 } 3641 }
3642 DartType keyType = typeNames[0].type; 3642 DartType keyType = typeNames[0].type;
3643 DartType valueType = typeNames[1].type; 3643 DartType valueType = typeNames[1].type;
3644 // Check every map entry. 3644 // Check every map entry.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3677 } 3677 }
3678 } 3678 }
3679 return hasProblems; 3679 return hasProblems;
3680 } 3680 }
3681 3681
3682 /** 3682 /**
3683 * This verifies that the [enclosingClass] does not define members with the sa me name as 3683 * This verifies that the [enclosingClass] does not define members with the sa me name as
3684 * the enclosing class. 3684 * the enclosing class.
3685 * 3685 *
3686 * @return `true` if and only if an error code is generated on the passed node 3686 * @return `true` if and only if an error code is generated on the passed node
3687 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME 3687 * See [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME].
3688 */ 3688 */
3689 bool _checkForMemberWithClassName() { 3689 bool _checkForMemberWithClassName() {
3690 if (_enclosingClass == null) { 3690 if (_enclosingClass == null) {
3691 return false; 3691 return false;
3692 } 3692 }
3693 String className = _enclosingClass.name; 3693 String className = _enclosingClass.name;
3694 if (className == null) { 3694 if (className == null) {
3695 return false; 3695 return false;
3696 } 3696 }
3697 bool problemReported = false; 3697 bool problemReported = false;
3698 // check accessors 3698 // check accessors
3699 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 3699 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
3700 if (className == accessor.name) { 3700 if (className == accessor.name) {
3701 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.MEMBER_WITH_CLA SS_NAME, accessor.nameOffset, className.length, []); 3701 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.MEMBER_WITH_CLA SS_NAME, accessor.nameOffset, className.length, []);
3702 problemReported = true; 3702 problemReported = true;
3703 } 3703 }
3704 } 3704 }
3705 // don't check methods, they would be constructors 3705 // don't check methods, they would be constructors
3706 // done 3706 // done
3707 return problemReported; 3707 return problemReported;
3708 } 3708 }
3709 3709
3710 /** 3710 /**
3711 * Check to make sure that all similarly typed accessors are of the same type (including inherited 3711 * Check to make sure that all similarly typed accessors are of the same type (including inherited
3712 * accessors). 3712 * accessors).
3713 * 3713 *
3714 * @param node the accessor currently being visited 3714 * @param node the accessor currently being visited
3715 * @return `true` if and only if an error code is generated on the passed node 3715 * @return `true` if and only if an error code is generated on the passed node
3716 * @see StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES 3716 * See [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES], and
3717 * @see StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE 3717 * [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE].
3718 */ 3718 */
3719 bool _checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String accessorTextName) { 3719 bool _checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String accessorTextName) {
3720 ExecutableElement accessorElement = accessorDeclaration.element as Executabl eElement; 3720 ExecutableElement accessorElement = accessorDeclaration.element as Executabl eElement;
3721 if (accessorElement is! PropertyAccessorElement) { 3721 if (accessorElement is! PropertyAccessorElement) {
3722 return false; 3722 return false;
3723 } 3723 }
3724 PropertyAccessorElement propertyAccessorElement = accessorElement as Propert yAccessorElement; 3724 PropertyAccessorElement propertyAccessorElement = accessorElement as Propert yAccessorElement;
3725 PropertyAccessorElement counterpartAccessor = null; 3725 PropertyAccessorElement counterpartAccessor = null;
3726 ClassElement enclosingClassForCounterpart = null; 3726 ClassElement enclosingClassForCounterpart = null;
3727 if (propertyAccessorElement.isGetter) { 3727 if (propertyAccessorElement.isGetter) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3837 } 3837 }
3838 return true; 3838 return true;
3839 } 3839 }
3840 3840
3841 /** 3841 /**
3842 * This verifies that the given function body does not contain return statemen ts that both have 3842 * This verifies that the given function body does not contain return statemen ts that both have
3843 * and do not have return values. 3843 * and do not have return values.
3844 * 3844 *
3845 * @param node the function body being tested 3845 * @param node the function body being tested
3846 * @return `true` if and only if an error code is generated on the passed node 3846 * @return `true` if and only if an error code is generated on the passed node
3847 * @see StaticWarningCode#MIXED_RETURN_TYPES 3847 * See [StaticWarningCode.MIXED_RETURN_TYPES].
3848 */ 3848 */
3849 bool _checkForMixedReturns(BlockFunctionBody node) { 3849 bool _checkForMixedReturns(BlockFunctionBody node) {
3850 if (_hasReturnWithoutValue) { 3850 if (_hasReturnWithoutValue) {
3851 return false; 3851 return false;
3852 } 3852 }
3853 int withCount = _returnsWith.length; 3853 int withCount = _returnsWith.length;
3854 int withoutCount = _returnsWithout.length; 3854 int withoutCount = _returnsWithout.length;
3855 if (withCount > 0 && withoutCount > 0) { 3855 if (withCount > 0 && withoutCount > 0) {
3856 for (int i = 0; i < withCount; i++) { 3856 for (int i = 0; i < withCount; i++) {
3857 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWith[i].keyword, []); 3857 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWith[i].keyword, []);
3858 } 3858 }
3859 for (int i = 0; i < withoutCount; i++) { 3859 for (int i = 0; i < withoutCount; i++) {
3860 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWithout[i].keyword, []); 3860 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWithout[i].keyword, []);
3861 } 3861 }
3862 return true; 3862 return true;
3863 } 3863 }
3864 return false; 3864 return false;
3865 } 3865 }
3866 3866
3867 /** 3867 /**
3868 * This verifies that the passed mixin does not have an explicitly declared co nstructor. 3868 * This verifies that the passed mixin does not have an explicitly declared co nstructor.
3869 * 3869 *
3870 * @param mixinName the node to report problem on 3870 * @param mixinName the node to report problem on
3871 * @param mixinElement the mixing to evaluate 3871 * @param mixinElement the mixing to evaluate
3872 * @return `true` if and only if an error code is generated on the passed node 3872 * @return `true` if and only if an error code is generated on the passed node
3873 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR 3873 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR].
3874 */ 3874 */
3875 bool _checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinE lement) { 3875 bool _checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinE lement) {
3876 for (ConstructorElement constructor in mixinElement.constructors) { 3876 for (ConstructorElement constructor in mixinElement.constructors) {
3877 if (!constructor.isSynthetic && !constructor.isFactory) { 3877 if (!constructor.isSynthetic && !constructor.isFactory) {
3878 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MIXIN_DECLARES_CO NSTRUCTOR, mixinName, [mixinElement.name]); 3878 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MIXIN_DECLARES_CO NSTRUCTOR, mixinName, [mixinElement.name]);
3879 return true; 3879 return true;
3880 } 3880 }
3881 } 3881 }
3882 return false; 3882 return false;
3883 } 3883 }
3884 3884
3885 /** 3885 /**
3886 * This verifies that the passed mixin has the 'Object' superclass. 3886 * This verifies that the passed mixin has the 'Object' superclass.
3887 * 3887 *
3888 * @param mixinName the node to report problem on 3888 * @param mixinName the node to report problem on
3889 * @param mixinElement the mixing to evaluate 3889 * @param mixinElement the mixing to evaluate
3890 * @return `true` if and only if an error code is generated on the passed node 3890 * @return `true` if and only if an error code is generated on the passed node
3891 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT 3891 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT].
3892 */ 3892 */
3893 bool _checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixi nElement) { 3893 bool _checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixi nElement) {
3894 InterfaceType mixinSupertype = mixinElement.supertype; 3894 InterfaceType mixinSupertype = mixinElement.supertype;
3895 if (mixinSupertype != null) { 3895 if (mixinSupertype != null) {
3896 if (!mixinSupertype.isObject || !mixinElement.isTypedef && mixinElement.mi xins.length != 0) { 3896 if (!mixinSupertype.isObject || !mixinElement.isTypedef && mixinElement.mi xins.length != 0) {
3897 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MIXIN_INHERITS_FR OM_NOT_OBJECT, mixinName, [mixinElement.name]); 3897 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MIXIN_INHERITS_FR OM_NOT_OBJECT, mixinName, [mixinElement.name]);
3898 return true; 3898 return true;
3899 } 3899 }
3900 } 3900 }
3901 return false; 3901 return false;
3902 } 3902 }
3903 3903
3904 /** 3904 /**
3905 * This verifies that the passed mixin does not reference 'super'. 3905 * This verifies that the passed mixin does not reference 'super'.
3906 * 3906 *
3907 * @param mixinName the node to report problem on 3907 * @param mixinName the node to report problem on
3908 * @param mixinElement the mixing to evaluate 3908 * @param mixinElement the mixing to evaluate
3909 * @return `true` if and only if an error code is generated on the passed node 3909 * @return `true` if and only if an error code is generated on the passed node
3910 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER 3910 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER].
3911 */ 3911 */
3912 bool _checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinEleme nt) { 3912 bool _checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinEleme nt) {
3913 if (mixinElement.hasReferenceToSuper) { 3913 if (mixinElement.hasReferenceToSuper) {
3914 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MIXIN_REFERENCES_SU PER, mixinName, [mixinElement.name]); 3914 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MIXIN_REFERENCES_SU PER, mixinName, [mixinElement.name]);
3915 } 3915 }
3916 return false; 3916 return false;
3917 } 3917 }
3918 3918
3919 /** 3919 /**
3920 * This verifies that the passed constructor has at most one 'super' initializ er. 3920 * This verifies that the passed constructor has at most one 'super' initializ er.
3921 * 3921 *
3922 * @param node the constructor declaration to evaluate 3922 * @param node the constructor declaration to evaluate
3923 * @return `true` if and only if an error code is generated on the passed node 3923 * @return `true` if and only if an error code is generated on the passed node
3924 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS 3924 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS].
3925 */ 3925 */
3926 bool _checkForMultipleSuperInitializers(ConstructorDeclaration node) { 3926 bool _checkForMultipleSuperInitializers(ConstructorDeclaration node) {
3927 int numSuperInitializers = 0; 3927 int numSuperInitializers = 0;
3928 for (ConstructorInitializer initializer in node.initializers) { 3928 for (ConstructorInitializer initializer in node.initializers) {
3929 if (initializer is SuperConstructorInvocation) { 3929 if (initializer is SuperConstructorInvocation) {
3930 numSuperInitializers++; 3930 numSuperInitializers++;
3931 if (numSuperInitializers > 1) { 3931 if (numSuperInitializers > 1) {
3932 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_SUPER_ INITIALIZERS, initializer, []); 3932 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_SUPER_ INITIALIZERS, initializer, []);
3933 } 3933 }
3934 } 3934 }
3935 } 3935 }
3936 return numSuperInitializers > 0; 3936 return numSuperInitializers > 0;
3937 } 3937 }
3938 3938
3939 /** 3939 /**
3940 * Checks to ensure that native function bodies can only in SDK code. 3940 * Checks to ensure that native function bodies can only in SDK code.
3941 * 3941 *
3942 * @param node the native function body to test 3942 * @param node the native function body to test
3943 * @return `true` if and only if an error code is generated on the passed node 3943 * @return `true` if and only if an error code is generated on the passed node
3944 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE 3944 * See [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE].
3945 */ 3945 */
3946 bool _checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { 3946 bool _checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) {
3947 if (!_isInSystemLibrary && !_hasExtUri) { 3947 if (!_isInSystemLibrary && !_hasExtUri) {
3948 _errorReporter.reportErrorForNode(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_ NON_SDK_CODE, node, []); 3948 _errorReporter.reportErrorForNode(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_ NON_SDK_CODE, node, []);
3949 return true; 3949 return true;
3950 } 3950 }
3951 return false; 3951 return false;
3952 } 3952 }
3953 3953
3954 /** 3954 /**
3955 * This verifies that the passed 'new' instance creation expression invokes ex isting constructor. 3955 * This verifies that the passed 'new' instance creation expression invokes ex isting constructor.
3956 * 3956 *
3957 * This method assumes that the instance creation was tested to be 'new' befor e being called. 3957 * This method assumes that the instance creation was tested to be 'new' befor e being called.
3958 * 3958 *
3959 * @param node the instance creation expression to evaluate 3959 * @param node the instance creation expression to evaluate
3960 * @param constructorName the constructor name, always non-`null` 3960 * @param constructorName the constructor name, always non-`null`
3961 * @param typeName the name of the type defining the constructor, always non-` null` 3961 * @param typeName the name of the type defining the constructor, always non-` null`
3962 * @return `true` if and only if an error code is generated on the passed node 3962 * @return `true` if and only if an error code is generated on the passed node
3963 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR 3963 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR].
3964 */ 3964 */
3965 bool _checkForNewWithUndefinedConstructor(InstanceCreationExpression node, Con structorName constructorName, TypeName typeName) { 3965 bool _checkForNewWithUndefinedConstructor(InstanceCreationExpression node, Con structorName constructorName, TypeName typeName) {
3966 // OK if resolved 3966 // OK if resolved
3967 if (node.staticElement != null) { 3967 if (node.staticElement != null) {
3968 return false; 3968 return false;
3969 } 3969 }
3970 DartType type = typeName.type; 3970 DartType type = typeName.type;
3971 if (type is InterfaceType) { 3971 if (type is InterfaceType) {
3972 ClassElement element = type.element; 3972 ClassElement element = type.element;
3973 if (element != null && element.isEnum) { 3973 if (element != null && element.isEnum) {
(...skipping 12 matching lines...) Expand all
3986 } 3986 }
3987 return true; 3987 return true;
3988 } 3988 }
3989 3989
3990 /** 3990 /**
3991 * This checks that if the passed class declaration implicitly calls default c onstructor of its 3991 * This checks that if the passed class declaration implicitly calls default c onstructor of its
3992 * superclass, there should be such default constructor - implicit or explicit . 3992 * superclass, there should be such default constructor - implicit or explicit .
3993 * 3993 *
3994 * @param node the [ClassDeclaration] to evaluate 3994 * @param node the [ClassDeclaration] to evaluate
3995 * @return `true` if and only if an error code is generated on the passed node 3995 * @return `true` if and only if an error code is generated on the passed node
3996 * @see CompileTimeErrorCode#NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 3996 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT].
3997 */ 3997 */
3998 bool _checkForNoDefaultSuperConstructorImplicit(ClassDeclaration node) { 3998 bool _checkForNoDefaultSuperConstructorImplicit(ClassDeclaration node) {
3999 // do nothing if there is explicit constructor 3999 // do nothing if there is explicit constructor
4000 List<ConstructorElement> constructors = _enclosingClass.constructors; 4000 List<ConstructorElement> constructors = _enclosingClass.constructors;
4001 if (!constructors[0].isSynthetic) { 4001 if (!constructors[0].isSynthetic) {
4002 return false; 4002 return false;
4003 } 4003 }
4004 // prepare super 4004 // prepare super
4005 InterfaceType superType = _enclosingClass.supertype; 4005 InterfaceType superType = _enclosingClass.supertype;
4006 if (superType == null) { 4006 if (superType == null) {
(...skipping 16 matching lines...) Expand all
4023 return true; 4023 return true;
4024 } 4024 }
4025 4025
4026 /** 4026 /**
4027 * This checks that passed class declaration overrides all members required by its superclasses 4027 * This checks that passed class declaration overrides all members required by its superclasses
4028 * and interfaces. 4028 * and interfaces.
4029 * 4029 *
4030 * @param classNameNode the [SimpleIdentifier] to be used if there is a violat ion, this is 4030 * @param classNameNode the [SimpleIdentifier] to be used if there is a violat ion, this is
4031 * either the named from the [ClassDeclaration] or from the [ClassTyp eAlias]. 4031 * either the named from the [ClassDeclaration] or from the [ClassTyp eAlias].
4032 * @return `true` if and only if an error code is generated on the passed node 4032 * @return `true` if and only if an error code is generated on the passed node
4033 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE 4033 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE],
4034 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO 4034 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO],
4035 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE 4035 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE],
4036 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR 4036 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR], and
4037 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU S 4037 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS].
4038 */ 4038 */
4039 bool _checkForNonAbstractClassInheritsAbstractMember(SimpleIdentifier classNam eNode) { 4039 bool _checkForNonAbstractClassInheritsAbstractMember(SimpleIdentifier classNam eNode) {
4040 if (_enclosingClass.isAbstract) { 4040 if (_enclosingClass.isAbstract) {
4041 return false; 4041 return false;
4042 } 4042 }
4043 // 4043 //
4044 // Store in local sets the set of all method and accessor names 4044 // Store in local sets the set of all method and accessor names
4045 // 4045 //
4046 List<MethodElement> methods = _enclosingClass.methods; 4046 List<MethodElement> methods = _enclosingClass.methods;
4047 for (MethodElement method in methods) { 4047 for (MethodElement method in methods) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
4165 _errorReporter.reportError(analysisError); 4165 _errorReporter.reportError(analysisError);
4166 return true; 4166 return true;
4167 } 4167 }
4168 4168
4169 /** 4169 /**
4170 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is 4170 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is
4171 * reported on the expression. 4171 * reported on the expression.
4172 * 4172 *
4173 * @param condition the conditional expression to test 4173 * @param condition the conditional expression to test
4174 * @return `true` if and only if an error code is generated on the passed node 4174 * @return `true` if and only if an error code is generated on the passed node
4175 * @see StaticTypeWarningCode#NON_BOOL_CONDITION 4175 * See [StaticTypeWarningCode.NON_BOOL_CONDITION].
4176 */ 4176 */
4177 bool _checkForNonBoolCondition(Expression condition) { 4177 bool _checkForNonBoolCondition(Expression condition) {
4178 DartType conditionType = getStaticType(condition); 4178 DartType conditionType = getStaticType(condition);
4179 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { 4179 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) {
4180 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_CONDITION , condition, []); 4180 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_CONDITION , condition, []);
4181 return true; 4181 return true;
4182 } 4182 }
4183 return false; 4183 return false;
4184 } 4184 }
4185 4185
4186 /** 4186 /**
4187 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input. 4187 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input.
4188 * 4188 *
4189 * @param node the assert statement to evaluate 4189 * @param node the assert statement to evaluate
4190 * @return `true` if and only if an error code is generated on the passed node 4190 * @return `true` if and only if an error code is generated on the passed node
4191 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION 4191 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION].
4192 */ 4192 */
4193 bool _checkForNonBoolExpression(AssertStatement node) { 4193 bool _checkForNonBoolExpression(AssertStatement node) {
4194 Expression expression = node.condition; 4194 Expression expression = node.condition;
4195 DartType type = getStaticType(expression); 4195 DartType type = getStaticType(expression);
4196 if (type is InterfaceType) { 4196 if (type is InterfaceType) {
4197 if (!type.isAssignableTo(_boolType)) { 4197 if (!type.isAssignableTo(_boolType)) {
4198 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []); 4198 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []);
4199 return true; 4199 return true;
4200 } 4200 }
4201 } else if (type is FunctionType) { 4201 } else if (type is FunctionType) {
4202 FunctionType functionType = type; 4202 FunctionType functionType = type;
4203 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_boolType)) { 4203 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_boolType)) {
4204 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []); 4204 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []);
4205 return true; 4205 return true;
4206 } 4206 }
4207 } 4207 }
4208 return false; 4208 return false;
4209 } 4209 }
4210 4210
4211 /** 4211 /**
4212 * Checks to ensure that the given expression is assignable to bool. 4212 * Checks to ensure that the given expression is assignable to bool.
4213 * 4213 *
4214 * @param expression the expression expression to test 4214 * @param expression the expression expression to test
4215 * @return `true` if and only if an error code is generated on the passed node 4215 * @return `true` if and only if an error code is generated on the passed node
4216 * @see StaticTypeWarningCode#NON_BOOL_NEGATION_EXPRESSION 4216 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION].
4217 */ 4217 */
4218 bool _checkForNonBoolNegationExpression(Expression expression) { 4218 bool _checkForNonBoolNegationExpression(Expression expression) {
4219 DartType conditionType = getStaticType(expression); 4219 DartType conditionType = getStaticType(expression);
4220 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { 4220 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) {
4221 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_NEGATION_ EXPRESSION, expression, []); 4221 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_NEGATION_ EXPRESSION, expression, []);
4222 return true; 4222 return true;
4223 } 4223 }
4224 return false; 4224 return false;
4225 } 4225 }
4226 4226
4227 /** 4227 /**
4228 * This verifies the passed map literal either: 4228 * This verifies the passed map literal either:
4229 * * has `const modifier` 4229 * * has `const modifier`
4230 * * has explicit type arguments 4230 * * has explicit type arguments
4231 * * is not start of the statement 4231 * * is not start of the statement
4232 * 4232 *
4233 * @param node the map literal to evaluate 4233 * @param node the map literal to evaluate
4234 * @return `true` if and only if an error code is generated on the passed node 4234 * @return `true` if and only if an error code is generated on the passed node
4235 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT 4235 * See [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT].
4236 */ 4236 */
4237 bool _checkForNonConstMapAsExpressionStatement(MapLiteral node) { 4237 bool _checkForNonConstMapAsExpressionStatement(MapLiteral node) {
4238 // "const" 4238 // "const"
4239 if (node.constKeyword != null) { 4239 if (node.constKeyword != null) {
4240 return false; 4240 return false;
4241 } 4241 }
4242 // has type arguments 4242 // has type arguments
4243 if (node.typeArguments != null) { 4243 if (node.typeArguments != null) {
4244 return false; 4244 return false;
4245 } 4245 }
(...skipping 10 matching lines...) Expand all
4256 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPR ESSION_STATEMENT, node, []); 4256 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPR ESSION_STATEMENT, node, []);
4257 return true; 4257 return true;
4258 } 4258 }
4259 4259
4260 /** 4260 /**
4261 * This verifies the passed method declaration of operator `[]=`, has `void` r eturn 4261 * This verifies the passed method declaration of operator `[]=`, has `void` r eturn
4262 * type. 4262 * type.
4263 * 4263 *
4264 * @param node the method declaration to evaluate 4264 * @param node the method declaration to evaluate
4265 * @return `true` if and only if an error code is generated on the passed node 4265 * @return `true` if and only if an error code is generated on the passed node
4266 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR 4266 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR].
4267 */ 4267 */
4268 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { 4268 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration node) {
4269 // check that []= operator 4269 // check that []= operator
4270 SimpleIdentifier name = node.name; 4270 SimpleIdentifier name = node.name;
4271 if (name.name != "[]=") { 4271 if (name.name != "[]=") {
4272 return false; 4272 return false;
4273 } 4273 }
4274 // check return type 4274 // check return type
4275 TypeName typeName = node.returnType; 4275 TypeName typeName = node.returnType;
4276 if (typeName != null) { 4276 if (typeName != null) {
4277 DartType type = typeName.type; 4277 DartType type = typeName.type;
4278 if (type != null && !type.isVoid) { 4278 if (type != null && !type.isVoid) {
4279 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_ OPERATOR, typeName, []); 4279 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_ OPERATOR, typeName, []);
4280 } 4280 }
4281 } 4281 }
4282 // no warning 4282 // no warning
4283 return false; 4283 return false;
4284 } 4284 }
4285 4285
4286 /** 4286 /**
4287 * This verifies the passed setter has no return type or the `void` return typ e. 4287 * This verifies the passed setter has no return type or the `void` return typ e.
4288 * 4288 *
4289 * @param typeName the type name to evaluate 4289 * @param typeName the type name to evaluate
4290 * @return `true` if and only if an error code is generated on the passed node 4290 * @return `true` if and only if an error code is generated on the passed node
4291 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER 4291 * See [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER].
4292 */ 4292 */
4293 bool _checkForNonVoidReturnTypeForSetter(TypeName typeName) { 4293 bool _checkForNonVoidReturnTypeForSetter(TypeName typeName) {
4294 if (typeName != null) { 4294 if (typeName != null) {
4295 DartType type = typeName.type; 4295 DartType type = typeName.type;
4296 if (type != null && !type.isVoid) { 4296 if (type != null && !type.isVoid) {
4297 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_ SETTER, typeName, []); 4297 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_ SETTER, typeName, []);
4298 } 4298 }
4299 } 4299 }
4300 return false; 4300 return false;
4301 } 4301 }
4302 4302
4303 /** 4303 /**
4304 * This verifies the passed operator-method declaration, does not have an opti onal parameter. 4304 * This verifies the passed operator-method declaration, does not have an opti onal parameter.
4305 * 4305 *
4306 * This method assumes that the method declaration was tested to be an operato r declaration before 4306 * This method assumes that the method declaration was tested to be an operato r declaration before
4307 * being called. 4307 * being called.
4308 * 4308 *
4309 * @param node the method declaration to evaluate 4309 * @param node the method declaration to evaluate
4310 * @return `true` if and only if an error code is generated on the passed node 4310 * @return `true` if and only if an error code is generated on the passed node
4311 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR 4311 * See [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR].
4312 */ 4312 */
4313 bool _checkForOptionalParameterInOperator(MethodDeclaration node) { 4313 bool _checkForOptionalParameterInOperator(MethodDeclaration node) {
4314 FormalParameterList parameterList = node.parameters; 4314 FormalParameterList parameterList = node.parameters;
4315 if (parameterList == null) { 4315 if (parameterList == null) {
4316 return false; 4316 return false;
4317 } 4317 }
4318 bool foundError = false; 4318 bool foundError = false;
4319 NodeList<FormalParameter> formalParameters = parameterList.parameters; 4319 NodeList<FormalParameter> formalParameters = parameterList.parameters;
4320 for (FormalParameter formalParameter in formalParameters) { 4320 for (FormalParameter formalParameter in formalParameters) {
4321 if (formalParameter.kind.isOptional) { 4321 if (formalParameter.kind.isOptional) {
4322 _errorReporter.reportErrorForNode(CompileTimeErrorCode.OPTIONAL_PARAMETE R_IN_OPERATOR, formalParameter, []); 4322 _errorReporter.reportErrorForNode(CompileTimeErrorCode.OPTIONAL_PARAMETE R_IN_OPERATOR, formalParameter, []);
4323 foundError = true; 4323 foundError = true;
4324 } 4324 }
4325 } 4325 }
4326 return foundError; 4326 return foundError;
4327 } 4327 }
4328 4328
4329 /** 4329 /**
4330 * This checks for named optional parameters that begin with '_'. 4330 * This checks for named optional parameters that begin with '_'.
4331 * 4331 *
4332 * @param node the default formal parameter to evaluate 4332 * @param node the default formal parameter to evaluate
4333 * @return `true` if and only if an error code is generated on the passed node 4333 * @return `true` if and only if an error code is generated on the passed node
4334 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER 4334 * See [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER].
4335 */ 4335 */
4336 bool _checkForPrivateOptionalParameter(FormalParameter node) { 4336 bool _checkForPrivateOptionalParameter(FormalParameter node) {
4337 // should be named parameter 4337 // should be named parameter
4338 if (node.kind != ParameterKind.NAMED) { 4338 if (node.kind != ParameterKind.NAMED) {
4339 return false; 4339 return false;
4340 } 4340 }
4341 // name should start with '_' 4341 // name should start with '_'
4342 SimpleIdentifier name = node.identifier; 4342 SimpleIdentifier name = node.identifier;
4343 if (name.isSynthetic || !StringUtilities.startsWithChar(name.name, 0x5F)) { 4343 if (name.isSynthetic || !StringUtilities.startsWithChar(name.name, 0x5F)) {
4344 return false; 4344 return false;
4345 } 4345 }
4346 // report problem 4346 // report problem
4347 _errorReporter.reportErrorForNode(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARA METER, node, []); 4347 _errorReporter.reportErrorForNode(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARA METER, node, []);
4348 return true; 4348 return true;
4349 } 4349 }
4350 4350
4351 /** 4351 /**
4352 * This checks if the passed constructor declaration is the redirecting genera tive constructor and 4352 * This checks if the passed constructor declaration is the redirecting genera tive constructor and
4353 * references itself directly or indirectly. 4353 * references itself directly or indirectly.
4354 * 4354 *
4355 * @param node the constructor declaration to evaluate 4355 * @param node the constructor declaration to evaluate
4356 * @param constructorElement the constructor element 4356 * @param constructorElement the constructor element
4357 * @return `true` if and only if an error code is generated on the passed node 4357 * @return `true` if and only if an error code is generated on the passed node
4358 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT 4358 * See [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT].
4359 */ 4359 */
4360 bool _checkForRecursiveConstructorRedirect(ConstructorDeclaration node, Constr uctorElement constructorElement) { 4360 bool _checkForRecursiveConstructorRedirect(ConstructorDeclaration node, Constr uctorElement constructorElement) {
4361 // we check generative constructor here 4361 // we check generative constructor here
4362 if (node.factoryKeyword != null) { 4362 if (node.factoryKeyword != null) {
4363 return false; 4363 return false;
4364 } 4364 }
4365 // try to find redirecting constructor invocation and analyzer it for recurs ion 4365 // try to find redirecting constructor invocation and analyzer it for recurs ion
4366 for (ConstructorInitializer initializer in node.initializers) { 4366 for (ConstructorInitializer initializer in node.initializers) {
4367 if (initializer is RedirectingConstructorInvocation) { 4367 if (initializer is RedirectingConstructorInvocation) {
4368 // OK if no cycle 4368 // OK if no cycle
4369 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) { 4369 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) {
4370 return false; 4370 return false;
4371 } 4371 }
4372 // report error 4372 // report error
4373 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_CONSTRU CTOR_REDIRECT, initializer, []); 4373 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_CONSTRU CTOR_REDIRECT, initializer, []);
4374 return true; 4374 return true;
4375 } 4375 }
4376 } 4376 }
4377 // OK, no redirecting constructor invocation 4377 // OK, no redirecting constructor invocation
4378 return false; 4378 return false;
4379 } 4379 }
4380 4380
4381 /** 4381 /**
4382 * This checks if the passed constructor declaration has redirected constructo r and references 4382 * This checks if the passed constructor declaration has redirected constructo r and references
4383 * itself directly or indirectly. 4383 * itself directly or indirectly.
4384 * 4384 *
4385 * @param node the constructor declaration to evaluate 4385 * @param node the constructor declaration to evaluate
4386 * @param constructorElement the constructor element 4386 * @param constructorElement the constructor element
4387 * @return `true` if and only if an error code is generated on the passed node 4387 * @return `true` if and only if an error code is generated on the passed node
4388 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT 4388 * See [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT].
4389 */ 4389 */
4390 bool _checkForRecursiveFactoryRedirect(ConstructorDeclaration node, Constructo rElement constructorElement) { 4390 bool _checkForRecursiveFactoryRedirect(ConstructorDeclaration node, Constructo rElement constructorElement) {
4391 // prepare redirected constructor 4391 // prepare redirected constructor
4392 ConstructorName redirectedConstructorNode = node.redirectedConstructor; 4392 ConstructorName redirectedConstructorNode = node.redirectedConstructor;
4393 if (redirectedConstructorNode == null) { 4393 if (redirectedConstructorNode == null) {
4394 return false; 4394 return false;
4395 } 4395 }
4396 // OK if no cycle 4396 // OK if no cycle
4397 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) { 4397 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) {
4398 return false; 4398 return false;
4399 } 4399 }
4400 // report error 4400 // report error
4401 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_FACTORY_RED IRECT, redirectedConstructorNode, []); 4401 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_FACTORY_RED IRECT, redirectedConstructorNode, []);
4402 return true; 4402 return true;
4403 } 4403 }
4404 4404
4405 /** 4405 /**
4406 * This checks the class declaration is not a superinterface to itself. 4406 * This checks the class declaration is not a superinterface to itself.
4407 * 4407 *
4408 * @param classElt the class element to test 4408 * @param classElt the class element to test
4409 * @return `true` if and only if an error code is generated on the passed elem ent 4409 * @return `true` if and only if an error code is generated on the passed elem ent
4410 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE 4410 * See [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE],
4411 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS 4411 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS], a nd
4412 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS 4412 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS] .
4413 */ 4413 */
4414 bool _checkForRecursiveInterfaceInheritance(ClassElement classElt) { 4414 bool _checkForRecursiveInterfaceInheritance(ClassElement classElt) {
4415 if (classElt == null) { 4415 if (classElt == null) {
4416 return false; 4416 return false;
4417 } 4417 }
4418 return _safeCheckForRecursiveInterfaceInheritance(classElt, new List<ClassEl ement>()); 4418 return _safeCheckForRecursiveInterfaceInheritance(classElt, new List<ClassEl ement>());
4419 } 4419 }
4420 4420
4421 /** 4421 /**
4422 * This checks the passed constructor declaration has a valid combination of r edirected 4422 * This checks the passed constructor declaration has a valid combination of r edirected
4423 * constructor invocation(s), super constructor invocations and field initiali zers. 4423 * constructor invocation(s), super constructor invocations and field initiali zers.
4424 * 4424 *
4425 * @param node the constructor declaration to evaluate 4425 * @param node the constructor declaration to evaluate
4426 * @return `true` if and only if an error code is generated on the passed node 4426 * @return `true` if and only if an error code is generated on the passed node
4427 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR 4427 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR] ,
4428 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR 4428 * [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR],
4429 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS 4429 * [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS],
4430 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR 4430 * [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR], and
4431 * @see CompileTimeErrorCode#REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR 4431 * [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR].
4432 */ 4432 */
4433 bool _checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { 4433 bool _checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) {
4434 bool errorReported = false; 4434 bool errorReported = false;
4435 // 4435 //
4436 // Check for default values in the parameters 4436 // Check for default values in the parameters
4437 // 4437 //
4438 ConstructorName redirectedConstructor = node.redirectedConstructor; 4438 ConstructorName redirectedConstructor = node.redirectedConstructor;
4439 if (redirectedConstructor != null) { 4439 if (redirectedConstructor != null) {
4440 for (FormalParameter parameter in node.parameters.parameters) { 4440 for (FormalParameter parameter in node.parameters.parameters) {
4441 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul l) { 4441 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul l) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4488 return errorReported; 4488 return errorReported;
4489 } 4489 }
4490 4490
4491 /** 4491 /**
4492 * This checks if the passed constructor declaration has redirected constructo r and references 4492 * This checks if the passed constructor declaration has redirected constructo r and references
4493 * itself directly or indirectly. 4493 * itself directly or indirectly.
4494 * 4494 *
4495 * @param node the constructor declaration to evaluate 4495 * @param node the constructor declaration to evaluate
4496 * @param constructorElement the constructor element 4496 * @param constructorElement the constructor element
4497 * @return `true` if and only if an error code is generated on the passed node 4497 * @return `true` if and only if an error code is generated on the passed node
4498 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR 4498 * See [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR].
4499 */ 4499 */
4500 bool _checkForRedirectToNonConstConstructor(ConstructorDeclaration node, Const ructorElement constructorElement) { 4500 bool _checkForRedirectToNonConstConstructor(ConstructorDeclaration node, Const ructorElement constructorElement) {
4501 // prepare redirected constructor 4501 // prepare redirected constructor
4502 ConstructorName redirectedConstructorNode = node.redirectedConstructor; 4502 ConstructorName redirectedConstructorNode = node.redirectedConstructor;
4503 if (redirectedConstructorNode == null) { 4503 if (redirectedConstructorNode == null) {
4504 return false; 4504 return false;
4505 } 4505 }
4506 // prepare element 4506 // prepare element
4507 if (constructorElement == null) { 4507 if (constructorElement == null) {
4508 return false; 4508 return false;
(...skipping 14 matching lines...) Expand all
4523 // report error 4523 // report error
4524 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_TO_NON_CONST _CONSTRUCTOR, redirectedConstructorNode, []); 4524 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_TO_NON_CONST _CONSTRUCTOR, redirectedConstructorNode, []);
4525 return true; 4525 return true;
4526 } 4526 }
4527 4527
4528 /** 4528 /**
4529 * This checks that the rethrow is inside of a catch clause. 4529 * This checks that the rethrow is inside of a catch clause.
4530 * 4530 *
4531 * @param node the rethrow expression to evaluate 4531 * @param node the rethrow expression to evaluate
4532 * @return `true` if and only if an error code is generated on the passed node 4532 * @return `true` if and only if an error code is generated on the passed node
4533 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH 4533 * See [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH].
4534 */ 4534 */
4535 bool _checkForRethrowOutsideCatch(RethrowExpression node) { 4535 bool _checkForRethrowOutsideCatch(RethrowExpression node) {
4536 if (!_isInCatchClause) { 4536 if (!_isInCatchClause) {
4537 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETHROW_OUTSIDE_CAT CH, node, []); 4537 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETHROW_OUTSIDE_CAT CH, node, []);
4538 return true; 4538 return true;
4539 } 4539 }
4540 return false; 4540 return false;
4541 } 4541 }
4542 4542
4543 /** 4543 /**
4544 * This checks that if the the given constructor declaration is generative, th en it does not have 4544 * This checks that if the the given constructor declaration is generative, th en it does not have
4545 * an expression function body. 4545 * an expression function body.
4546 * 4546 *
4547 * @param node the constructor to evaluate 4547 * @param node the constructor to evaluate
4548 * @return `true` if and only if an error code is generated on the passed node 4548 * @return `true` if and only if an error code is generated on the passed node
4549 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR 4549 * See [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR].
4550 */ 4550 */
4551 bool _checkForReturnInGenerativeConstructor(ConstructorDeclaration node) { 4551 bool _checkForReturnInGenerativeConstructor(ConstructorDeclaration node) {
4552 // ignore factory 4552 // ignore factory
4553 if (node.factoryKeyword != null) { 4553 if (node.factoryKeyword != null) {
4554 return false; 4554 return false;
4555 } 4555 }
4556 // block body (with possible return statement) is checked elsewhere 4556 // block body (with possible return statement) is checked elsewhere
4557 FunctionBody body = node.body; 4557 FunctionBody body = node.body;
4558 if (body is! ExpressionFunctionBody) { 4558 if (body is! ExpressionFunctionBody) {
4559 return false; 4559 return false;
4560 } 4560 }
4561 // report error 4561 // report error
4562 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIVE_ CONSTRUCTOR, body, []); 4562 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIVE_ CONSTRUCTOR, body, []);
4563 return true; 4563 return true;
4564 } 4564 }
4565 4565
4566 /** 4566 /**
4567 * This checks that a type mis-match between the return type and the expressed return type by the 4567 * This checks that a type mis-match between the return type and the expressed return type by the
4568 * enclosing method or function. 4568 * enclosing method or function.
4569 * 4569 *
4570 * This method is called both by [checkForAllReturnStatementErrorCodes] 4570 * This method is called both by [checkForAllReturnStatementErrorCodes]
4571 * and [visitExpressionFunctionBody]. 4571 * and [visitExpressionFunctionBody].
4572 * 4572 *
4573 * @param returnExpression the returned expression to evaluate 4573 * @param returnExpression the returned expression to evaluate
4574 * @param expectedReturnType the expressed return type by the enclosing method or function 4574 * @param expectedReturnType the expressed return type by the enclosing method or function
4575 * @return `true` if and only if an error code is generated on the passed node 4575 * @return `true` if and only if an error code is generated on the passed node
4576 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE 4576 * See [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE].
4577 */ 4577 */
4578 bool _checkForReturnOfInvalidType(Expression returnExpression, DartType expect edReturnType) { 4578 bool _checkForReturnOfInvalidType(Expression returnExpression, DartType expect edReturnType) {
4579 if (_enclosingFunction == null) { 4579 if (_enclosingFunction == null) {
4580 return false; 4580 return false;
4581 } 4581 }
4582 DartType staticReturnType = getStaticType(returnExpression); 4582 DartType staticReturnType = getStaticType(returnExpression);
4583 if (expectedReturnType.isVoid) { 4583 if (expectedReturnType.isVoid) {
4584 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) { 4584 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) {
4585 return false; 4585 return false;
4586 } 4586 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4631 4631
4632 /** 4632 /**
4633 * This checks the given "typeReference" and that the "name" is not the refere nce to an instance 4633 * This checks the given "typeReference" and that the "name" is not the refere nce to an instance
4634 * member. 4634 * member.
4635 * 4635 *
4636 * @param typeReference the resolved [ClassElement] of the left hand side of t he expression, 4636 * @param typeReference the resolved [ClassElement] of the left hand side of t he expression,
4637 * or `null`, aka, the class element of 'C' in 'C.x', see 4637 * or `null`, aka, the class element of 'C' in 'C.x', see
4638 * [getTypeReference] 4638 * [getTypeReference]
4639 * @param name the accessed name to evaluate 4639 * @param name the accessed name to evaluate
4640 * @return `true` if and only if an error code is generated on the passed node 4640 * @return `true` if and only if an error code is generated on the passed node
4641 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER 4641 * See [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER].
4642 */ 4642 */
4643 bool _checkForStaticAccessToInstanceMember(ClassElement typeReference, SimpleI dentifier name) { 4643 bool _checkForStaticAccessToInstanceMember(ClassElement typeReference, SimpleI dentifier name) {
4644 // OK, target is not a type 4644 // OK, target is not a type
4645 if (typeReference == null) { 4645 if (typeReference == null) {
4646 return false; 4646 return false;
4647 } 4647 }
4648 // prepare member Element 4648 // prepare member Element
4649 Element element = name.staticElement; 4649 Element element = name.staticElement;
4650 if (element is! ExecutableElement) { 4650 if (element is! ExecutableElement) {
4651 return false; 4651 return false;
4652 } 4652 }
4653 ExecutableElement memberElement = element as ExecutableElement; 4653 ExecutableElement memberElement = element as ExecutableElement;
4654 // OK, static 4654 // OK, static
4655 if (memberElement.isStatic) { 4655 if (memberElement.isStatic) {
4656 return false; 4656 return false;
4657 } 4657 }
4658 // report problem 4658 // report problem
4659 _errorReporter.reportErrorForNode(StaticWarningCode.STATIC_ACCESS_TO_INSTANC E_MEMBER, name, [name.name]); 4659 _errorReporter.reportErrorForNode(StaticWarningCode.STATIC_ACCESS_TO_INSTANC E_MEMBER, name, [name.name]);
4660 return true; 4660 return true;
4661 } 4661 }
4662 4662
4663 /** 4663 /**
4664 * This checks that the type of the passed 'switch' expression is assignable t o the type of the 4664 * This checks that the type of the passed 'switch' expression is assignable t o the type of the
4665 * 'case' members. 4665 * 'case' members.
4666 * 4666 *
4667 * @param node the 'switch' statement to evaluate 4667 * @param node the 'switch' statement to evaluate
4668 * @return `true` if and only if an error code is generated on the passed node 4668 * @return `true` if and only if an error code is generated on the passed node
4669 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE 4669 * See [StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE].
4670 */ 4670 */
4671 bool _checkForSwitchExpressionNotAssignable(SwitchStatement node) { 4671 bool _checkForSwitchExpressionNotAssignable(SwitchStatement node) {
4672 // prepare 'switch' expression type 4672 // prepare 'switch' expression type
4673 Expression expression = node.expression; 4673 Expression expression = node.expression;
4674 DartType expressionType = getStaticType(expression); 4674 DartType expressionType = getStaticType(expression);
4675 if (expressionType == null) { 4675 if (expressionType == null) {
4676 return false; 4676 return false;
4677 } 4677 }
4678 // compare with type of the first 'case' 4678 // compare with type of the first 'case'
4679 NodeList<SwitchMember> members = node.members; 4679 NodeList<SwitchMember> members = node.members;
(...skipping 14 matching lines...) Expand all
4694 return true; 4694 return true;
4695 } 4695 }
4696 return false; 4696 return false;
4697 } 4697 }
4698 4698
4699 /** 4699 /**
4700 * This verifies that the passed function type alias does not reference itself directly. 4700 * This verifies that the passed function type alias does not reference itself directly.
4701 * 4701 *
4702 * @param node the function type alias to evaluate 4702 * @param node the function type alias to evaluate
4703 * @return `true` if and only if an error code is generated on the passed node 4703 * @return `true` if and only if an error code is generated on the passed node
4704 * @see CompileTimeErrorCode#TYPE_ALIAS_CANNOT_REFERENCE_ITSELF 4704 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF].
4705 */ 4705 */
4706 bool _checkForTypeAliasCannotReferenceItself_function(FunctionTypeAlias node) { 4706 bool _checkForTypeAliasCannotReferenceItself_function(FunctionTypeAlias node) {
4707 FunctionTypeAliasElement element = node.element; 4707 FunctionTypeAliasElement element = node.element;
4708 if (!_hasTypedefSelfReference(element)) { 4708 if (!_hasTypedefSelfReference(element)) {
4709 return false; 4709 return false;
4710 } 4710 }
4711 _errorReporter.reportErrorForNode(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REF ERENCE_ITSELF, node, []); 4711 _errorReporter.reportErrorForNode(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REF ERENCE_ITSELF, node, []);
4712 return true; 4712 return true;
4713 } 4713 }
4714 4714
4715 /** 4715 /**
4716 * This verifies that the passed type name is not a deferred type. 4716 * This verifies that the passed type name is not a deferred type.
4717 * 4717 *
4718 * @param expression the expression to evaluate 4718 * @param expression the expression to evaluate
4719 * @return `true` if and only if an error code is generated on the passed node 4719 * @return `true` if and only if an error code is generated on the passed node
4720 * @see StaticWarningCode#TYPE_ANNOTATION_DEFERRED_CLASS 4720 * See [StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS].
4721 */ 4721 */
4722 bool _checkForTypeAnnotationDeferredClass(TypeName node) { 4722 bool _checkForTypeAnnotationDeferredClass(TypeName node) {
4723 if (node != null && node.isDeferred) { 4723 if (node != null && node.isDeferred) {
4724 _errorReporter.reportErrorForNode(StaticWarningCode.TYPE_ANNOTATION_DEFERR ED_CLASS, node, [node.name]); 4724 _errorReporter.reportErrorForNode(StaticWarningCode.TYPE_ANNOTATION_DEFERR ED_CLASS, node, [node.name]);
4725 } 4725 }
4726 return false; 4726 return false;
4727 } 4727 }
4728 4728
4729 /** 4729 /**
4730 * This verifies that the type arguments in the passed type name are all withi n their bounds. 4730 * This verifies that the type arguments in the passed type name are all withi n their bounds.
4731 * 4731 *
4732 * @param node the [TypeName] to evaluate 4732 * @param node the [TypeName] to evaluate
4733 * @return `true` if and only if an error code is generated on the passed node 4733 * @return `true` if and only if an error code is generated on the passed node
4734 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS 4734 * See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS].
4735 */ 4735 */
4736 bool _checkForTypeArgumentNotMatchingBounds(TypeName node) { 4736 bool _checkForTypeArgumentNotMatchingBounds(TypeName node) {
4737 if (node.typeArguments == null) { 4737 if (node.typeArguments == null) {
4738 return false; 4738 return false;
4739 } 4739 }
4740 // prepare Type 4740 // prepare Type
4741 DartType type = node.type; 4741 DartType type = node.type;
4742 if (type == null) { 4742 if (type == null) {
4743 return false; 4743 return false;
4744 } 4744 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
4778 } 4778 }
4779 return foundError; 4779 return foundError;
4780 } 4780 }
4781 4781
4782 /** 4782 /**
4783 * This checks that if the passed type name is a type parameter being used to define a static 4783 * This checks that if the passed type name is a type parameter being used to define a static
4784 * member. 4784 * member.
4785 * 4785 *
4786 * @param node the type name to evaluate 4786 * @param node the type name to evaluate
4787 * @return `true` if and only if an error code is generated on the passed node 4787 * @return `true` if and only if an error code is generated on the passed node
4788 * @see StaticWarningCode#TYPE_PARAMETER_REFERENCED_BY_STATIC 4788 * See [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC].
4789 */ 4789 */
4790 bool _checkForTypeParameterReferencedByStatic(TypeName node) { 4790 bool _checkForTypeParameterReferencedByStatic(TypeName node) {
4791 if (_isInStaticMethod || _isInStaticVariableDeclaration) { 4791 if (_isInStaticMethod || _isInStaticVariableDeclaration) {
4792 DartType type = node.type; 4792 DartType type = node.type;
4793 if (type is TypeParameterType) { 4793 if (type is TypeParameterType) {
4794 _errorReporter.reportErrorForNode(StaticWarningCode.TYPE_PARAMETER_REFER ENCED_BY_STATIC, node, []); 4794 _errorReporter.reportErrorForNode(StaticWarningCode.TYPE_PARAMETER_REFER ENCED_BY_STATIC, node, []);
4795 return true; 4795 return true;
4796 } 4796 }
4797 } 4797 }
4798 return false; 4798 return false;
4799 } 4799 }
4800 4800
4801 /** 4801 /**
4802 * This checks that if the passed type parameter is a supertype of its bound. 4802 * This checks that if the passed type parameter is a supertype of its bound.
4803 * 4803 *
4804 * @param node the type parameter to evaluate 4804 * @param node the type parameter to evaluate
4805 * @return `true` if and only if an error code is generated on the passed node 4805 * @return `true` if and only if an error code is generated on the passed node
4806 * @see StaticTypeWarningCode#TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND 4806 * See [StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND].
4807 */ 4807 */
4808 bool _checkForTypeParameterSupertypeOfItsBound(TypeParameter node) { 4808 bool _checkForTypeParameterSupertypeOfItsBound(TypeParameter node) {
4809 TypeParameterElement element = node.element; 4809 TypeParameterElement element = node.element;
4810 // prepare bound 4810 // prepare bound
4811 DartType bound = element.bound; 4811 DartType bound = element.bound;
4812 if (bound == null) { 4812 if (bound == null) {
4813 return false; 4813 return false;
4814 } 4814 }
4815 // OK, type parameter is not supertype of its bound 4815 // OK, type parameter is not supertype of its bound
4816 if (!bound.isMoreSpecificThan(element.type)) { 4816 if (!bound.isMoreSpecificThan(element.type)) {
4817 return false; 4817 return false;
4818 } 4818 }
4819 // report problem 4819 // report problem
4820 _errorReporter.reportErrorForNode(StaticTypeWarningCode.TYPE_PARAMETER_SUPER TYPE_OF_ITS_BOUND, node, [element.displayName]); 4820 _errorReporter.reportErrorForNode(StaticTypeWarningCode.TYPE_PARAMETER_SUPER TYPE_OF_ITS_BOUND, node, [element.displayName]);
4821 return true; 4821 return true;
4822 } 4822 }
4823 4823
4824 /** 4824 /**
4825 * This checks that if the passed generative constructor has neither an explic it super constructor 4825 * This checks that if the passed generative constructor has neither an explic it super constructor
4826 * invocation nor a redirecting constructor invocation, that the superclass ha s a default 4826 * invocation nor a redirecting constructor invocation, that the superclass ha s a default
4827 * generative constructor. 4827 * generative constructor.
4828 * 4828 *
4829 * @param node the constructor declaration to evaluate 4829 * @param node the constructor declaration to evaluate
4830 * @return `true` if and only if an error code is generated on the passed node 4830 * @return `true` if and only if an error code is generated on the passed node
4831 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT 4831 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT],
4832 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR 4832 * [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR], and
4833 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT 4833 * [StaticWarningCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT].
4834 */ 4834 */
4835 bool _checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration node) { 4835 bool _checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration node) {
4836 // 4836 //
4837 // Ignore if the constructor is not generative. 4837 // Ignore if the constructor is not generative.
4838 // 4838 //
4839 if (node.factoryKeyword != null) { 4839 if (node.factoryKeyword != null) {
4840 return false; 4840 return false;
4841 } 4841 }
4842 // 4842 //
4843 // Ignore if the constructor has either an implicit super constructor invoca tion or a 4843 // Ignore if the constructor has either an implicit super constructor invoca tion or a
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4881 _errorReporter.reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR _IN_INITIALIZER_DEFAULT, node.returnType, [superElement.name]); 4881 _errorReporter.reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR _IN_INITIALIZER_DEFAULT, node.returnType, [superElement.name]);
4882 return true; 4882 return true;
4883 } 4883 }
4884 4884
4885 /** 4885 /**
4886 * This checks that if the given name is a reference to a static member it is defined in the 4886 * This checks that if the given name is a reference to a static member it is defined in the
4887 * enclosing class rather than in a superclass. 4887 * enclosing class rather than in a superclass.
4888 * 4888 *
4889 * @param name the name to be evaluated 4889 * @param name the name to be evaluated
4890 * @return `true` if and only if an error code is generated on the passed node 4890 * @return `true` if and only if an error code is generated on the passed node
4891 * @see StaticTypeWarningCode#UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER 4891 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER ].
4892 */ 4892 */
4893 bool _checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name ) { 4893 bool _checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name ) {
4894 Element element = name.staticElement; 4894 Element element = name.staticElement;
4895 if (element == null || element is TypeParameterElement) { 4895 if (element == null || element is TypeParameterElement) {
4896 return false; 4896 return false;
4897 } 4897 }
4898 Element enclosingElement = element.enclosingElement; 4898 Element enclosingElement = element.enclosingElement;
4899 if (enclosingElement is! ClassElement) { 4899 if (enclosingElement is! ClassElement) {
4900 return false; 4900 return false;
4901 } 4901 }
(...skipping 30 matching lines...) Expand all
4932 if (fieldElement.isSynthetic) { 4932 if (fieldElement.isSynthetic) {
4933 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_NON_EXISTENT_FIELD, node, [node.identifier.name]); 4933 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_NON_EXISTENT_FIELD, node, [node.identifier.name]);
4934 } else if (fieldElement.isStatic) { 4934 } else if (fieldElement.isStatic) {
4935 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_STATIC_FIELD, node, [node.identifier.name]); 4935 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_STATIC_FIELD, node, [node.identifier.name]);
4936 } 4936 }
4937 } 4937 }
4938 } 4938 }
4939 } 4939 }
4940 // else { 4940 // else {
4941 // // TODO(jwren) Report error, constructor initializer variable is a top level element 4941 // // TODO(jwren) Report error, constructor initializer variable is a top level element
4942 // // (Either here or in ErrorVerifier#checkForAllFinalInitializedErrorCo des) 4942 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo des)
4943 // } 4943 // }
4944 } 4944 }
4945 4945
4946 /** 4946 /**
4947 * This verifies that the given getter does not have a return type of 'void'. 4947 * This verifies that the given getter does not have a return type of 'void'.
4948 * 4948 *
4949 * @param node the method declaration to evaluate 4949 * @param node the method declaration to evaluate
4950 * @return `true` if and only if an error code is generated on the passed node 4950 * @return `true` if and only if an error code is generated on the passed node
4951 * @see StaticWarningCode#VOID_RETURN_FOR_GETTER 4951 * See [StaticWarningCode.VOID_RETURN_FOR_GETTER].
4952 */ 4952 */
4953 bool _checkForVoidReturnType(MethodDeclaration node) { 4953 bool _checkForVoidReturnType(MethodDeclaration node) {
4954 TypeName returnType = node.returnType; 4954 TypeName returnType = node.returnType;
4955 if (returnType == null || returnType.name.name != "void") { 4955 if (returnType == null || returnType.name.name != "void") {
4956 return false; 4956 return false;
4957 } 4957 }
4958 _errorReporter.reportErrorForNode(StaticWarningCode.VOID_RETURN_FOR_GETTER, returnType, []); 4958 _errorReporter.reportErrorForNode(StaticWarningCode.VOID_RETURN_FOR_GETTER, returnType, []);
4959 return true; 4959 return true;
4960 } 4960 }
4961 4961
4962 /** 4962 /**
4963 * This verifies the passed operator-method declaration, has correct number of parameters. 4963 * This verifies the passed operator-method declaration, has correct number of parameters.
4964 * 4964 *
4965 * This method assumes that the method declaration was tested to be an operato r declaration before 4965 * This method assumes that the method declaration was tested to be an operato r declaration before
4966 * being called. 4966 * being called.
4967 * 4967 *
4968 * @param node the method declaration to evaluate 4968 * @param node the method declaration to evaluate
4969 * @return `true` if and only if an error code is generated on the passed node 4969 * @return `true` if and only if an error code is generated on the passed node
4970 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR 4970 * See [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR].
4971 */ 4971 */
4972 bool _checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { 4972 bool _checkForWrongNumberOfParametersForOperator(MethodDeclaration node) {
4973 // prepare number of parameters 4973 // prepare number of parameters
4974 FormalParameterList parameterList = node.parameters; 4974 FormalParameterList parameterList = node.parameters;
4975 if (parameterList == null) { 4975 if (parameterList == null) {
4976 return false; 4976 return false;
4977 } 4977 }
4978 int numParameters = parameterList.parameters.length; 4978 int numParameters = parameterList.parameters.length;
4979 // prepare operator name 4979 // prepare operator name
4980 SimpleIdentifier nameNode = node.name; 4980 SimpleIdentifier nameNode = node.name;
(...skipping 24 matching lines...) Expand all
5005 } 5005 }
5006 5006
5007 /** 5007 /**
5008 * This verifies if the passed setter parameter list have only one required pa rameter. 5008 * This verifies if the passed setter parameter list have only one required pa rameter.
5009 * 5009 *
5010 * This method assumes that the method declaration was tested to be a setter b efore being called. 5010 * This method assumes that the method declaration was tested to be a setter b efore being called.
5011 * 5011 *
5012 * @param setterName the name of the setter to report problems on 5012 * @param setterName the name of the setter to report problems on
5013 * @param parameterList the parameter list to evaluate 5013 * @param parameterList the parameter list to evaluate
5014 * @return `true` if and only if an error code is generated on the passed node 5014 * @return `true` if and only if an error code is generated on the passed node
5015 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER 5015 * See [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER].
5016 */ 5016 */
5017 bool _checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, Fo rmalParameterList parameterList) { 5017 bool _checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, Fo rmalParameterList parameterList) {
5018 if (setterName == null) { 5018 if (setterName == null) {
5019 return false; 5019 return false;
5020 } 5020 }
5021 if (parameterList == null) { 5021 if (parameterList == null) {
5022 return false; 5022 return false;
5023 } 5023 }
5024 NodeList<FormalParameter> parameters = parameterList.parameters; 5024 NodeList<FormalParameter> parameters = parameterList.parameters;
5025 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED) { 5025 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED) {
5026 _errorReporter.reportErrorForNode(CompileTimeErrorCode.WRONG_NUMBER_OF_PAR AMETERS_FOR_SETTER, setterName, []); 5026 _errorReporter.reportErrorForNode(CompileTimeErrorCode.WRONG_NUMBER_OF_PAR AMETERS_FOR_SETTER, setterName, []);
5027 return true; 5027 return true;
5028 } 5028 }
5029 return false; 5029 return false;
5030 } 5030 }
5031 5031
5032 /** 5032 /**
5033 * This verifies that if the given class declaration implements the class Func tion that it has a 5033 * This verifies that if the given class declaration implements the class Func tion that it has a
5034 * concrete implementation of the call method. 5034 * concrete implementation of the call method.
5035 * 5035 *
5036 * @return `true` if and only if an error code is generated on the passed node 5036 * @return `true` if and only if an error code is generated on the passed node
5037 * @see StaticWarningCode#FUNCTION_WITHOUT_CALL 5037 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL].
5038 */ 5038 */
5039 bool _checkImplementsFunctionWithoutCall(ClassDeclaration node) { 5039 bool _checkImplementsFunctionWithoutCall(ClassDeclaration node) {
5040 if (node.isAbstract) { 5040 if (node.isAbstract) {
5041 return false; 5041 return false;
5042 } 5042 }
5043 ClassElement classElement = node.element; 5043 ClassElement classElement = node.element;
5044 if (classElement == null) { 5044 if (classElement == null) {
5045 return false; 5045 return false;
5046 } 5046 }
5047 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { 5047 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) {
5048 return false; 5048 return false;
5049 } 5049 }
5050 // If there is a noSuchMethod method, then don't report the warning, see dar tbug.com/16078 5050 // If there is a noSuchMethod method, then don't report the warning, see dar tbug.com/16078
5051 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != nu ll) { 5051 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != nu ll) {
5052 return false; 5052 return false;
5053 } 5053 }
5054 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call"); 5054 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call");
5055 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met hodElement).isAbstract) { 5055 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met hodElement).isAbstract) {
5056 _errorReporter.reportErrorForNode(StaticWarningCode.FUNCTION_WITHOUT_CALL, node.name, []); 5056 _errorReporter.reportErrorForNode(StaticWarningCode.FUNCTION_WITHOUT_CALL, node.name, []);
5057 return true; 5057 return true;
5058 } 5058 }
5059 return false; 5059 return false;
5060 } 5060 }
5061 5061
5062 /** 5062 /**
5063 * This verifies that the given class declaration does not have the same class in the 'extends' 5063 * This verifies that the given class declaration does not have the same class in the 'extends'
5064 * and 'implements' clauses. 5064 * and 'implements' clauses.
5065 * 5065 *
5066 * @return `true` if and only if an error code is generated on the passed node 5066 * @return `true` if and only if an error code is generated on the passed node
5067 * @see CompileTimeErrorCode#IMPLEMENTS_SUPER_CLASS 5067 * See [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS].
5068 */ 5068 */
5069 bool _checkImplementsSuperClass(ClassDeclaration node) { 5069 bool _checkImplementsSuperClass(ClassDeclaration node) {
5070 // prepare super type 5070 // prepare super type
5071 InterfaceType superType = _enclosingClass.supertype; 5071 InterfaceType superType = _enclosingClass.supertype;
5072 if (superType == null) { 5072 if (superType == null) {
5073 return false; 5073 return false;
5074 } 5074 }
5075 // prepare interfaces 5075 // prepare interfaces
5076 ImplementsClause implementsClause = node.implementsClause; 5076 ImplementsClause implementsClause = node.implementsClause;
5077 if (implementsClause == null) { 5077 if (implementsClause == null) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
5158 } 5158 }
5159 return setterParameters[0].type; 5159 return setterParameters[0].type;
5160 } 5160 }
5161 5161
5162 /** 5162 /**
5163 * Given a list of directives that have the same prefix, generate an error if there is more than 5163 * Given a list of directives that have the same prefix, generate an error if there is more than
5164 * one import and any of those imports is deferred. 5164 * one import and any of those imports is deferred.
5165 * 5165 *
5166 * @param directives the list of directives that have the same prefix 5166 * @param directives the list of directives that have the same prefix
5167 * @return `true` if an error was generated 5167 * @return `true` if an error was generated
5168 * @see CompileTimeErrorCode#SHARED_DEFERRED_PREFIX 5168 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX].
5169 */ 5169 */
5170 bool _hasDeferredPrefixCollision(List<ImportDirective> directives) { 5170 bool _hasDeferredPrefixCollision(List<ImportDirective> directives) {
5171 bool foundError = false; 5171 bool foundError = false;
5172 int count = directives.length; 5172 int count = directives.length;
5173 if (count > 1) { 5173 if (count > 1) {
5174 for (int i = 0; i < count; i++) { 5174 for (int i = 0; i < count; i++) {
5175 sc.Token deferredToken = directives[i].deferredToken; 5175 sc.Token deferredToken = directives[i].deferredToken;
5176 if (deferredToken != null) { 5176 if (deferredToken != null) {
5177 _errorReporter.reportErrorForToken(CompileTimeErrorCode.SHARED_DEFERRE D_PREFIX, deferredToken, []); 5177 _errorReporter.reportErrorForToken(CompileTimeErrorCode.SHARED_DEFERRE D_PREFIX, deferredToken, []);
5178 foundError = true; 5178 foundError = true;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
5385 } 5385 }
5386 5386
5387 bool _isUserDefinedObject(EvaluationResultImpl result) => result == null || (r esult.value != null && result.value.isUserDefinedObject); 5387 bool _isUserDefinedObject(EvaluationResultImpl result) => result == null || (r esult.value != null && result.value.isUserDefinedObject);
5388 5388
5389 /** 5389 /**
5390 * This checks the class declaration is not a superinterface to itself. 5390 * This checks the class declaration is not a superinterface to itself.
5391 * 5391 *
5392 * @param classElt the class element to test 5392 * @param classElt the class element to test
5393 * @param path a list containing the potentially cyclic implements path 5393 * @param path a list containing the potentially cyclic implements path
5394 * @return `true` if and only if an error code is generated on the passed elem ent 5394 * @return `true` if and only if an error code is generated on the passed elem ent
5395 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE 5395 * See [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE],
5396 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS 5396 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS],
5397 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS 5397 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS] , and
5398 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH 5398 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH].
5399 */ 5399 */
5400 bool _safeCheckForRecursiveInterfaceInheritance(ClassElement classElt, List<Cl assElement> path) { 5400 bool _safeCheckForRecursiveInterfaceInheritance(ClassElement classElt, List<Cl assElement> path) {
5401 // Detect error condition. 5401 // Detect error condition.
5402 int size = path.length; 5402 int size = path.length;
5403 // If this is not the base case (size > 0), and the enclosing class is the p assed class 5403 // If this is not the base case (size > 0), and the enclosing class is the p assed class
5404 // element then an error an error. 5404 // element then an error an error.
5405 if (size > 0 && _enclosingClass == classElt) { 5405 if (size > 0 && _enclosingClass == classElt) {
5406 String enclosingClassName = _enclosingClass.displayName; 5406 String enclosingClassName = _enclosingClass.displayName;
5407 if (size > 1) { 5407 if (size > 1) {
5408 // Construct a string showing the cyclic implements path: "A, B, C, D, A " 5408 // Construct a string showing the cyclic implements path: "A, B, C, D, A "
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
5487 toCheck.add(type.element); 5487 toCheck.add(type.element);
5488 // type arguments 5488 // type arguments
5489 if (type is InterfaceType) { 5489 if (type is InterfaceType) {
5490 InterfaceType interfaceType = type; 5490 InterfaceType interfaceType = type;
5491 for (DartType typeArgument in interfaceType.typeArguments) { 5491 for (DartType typeArgument in interfaceType.typeArguments) {
5492 _addTypeToCheck(typeArgument); 5492 _addTypeToCheck(typeArgument);
5493 } 5493 }
5494 } 5494 }
5495 } 5495 }
5496 } 5496 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/lib/src/generated/html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698