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

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

Issue 975453004: Reformat (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months 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/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.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; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 17 matching lines...) Expand all
28 /** 28 /**
29 * Callback signature used by ImplicitConstructorBuilder to register 29 * Callback signature used by ImplicitConstructorBuilder to register
30 * computations to be performed, and their dependencies. A call to this 30 * computations to be performed, and their dependencies. A call to this
31 * callback indicates that [computation] may be used to compute implicit 31 * callback indicates that [computation] may be used to compute implicit
32 * constructors for [classElement], but that the computation may not be invoked 32 * constructors for [classElement], but that the computation may not be invoked
33 * until after implicit constructors have been built for [superclassElement]. 33 * until after implicit constructors have been built for [superclassElement].
34 */ 34 */
35 typedef void ImplicitConstructorBuilderCallback(ClassElement classElement, 35 typedef void ImplicitConstructorBuilderCallback(ClassElement classElement,
36 ClassElement superclassElement, void computation()); 36 ClassElement superclassElement, void computation());
37 37
38 typedef ResolverVisitor ResolverVisitorFactory(Library library, Source source, 38 typedef ResolverVisitor ResolverVisitorFactory(
39 TypeProvider typeProvider); 39 Library library, Source source, TypeProvider typeProvider);
40 40
41 typedef StaticTypeAnalyzer StaticTypeAnalyzerFactory(ResolverVisitor visitor); 41 typedef StaticTypeAnalyzer StaticTypeAnalyzerFactory(ResolverVisitor visitor);
42 42
43 typedef TypeResolverVisitor TypeResolverVisitorFactory(Library library, 43 typedef TypeResolverVisitor TypeResolverVisitorFactory(
44 Source source, TypeProvider typeProvider); 44 Library library, Source source, TypeProvider typeProvider);
45 45
46 typedef void VoidFunction(); 46 typedef void VoidFunction();
47 47
48 /** 48 /**
49 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 49 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
50 * violations of Dart best practices. 50 * violations of Dart best practices.
51 */ 51 */
52 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { 52 class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
53 // static String _HASHCODE_GETTER_NAME = "hashCode"; 53 // static String _HASHCODE_GETTER_NAME = "hashCode";
54 54
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return super.visitPostfixExpression(node); 181 return super.visitPostfixExpression(node);
182 } 182 }
183 183
184 @override 184 @override
185 Object visitPrefixExpression(PrefixExpression node) { 185 Object visitPrefixExpression(PrefixExpression node) {
186 _checkForDeprecatedMemberUse(node.bestElement, node); 186 _checkForDeprecatedMemberUse(node.bestElement, node);
187 return super.visitPrefixExpression(node); 187 return super.visitPrefixExpression(node);
188 } 188 }
189 189
190 @override 190 @override
191 Object 191 Object visitRedirectingConstructorInvocation(
192 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation nod e) { 192 RedirectingConstructorInvocation node) {
193 _checkForDeprecatedMemberUse(node.staticElement, node); 193 _checkForDeprecatedMemberUse(node.staticElement, node);
194 return super.visitRedirectingConstructorInvocation(node); 194 return super.visitRedirectingConstructorInvocation(node);
195 } 195 }
196 196
197 @override 197 @override
198 Object visitSimpleIdentifier(SimpleIdentifier node) { 198 Object visitSimpleIdentifier(SimpleIdentifier node) {
199 _checkForDeprecatedMemberUseAtIdentifier(node); 199 _checkForDeprecatedMemberUseAtIdentifier(node);
200 return super.visitSimpleIdentifier(node); 200 return super.visitSimpleIdentifier(node);
201 } 201 }
202 202
(...skipping 27 matching lines...) Expand all
230 DartType rhsType = typeName.type; 230 DartType rhsType = typeName.type;
231 if (lhsType == null || rhsType == null) { 231 if (lhsType == null || rhsType == null) {
232 return false; 232 return false;
233 } 233 }
234 String rhsNameStr = typeName.name.name; 234 String rhsNameStr = typeName.name.name;
235 // if x is dynamic 235 // if x is dynamic
236 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) { 236 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) {
237 if (node.notOperator == null) { 237 if (node.notOperator == null) {
238 // the is case 238 // the is case
239 _errorReporter.reportErrorForNode( 239 _errorReporter.reportErrorForNode(
240 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, 240 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node);
241 node);
242 } else { 241 } else {
243 // the is not case 242 // the is not case
244 _errorReporter.reportErrorForNode( 243 _errorReporter
245 HintCode.UNNECESSARY_TYPE_CHECK_FALSE, 244 .reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node);
246 node);
247 } 245 }
248 return true; 246 return true;
249 } 247 }
250 Element rhsElement = rhsType.element; 248 Element rhsElement = rhsType.element;
251 LibraryElement libraryElement = 249 LibraryElement libraryElement =
252 rhsElement != null ? rhsElement.library : null; 250 rhsElement != null ? rhsElement.library : null;
253 if (libraryElement != null && libraryElement.isDartCore) { 251 if (libraryElement != null && libraryElement.isDartCore) {
254 // if x is Object or null is Null 252 // if x is Object or null is Null
255 if (rhsType.isObject || 253 if (rhsType.isObject ||
256 (expression is NullLiteral && rhsNameStr == _NULL_TYPE_NAME)) { 254 (expression is NullLiteral && rhsNameStr == _NULL_TYPE_NAME)) {
257 if (node.notOperator == null) { 255 if (node.notOperator == null) {
258 // the is case 256 // the is case
259 _errorReporter.reportErrorForNode( 257 _errorReporter.reportErrorForNode(
260 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, 258 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node);
261 node);
262 } else { 259 } else {
263 // the is not case 260 // the is not case
264 _errorReporter.reportErrorForNode( 261 _errorReporter
265 HintCode.UNNECESSARY_TYPE_CHECK_FALSE, 262 .reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node);
266 node);
267 } 263 }
268 return true; 264 return true;
269 } else if (rhsNameStr == _NULL_TYPE_NAME) { 265 } else if (rhsNameStr == _NULL_TYPE_NAME) {
270 if (node.notOperator == null) { 266 if (node.notOperator == null) {
271 // the is case 267 // the is case
272 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NULL, node); 268 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NULL, node);
273 } else { 269 } else {
274 // the is not case 270 // the is not case
275 _errorReporter.reportErrorForNode( 271 _errorReporter
276 HintCode.TYPE_CHECK_IS_NOT_NULL, 272 .reportErrorForNode(HintCode.TYPE_CHECK_IS_NOT_NULL, node);
277 node);
278 } 273 }
279 return true; 274 return true;
280 } 275 }
281 } 276 }
282 return false; 277 return false;
283 } 278 }
284 279
285 /** 280 /**
286 * This verifies that the passed expression can be assigned to its correspondi ng parameters. 281 * This verifies that the passed expression can be assigned to its correspondi ng parameters.
287 * 282 *
(...skipping 22 matching lines...) Expand all
310 if (!actualStaticType.isAssignableTo(expectedStaticType)) { 305 if (!actualStaticType.isAssignableTo(expectedStaticType)) {
311 // A warning was created in the ErrorVerifier, return false, don't 306 // A warning was created in the ErrorVerifier, return false, don't
312 // create a hint when a warning has already been created. 307 // create a hint when a warning has already been created.
313 return false; 308 return false;
314 } 309 }
315 } 310 }
316 // 311 //
317 // Hint case: test propagated type information 312 // Hint case: test propagated type information
318 // 313 //
319 // Compute the best types to use. 314 // Compute the best types to use.
320 DartType expectedBestType = 315 DartType expectedBestType = expectedPropagatedType != null
321 expectedPropagatedType != null ? expectedPropagatedType : expectedStatic Type; 316 ? expectedPropagatedType
317 : expectedStaticType;
322 DartType actualBestType = 318 DartType actualBestType =
323 actualPropagatedType != null ? actualPropagatedType : actualStaticType; 319 actualPropagatedType != null ? actualPropagatedType : actualStaticType;
324 if (actualBestType != null && expectedBestType != null) { 320 if (actualBestType != null && expectedBestType != null) {
325 if (!actualBestType.isAssignableTo(expectedBestType)) { 321 if (!actualBestType.isAssignableTo(expectedBestType)) {
326 _errorReporter.reportTypeErrorForNode( 322 _errorReporter.reportTypeErrorForNode(
327 hintCode, 323 hintCode, expression, [actualBestType, expectedBestType]);
328 expression,
329 [actualBestType, expectedBestType]);
330 return true; 324 return true;
331 } 325 }
332 } 326 }
333 return false; 327 return false;
334 } 328 }
335 329
336 /** 330 /**
337 * This verifies that the passed argument can be assigned to its corresponding parameter. 331 * This verifies that the passed argument can be assigned to its corresponding parameter.
338 * 332 *
339 * This method corresponds to ErrorCode.checkForArgumentTypeNotAssignableForAr gument. 333 * This method corresponds to ErrorCode.checkForArgumentTypeNotAssignableForAr gument.
340 * 334 *
341 * @param argument the argument to evaluate 335 * @param argument the argument to evaluate
342 * @return `true` if and only if an hint code is generated on the passed node 336 * @return `true` if and only if an hint code is generated on the passed node
343 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. 337 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE].
344 */ 338 */
345 bool _checkForArgumentTypeNotAssignableForArgument(Expression argument) { 339 bool _checkForArgumentTypeNotAssignableForArgument(Expression argument) {
346 if (argument == null) { 340 if (argument == null) {
347 return false; 341 return false;
348 } 342 }
349 ParameterElement staticParameterElement = argument.staticParameterElement; 343 ParameterElement staticParameterElement = argument.staticParameterElement;
350 DartType staticParameterType = 344 DartType staticParameterType =
351 staticParameterElement == null ? null : staticParameterElement.type; 345 staticParameterElement == null ? null : staticParameterElement.type;
352 ParameterElement propagatedParameterElement = 346 ParameterElement propagatedParameterElement =
353 argument.propagatedParameterElement; 347 argument.propagatedParameterElement;
354 DartType propagatedParameterType = 348 DartType propagatedParameterType = propagatedParameterElement == null
355 propagatedParameterElement == null ? null : propagatedParameterElement.t ype; 349 ? null
356 return _checkForArgumentTypeNotAssignableWithExpectedTypes( 350 : propagatedParameterElement.type;
357 argument, 351 return _checkForArgumentTypeNotAssignableWithExpectedTypes(argument,
358 staticParameterType, 352 staticParameterType, propagatedParameterType,
359 propagatedParameterType,
360 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); 353 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE);
361 } 354 }
362 355
363 /** 356 /**
364 * This verifies that the passed expression can be assigned to its correspondi ng parameters. 357 * This verifies that the passed expression can be assigned to its correspondi ng parameters.
365 * 358 *
366 * This method corresponds to ErrorCode.checkForArgumentTypeNotAssignableWithE xpectedTypes. 359 * This method corresponds to ErrorCode.checkForArgumentTypeNotAssignableWithE xpectedTypes.
367 * 360 *
368 * @param expression the expression to evaluate 361 * @param expression the expression to evaluate
369 * @param expectedStaticType the expected static type 362 * @param expectedStaticType the expected static type
370 * @param expectedPropagatedType the expected propagated type, may be `null` 363 * @param expectedPropagatedType the expected propagated type, may be `null`
371 * @return `true` if and only if an hint code is generated on the passed node 364 * @return `true` if and only if an hint code is generated on the passed node
372 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. 365 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE].
373 */ 366 */
374 bool 367 bool _checkForArgumentTypeNotAssignableWithExpectedTypes(
375 _checkForArgumentTypeNotAssignableWithExpectedTypes(Expression expression, 368 Expression expression, DartType expectedStaticType,
376 DartType expectedStaticType, DartType expectedPropagatedType, 369 DartType expectedPropagatedType, ErrorCode errorCode) =>
377 ErrorCode errorCode) => 370 _checkForArgumentTypeNotAssignable(expression, expectedStaticType,
378 _checkForArgumentTypeNotAssignable( 371 expression.staticType, expectedPropagatedType,
379 expression, 372 expression.propagatedType, errorCode);
380 expectedStaticType,
381 expression.staticType,
382 expectedPropagatedType,
383 expression.propagatedType,
384 errorCode);
385 373
386 /** 374 /**
387 * This verifies that the passed arguments can be assigned to their correspond ing parameters. 375 * This verifies that the passed arguments can be assigned to their correspond ing parameters.
388 * 376 *
389 * This method corresponds to ErrorCode.checkForArgumentTypesNotAssignableInLi st. 377 * This method corresponds to ErrorCode.checkForArgumentTypesNotAssignableInLi st.
390 * 378 *
391 * @param node the arguments to evaluate 379 * @param node the arguments to evaluate
392 * @return `true` if and only if an hint code is generated on the passed node 380 * @return `true` if and only if an hint code is generated on the passed node
393 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. 381 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE].
394 */ 382 */
(...skipping 26 matching lines...) Expand all
421 // TODO(jwren) We should modify ConstructorElement.getDisplayName(), 409 // TODO(jwren) We should modify ConstructorElement.getDisplayName(),
422 // or have the logic centralized elsewhere, instead of doing this logic 410 // or have the logic centralized elsewhere, instead of doing this logic
423 // here. 411 // here.
424 ConstructorElement constructorElement = element; 412 ConstructorElement constructorElement = element;
425 displayName = constructorElement.enclosingElement.displayName; 413 displayName = constructorElement.enclosingElement.displayName;
426 if (!constructorElement.displayName.isEmpty) { 414 if (!constructorElement.displayName.isEmpty) {
427 displayName = "$displayName.${constructorElement.displayName}"; 415 displayName = "$displayName.${constructorElement.displayName}";
428 } 416 }
429 } 417 }
430 _errorReporter.reportErrorForNode( 418 _errorReporter.reportErrorForNode(
431 HintCode.DEPRECATED_MEMBER_USE, 419 HintCode.DEPRECATED_MEMBER_USE, node, [displayName]);
432 node,
433 [displayName]);
434 return true; 420 return true;
435 } 421 }
436 return false; 422 return false;
437 } 423 }
438 424
439 /** 425 /**
440 * For [SimpleIdentifier]s, only call [checkForDeprecatedMemberUse] 426 * For [SimpleIdentifier]s, only call [checkForDeprecatedMemberUse]
441 * if the node is not in a declaration context. 427 * if the node is not in a declaration context.
442 * 428 *
443 * Also, if the identifier is a constructor name in a constructor invocation, then calls to the 429 * Also, if the identifier is a constructor name in a constructor invocation, then calls to the
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 // Report error if the (x/y) has toInt() invoked on it 475 // Report error if the (x/y) has toInt() invoked on it
490 if (node.parent is ParenthesizedExpression) { 476 if (node.parent is ParenthesizedExpression) {
491 ParenthesizedExpression parenthesizedExpression = 477 ParenthesizedExpression parenthesizedExpression =
492 _wrapParenthesizedExpression(node.parent as ParenthesizedExpression); 478 _wrapParenthesizedExpression(node.parent as ParenthesizedExpression);
493 if (parenthesizedExpression.parent is MethodInvocation) { 479 if (parenthesizedExpression.parent is MethodInvocation) {
494 MethodInvocation methodInvocation = 480 MethodInvocation methodInvocation =
495 parenthesizedExpression.parent as MethodInvocation; 481 parenthesizedExpression.parent as MethodInvocation;
496 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && 482 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name &&
497 methodInvocation.argumentList.arguments.isEmpty) { 483 methodInvocation.argumentList.arguments.isEmpty) {
498 _errorReporter.reportErrorForNode( 484 _errorReporter.reportErrorForNode(
499 HintCode.DIVISION_OPTIMIZATION, 485 HintCode.DIVISION_OPTIMIZATION, methodInvocation);
500 methodInvocation);
501 return true; 486 return true;
502 } 487 }
503 } 488 }
504 } 489 }
505 return false; 490 return false;
506 } 491 }
507 492
508 /** 493 /**
509 * This verifies that the passed left hand side and right hand side represent a valid assignment. 494 * This verifies that the passed left hand side and right hand side represent a valid assignment.
510 * 495 *
511 * This method corresponds to ErrorVerifier.checkForInvalidAssignment. 496 * This method corresponds to ErrorVerifier.checkForInvalidAssignment.
512 * 497 *
513 * @param lhs the left hand side expression 498 * @param lhs the left hand side expression
514 * @param rhs the right hand side expression 499 * @param rhs the right hand side expression
515 * @return `true` if and only if an error code is generated on the passed node 500 * @return `true` if and only if an error code is generated on the passed node
516 * See [HintCode.INVALID_ASSIGNMENT]. 501 * See [HintCode.INVALID_ASSIGNMENT].
517 */ 502 */
518 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { 503 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) {
519 if (lhs == null || rhs == null) { 504 if (lhs == null || rhs == null) {
520 return false; 505 return false;
521 } 506 }
522 VariableElement leftVariableElement = ErrorVerifier.getVariableElement(lhs); 507 VariableElement leftVariableElement = ErrorVerifier.getVariableElement(lhs);
523 DartType leftType = (leftVariableElement == null) ? 508 DartType leftType = (leftVariableElement == null)
524 ErrorVerifier.getStaticType(lhs) : 509 ? ErrorVerifier.getStaticType(lhs)
525 leftVariableElement.type; 510 : leftVariableElement.type;
526 DartType staticRightType = ErrorVerifier.getStaticType(rhs); 511 DartType staticRightType = ErrorVerifier.getStaticType(rhs);
527 if (!staticRightType.isAssignableTo(leftType)) { 512 if (!staticRightType.isAssignableTo(leftType)) {
528 // The warning was generated on this rhs 513 // The warning was generated on this rhs
529 return false; 514 return false;
530 } 515 }
531 // Test for, and then generate the hint 516 // Test for, and then generate the hint
532 DartType bestRightType = rhs.bestType; 517 DartType bestRightType = rhs.bestType;
533 if (leftType != null && bestRightType != null) { 518 if (leftType != null && bestRightType != null) {
534 if (!bestRightType.isAssignableTo(leftType)) { 519 if (!bestRightType.isAssignableTo(leftType)) {
535 _errorReporter.reportTypeErrorForNode( 520 _errorReporter.reportTypeErrorForNode(
536 HintCode.INVALID_ASSIGNMENT, 521 HintCode.INVALID_ASSIGNMENT, rhs, [bestRightType, leftType]);
537 rhs,
538 [bestRightType, leftType]);
539 return true; 522 return true;
540 } 523 }
541 } 524 }
542 return false; 525 return false;
543 } 526 }
544 527
545 /** 528 /**
546 * Check that the imported library does not define a loadLibrary function. The import has already 529 * Check that the imported library does not define a loadLibrary function. The import has already
547 * been determined to be deferred when this is called. 530 * been determined to be deferred when this is called.
548 * 531 *
549 * @param node the import directive to evaluate 532 * @param node the import directive to evaluate
550 * @param importElement the [ImportElement] retrieved from the node 533 * @param importElement the [ImportElement] retrieved from the node
551 * @return `true` if and only if an error code is generated on the passed node 534 * @return `true` if and only if an error code is generated on the passed node
552 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]. 535 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION].
553 */ 536 */
554 bool _checkForLoadLibraryFunction(ImportDirective node, 537 bool _checkForLoadLibraryFunction(
555 ImportElement importElement) { 538 ImportDirective node, ImportElement importElement) {
556 LibraryElement importedLibrary = importElement.importedLibrary; 539 LibraryElement importedLibrary = importElement.importedLibrary;
557 if (importedLibrary == null) { 540 if (importedLibrary == null) {
558 return false; 541 return false;
559 } 542 }
560 if (importedLibrary.hasLoadLibraryFunction) { 543 if (importedLibrary.hasLoadLibraryFunction) {
561 _errorReporter.reportErrorForNode( 544 _errorReporter.reportErrorForNode(
562 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION, 545 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION, node, [
563 node, 546 importedLibrary.name
564 [importedLibrary.name]); 547 ]);
565 return true; 548 return true;
566 } 549 }
567 return false; 550 return false;
568 } 551 }
569 552
570 /** 553 /**
571 * Generate a hint for functions or methods that have a return type, but do no t have a return 554 * Generate a hint for functions or methods that have a return type, but do no t have a return
572 * statement on all branches. At the end of blocks with no return, Dart implic itly returns 555 * statement on all branches. At the end of blocks with no return, Dart implic itly returns
573 * `null`, avoiding these implicit returns is considered a best practice. 556 * `null`, avoiding these implicit returns is considered a best practice.
574 * 557 *
(...skipping 25 matching lines...) Expand all
600 } 583 }
601 // For async, give no hint if Future<Null> is assignable to the return 584 // For async, give no hint if Future<Null> is assignable to the return
602 // type. 585 // type.
603 if (body.isAsynchronous && _futureNullType.isAssignableTo(returnTypeType)) { 586 if (body.isAsynchronous && _futureNullType.isAssignableTo(returnTypeType)) {
604 return false; 587 return false;
605 } 588 }
606 // Check the block for a return statement, if not, create the hint 589 // Check the block for a return statement, if not, create the hint
607 BlockFunctionBody blockFunctionBody = body as BlockFunctionBody; 590 BlockFunctionBody blockFunctionBody = body as BlockFunctionBody;
608 if (!ExitDetector.exits(blockFunctionBody)) { 591 if (!ExitDetector.exits(blockFunctionBody)) {
609 _errorReporter.reportErrorForNode( 592 _errorReporter.reportErrorForNode(
610 HintCode.MISSING_RETURN, 593 HintCode.MISSING_RETURN, returnType, [returnTypeType.displayName]);
611 returnType,
612 [returnTypeType.displayName]);
613 return true; 594 return true;
614 } 595 }
615 return false; 596 return false;
616 } 597 }
617 598
618 /** 599 /**
619 * Check for the passed class declaration for the 600 * Check for the passed class declaration for the
620 * [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. 601 * [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code.
621 * 602 *
622 * @param node the class declaration to check 603 * @param node the class declaration to check
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 * See [HintCode.USE_OF_VOID_RESULT]. 686 * See [HintCode.USE_OF_VOID_RESULT].
706 */ 687 */
707 bool _checkForUseOfVoidResult(Expression expression) { 688 bool _checkForUseOfVoidResult(Expression expression) {
708 if (expression == null || expression is! MethodInvocation) { 689 if (expression == null || expression is! MethodInvocation) {
709 return false; 690 return false;
710 } 691 }
711 MethodInvocation methodInvocation = expression as MethodInvocation; 692 MethodInvocation methodInvocation = expression as MethodInvocation;
712 if (identical(methodInvocation.staticType, VoidTypeImpl.instance)) { 693 if (identical(methodInvocation.staticType, VoidTypeImpl.instance)) {
713 SimpleIdentifier methodName = methodInvocation.methodName; 694 SimpleIdentifier methodName = methodInvocation.methodName;
714 _errorReporter.reportErrorForNode( 695 _errorReporter.reportErrorForNode(
715 HintCode.USE_OF_VOID_RESULT, 696 HintCode.USE_OF_VOID_RESULT, methodName, [methodName.name]);
716 methodName,
717 [methodName.name]);
718 return true; 697 return true;
719 } 698 }
720 return false; 699 return false;
721 } 700 }
722 701
723 /** 702 /**
724 * Given a parenthesized expression, this returns the parent (or recursively g rand-parent) of the 703 * Given a parenthesized expression, this returns the parent (or recursively g rand-parent) of the
725 * expression that is a parenthesized expression, but whose parent is not a pa renthesized 704 * expression that is a parenthesized expression, but whose parent is not a pa renthesized
726 * expression. 705 * expression.
727 * 706 *
728 * For example given the code `(((e)))`: `(e) -> (((e)))`. 707 * For example given the code `(((e)))`: `(e) -> (((e)))`.
729 * 708 *
730 * @param parenthesizedExpression some expression whose parent is a parenthesi zed expression 709 * @param parenthesizedExpression some expression whose parent is a parenthesi zed expression
731 * @return the first parent or grand-parent that is a parenthesized expression , that does not have 710 * @return the first parent or grand-parent that is a parenthesized expression , that does not have
732 * a parenthesized expression parent 711 * a parenthesized expression parent
733 */ 712 */
734 static ParenthesizedExpression 713 static ParenthesizedExpression _wrapParenthesizedExpression(
735 _wrapParenthesizedExpression(ParenthesizedExpression parenthesizedExpressi on) { 714 ParenthesizedExpression parenthesizedExpression) {
736 if (parenthesizedExpression.parent is ParenthesizedExpression) { 715 if (parenthesizedExpression.parent is ParenthesizedExpression) {
737 return _wrapParenthesizedExpression( 716 return _wrapParenthesizedExpression(
738 parenthesizedExpression.parent as ParenthesizedExpression); 717 parenthesizedExpression.parent as ParenthesizedExpression);
739 } 718 }
740 return parenthesizedExpression; 719 return parenthesizedExpression;
741 } 720 }
742 } 721 }
743 722
744 /** 723 /**
745 * Instances of the class `ClassScope` implement the scope defined by a class. 724 * Instances of the class `ClassScope` implement the scope defined by a class.
(...skipping 10 matching lines...) Expand all
756 if (typeElement == null) { 735 if (typeElement == null) {
757 throw new IllegalArgumentException("class element cannot be null"); 736 throw new IllegalArgumentException("class element cannot be null");
758 } 737 }
759 _defineMembers(typeElement); 738 _defineMembers(typeElement);
760 } 739 }
761 740
762 @override 741 @override
763 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 742 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
764 if (existing is PropertyAccessorElement && duplicate is MethodElement) { 743 if (existing is PropertyAccessorElement && duplicate is MethodElement) {
765 if (existing.nameOffset < duplicate.nameOffset) { 744 if (existing.nameOffset < duplicate.nameOffset) {
766 return new AnalysisError.con2( 745 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset,
767 duplicate.source,
768 duplicate.nameOffset,
769 duplicate.displayName.length, 746 duplicate.displayName.length,
770 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME, 747 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME, [
771 [existing.displayName]); 748 existing.displayName
749 ]);
772 } else { 750 } else {
773 return new AnalysisError.con2( 751 return new AnalysisError.con2(existing.source, existing.nameOffset,
774 existing.source,
775 existing.nameOffset,
776 existing.displayName.length, 752 existing.displayName.length,
777 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, 753 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, [
778 [existing.displayName]); 754 existing.displayName
755 ]);
779 } 756 }
780 } 757 }
781 return super.getErrorForDuplicate(existing, duplicate); 758 return super.getErrorForDuplicate(existing, duplicate);
782 } 759 }
783 760
784 /** 761 /**
785 * Define the instance members defined by the class. 762 * Define the instance members defined by the class.
786 * 763 *
787 * @param typeElement the element representing the type represented by this sc ope 764 * @param typeElement the element representing the type represented by this sc ope
788 */ 765 */
(...skipping 10 matching lines...) Expand all
799 /** 776 /**
800 * A `CompilationUnitBuilder` builds an element model for a single compilation 777 * A `CompilationUnitBuilder` builds an element model for a single compilation
801 * unit. 778 * unit.
802 */ 779 */
803 class CompilationUnitBuilder { 780 class CompilationUnitBuilder {
804 /** 781 /**
805 * Build the compilation unit element for the given [source] based on the 782 * Build the compilation unit element for the given [source] based on the
806 * compilation [unit] associated with the source. Throw an AnalysisException 783 * compilation [unit] associated with the source. Throw an AnalysisException
807 * if the element could not be built. 784 * if the element could not be built.
808 */ 785 */
809 CompilationUnitElementImpl buildCompilationUnit(Source source, 786 CompilationUnitElementImpl buildCompilationUnit(
810 CompilationUnit unit) { 787 Source source, CompilationUnit unit) {
811 return PerformanceStatistics.resolve.makeCurrentWhile(() { 788 return PerformanceStatistics.resolve.makeCurrentWhile(() {
812 if (unit == null) { 789 if (unit == null) {
813 return null; 790 return null;
814 } 791 }
815 ElementHolder holder = new ElementHolder(); 792 ElementHolder holder = new ElementHolder();
816 ElementBuilder builder = new ElementBuilder(holder); 793 ElementBuilder builder = new ElementBuilder(holder);
817 unit.accept(builder); 794 unit.accept(builder);
818 CompilationUnitElementImpl element = 795 CompilationUnitElementImpl element =
819 new CompilationUnitElementImpl(source.shortName); 796 new CompilationUnitElementImpl(source.shortName);
820 element.accessors = holder.accessors; 797 element.accessors = holder.accessors;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 /** 847 /**
871 * The current library that is being analyzed. 848 * The current library that is being analyzed.
872 */ 849 */
873 final LibraryElement _currentLibrary; 850 final LibraryElement _currentLibrary;
874 851
875 /** 852 /**
876 * Initialize a newly created constant verifier. 853 * Initialize a newly created constant verifier.
877 * 854 *
878 * @param errorReporter the error reporter by which errors will be reported 855 * @param errorReporter the error reporter by which errors will be reported
879 */ 856 */
880 ConstantVerifier(this._errorReporter, this._currentLibrary, 857 ConstantVerifier(
881 this._typeProvider) { 858 this._errorReporter, this._currentLibrary, this._typeProvider) {
882 this._boolType = _typeProvider.boolType; 859 this._boolType = _typeProvider.boolType;
883 this._intType = _typeProvider.intType; 860 this._intType = _typeProvider.intType;
884 this._numType = _typeProvider.numType; 861 this._numType = _typeProvider.numType;
885 this._stringType = _typeProvider.stringType; 862 this._stringType = _typeProvider.stringType;
886 } 863 }
887 864
888 @override 865 @override
889 Object visitAnnotation(Annotation node) { 866 Object visitAnnotation(Annotation node) {
890 super.visitAnnotation(node); 867 super.visitAnnotation(node);
891 // check annotation creation 868 // check annotation creation
892 Element element = node.element; 869 Element element = node.element;
893 if (element is ConstructorElement) { 870 if (element is ConstructorElement) {
894 ConstructorElement constructorElement = element; 871 ConstructorElement constructorElement = element;
895 // should 'const' constructor 872 // should 'const' constructor
896 if (!constructorElement.isConst) { 873 if (!constructorElement.isConst) {
897 _errorReporter.reportErrorForNode( 874 _errorReporter.reportErrorForNode(
898 CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR, 875 CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR, node);
899 node);
900 return null; 876 return null;
901 } 877 }
902 // should have arguments 878 // should have arguments
903 ArgumentList argumentList = node.arguments; 879 ArgumentList argumentList = node.arguments;
904 if (argumentList == null) { 880 if (argumentList == null) {
905 _errorReporter.reportErrorForNode( 881 _errorReporter.reportErrorForNode(
906 CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS, 882 CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS, node);
907 node);
908 return null; 883 return null;
909 } 884 }
910 // arguments should be constants 885 // arguments should be constants
911 _validateConstantArguments(argumentList); 886 _validateConstantArguments(argumentList);
912 } 887 }
913 return null; 888 return null;
914 } 889 }
915 890
916 @override 891 @override
917 Object visitConstructorDeclaration(ConstructorDeclaration node) { 892 Object visitConstructorDeclaration(ConstructorDeclaration node) {
(...skipping 28 matching lines...) Expand all
946 921
947 @override 922 @override
948 Object visitListLiteral(ListLiteral node) { 923 Object visitListLiteral(ListLiteral node) {
949 super.visitListLiteral(node); 924 super.visitListLiteral(node);
950 if (node.constKeyword != null) { 925 if (node.constKeyword != null) {
951 DartObjectImpl result; 926 DartObjectImpl result;
952 for (Expression element in node.elements) { 927 for (Expression element in node.elements) {
953 result = 928 result =
954 _validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT); 929 _validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT);
955 if (result != null) { 930 if (result != null) {
956 _reportErrorIfFromDeferredLibrary( 931 _reportErrorIfFromDeferredLibrary(element,
957 element,
958 CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRA RY); 932 CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRA RY);
959 } 933 }
960 } 934 }
961 } 935 }
962 return null; 936 return null;
963 } 937 }
964 938
965 @override 939 @override
966 Object visitMapLiteral(MapLiteral node) { 940 Object visitMapLiteral(MapLiteral node) {
967 super.visitMapLiteral(node); 941 super.visitMapLiteral(node);
968 bool isConst = node.constKeyword != null; 942 bool isConst = node.constKeyword != null;
969 bool reportEqualKeys = true; 943 bool reportEqualKeys = true;
970 HashSet<DartObject> keys = new HashSet<DartObject>(); 944 HashSet<DartObject> keys = new HashSet<DartObject>();
971 List<Expression> invalidKeys = new List<Expression>(); 945 List<Expression> invalidKeys = new List<Expression>();
972 for (MapLiteralEntry entry in node.entries) { 946 for (MapLiteralEntry entry in node.entries) {
973 Expression key = entry.key; 947 Expression key = entry.key;
974 if (isConst) { 948 if (isConst) {
975 DartObjectImpl keyResult = 949 DartObjectImpl keyResult =
976 _validate(key, CompileTimeErrorCode.NON_CONSTANT_MAP_KEY); 950 _validate(key, CompileTimeErrorCode.NON_CONSTANT_MAP_KEY);
977 Expression valueExpression = entry.value; 951 Expression valueExpression = entry.value;
978 DartObjectImpl valueResult = 952 DartObjectImpl valueResult = _validate(
979 _validate(valueExpression, CompileTimeErrorCode.NON_CONSTANT_MAP_VAL UE); 953 valueExpression, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE);
980 if (valueResult != null) { 954 if (valueResult != null) {
981 _reportErrorIfFromDeferredLibrary( 955 _reportErrorIfFromDeferredLibrary(valueExpression,
982 valueExpression,
983 CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY) ; 956 CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY) ;
984 } 957 }
985 if (keyResult != null) { 958 if (keyResult != null) {
986 _reportErrorIfFromDeferredLibrary( 959 _reportErrorIfFromDeferredLibrary(key,
987 key,
988 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY); 960 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY);
989 if (keys.contains(keyResult)) { 961 if (keys.contains(keyResult)) {
990 invalidKeys.add(key); 962 invalidKeys.add(key);
991 } else { 963 } else {
992 keys.add(keyResult); 964 keys.add(keyResult);
993 } 965 }
994 DartType type = keyResult.type; 966 DartType type = keyResult.type;
995 if (_implementsEqualsWhenNotAllowed(type)) { 967 if (_implementsEqualsWhenNotAllowed(type)) {
996 _errorReporter.reportErrorForNode( 968 _errorReporter.reportErrorForNode(
997 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQ UALS, 969 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQ UALS,
998 key, 970 key, [type.displayName]);
999 [type.displayName]);
1000 } 971 }
1001 } 972 }
1002 } else { 973 } else {
1003 // Note: we throw the errors away because this isn't actually a const. 974 // Note: we throw the errors away because this isn't actually a const.
1004 AnalysisErrorListener errorListener = 975 AnalysisErrorListener errorListener =
1005 AnalysisErrorListener.NULL_LISTENER; 976 AnalysisErrorListener.NULL_LISTENER;
1006 ErrorReporter subErrorReporter = 977 ErrorReporter subErrorReporter =
1007 new ErrorReporter(errorListener, _errorReporter.source); 978 new ErrorReporter(errorListener, _errorReporter.source);
1008 DartObjectImpl result = 979 DartObjectImpl result = key
1009 key.accept(new ConstantVisitor.con1(_typeProvider, subErrorReporter) ); 980 .accept(new ConstantVisitor.con1(_typeProvider, subErrorReporter));
1010 if (result != null) { 981 if (result != null) {
1011 if (keys.contains(result)) { 982 if (keys.contains(result)) {
1012 invalidKeys.add(key); 983 invalidKeys.add(key);
1013 } else { 984 } else {
1014 keys.add(result); 985 keys.add(result);
1015 } 986 }
1016 } else { 987 } else {
1017 reportEqualKeys = false; 988 reportEqualKeys = false;
1018 } 989 }
1019 } 990 }
1020 } 991 }
1021 if (reportEqualKeys) { 992 if (reportEqualKeys) {
1022 for (Expression key in invalidKeys) { 993 for (Expression key in invalidKeys) {
1023 _errorReporter.reportErrorForNode( 994 _errorReporter.reportErrorForNode(
1024 StaticWarningCode.EQUAL_KEYS_IN_MAP, 995 StaticWarningCode.EQUAL_KEYS_IN_MAP, key);
1025 key);
1026 } 996 }
1027 } 997 }
1028 return null; 998 return null;
1029 } 999 }
1030 1000
1031 @override 1001 @override
1032 Object visitMethodDeclaration(MethodDeclaration node) { 1002 Object visitMethodDeclaration(MethodDeclaration node) {
1033 super.visitMethodDeclaration(node); 1003 super.visitMethodDeclaration(node);
1034 _validateDefaultValues(node.parameters); 1004 _validateDefaultValues(node.parameters);
1035 return null; 1005 return null;
1036 } 1006 }
1037 1007
1038 @override 1008 @override
1039 Object visitSwitchStatement(SwitchStatement node) { 1009 Object visitSwitchStatement(SwitchStatement node) {
1040 // TODO(paulberry): to minimize error messages, it would be nice to 1010 // TODO(paulberry): to minimize error messages, it would be nice to
1041 // compare all types with the most popular type rather than the first 1011 // compare all types with the most popular type rather than the first
1042 // type. 1012 // type.
1043 NodeList<SwitchMember> switchMembers = node.members; 1013 NodeList<SwitchMember> switchMembers = node.members;
1044 bool foundError = false; 1014 bool foundError = false;
1045 DartType firstType = null; 1015 DartType firstType = null;
1046 for (SwitchMember switchMember in switchMembers) { 1016 for (SwitchMember switchMember in switchMembers) {
1047 if (switchMember is SwitchCase) { 1017 if (switchMember is SwitchCase) {
1048 SwitchCase switchCase = switchMember; 1018 SwitchCase switchCase = switchMember;
1049 Expression expression = switchCase.expression; 1019 Expression expression = switchCase.expression;
1050 DartObjectImpl caseResult = 1020 DartObjectImpl caseResult = _validate(
1051 _validate(expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESS ION); 1021 expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION);
1052 if (caseResult != null) { 1022 if (caseResult != null) {
1053 _reportErrorIfFromDeferredLibrary( 1023 _reportErrorIfFromDeferredLibrary(expression,
1054 expression,
1055 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LI BRARY); 1024 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LI BRARY);
1056 DartObject value = caseResult; 1025 DartObject value = caseResult;
1057 if (firstType == null) { 1026 if (firstType == null) {
1058 firstType = value.type; 1027 firstType = value.type;
1059 } else { 1028 } else {
1060 DartType nType = value.type; 1029 DartType nType = value.type;
1061 if (firstType != nType) { 1030 if (firstType != nType) {
1062 _errorReporter.reportErrorForNode( 1031 _errorReporter.reportErrorForNode(
1063 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, 1032 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES,
1064 expression, 1033 expression, [expression.toSource(), firstType.displayName]);
1065 [expression.toSource(), firstType.displayName]);
1066 foundError = true; 1034 foundError = true;
1067 } 1035 }
1068 } 1036 }
1069 } 1037 }
1070 } 1038 }
1071 } 1039 }
1072 if (!foundError) { 1040 if (!foundError) {
1073 _checkForCaseExpressionTypeImplementsEquals(node, firstType); 1041 _checkForCaseExpressionTypeImplementsEquals(node, firstType);
1074 } 1042 }
1075 return super.visitSwitchStatement(node); 1043 return super.visitSwitchStatement(node);
1076 } 1044 }
1077 1045
1078 @override 1046 @override
1079 Object visitVariableDeclaration(VariableDeclaration node) { 1047 Object visitVariableDeclaration(VariableDeclaration node) {
1080 super.visitVariableDeclaration(node); 1048 super.visitVariableDeclaration(node);
1081 Expression initializer = node.initializer; 1049 Expression initializer = node.initializer;
1082 if (initializer != null && node.isConst) { 1050 if (initializer != null && node.isConst) {
1083 VariableElementImpl element = node.element as VariableElementImpl; 1051 VariableElementImpl element = node.element as VariableElementImpl;
1084 EvaluationResultImpl result = element.evaluationResult; 1052 EvaluationResultImpl result = element.evaluationResult;
1085 if (result == null) { 1053 if (result == null) {
1086 // 1054 //
1087 // Normally we don't need to visit const variable declarations because 1055 // Normally we don't need to visit const variable declarations because
1088 // we have already computed their values. But if we missed it for some 1056 // we have already computed their values. But if we missed it for some
1089 // reason, this gives us a second chance. 1057 // reason, this gives us a second chance.
1090 // 1058 //
1091 result = new EvaluationResultImpl.con1( 1059 result = new EvaluationResultImpl.con1(_validate(initializer,
1092 _validate( 1060 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE));
1093 initializer,
1094 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE)) ;
1095 element.evaluationResult = result; 1061 element.evaluationResult = result;
1096 return null; 1062 return null;
1097 } 1063 }
1098 _reportErrors( 1064 _reportErrors(result.errors,
1099 result.errors,
1100 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE); 1065 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE);
1101 _reportErrorIfFromDeferredLibrary( 1066 _reportErrorIfFromDeferredLibrary(initializer,
1102 initializer,
1103 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DE FERRED_LIBRARY); 1067 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DE FERRED_LIBRARY);
1104 } 1068 }
1105 return null; 1069 return null;
1106 } 1070 }
1107 1071
1108 /** 1072 /**
1109 * This verifies that the passed switch statement does not have a case express ion with the 1073 * This verifies that the passed switch statement does not have a case express ion with the
1110 * operator '==' overridden. 1074 * operator '==' overridden.
1111 * 1075 *
1112 * @param node the switch statement to evaluate 1076 * @param node the switch statement to evaluate
1113 * @param type the common type of all 'case' expressions 1077 * @param type the common type of all 'case' expressions
1114 * @return `true` if and only if an error code is generated on the passed node 1078 * @return `true` if and only if an error code is generated on the passed node
1115 * See [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]. 1079 * See [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS].
1116 */ 1080 */
1117 bool _checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, 1081 bool _checkForCaseExpressionTypeImplementsEquals(
1118 DartType type) { 1082 SwitchStatement node, DartType type) {
1119 if (!_implementsEqualsWhenNotAllowed(type)) { 1083 if (!_implementsEqualsWhenNotAllowed(type)) {
1120 return false; 1084 return false;
1121 } 1085 }
1122 // report error 1086 // report error
1123 _errorReporter.reportErrorForToken( 1087 _errorReporter.reportErrorForToken(
1124 CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, 1088 CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS,
1125 node.switchKeyword, 1089 node.switchKeyword, [type.displayName]);
1126 [type.displayName]);
1127 return true; 1090 return true;
1128 } 1091 }
1129 1092
1130 /** 1093 /**
1131 * @return `true` if given [Type] implements operator <i>==</i>, and it is not 1094 * @return `true` if given [Type] implements operator <i>==</i>, and it is not
1132 * <i>int</i> or <i>String</i>. 1095 * <i>int</i> or <i>String</i>.
1133 */ 1096 */
1134 bool _implementsEqualsWhenNotAllowed(DartType type) { 1097 bool _implementsEqualsWhenNotAllowed(DartType type) {
1135 // ignore int or String 1098 // ignore int or String
1136 if (type == null || type == _intType || type == _typeProvider.stringType) { 1099 if (type == null || type == _intType || type == _typeProvider.stringType) {
(...skipping 18 matching lines...) Expand all
1155 } 1118 }
1156 1119
1157 /** 1120 /**
1158 * Given some computed [Expression], this method generates the passed [ErrorCo de] on 1121 * Given some computed [Expression], this method generates the passed [ErrorCo de] on
1159 * the node if its' value consists of information from a deferred library. 1122 * the node if its' value consists of information from a deferred library.
1160 * 1123 *
1161 * @param expression the expression to be tested for a deferred library refere nce 1124 * @param expression the expression to be tested for a deferred library refere nce
1162 * @param errorCode the error code to be used if the expression is or consists of a reference to a 1125 * @param errorCode the error code to be used if the expression is or consists of a reference to a
1163 * deferred library 1126 * deferred library
1164 */ 1127 */
1165 void _reportErrorIfFromDeferredLibrary(Expression expression, 1128 void _reportErrorIfFromDeferredLibrary(
1166 ErrorCode errorCode) { 1129 Expression expression, ErrorCode errorCode) {
1167 DeferredLibraryReferenceDetector referenceDetector = 1130 DeferredLibraryReferenceDetector referenceDetector =
1168 new DeferredLibraryReferenceDetector(); 1131 new DeferredLibraryReferenceDetector();
1169 expression.accept(referenceDetector); 1132 expression.accept(referenceDetector);
1170 if (referenceDetector.result) { 1133 if (referenceDetector.result) {
1171 _errorReporter.reportErrorForNode(errorCode, expression); 1134 _errorReporter.reportErrorForNode(errorCode, expression);
1172 } 1135 }
1173 } 1136 }
1174 1137
1175 /** 1138 /**
1176 * Report any errors in the given list. Except for special cases, use the give n error code rather 1139 * Report any errors in the given list. Except for special cases, use the give n error code rather
1177 * than the one reported in the error. 1140 * than the one reported in the error.
1178 * 1141 *
1179 * @param errors the errors that need to be reported 1142 * @param errors the errors that need to be reported
1180 * @param errorCode the error code to be used 1143 * @param errorCode the error code to be used
1181 */ 1144 */
1182 void _reportErrors(List<AnalysisError> errors, ErrorCode errorCode) { 1145 void _reportErrors(List<AnalysisError> errors, ErrorCode errorCode) {
1183 for (AnalysisError data in errors) { 1146 for (AnalysisError data in errors) {
1184 ErrorCode dataErrorCode = data.errorCode; 1147 ErrorCode dataErrorCode = data.errorCode;
1185 if (identical( 1148 if (identical(dataErrorCode,
1186 dataErrorCode, 1149 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) ||
1187 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) ||
1188 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) ||
1189 identical( 1150 identical(
1190 dataErrorCode, 1151 dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) ||
1152 identical(dataErrorCode,
1191 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) || 1153 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) ||
1192 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || 1154 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) ||
1193 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || 1155 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) ||
1194 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || 1156 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) ||
1195 identical( 1157 identical(dataErrorCode,
1196 dataErrorCode,
1197 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMA TCH) || 1158 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMA TCH) ||
1198 identical( 1159 identical(dataErrorCode,
1199 dataErrorCode,
1200 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA TCH) || 1160 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA TCH) ||
1201 identical( 1161 identical(dataErrorCode,
1202 dataErrorCode,
1203 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH)) { 1162 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH)) {
1204 _errorReporter.reportError(data); 1163 _errorReporter.reportError(data);
1205 } else if (errorCode != null) { 1164 } else if (errorCode != null) {
1206 _errorReporter.reportError( 1165 _errorReporter.reportError(new AnalysisError.con2(
1207 new AnalysisError.con2(data.source, data.offset, data.length, errorC ode)); 1166 data.source, data.offset, data.length, errorCode));
1208 } 1167 }
1209 } 1168 }
1210 } 1169 }
1211 1170
1212 /** 1171 /**
1213 * Validate that the given expression is a compile time constant. Return the v alue of the compile 1172 * Validate that the given expression is a compile time constant. Return the v alue of the compile
1214 * time constant, or `null` if the expression is not a compile time constant. 1173 * time constant, or `null` if the expression is not a compile time constant.
1215 * 1174 *
1216 * @param expression the expression to be validated 1175 * @param expression the expression to be validated
1217 * @param errorCode the error code to be used if the expression is not a compi le time constant 1176 * @param errorCode the error code to be used if the expression is not a compi le time constant
1218 * @return the value of the compile time constant 1177 * @return the value of the compile time constant
1219 */ 1178 */
1220 DartObjectImpl _validate(Expression expression, ErrorCode errorCode) { 1179 DartObjectImpl _validate(Expression expression, ErrorCode errorCode) {
1221 RecordingErrorListener errorListener = new RecordingErrorListener(); 1180 RecordingErrorListener errorListener = new RecordingErrorListener();
1222 ErrorReporter subErrorReporter = 1181 ErrorReporter subErrorReporter =
1223 new ErrorReporter(errorListener, _errorReporter.source); 1182 new ErrorReporter(errorListener, _errorReporter.source);
1224 DartObjectImpl result = 1183 DartObjectImpl result = expression
1225 expression.accept(new ConstantVisitor.con1(_typeProvider, subErrorReport er)); 1184 .accept(new ConstantVisitor.con1(_typeProvider, subErrorReporter));
1226 _reportErrors(errorListener.errors, errorCode); 1185 _reportErrors(errorListener.errors, errorCode);
1227 return result; 1186 return result;
1228 } 1187 }
1229 1188
1230 /** 1189 /**
1231 * Validate that if the passed arguments are constant expressions. 1190 * Validate that if the passed arguments are constant expressions.
1232 * 1191 *
1233 * @param argumentList the argument list to evaluate 1192 * @param argumentList the argument list to evaluate
1234 */ 1193 */
1235 void _validateConstantArguments(ArgumentList argumentList) { 1194 void _validateConstantArguments(ArgumentList argumentList) {
1236 for (Expression argument in argumentList.arguments) { 1195 for (Expression argument in argumentList.arguments) {
1237 if (argument is NamedExpression) { 1196 if (argument is NamedExpression) {
1238 argument = (argument as NamedExpression).expression; 1197 argument = (argument as NamedExpression).expression;
1239 } 1198 }
1240 _validate( 1199 _validate(
1241 argument, 1200 argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT);
1242 CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT);
1243 } 1201 }
1244 } 1202 }
1245 1203
1246 /** 1204 /**
1247 * Validates that the expressions of the given initializers (of a constant con structor) are all 1205 * Validates that the expressions of the given initializers (of a constant con structor) are all
1248 * compile time constants. 1206 * compile time constants.
1249 * 1207 *
1250 * @param constructor the constant constructor declaration to validate 1208 * @param constructor the constant constructor declaration to validate
1251 */ 1209 */
1252 void _validateConstructorInitializers(ConstructorDeclaration constructor) { 1210 void _validateConstructorInitializers(ConstructorDeclaration constructor) {
1253 List<ParameterElement> parameterElements = 1211 List<ParameterElement> parameterElements =
1254 constructor.parameters.parameterElements; 1212 constructor.parameters.parameterElements;
1255 NodeList<ConstructorInitializer> initializers = constructor.initializers; 1213 NodeList<ConstructorInitializer> initializers = constructor.initializers;
1256 for (ConstructorInitializer initializer in initializers) { 1214 for (ConstructorInitializer initializer in initializers) {
1257 if (initializer is ConstructorFieldInitializer) { 1215 if (initializer is ConstructorFieldInitializer) {
1258 ConstructorFieldInitializer fieldInitializer = initializer; 1216 ConstructorFieldInitializer fieldInitializer = initializer;
1259 _validateInitializerExpression( 1217 _validateInitializerExpression(
1260 parameterElements, 1218 parameterElements, fieldInitializer.expression);
1261 fieldInitializer.expression);
1262 } 1219 }
1263 if (initializer is RedirectingConstructorInvocation) { 1220 if (initializer is RedirectingConstructorInvocation) {
1264 RedirectingConstructorInvocation invocation = initializer; 1221 RedirectingConstructorInvocation invocation = initializer;
1265 _validateInitializerInvocationArguments( 1222 _validateInitializerInvocationArguments(
1266 parameterElements, 1223 parameterElements, invocation.argumentList);
1267 invocation.argumentList);
1268 } 1224 }
1269 if (initializer is SuperConstructorInvocation) { 1225 if (initializer is SuperConstructorInvocation) {
1270 SuperConstructorInvocation invocation = initializer; 1226 SuperConstructorInvocation invocation = initializer;
1271 _validateInitializerInvocationArguments( 1227 _validateInitializerInvocationArguments(
1272 parameterElements, 1228 parameterElements, invocation.argumentList);
1273 invocation.argumentList);
1274 } 1229 }
1275 } 1230 }
1276 } 1231 }
1277 1232
1278 /** 1233 /**
1279 * Validate that the default value associated with each of the parameters in t he given list is a 1234 * Validate that the default value associated with each of the parameters in t he given list is a
1280 * compile time constant. 1235 * compile time constant.
1281 * 1236 *
1282 * @param parameters the list of parameters to be validated 1237 * @param parameters the list of parameters to be validated
1283 */ 1238 */
1284 void _validateDefaultValues(FormalParameterList parameters) { 1239 void _validateDefaultValues(FormalParameterList parameters) {
1285 if (parameters == null) { 1240 if (parameters == null) {
1286 return; 1241 return;
1287 } 1242 }
1288 for (FormalParameter parameter in parameters.parameters) { 1243 for (FormalParameter parameter in parameters.parameters) {
1289 if (parameter is DefaultFormalParameter) { 1244 if (parameter is DefaultFormalParameter) {
1290 DefaultFormalParameter defaultParameter = parameter; 1245 DefaultFormalParameter defaultParameter = parameter;
1291 Expression defaultValue = defaultParameter.defaultValue; 1246 Expression defaultValue = defaultParameter.defaultValue;
1292 DartObjectImpl result; 1247 DartObjectImpl result;
1293 if (defaultValue == null) { 1248 if (defaultValue == null) {
1294 result = 1249 result =
1295 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE); 1250 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE);
1296 } else { 1251 } else {
1297 result = 1252 result = _validate(
1298 _validate(defaultValue, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_ VALUE); 1253 defaultValue, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE);
1299 if (result != null) { 1254 if (result != null) {
1300 _reportErrorIfFromDeferredLibrary( 1255 _reportErrorIfFromDeferredLibrary(defaultValue,
1301 defaultValue,
1302 CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LI BRARY); 1256 CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LI BRARY);
1303 } 1257 }
1304 } 1258 }
1305 VariableElementImpl element = parameter.element as VariableElementImpl; 1259 VariableElementImpl element = parameter.element as VariableElementImpl;
1306 element.evaluationResult = new EvaluationResultImpl.con1(result); 1260 element.evaluationResult = new EvaluationResultImpl.con1(result);
1307 } 1261 }
1308 } 1262 }
1309 } 1263 }
1310 1264
1311 /** 1265 /**
1312 * Validates that the expressions of any field initializers in the class decla ration are all 1266 * Validates that the expressions of any field initializers in the class decla ration are all
1313 * compile time constants. Since this is only required if the class has a cons tant constructor, 1267 * compile time constants. Since this is only required if the class has a cons tant constructor,
1314 * the error is reported at the constructor site. 1268 * the error is reported at the constructor site.
1315 * 1269 *
1316 * @param classDeclaration the class which should be validated 1270 * @param classDeclaration the class which should be validated
1317 * @param errorSite the site at which errors should be reported. 1271 * @param errorSite the site at which errors should be reported.
1318 */ 1272 */
1319 void _validateFieldInitializers(ClassDeclaration classDeclaration, 1273 void _validateFieldInitializers(
1320 ConstructorDeclaration errorSite) { 1274 ClassDeclaration classDeclaration, ConstructorDeclaration errorSite) {
1321 NodeList<ClassMember> members = classDeclaration.members; 1275 NodeList<ClassMember> members = classDeclaration.members;
1322 for (ClassMember member in members) { 1276 for (ClassMember member in members) {
1323 if (member is FieldDeclaration) { 1277 if (member is FieldDeclaration) {
1324 FieldDeclaration fieldDeclaration = member; 1278 FieldDeclaration fieldDeclaration = member;
1325 if (!fieldDeclaration.isStatic) { 1279 if (!fieldDeclaration.isStatic) {
1326 for (VariableDeclaration variableDeclaration in 1280 for (VariableDeclaration variableDeclaration
1327 fieldDeclaration.fields.variables) { 1281 in fieldDeclaration.fields.variables) {
1328 Expression initializer = variableDeclaration.initializer; 1282 Expression initializer = variableDeclaration.initializer;
1329 if (initializer != null) { 1283 if (initializer != null) {
1330 // Ignore any errors produced during validation--if the constant 1284 // Ignore any errors produced during validation--if the constant
1331 // can't be eavluated we'll just report a single error. 1285 // can't be eavluated we'll just report a single error.
1332 AnalysisErrorListener errorListener = 1286 AnalysisErrorListener errorListener =
1333 AnalysisErrorListener.NULL_LISTENER; 1287 AnalysisErrorListener.NULL_LISTENER;
1334 ErrorReporter subErrorReporter = 1288 ErrorReporter subErrorReporter =
1335 new ErrorReporter(errorListener, _errorReporter.source); 1289 new ErrorReporter(errorListener, _errorReporter.source);
1336 DartObjectImpl result = 1290 DartObjectImpl result = initializer.accept(
1337 initializer.accept(new ConstantVisitor.con1(_typeProvider, sub ErrorReporter)); 1291 new ConstantVisitor.con1(_typeProvider, subErrorReporter));
1338 if (result == null) { 1292 if (result == null) {
1339 _errorReporter.reportErrorForNode( 1293 _errorReporter.reportErrorForNode(
1340 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE D_BY_NON_CONST, 1294 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE D_BY_NON_CONST,
1341 errorSite, 1295 errorSite, [variableDeclaration.name.name]);
1342 [variableDeclaration.name.name]);
1343 } 1296 }
1344 } 1297 }
1345 } 1298 }
1346 } 1299 }
1347 } 1300 }
1348 } 1301 }
1349 } 1302 }
1350 1303
1351 /** 1304 /**
1352 * Validates that the given expression is a compile time constant. 1305 * Validates that the given expression is a compile time constant.
1353 * 1306 *
1354 * @param parameterElements the elements of parameters of constant constructor , they are 1307 * @param parameterElements the elements of parameters of constant constructor , they are
1355 * considered as a valid potentially constant expressions 1308 * considered as a valid potentially constant expressions
1356 * @param expression the expression to validate 1309 * @param expression the expression to validate
1357 */ 1310 */
1358 void _validateInitializerExpression(List<ParameterElement> parameterElements, 1311 void _validateInitializerExpression(
1359 Expression expression) { 1312 List<ParameterElement> parameterElements, Expression expression) {
1360 RecordingErrorListener errorListener = new RecordingErrorListener(); 1313 RecordingErrorListener errorListener = new RecordingErrorListener();
1361 ErrorReporter subErrorReporter = 1314 ErrorReporter subErrorReporter =
1362 new ErrorReporter(errorListener, _errorReporter.source); 1315 new ErrorReporter(errorListener, _errorReporter.source);
1363 DartObjectImpl result = expression.accept( 1316 DartObjectImpl result = expression.accept(
1364 new _ConstantVerifier_validateInitializerExpression( 1317 new _ConstantVerifier_validateInitializerExpression(
1365 _typeProvider, 1318 _typeProvider, subErrorReporter, this, parameterElements));
1366 subErrorReporter, 1319 _reportErrors(errorListener.errors,
1367 this,
1368 parameterElements));
1369 _reportErrors(
1370 errorListener.errors,
1371 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER); 1320 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER);
1372 if (result != null) { 1321 if (result != null) {
1373 _reportErrorIfFromDeferredLibrary( 1322 _reportErrorIfFromDeferredLibrary(expression,
1374 expression,
1375 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_L IBRARY); 1323 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_L IBRARY);
1376 } 1324 }
1377 } 1325 }
1378 1326
1379 /** 1327 /**
1380 * Validates that all of the arguments of a constructor initializer are compil e time constants. 1328 * Validates that all of the arguments of a constructor initializer are compil e time constants.
1381 * 1329 *
1382 * @param parameterElements the elements of parameters of constant constructor , they are 1330 * @param parameterElements the elements of parameters of constant constructor , they are
1383 * considered as a valid potentially constant expressions 1331 * considered as a valid potentially constant expressions
1384 * @param argumentList the argument list to validate 1332 * @param argumentList the argument list to validate
1385 */ 1333 */
1386 void 1334 void _validateInitializerInvocationArguments(
1387 _validateInitializerInvocationArguments(List<ParameterElement> parameterEl ements, 1335 List<ParameterElement> parameterElements, ArgumentList argumentList) {
1388 ArgumentList argumentList) {
1389 if (argumentList == null) { 1336 if (argumentList == null) {
1390 return; 1337 return;
1391 } 1338 }
1392 for (Expression argument in argumentList.arguments) { 1339 for (Expression argument in argumentList.arguments) {
1393 _validateInitializerExpression(parameterElements, argument); 1340 _validateInitializerExpression(parameterElements, argument);
1394 } 1341 }
1395 } 1342 }
1396 1343
1397 /** 1344 /**
1398 * Validate that if the passed instance creation is 'const' then all its argum ents are constant 1345 * Validate that if the passed instance creation is 'const' then all its argum ents are constant
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 bool isAmpAmp = operator.type == sc.TokenType.AMPERSAND_AMPERSAND; 1452 bool isAmpAmp = operator.type == sc.TokenType.AMPERSAND_AMPERSAND;
1506 bool isBarBar = operator.type == sc.TokenType.BAR_BAR; 1453 bool isBarBar = operator.type == sc.TokenType.BAR_BAR;
1507 if (isAmpAmp || isBarBar) { 1454 if (isAmpAmp || isBarBar) {
1508 Expression lhsCondition = node.leftOperand; 1455 Expression lhsCondition = node.leftOperand;
1509 if (!_isDebugConstant(lhsCondition)) { 1456 if (!_isDebugConstant(lhsCondition)) {
1510 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition); 1457 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition);
1511 if (lhsResult != null) { 1458 if (lhsResult != null) {
1512 if (lhsResult.value.isTrue && isBarBar) { 1459 if (lhsResult.value.isTrue && isBarBar) {
1513 // report error on else block: true || !e! 1460 // report error on else block: true || !e!
1514 _errorReporter.reportErrorForNode( 1461 _errorReporter.reportErrorForNode(
1515 HintCode.DEAD_CODE, 1462 HintCode.DEAD_CODE, node.rightOperand);
1516 node.rightOperand);
1517 // only visit the LHS: 1463 // only visit the LHS:
1518 _safelyVisit(lhsCondition); 1464 _safelyVisit(lhsCondition);
1519 return null; 1465 return null;
1520 } else if (lhsResult.value.isFalse && isAmpAmp) { 1466 } else if (lhsResult.value.isFalse && isAmpAmp) {
1521 // report error on if block: false && !e! 1467 // report error on if block: false && !e!
1522 _errorReporter.reportErrorForNode( 1468 _errorReporter.reportErrorForNode(
1523 HintCode.DEAD_CODE, 1469 HintCode.DEAD_CODE, node.rightOperand);
1524 node.rightOperand);
1525 // only visit the LHS: 1470 // only visit the LHS:
1526 _safelyVisit(lhsCondition); 1471 _safelyVisit(lhsCondition);
1527 return null; 1472 return null;
1528 } 1473 }
1529 } 1474 }
1530 } 1475 }
1531 // How do we want to handle the RHS? It isn't dead code, but "pointless" 1476 // How do we want to handle the RHS? It isn't dead code, but "pointless"
1532 // or "obscure"... 1477 // or "obscure"...
1533 // Expression rhsCondition = node.getRightOperand(); 1478 // Expression rhsCondition = node.getRightOperand();
1534 // ValidResult rhsResult = getConstantBooleanValue(rhsCondition); 1479 // ValidResult rhsResult = getConstantBooleanValue(rhsCondition);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 Object visitConditionalExpression(ConditionalExpression node) { 1513 Object visitConditionalExpression(ConditionalExpression node) {
1569 Expression conditionExpression = node.condition; 1514 Expression conditionExpression = node.condition;
1570 _safelyVisit(conditionExpression); 1515 _safelyVisit(conditionExpression);
1571 if (!_isDebugConstant(conditionExpression)) { 1516 if (!_isDebugConstant(conditionExpression)) {
1572 EvaluationResultImpl result = 1517 EvaluationResultImpl result =
1573 _getConstantBooleanValue(conditionExpression); 1518 _getConstantBooleanValue(conditionExpression);
1574 if (result != null) { 1519 if (result != null) {
1575 if (result.value.isTrue) { 1520 if (result.value.isTrue) {
1576 // report error on else block: true ? 1 : !2! 1521 // report error on else block: true ? 1 : !2!
1577 _errorReporter.reportErrorForNode( 1522 _errorReporter.reportErrorForNode(
1578 HintCode.DEAD_CODE, 1523 HintCode.DEAD_CODE, node.elseExpression);
1579 node.elseExpression);
1580 _safelyVisit(node.thenExpression); 1524 _safelyVisit(node.thenExpression);
1581 return null; 1525 return null;
1582 } else { 1526 } else {
1583 // report error on if block: false ? !1! : 2 1527 // report error on if block: false ? !1! : 2
1584 _errorReporter.reportErrorForNode( 1528 _errorReporter
1585 HintCode.DEAD_CODE, 1529 .reportErrorForNode(HintCode.DEAD_CODE, node.thenExpression);
1586 node.thenExpression);
1587 _safelyVisit(node.elseExpression); 1530 _safelyVisit(node.elseExpression);
1588 return null; 1531 return null;
1589 } 1532 }
1590 } 1533 }
1591 } 1534 }
1592 return super.visitConditionalExpression(node); 1535 return super.visitConditionalExpression(node);
1593 } 1536 }
1594 1537
1595 @override 1538 @override
1596 Object visitIfStatement(IfStatement node) { 1539 Object visitIfStatement(IfStatement node) {
1597 Expression conditionExpression = node.condition; 1540 Expression conditionExpression = node.condition;
1598 _safelyVisit(conditionExpression); 1541 _safelyVisit(conditionExpression);
1599 if (!_isDebugConstant(conditionExpression)) { 1542 if (!_isDebugConstant(conditionExpression)) {
1600 EvaluationResultImpl result = 1543 EvaluationResultImpl result =
1601 _getConstantBooleanValue(conditionExpression); 1544 _getConstantBooleanValue(conditionExpression);
1602 if (result != null) { 1545 if (result != null) {
1603 if (result.value.isTrue) { 1546 if (result.value.isTrue) {
1604 // report error on else block: if(true) {} else {!} 1547 // report error on else block: if(true) {} else {!}
1605 Statement elseStatement = node.elseStatement; 1548 Statement elseStatement = node.elseStatement;
1606 if (elseStatement != null) { 1549 if (elseStatement != null) {
1607 _errorReporter.reportErrorForNode( 1550 _errorReporter.reportErrorForNode(
1608 HintCode.DEAD_CODE, 1551 HintCode.DEAD_CODE, elseStatement);
1609 elseStatement);
1610 _safelyVisit(node.thenStatement); 1552 _safelyVisit(node.thenStatement);
1611 return null; 1553 return null;
1612 } 1554 }
1613 } else { 1555 } else {
1614 // report error on if block: if (false) {!} else {} 1556 // report error on if block: if (false) {!} else {}
1615 _errorReporter.reportErrorForNode( 1557 _errorReporter
1616 HintCode.DEAD_CODE, 1558 .reportErrorForNode(HintCode.DEAD_CODE, node.thenStatement);
1617 node.thenStatement);
1618 _safelyVisit(node.elseStatement); 1559 _safelyVisit(node.elseStatement);
1619 return null; 1560 return null;
1620 } 1561 }
1621 } 1562 }
1622 } 1563 }
1623 return super.visitIfStatement(node); 1564 return super.visitIfStatement(node);
1624 } 1565 }
1625 1566
1626 @override 1567 @override
1627 Object visitSwitchCase(SwitchCase node) { 1568 Object visitSwitchCase(SwitchCase node) {
(...skipping 28 matching lines...) Expand all
1656 // exception type, visit the block, but generate an error on any 1597 // exception type, visit the block, but generate an error on any
1657 // following catch clauses (and don't visit them). 1598 // following catch clauses (and don't visit them).
1658 _safelyVisit(catchClause); 1599 _safelyVisit(catchClause);
1659 if (i + 1 != numOfCatchClauses) { 1600 if (i + 1 != numOfCatchClauses) {
1660 // this catch clause is not the last in the try statement 1601 // this catch clause is not the last in the try statement
1661 CatchClause nextCatchClause = catchClauses[i + 1]; 1602 CatchClause nextCatchClause = catchClauses[i + 1];
1662 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1603 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1663 int offset = nextCatchClause.offset; 1604 int offset = nextCatchClause.offset;
1664 int length = lastCatchClause.end - offset; 1605 int length = lastCatchClause.end - offset;
1665 _errorReporter.reportErrorForOffset( 1606 _errorReporter.reportErrorForOffset(
1666 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, 1607 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length);
1667 offset,
1668 length);
1669 return null; 1608 return null;
1670 } 1609 }
1671 } 1610 }
1672 for (DartType type in visitedTypes) { 1611 for (DartType type in visitedTypes) {
1673 if (currentType.isSubtypeOf(type)) { 1612 if (currentType.isSubtypeOf(type)) {
1674 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1613 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1675 int offset = catchClause.offset; 1614 int offset = catchClause.offset;
1676 int length = lastCatchClause.end - offset; 1615 int length = lastCatchClause.end - offset;
1677 _errorReporter.reportErrorForOffset( 1616 _errorReporter.reportErrorForOffset(
1678 HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, 1617 HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, offset, length, [
1679 offset, 1618 currentType.displayName,
1680 length, 1619 type.displayName
1681 [currentType.displayName, type.displayName]); 1620 ]);
1682 return null; 1621 return null;
1683 } 1622 }
1684 } 1623 }
1685 visitedTypes.add(currentType); 1624 visitedTypes.add(currentType);
1686 } 1625 }
1687 _safelyVisit(catchClause); 1626 _safelyVisit(catchClause);
1688 } else { 1627 } else {
1689 // Found catch clause clause that doesn't have an exception type, 1628 // Found catch clause clause that doesn't have an exception type,
1690 // visit the block, but generate an error on any following catch clauses 1629 // visit the block, but generate an error on any following catch clauses
1691 // (and don't visit them). 1630 // (and don't visit them).
1692 _safelyVisit(catchClause); 1631 _safelyVisit(catchClause);
1693 if (i + 1 != numOfCatchClauses) { 1632 if (i + 1 != numOfCatchClauses) {
1694 // this catch clause is not the last in the try statement 1633 // this catch clause is not the last in the try statement
1695 CatchClause nextCatchClause = catchClauses[i + 1]; 1634 CatchClause nextCatchClause = catchClauses[i + 1];
1696 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1635 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1697 int offset = nextCatchClause.offset; 1636 int offset = nextCatchClause.offset;
1698 int length = lastCatchClause.end - offset; 1637 int length = lastCatchClause.end - offset;
1699 _errorReporter.reportErrorForOffset( 1638 _errorReporter.reportErrorForOffset(
1700 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, 1639 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length);
1701 offset,
1702 length);
1703 return null; 1640 return null;
1704 } 1641 }
1705 } 1642 }
1706 } 1643 }
1707 return null; 1644 return null;
1708 } 1645 }
1709 1646
1710 @override 1647 @override
1711 Object visitWhileStatement(WhileStatement node) { 1648 Object visitWhileStatement(WhileStatement node) {
1712 Expression conditionExpression = node.condition; 1649 Expression conditionExpression = node.condition;
(...skipping 18 matching lines...) Expand all
1731 * [SwitchMember], this loops through the list in reverse order searching for statements 1668 * [SwitchMember], this loops through the list in reverse order searching for statements
1732 * after a return, unlabeled break or unlabeled continue statement to mark the m as dead code. 1669 * after a return, unlabeled break or unlabeled continue statement to mark the m as dead code.
1733 * 1670 *
1734 * @param statements some ordered list of statements in a [Block] or [SwitchMe mber] 1671 * @param statements some ordered list of statements in a [Block] or [SwitchMe mber]
1735 */ 1672 */
1736 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) { 1673 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) {
1737 int size = statements.length; 1674 int size = statements.length;
1738 for (int i = 0; i < size; i++) { 1675 for (int i = 0; i < size; i++) {
1739 Statement currentStatement = statements[i]; 1676 Statement currentStatement = statements[i];
1740 _safelyVisit(currentStatement); 1677 _safelyVisit(currentStatement);
1741 bool returnOrBreakingStatement = 1678 bool returnOrBreakingStatement = currentStatement is ReturnStatement ||
1742 currentStatement is ReturnStatement || 1679 (currentStatement is BreakStatement &&
1743 (currentStatement is BreakStatement && currentStatement.label == null) || 1680 currentStatement.label == null) ||
1744 (currentStatement is ContinueStatement && currentStatement.label == nu ll); 1681 (currentStatement is ContinueStatement &&
1682 currentStatement.label == null);
1745 if (returnOrBreakingStatement && i != size - 1) { 1683 if (returnOrBreakingStatement && i != size - 1) {
1746 Statement nextStatement = statements[i + 1]; 1684 Statement nextStatement = statements[i + 1];
1747 Statement lastStatement = statements[size - 1]; 1685 Statement lastStatement = statements[size - 1];
1748 int offset = nextStatement.offset; 1686 int offset = nextStatement.offset;
1749 int length = lastStatement.end - offset; 1687 int length = lastStatement.end - offset;
1750 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length); 1688 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length);
1751 return; 1689 return;
1752 } 1690 }
1753 } 1691 }
1754 } 1692 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 _findIdentifier(constants, constant.name); 1908 _findIdentifier(constants, constant.name);
1971 } 1909 }
1972 return super.visitEnumDeclaration(node); 1910 return super.visitEnumDeclaration(node);
1973 } 1911 }
1974 1912
1975 @override 1913 @override
1976 Object visitExportDirective(ExportDirective node) { 1914 Object visitExportDirective(ExportDirective node) {
1977 String uri = _getStringValue(node.uri); 1915 String uri = _getStringValue(node.uri);
1978 if (uri != null) { 1916 if (uri != null) {
1979 LibraryElement library = _enclosingUnit.library; 1917 LibraryElement library = _enclosingUnit.library;
1980 ExportElement exportElement = _findExport( 1918 ExportElement exportElement = _findExport(library.exports,
1981 library.exports, 1919 _enclosingUnit.context.sourceFactory.resolveUri(
1982 _enclosingUnit.context.sourceFactory.resolveUri(_enclosingUnit.source, uri)); 1920 _enclosingUnit.source, uri));
1983 node.element = exportElement; 1921 node.element = exportElement;
1984 } 1922 }
1985 return super.visitExportDirective(node); 1923 return super.visitExportDirective(node);
1986 } 1924 }
1987 1925
1988 @override 1926 @override
1989 Object visitFieldFormalParameter(FieldFormalParameter node) { 1927 Object visitFieldFormalParameter(FieldFormalParameter node) {
1990 if (node.parent is! DefaultFormalParameter) { 1928 if (node.parent is! DefaultFormalParameter) {
1991 SimpleIdentifier parameterName = node.identifier; 1929 SimpleIdentifier parameterName = node.identifier;
1992 ParameterElement element = _getElementForParameter(node, parameterName); 1930 ParameterElement element = _getElementForParameter(node, parameterName);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 } else { 2014 } else {
2077 return super.visitFunctionTypedFormalParameter(node); 2015 return super.visitFunctionTypedFormalParameter(node);
2078 } 2016 }
2079 } 2017 }
2080 2018
2081 @override 2019 @override
2082 Object visitImportDirective(ImportDirective node) { 2020 Object visitImportDirective(ImportDirective node) {
2083 String uri = _getStringValue(node.uri); 2021 String uri = _getStringValue(node.uri);
2084 if (uri != null) { 2022 if (uri != null) {
2085 LibraryElement library = _enclosingUnit.library; 2023 LibraryElement library = _enclosingUnit.library;
2086 ImportElement importElement = _findImport( 2024 ImportElement importElement = _findImport(library.imports,
2087 library.imports, 2025 _enclosingUnit.context.sourceFactory.resolveUri(
2088 _enclosingUnit.context.sourceFactory.resolveUri(_enclosingUnit.source, uri), 2026 _enclosingUnit.source, uri), node.prefix);
2089 node.prefix);
2090 node.element = importElement; 2027 node.element = importElement;
2091 } 2028 }
2092 return super.visitImportDirective(node); 2029 return super.visitImportDirective(node);
2093 } 2030 }
2094 2031
2095 @override 2032 @override
2096 Object visitLabeledStatement(LabeledStatement node) { 2033 Object visitLabeledStatement(LabeledStatement node) {
2097 for (Label label in node.labels) { 2034 for (Label label in node.labels) {
2098 SimpleIdentifier labelName = label.label; 2035 SimpleIdentifier labelName = label.label;
2099 _findIdentifier(_enclosingExecutable.labels, labelName); 2036 _findIdentifier(_enclosingExecutable.labels, labelName);
(...skipping 13 matching lines...) Expand all
2113 try { 2050 try {
2114 sc.Token property = node.propertyKeyword; 2051 sc.Token property = node.propertyKeyword;
2115 SimpleIdentifier methodName = node.name; 2052 SimpleIdentifier methodName = node.name;
2116 String nameOfMethod = methodName.name; 2053 String nameOfMethod = methodName.name;
2117 if (nameOfMethod == sc.TokenType.MINUS.lexeme && 2054 if (nameOfMethod == sc.TokenType.MINUS.lexeme &&
2118 node.parameters.parameters.length == 0) { 2055 node.parameters.parameters.length == 0) {
2119 nameOfMethod = "unary-"; 2056 nameOfMethod = "unary-";
2120 } 2057 }
2121 if (property == null) { 2058 if (property == null) {
2122 _enclosingExecutable = _findWithNameAndOffset( 2059 _enclosingExecutable = _findWithNameAndOffset(
2123 _enclosingClass.methods, 2060 _enclosingClass.methods, nameOfMethod, methodName.offset);
2124 nameOfMethod,
2125 methodName.offset);
2126 methodName.staticElement = _enclosingExecutable; 2061 methodName.staticElement = _enclosingExecutable;
2127 } else { 2062 } else {
2128 PropertyAccessorElement accessor = 2063 PropertyAccessorElement accessor =
2129 _findIdentifier(_enclosingClass.accessors, methodName); 2064 _findIdentifier(_enclosingClass.accessors, methodName);
2130 if ((property as sc.KeywordToken).keyword == sc.Keyword.SET) { 2065 if ((property as sc.KeywordToken).keyword == sc.Keyword.SET) {
2131 accessor = accessor.variable.setter; 2066 accessor = accessor.variable.setter;
2132 methodName.staticElement = accessor; 2067 methodName.staticElement = accessor;
2133 } 2068 }
2134 _enclosingExecutable = accessor; 2069 _enclosingExecutable = accessor;
2135 } 2070 }
2136 return super.visitMethodDeclaration(node); 2071 return super.visitMethodDeclaration(node);
2137 } finally { 2072 } finally {
2138 _enclosingExecutable = outerExecutable; 2073 _enclosingExecutable = outerExecutable;
2139 } 2074 }
2140 } 2075 }
2141 2076
2142 @override 2077 @override
2143 Object visitPartDirective(PartDirective node) { 2078 Object visitPartDirective(PartDirective node) {
2144 String uri = _getStringValue(node.uri); 2079 String uri = _getStringValue(node.uri);
2145 if (uri != null) { 2080 if (uri != null) {
2146 Source partSource = 2081 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(
2147 _enclosingUnit.context.sourceFactory.resolveUri(_enclosingUnit.source, uri); 2082 _enclosingUnit.source, uri);
2148 node.element = _findPart(_enclosingUnit.library.parts, partSource); 2083 node.element = _findPart(_enclosingUnit.library.parts, partSource);
2149 } 2084 }
2150 return super.visitPartDirective(node); 2085 return super.visitPartDirective(node);
2151 } 2086 }
2152 2087
2153 @override 2088 @override
2154 Object visitPartOfDirective(PartOfDirective node) { 2089 Object visitPartOfDirective(PartOfDirective node) {
2155 node.element = _enclosingUnit.library; 2090 node.element = _enclosingUnit.library;
2156 return super.visitPartOfDirective(node); 2091 return super.visitPartOfDirective(node);
2157 } 2092 }
2158 2093
2159 @override 2094 @override
2160 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 2095 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
2161 if (node.parent is! DefaultFormalParameter) { 2096 if (node.parent is! DefaultFormalParameter) {
2162 SimpleIdentifier parameterName = node.identifier; 2097 SimpleIdentifier parameterName = node.identifier;
2163 ParameterElement element = _getElementForParameter(node, parameterName); 2098 ParameterElement element = _getElementForParameter(node, parameterName);
2164 ParameterElement outerParameter = _enclosingParameter; 2099 ParameterElement outerParameter = _enclosingParameter;
2165 try { 2100 try {
2166 _enclosingParameter = element; 2101 _enclosingParameter = element;
2167 return super.visitSimpleFormalParameter(node); 2102 return super.visitSimpleFormalParameter(node);
2168 } finally { 2103 } finally {
2169 _enclosingParameter = outerParameter; 2104 _enclosingParameter = outerParameter;
2170 } 2105 }
2171 } else { 2106 } else {}
2172 }
2173 return super.visitSimpleFormalParameter(node); 2107 return super.visitSimpleFormalParameter(node);
2174 } 2108 }
2175 2109
2176 @override 2110 @override
2177 Object visitSwitchCase(SwitchCase node) { 2111 Object visitSwitchCase(SwitchCase node) {
2178 for (Label label in node.labels) { 2112 for (Label label in node.labels) {
2179 SimpleIdentifier labelName = label.label; 2113 SimpleIdentifier labelName = label.label;
2180 _findIdentifier(_enclosingExecutable.labels, labelName); 2114 _findIdentifier(_enclosingExecutable.labels, labelName);
2181 } 2115 }
2182 return super.visitSwitchCase(node); 2116 return super.visitSwitchCase(node);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 /** 2214 /**
2281 * Return the import element from the given array whose library has the given source and that has 2215 * Return the import element from the given array whose library has the given source and that has
2282 * the given prefix, or `null` if there is no such import. 2216 * the given prefix, or `null` if there is no such import.
2283 * 2217 *
2284 * @param imports the import elements being searched 2218 * @param imports the import elements being searched
2285 * @param source the source of the library associated with the import element to being searched 2219 * @param source the source of the library associated with the import element to being searched
2286 * for 2220 * for
2287 * @param prefix the prefix with which the library was imported 2221 * @param prefix the prefix with which the library was imported
2288 * @return the import element whose library has the given source and prefix 2222 * @return the import element whose library has the given source and prefix
2289 */ 2223 */
2290 ImportElement _findImport(List<ImportElement> imports, Source source, 2224 ImportElement _findImport(
2291 SimpleIdentifier prefix) { 2225 List<ImportElement> imports, Source source, SimpleIdentifier prefix) {
2292 for (ImportElement element in imports) { 2226 for (ImportElement element in imports) {
2293 if (element.importedLibrary.source == source) { 2227 if (element.importedLibrary.source == source) {
2294 PrefixElement prefixElement = element.prefix; 2228 PrefixElement prefixElement = element.prefix;
2295 if (prefix == null) { 2229 if (prefix == null) {
2296 if (prefixElement == null) { 2230 if (prefixElement == null) {
2297 return element; 2231 return element;
2298 } 2232 }
2299 } else { 2233 } else {
2300 if (prefixElement != null && 2234 if (prefixElement != null &&
2301 prefix.name == prefixElement.displayName) { 2235 prefix.name == prefixElement.displayName) {
2302 return element; 2236 return element;
2303 } 2237 }
2304 } 2238 }
2305 } 2239 }
2306 } 2240 }
2307 return null; 2241 return null;
2308 } 2242 }
2309 2243
2310 /** 2244 /**
2311 * Return the element for the part with the given source, or `null` if there i s no element 2245 * Return the element for the part with the given source, or `null` if there i s no element
2312 * for the given source. 2246 * for the given source.
2313 * 2247 *
2314 * @param parts the elements for the parts 2248 * @param parts the elements for the parts
2315 * @param partSource the source for the part whose element is to be returned 2249 * @param partSource the source for the part whose element is to be returned
2316 * @return the element for the part with the given source 2250 * @return the element for the part with the given source
2317 */ 2251 */
2318 CompilationUnitElement _findPart(List<CompilationUnitElement> parts, 2252 CompilationUnitElement _findPart(
2319 Source partSource) { 2253 List<CompilationUnitElement> parts, Source partSource) {
2320 for (CompilationUnitElement part in parts) { 2254 for (CompilationUnitElement part in parts) {
2321 if (part.source == partSource) { 2255 if (part.source == partSource) {
2322 return part; 2256 return part;
2323 } 2257 }
2324 } 2258 }
2325 return null; 2259 return null;
2326 } 2260 }
2327 2261
2328 /** 2262 /**
2329 * Return the element in the given array of elements that was created for the declaration with the 2263 * Return the element in the given array of elements that was created for the declaration with the
2330 * given name at the given offset. 2264 * given name at the given offset.
2331 * 2265 *
2332 * @param elements the elements of the appropriate kind that exist in the curr ent context 2266 * @param elements the elements of the appropriate kind that exist in the curr ent context
2333 * @param name the name of the element to be returned 2267 * @param name the name of the element to be returned
2334 * @param offset the offset of the name of the element to be returned 2268 * @param offset the offset of the name of the element to be returned
2335 * @return the element with the given name and offset 2269 * @return the element with the given name and offset
2336 */ 2270 */
2337 Element _findWithNameAndOffset(List<Element> elements, String name, 2271 Element _findWithNameAndOffset(
2338 int offset) { 2272 List<Element> elements, String name, int offset) {
2339 for (Element element in elements) { 2273 for (Element element in elements) {
2340 if (element.displayName == name && element.nameOffset == offset) { 2274 if (element.displayName == name && element.nameOffset == offset) {
2341 return element; 2275 return element;
2342 } 2276 }
2343 } 2277 }
2344 return null; 2278 return null;
2345 } 2279 }
2346 2280
2347 /** 2281 /**
2348 * Search the most closely enclosing list of parameters for a parameter with t he given name. 2282 * Search the most closely enclosing list of parameters for a parameter with t he given name.
2349 * 2283 *
2350 * @param node the node defining the parameter with the given name 2284 * @param node the node defining the parameter with the given name
2351 * @param parameterName the name of the parameter being searched for 2285 * @param parameterName the name of the parameter being searched for
2352 * @return the element representing the parameter with that name 2286 * @return the element representing the parameter with that name
2353 */ 2287 */
2354 ParameterElement _getElementForParameter(FormalParameter node, 2288 ParameterElement _getElementForParameter(
2355 SimpleIdentifier parameterName) { 2289 FormalParameter node, SimpleIdentifier parameterName) {
2356 List<ParameterElement> parameters = null; 2290 List<ParameterElement> parameters = null;
2357 if (_enclosingParameter != null) { 2291 if (_enclosingParameter != null) {
2358 parameters = _enclosingParameter.parameters; 2292 parameters = _enclosingParameter.parameters;
2359 } 2293 }
2360 if (parameters == null && _enclosingExecutable != null) { 2294 if (parameters == null && _enclosingExecutable != null) {
2361 parameters = _enclosingExecutable.parameters; 2295 parameters = _enclosingExecutable.parameters;
2362 } 2296 }
2363 if (parameters == null && _enclosingAlias != null) { 2297 if (parameters == null && _enclosingAlias != null) {
2364 parameters = _enclosingAlias.parameters; 2298 parameters = _enclosingAlias.parameters;
2365 } 2299 }
2366 ParameterElement element = 2300 ParameterElement element =
2367 parameters == null ? null : _findIdentifier(parameters, parameterName); 2301 parameters == null ? null : _findIdentifier(parameters, parameterName);
2368 if (element == null) { 2302 if (element == null) {
2369 StringBuffer buffer = new StringBuffer(); 2303 StringBuffer buffer = new StringBuffer();
2370 buffer.writeln("Invalid state found in the Analysis Engine:"); 2304 buffer.writeln("Invalid state found in the Analysis Engine:");
2371 buffer.writeln( 2305 buffer.writeln(
2372 "DeclarationResolver.getElementForParameter() is visiting a parameter that does not appear to be in a method or function."); 2306 "DeclarationResolver.getElementForParameter() is visiting a parameter that does not appear to be in a method or function.");
2373 buffer.writeln("Ancestors:"); 2307 buffer.writeln("Ancestors:");
2374 AstNode parent = node.parent; 2308 AstNode parent = node.parent;
2375 while (parent != null) { 2309 while (parent != null) {
2376 buffer.writeln(parent.runtimeType.toString()); 2310 buffer.writeln(parent.runtimeType.toString());
2377 buffer.writeln("---------"); 2311 buffer.writeln("---------");
2378 parent = parent.parent; 2312 parent = parent.parent;
2379 } 2313 }
2380 AnalysisEngine.instance.logger.logError( 2314 AnalysisEngine.instance.logger.logError(buffer.toString(),
2381 buffer.toString(),
2382 new CaughtException(new AnalysisException(), null)); 2315 new CaughtException(new AnalysisException(), null));
2383 } 2316 }
2384 return element; 2317 return element;
2385 } 2318 }
2386 2319
2387 /** 2320 /**
2388 * Return the value of the given string literal, or `null` if the string is no t a constant 2321 * Return the value of the given string literal, or `null` if the string is no t a constant
2389 * string without any string interpolation. 2322 * string without any string interpolation.
2390 * 2323 *
2391 * @param literal the string literal whose value is to be returned 2324 * @param literal the string literal whose value is to be returned
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 _currentHolder.addFunction(element); 2703 _currentHolder.addFunction(element);
2771 expression.element = element; 2704 expression.element = element;
2772 functionName.staticElement = element; 2705 functionName.staticElement = element;
2773 } else { 2706 } else {
2774 SimpleIdentifier propertyNameNode = node.name; 2707 SimpleIdentifier propertyNameNode = node.name;
2775 if (propertyNameNode == null) { 2708 if (propertyNameNode == null) {
2776 // TODO(brianwilkerson) Report this internal error. 2709 // TODO(brianwilkerson) Report this internal error.
2777 return null; 2710 return null;
2778 } 2711 }
2779 String propertyName = propertyNameNode.name; 2712 String propertyName = propertyNameNode.name;
2780 TopLevelVariableElementImpl variable = 2713 TopLevelVariableElementImpl variable = _currentHolder
2781 _currentHolder.getTopLevelVariable(propertyName) as TopLevelVariable ElementImpl; 2714 .getTopLevelVariable(propertyName) as TopLevelVariableElementImpl;
2782 if (variable == null) { 2715 if (variable == null) {
2783 variable = new TopLevelVariableElementImpl(node.name.name, -1); 2716 variable = new TopLevelVariableElementImpl(node.name.name, -1);
2784 variable.final2 = true; 2717 variable.final2 = true;
2785 variable.synthetic = true; 2718 variable.synthetic = true;
2786 _currentHolder.addTopLevelVariable(variable); 2719 _currentHolder.addTopLevelVariable(variable);
2787 } 2720 }
2788 if (node.isGetter) { 2721 if (node.isGetter) {
2789 PropertyAccessorElementImpl getter = 2722 PropertyAccessorElementImpl getter =
2790 new PropertyAccessorElementImpl.forNode(propertyNameNode); 2723 new PropertyAccessorElementImpl.forNode(propertyNameNode);
2791 getter.functions = holder.functions; 2724 getter.functions = holder.functions;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
3025 if (node.name.staticElement == null) { 2958 if (node.name.staticElement == null) {
3026 ClassDeclaration classNode = 2959 ClassDeclaration classNode =
3027 node.getAncestor((node) => node is ClassDeclaration); 2960 node.getAncestor((node) => node is ClassDeclaration);
3028 StringBuffer buffer = new StringBuffer(); 2961 StringBuffer buffer = new StringBuffer();
3029 buffer.write("The element for the method "); 2962 buffer.write("The element for the method ");
3030 buffer.write(node.name); 2963 buffer.write(node.name);
3031 buffer.write(" in "); 2964 buffer.write(" in ");
3032 buffer.write(classNode.name); 2965 buffer.write(classNode.name);
3033 buffer.write(" was not set while trying to build the element model."); 2966 buffer.write(" was not set while trying to build the element model.");
3034 AnalysisEngine.instance.logger.logError( 2967 AnalysisEngine.instance.logger.logError(
3035 buffer.toString(), 2968 buffer.toString(), new CaughtException(exception, stackTrace));
3036 new CaughtException(exception, stackTrace));
3037 } else { 2969 } else {
3038 String message = 2970 String message =
3039 "Exception caught in ElementBuilder.visitMethodDeclaration()"; 2971 "Exception caught in ElementBuilder.visitMethodDeclaration()";
3040 AnalysisEngine.instance.logger.logError( 2972 AnalysisEngine.instance.logger.logError(
3041 message, 2973 message, new CaughtException(exception, stackTrace));
3042 new CaughtException(exception, stackTrace));
3043 } 2974 }
3044 } finally { 2975 } finally {
3045 if (node.name.staticElement == null) { 2976 if (node.name.staticElement == null) {
3046 ClassDeclaration classNode = 2977 ClassDeclaration classNode =
3047 node.getAncestor((node) => node is ClassDeclaration); 2978 node.getAncestor((node) => node is ClassDeclaration);
3048 StringBuffer buffer = new StringBuffer(); 2979 StringBuffer buffer = new StringBuffer();
3049 buffer.write("The element for the method "); 2980 buffer.write("The element for the method ");
3050 buffer.write(node.name); 2981 buffer.write(node.name);
3051 buffer.write(" in "); 2982 buffer.write(" in ");
3052 buffer.write(classNode.name); 2983 buffer.write(classNode.name);
3053 buffer.write(" was not set while trying to resolve types."); 2984 buffer.write(" was not set while trying to resolve types.");
3054 AnalysisEngine.instance.logger.logError( 2985 AnalysisEngine.instance.logger.logError(buffer.toString(),
3055 buffer.toString(), 2986 new CaughtException(
3056 new CaughtException(new AnalysisException(buffer.toString()), null)) ; 2987 new AnalysisException(buffer.toString()), null));
3057 } 2988 }
3058 } 2989 }
3059 return null; 2990 return null;
3060 } 2991 }
3061 2992
3062 @override 2993 @override
3063 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 2994 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
3064 if (node.parent is! DefaultFormalParameter) { 2995 if (node.parent is! DefaultFormalParameter) {
3065 SimpleIdentifier parameterName = node.identifier; 2996 SimpleIdentifier parameterName = node.identifier;
3066 ParameterElementImpl parameter = 2997 ParameterElementImpl parameter =
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3224 _fieldMap[field.name] = field; 3155 _fieldMap[field.name] = field;
3225 } 3156 }
3226 } 3157 }
3227 3158
3228 /** 3159 /**
3229 * Creates the [ConstructorElement]s array with the single default constructor element. 3160 * Creates the [ConstructorElement]s array with the single default constructor element.
3230 * 3161 *
3231 * @param interfaceType the interface type for which to create a default const ructor 3162 * @param interfaceType the interface type for which to create a default const ructor
3232 * @return the [ConstructorElement]s array with the single default constructor element 3163 * @return the [ConstructorElement]s array with the single default constructor element
3233 */ 3164 */
3234 List<ConstructorElement> 3165 List<ConstructorElement> _createDefaultConstructors(
3235 _createDefaultConstructors(InterfaceTypeImpl interfaceType) { 3166 InterfaceTypeImpl interfaceType) {
3236 ConstructorElementImpl constructor = 3167 ConstructorElementImpl constructor =
3237 new ConstructorElementImpl.forNode(null); 3168 new ConstructorElementImpl.forNode(null);
3238 constructor.synthetic = true; 3169 constructor.synthetic = true;
3239 constructor.returnType = interfaceType; 3170 constructor.returnType = interfaceType;
3240 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); 3171 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor);
3241 _functionTypesToFix.add(type); 3172 _functionTypesToFix.add(type);
3242 constructor.type = type; 3173 constructor.type = type;
3243 return <ConstructorElement>[constructor]; 3174 return <ConstructorElement>[constructor];
3244 } 3175 }
3245 3176
3246 /** 3177 /**
3247 * Create the types associated with the given type parameters, setting the typ e of each type 3178 * Create the types associated with the given type parameters, setting the typ e of each type
3248 * parameter, and return an array of types corresponding to the given paramete rs. 3179 * parameter, and return an array of types corresponding to the given paramete rs.
3249 * 3180 *
3250 * @param typeParameters the type parameters for which types are to be created 3181 * @param typeParameters the type parameters for which types are to be created
3251 * @return an array of types corresponding to the given parameters 3182 * @return an array of types corresponding to the given parameters
3252 */ 3183 */
3253 List<DartType> 3184 List<DartType> _createTypeParameterTypes(
3254 _createTypeParameterTypes(List<TypeParameterElement> typeParameters) { 3185 List<TypeParameterElement> typeParameters) {
3255 int typeParameterCount = typeParameters.length; 3186 int typeParameterCount = typeParameters.length;
3256 List<DartType> typeArguments = new List<DartType>(typeParameterCount); 3187 List<DartType> typeArguments = new List<DartType>(typeParameterCount);
3257 for (int i = 0; i < typeParameterCount; i++) { 3188 for (int i = 0; i < typeParameterCount; i++) {
3258 TypeParameterElementImpl typeParameter = 3189 TypeParameterElementImpl typeParameter =
3259 typeParameters[i] as TypeParameterElementImpl; 3190 typeParameters[i] as TypeParameterElementImpl;
3260 TypeParameterTypeImpl typeParameterType = 3191 TypeParameterTypeImpl typeParameterType =
3261 new TypeParameterTypeImpl(typeParameter); 3192 new TypeParameterTypeImpl(typeParameter);
3262 typeParameter.type = typeParameterType; 3193 typeParameter.type = typeParameterType;
3263 typeArguments[i] = typeParameterType; 3194 typeArguments[i] = typeParameterType;
3264 } 3195 }
(...skipping 18 matching lines...) Expand all
3283 return (parent as MethodDeclaration).body; 3214 return (parent as MethodDeclaration).body;
3284 } 3215 }
3285 parent = parent.parent; 3216 parent = parent.parent;
3286 } 3217 }
3287 return null; 3218 return null;
3288 } 3219 }
3289 3220
3290 /** 3221 /**
3291 * Sets the visible source range for formal parameter. 3222 * Sets the visible source range for formal parameter.
3292 */ 3223 */
3293 void _setParameterVisibleRange(FormalParameter node, 3224 void _setParameterVisibleRange(
3294 ParameterElementImpl element) { 3225 FormalParameter node, ParameterElementImpl element) {
3295 FunctionBody body = _getFunctionBody(node); 3226 FunctionBody body = _getFunctionBody(node);
3296 if (body != null) { 3227 if (body != null) {
3297 element.setVisibleRange(body.offset, body.length); 3228 element.setVisibleRange(body.offset, body.length);
3298 } 3229 }
3299 } 3230 }
3300 3231
3301 /** 3232 /**
3302 * Make the given holder be the current holder while visiting the given node. 3233 * Make the given holder be the current holder while visiting the given node.
3303 * 3234 *
3304 * @param holder the holder that will gather elements that are built while vis iting the children 3235 * @param holder the holder that will gather elements that are built while vis iting the children
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
3683 buffer.write(" type aliases"); 3614 buffer.write(" type aliases");
3684 } 3615 }
3685 if (_typeParameters != null) { 3616 if (_typeParameters != null) {
3686 if (buffer.length > 0) { 3617 if (buffer.length > 0) {
3687 buffer.write("; "); 3618 buffer.write("; ");
3688 } 3619 }
3689 buffer.write(_typeParameters.length); 3620 buffer.write(_typeParameters.length);
3690 buffer.write(" type parameters"); 3621 buffer.write(" type parameters");
3691 } 3622 }
3692 if (buffer.length > 0) { 3623 if (buffer.length > 0) {
3693 AnalysisEngine.instance.logger.logError( 3624 AnalysisEngine.instance.logger
3694 "Failed to capture elements: $buffer"); 3625 .logError("Failed to capture elements: $buffer");
3695 } 3626 }
3696 } 3627 }
3697 } 3628 }
3698 3629
3699 /** 3630 /**
3700 * Instances of the class `EnclosedScope` implement a scope that is lexically en closed in 3631 * Instances of the class `EnclosedScope` implement a scope that is lexically en closed in
3701 * another scope. 3632 * another scope.
3702 */ 3633 */
3703 class EnclosedScope extends Scope { 3634 class EnclosedScope extends Scope {
3704 /** 3635 /**
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3739 if (element != null) { 3670 if (element != null) {
3740 String name = element.name; 3671 String name = element.name;
3741 if (name != null && !name.isEmpty) { 3672 if (name != null && !name.isEmpty) {
3742 _hiddenElements[name] = element; 3673 _hiddenElements[name] = element;
3743 _hasHiddenName = true; 3674 _hasHiddenName = true;
3744 } 3675 }
3745 } 3676 }
3746 } 3677 }
3747 3678
3748 @override 3679 @override
3749 Element internalLookup(Identifier identifier, String name, 3680 Element internalLookup(
3750 LibraryElement referencingLibrary) { 3681 Identifier identifier, String name, LibraryElement referencingLibrary) {
3751 Element element = localLookup(name, referencingLibrary); 3682 Element element = localLookup(name, referencingLibrary);
3752 if (element != null) { 3683 if (element != null) {
3753 return element; 3684 return element;
3754 } 3685 }
3755 // May be there is a hidden Element. 3686 // May be there is a hidden Element.
3756 if (_hasHiddenName) { 3687 if (_hasHiddenName) {
3757 Element hiddenElement = _hiddenElements[name]; 3688 Element hiddenElement = _hiddenElements[name];
3758 if (hiddenElement != null) { 3689 if (hiddenElement != null) {
3759 errorListener.onError( 3690 errorListener.onError(new AnalysisError.con2(getSource(identifier),
3760 new AnalysisError.con2( 3691 identifier.offset, identifier.length,
3761 getSource(identifier), 3692 CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, []));
3762 identifier.offset,
3763 identifier.length,
3764 CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION,
3765 []));
3766 return hiddenElement; 3693 return hiddenElement;
3767 } 3694 }
3768 } 3695 }
3769 // Check enclosing scope. 3696 // Check enclosing scope.
3770 return enclosingScope.internalLookup(identifier, name, referencingLibrary); 3697 return enclosingScope.internalLookup(identifier, name, referencingLibrary);
3771 } 3698 }
3772 } 3699 }
3773 3700
3774 /** 3701 /**
3775 * Instances of the class `EnumMemberBuilder` build the members in enum declarat ions. 3702 * Instances of the class `EnumMemberBuilder` build the members in enum declarat ions.
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
4025 Expression conditionExpression = node.condition; 3952 Expression conditionExpression = node.condition;
4026 if (conditionExpression != null && _nodeExits(conditionExpression)) { 3953 if (conditionExpression != null && _nodeExits(conditionExpression)) {
4027 return true; 3954 return true;
4028 } 3955 }
4029 if (_visitExpressions(node.updaters)) { 3956 if (_visitExpressions(node.updaters)) {
4030 return true; 3957 return true;
4031 } 3958 }
4032 // TODO(jwren) Do we want to take all constant expressions into account? 3959 // TODO(jwren) Do we want to take all constant expressions into account?
4033 // If for(; true; ) (or for(;;)), and the body doesn't return or the body 3960 // If for(; true; ) (or for(;;)), and the body doesn't return or the body
4034 // doesn't have a break, then return true. 3961 // doesn't have a break, then return true.
4035 bool implicitOrExplictTrue = 3962 bool implicitOrExplictTrue = conditionExpression == null ||
4036 conditionExpression == null ||
4037 (conditionExpression is BooleanLiteral && conditionExpression.value); 3963 (conditionExpression is BooleanLiteral && conditionExpression.value);
4038 if (implicitOrExplictTrue) { 3964 if (implicitOrExplictTrue) {
4039 bool blockReturns = _nodeExits(node.body); 3965 bool blockReturns = _nodeExits(node.body);
4040 if (blockReturns || !_enclosingBlockContainsBreak) { 3966 if (blockReturns || !_enclosingBlockContainsBreak) {
4041 return true; 3967 return true;
4042 } 3968 }
4043 } 3969 }
4044 return false; 3970 return false;
4045 } finally { 3971 } finally {
4046 _enclosingBlockContainsBreak = outerBreakValue; 3972 _enclosingBlockContainsBreak = outerBreakValue;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4304 4230
4305 bool _visitStatements(NodeList<Statement> statements) { 4231 bool _visitStatements(NodeList<Statement> statements) {
4306 for (int i = statements.length - 1; i >= 0; i--) { 4232 for (int i = statements.length - 1; i >= 0; i--) {
4307 if (statements[i].accept(this)) { 4233 if (statements[i].accept(this)) {
4308 return true; 4234 return true;
4309 } 4235 }
4310 } 4236 }
4311 return false; 4237 return false;
4312 } 4238 }
4313 4239
4314 bool 4240 bool _visitVariableDeclarations(
4315 _visitVariableDeclarations(NodeList<VariableDeclaration> variableDeclarati ons) { 4241 NodeList<VariableDeclaration> variableDeclarations) {
4316 for (int i = variableDeclarations.length - 1; i >= 0; i--) { 4242 for (int i = variableDeclarations.length - 1; i >= 0; i--) {
4317 if (variableDeclarations[i].accept(this)) { 4243 if (variableDeclarations[i].accept(this)) {
4318 return true; 4244 return true;
4319 } 4245 }
4320 } 4246 }
4321 return false; 4247 return false;
4322 } 4248 }
4323 4249
4324 /** 4250 /**
4325 * Return `true` if the given [node] exits. 4251 * Return `true` if the given [node] exits.
4326 */ 4252 */
4327 static bool exits(AstNode node) { 4253 static bool exits(AstNode node) {
4328 return new ExitDetector()._nodeExits(node); 4254 return new ExitDetector()._nodeExits(node);
4329 } 4255 }
4330 } 4256 }
4331 4257
4332
4333 /** 4258 /**
4334 * Instances of the class `FunctionScope` implement the scope defined by a funct ion. 4259 * Instances of the class `FunctionScope` implement the scope defined by a funct ion.
4335 */ 4260 */
4336 class FunctionScope extends EnclosedScope { 4261 class FunctionScope extends EnclosedScope {
4337 final ExecutableElement _functionElement; 4262 final ExecutableElement _functionElement;
4338 4263
4339 bool _parametersDefined = false; 4264 bool _parametersDefined = false;
4340 4265
4341 /** 4266 /**
4342 * Initialize a newly created scope enclosed within another scope. 4267 * Initialize a newly created scope enclosed within another scope.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
4457 if (element != null) { 4382 if (element != null) {
4458 if (i == 0) { 4383 if (i == 0) {
4459 _importsVerifier.inDefiningCompilationUnit = true; 4384 _importsVerifier.inDefiningCompilationUnit = true;
4460 _generateForCompilationUnit(_compilationUnits[i], element.source); 4385 _generateForCompilationUnit(_compilationUnits[i], element.source);
4461 _importsVerifier.inDefiningCompilationUnit = false; 4386 _importsVerifier.inDefiningCompilationUnit = false;
4462 } else { 4387 } else {
4463 _generateForCompilationUnit(_compilationUnits[i], element.source); 4388 _generateForCompilationUnit(_compilationUnits[i], element.source);
4464 } 4389 }
4465 } 4390 }
4466 } 4391 }
4467 ErrorReporter definingCompilationUnitErrorReporter = 4392 ErrorReporter definingCompilationUnitErrorReporter = new ErrorReporter(
4468 new ErrorReporter(_errorListener, _compilationUnits[0].element.source) ; 4393 _errorListener, _compilationUnits[0].element.source);
4469 _importsVerifier.generateDuplicateImportHints( 4394 _importsVerifier
4470 definingCompilationUnitErrorReporter); 4395 .generateDuplicateImportHints(definingCompilationUnitErrorReporter);
4471 _importsVerifier.generateUnusedImportHints( 4396 _importsVerifier
4472 definingCompilationUnitErrorReporter); 4397 .generateUnusedImportHints(definingCompilationUnitErrorReporter);
4473 _library.accept( 4398 _library.accept(new _UnusedElementsVerifier(
4474 new _UnusedElementsVerifier(_errorListener, _usedElementsVisitor.usedE lements)); 4399 _errorListener, _usedElementsVisitor.usedElements));
4475 }); 4400 });
4476 } 4401 }
4477 4402
4478 void _generateForCompilationUnit(CompilationUnit unit, Source source) { 4403 void _generateForCompilationUnit(CompilationUnit unit, Source source) {
4479 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 4404 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
4480 unit.accept(_importsVerifier); 4405 unit.accept(_importsVerifier);
4481 // dead code analysis 4406 // dead code analysis
4482 unit.accept(new DeadCodeVerifier(errorReporter)); 4407 unit.accept(new DeadCodeVerifier(errorReporter));
4483 unit.accept(_usedElementsVisitor); 4408 unit.accept(_usedElementsVisitor);
4484 // dart2js analysis 4409 // dart2js analysis
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
4614 visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) { 4539 visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) {
4615 visitXmlTagNode(node); 4540 visitXmlTagNode(node);
4616 } 4541 }
4617 4542
4618 @override 4543 @override
4619 visitHtmlUnit(ht.HtmlUnit node) { 4544 visitHtmlUnit(ht.HtmlUnit node) {
4620 node.visitChildren(this); 4545 node.visitChildren(this);
4621 } 4546 }
4622 4547
4623 @override 4548 @override
4624 visitXmlAttributeNode(ht.XmlAttributeNode node) { 4549 visitXmlAttributeNode(ht.XmlAttributeNode node) {}
4625 }
4626 4550
4627 @override 4551 @override
4628 visitXmlTagNode(ht.XmlTagNode node) { 4552 visitXmlTagNode(ht.XmlTagNode node) {
4629 node.visitChildren(this); 4553 node.visitChildren(this);
4630 String tagName = node.tag; 4554 String tagName = node.tag;
4631 tagSet.add(tagName); 4555 tagSet.add(tagName);
4632 for (ht.XmlAttributeNode attribute in node.attributes) { 4556 for (ht.XmlAttributeNode attribute in node.attributes) {
4633 String attributeName = attribute.name; 4557 String attributeName = attribute.name;
4634 if (attributeName == ID_ATTRIBUTE) { 4558 if (attributeName == ID_ATTRIBUTE) {
4635 String attributeValue = attribute.text; 4559 String attributeValue = attribute.text;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
4806 if (scriptSourcePath != null) { 4730 if (scriptSourcePath != null) {
4807 try { 4731 try {
4808 scriptSourcePath = Uri.encodeFull(scriptSourcePath); 4732 scriptSourcePath = Uri.encodeFull(scriptSourcePath);
4809 // Force an exception to be thrown if the URI is invalid so that we 4733 // Force an exception to be thrown if the URI is invalid so that we
4810 // can report the problem. 4734 // can report the problem.
4811 parseUriWithException(scriptSourcePath); 4735 parseUriWithException(scriptSourcePath);
4812 Source scriptSource = 4736 Source scriptSource =
4813 _context.sourceFactory.resolveUri(htmlSource, scriptSourcePath); 4737 _context.sourceFactory.resolveUri(htmlSource, scriptSourcePath);
4814 script.scriptSource = scriptSource; 4738 script.scriptSource = scriptSource;
4815 if (!_context.exists(scriptSource)) { 4739 if (!_context.exists(scriptSource)) {
4816 _reportValueError( 4740 _reportValueError(HtmlWarningCode.URI_DOES_NOT_EXIST,
4817 HtmlWarningCode.URI_DOES_NOT_EXIST, 4741 scriptAttribute, [scriptSourcePath]);
4818 scriptAttribute,
4819 [scriptSourcePath]);
4820 } 4742 }
4821 } on URISyntaxException catch (exception) { 4743 } on URISyntaxException catch (exception) {
4822 _reportValueError( 4744 _reportValueError(HtmlWarningCode.INVALID_URI, scriptAttribute, [
4823 HtmlWarningCode.INVALID_URI, 4745 scriptSourcePath
4824 scriptAttribute, 4746 ]);
4825 [scriptSourcePath]);
4826 } 4747 }
4827 } 4748 }
4828 node.scriptElement = script; 4749 node.scriptElement = script;
4829 _scripts.add(script); 4750 _scripts.add(script);
4830 } 4751 }
4831 } finally { 4752 } finally {
4832 _parentNodes.remove(node); 4753 _parentNodes.remove(node);
4833 } 4754 }
4834 return null; 4755 return null;
4835 } 4756 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4910 4831
4911 /** 4832 /**
4912 * Report an error with the given error code at the given location. Use the gi ven arguments to 4833 * Report an error with the given error code at the given location. Use the gi ven arguments to
4913 * compose the error message. 4834 * compose the error message.
4914 * 4835 *
4915 * @param errorCode the error code of the error to be reported 4836 * @param errorCode the error code of the error to be reported
4916 * @param offset the offset of the first character to be highlighted 4837 * @param offset the offset of the first character to be highlighted
4917 * @param length the number of characters to be highlighted 4838 * @param length the number of characters to be highlighted
4918 * @param arguments the arguments used to compose the error message 4839 * @param arguments the arguments used to compose the error message
4919 */ 4840 */
4920 void _reportErrorForOffset(ErrorCode errorCode, int offset, int length, 4841 void _reportErrorForOffset(
4921 List<Object> arguments) { 4842 ErrorCode errorCode, int offset, int length, List<Object> arguments) {
4922 _errorListener.onError( 4843 _errorListener.onError(new AnalysisError.con2(
4923 new AnalysisError.con2( 4844 _htmlElement.source, offset, length, errorCode, arguments));
4924 _htmlElement.source,
4925 offset,
4926 length,
4927 errorCode,
4928 arguments));
4929 } 4845 }
4930 4846
4931 /** 4847 /**
4932 * Report an error with the given error code at the location of the value of t he given attribute. 4848 * Report an error with the given error code at the location of the value of t he given attribute.
4933 * Use the given arguments to compose the error message. 4849 * Use the given arguments to compose the error message.
4934 * 4850 *
4935 * @param errorCode the error code of the error to be reported 4851 * @param errorCode the error code of the error to be reported
4936 * @param offset the offset of the first character to be highlighted 4852 * @param offset the offset of the first character to be highlighted
4937 * @param length the number of characters to be highlighted 4853 * @param length the number of characters to be highlighted
4938 * @param arguments the arguments used to compose the error message 4854 * @param arguments the arguments used to compose the error message
(...skipping 26 matching lines...) Expand all
4965 /** 4881 /**
4966 * Initialize a newly created visitor to build implicit constructors for file 4882 * Initialize a newly created visitor to build implicit constructors for file
4967 * [source], in library [libraryElement], which has scope [libraryScope]. Use 4883 * [source], in library [libraryElement], which has scope [libraryScope]. Use
4968 * [typeProvider] to access types from the core library. 4884 * [typeProvider] to access types from the core library.
4969 * 4885 *
4970 * The visit methods will pass closures to [_callback] to indicate what 4886 * The visit methods will pass closures to [_callback] to indicate what
4971 * computation needs to be performed, and its dependency order. 4887 * computation needs to be performed, and its dependency order.
4972 */ 4888 */
4973 ImplicitConstructorBuilder(Source source, LibraryElement libraryElement, 4889 ImplicitConstructorBuilder(Source source, LibraryElement libraryElement,
4974 LibraryScope libraryScope, TypeProvider typeProvider, this._callback) 4890 LibraryScope libraryScope, TypeProvider typeProvider, this._callback)
4975 : super.con3( 4891 : super.con3(libraryElement, source, typeProvider, libraryScope,
4976 libraryElement,
4977 source,
4978 typeProvider,
4979 libraryScope,
4980 libraryScope.errorListener); 4892 libraryScope.errorListener);
4981 4893
4982 @override 4894 @override
4983 Object visitClassDeclaration(ClassDeclaration node) { 4895 Object visitClassDeclaration(ClassDeclaration node) {
4984 ClassElementImpl classElement = node.element; 4896 ClassElementImpl classElement = node.element;
4985 classElement.mixinErrorsReported = false; 4897 classElement.mixinErrorsReported = false;
4986 if (node.extendsClause != null && node.withClause != null) { 4898 if (node.extendsClause != null && node.withClause != null) {
4987 // We don't need to build any implicitly constructors for the mixin 4899 // We don't need to build any implicitly constructors for the mixin
4988 // application (since there isn't an explicit element for it), but we 4900 // application (since there isn't an explicit element for it), but we
4989 // need to verify that they _could_ be built. 4901 // need to verify that they _could_ be built.
4990 InterfaceType superclassType = null; 4902 InterfaceType superclassType = null;
4991 TypeName superclassName = node.extendsClause.superclass; 4903 TypeName superclassName = node.extendsClause.superclass;
4992 DartType type = superclassName.type; 4904 DartType type = superclassName.type;
4993 if (type is InterfaceType) { 4905 if (type is InterfaceType) {
4994 superclassType = type; 4906 superclassType = type;
4995 } else { 4907 } else {
4996 superclassType = typeProvider.objectType; 4908 superclassType = typeProvider.objectType;
4997 } 4909 }
4998 ClassElement superclassElement = classElement.supertype.element; 4910 ClassElement superclassElement = classElement.supertype.element;
4999 if (superclassElement != null) { 4911 if (superclassElement != null) {
5000 _callback(classElement, superclassElement, () { 4912 _callback(classElement, superclassElement, () {
5001 bool constructorFound = false; 4913 bool constructorFound = false;
5002 void callback(ConstructorElement explicitConstructor, 4914 void callback(ConstructorElement explicitConstructor,
5003 List<DartType> parameterTypes, List<DartType> argumentTypes) { 4915 List<DartType> parameterTypes, List<DartType> argumentTypes) {
5004 constructorFound = true; 4916 constructorFound = true;
5005 } 4917 }
5006 if (_findForwardedConstructors( 4918 if (_findForwardedConstructors(
5007 classElement, 4919 classElement, superclassName, superclassType, callback) &&
5008 superclassName,
5009 superclassType,
5010 callback) &&
5011 !constructorFound) { 4920 !constructorFound) {
5012 reportErrorForNode( 4921 reportErrorForNode(CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS,
5013 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, 4922 node.withClause, [superclassType.element.name]);
5014 node.withClause,
5015 [superclassType.element.name]);
5016 classElement.mixinErrorsReported = true; 4923 classElement.mixinErrorsReported = true;
5017 } 4924 }
5018 }); 4925 });
5019 } 4926 }
5020 } 4927 }
5021 return null; 4928 return null;
5022 } 4929 }
5023 4930
5024 @override 4931 @override
5025 Object visitClassTypeAlias(ClassTypeAlias node) { 4932 Object visitClassTypeAlias(ClassTypeAlias node) {
5026 super.visitClassTypeAlias(node); 4933 super.visitClassTypeAlias(node);
5027 InterfaceType superclassType = null; 4934 InterfaceType superclassType = null;
5028 TypeName superclassName = node.superclass; 4935 TypeName superclassName = node.superclass;
5029 DartType type = superclassName.type; 4936 DartType type = superclassName.type;
5030 if (type is InterfaceType) { 4937 if (type is InterfaceType) {
5031 superclassType = type; 4938 superclassType = type;
5032 } else { 4939 } else {
5033 superclassType = typeProvider.objectType; 4940 superclassType = typeProvider.objectType;
5034 } 4941 }
5035 ClassElementImpl classElement = node.element as ClassElementImpl; 4942 ClassElementImpl classElement = node.element as ClassElementImpl;
5036 if (classElement != null) { 4943 if (classElement != null) {
5037 ClassElement superclassElement = superclassType.element; 4944 ClassElement superclassElement = superclassType.element;
5038 if (superclassElement != null) { 4945 if (superclassElement != null) {
5039 _callback(classElement, superclassElement, () { 4946 _callback(classElement, superclassElement, () {
5040 List<ConstructorElement> implicitConstructors = 4947 List<ConstructorElement> implicitConstructors =
5041 new List<ConstructorElement>(); 4948 new List<ConstructorElement>();
5042 void callback(ConstructorElement explicitConstructor, 4949 void callback(ConstructorElement explicitConstructor,
5043 List<DartType> parameterTypes, List<DartType> argumentTypes) { 4950 List<DartType> parameterTypes, List<DartType> argumentTypes) {
5044 implicitConstructors.add( 4951 implicitConstructors.add(_createImplicitContructor(
5045 _createImplicitContructor( 4952 classElement.type, explicitConstructor, parameterTypes,
5046 classElement.type, 4953 argumentTypes));
5047 explicitConstructor,
5048 parameterTypes,
5049 argumentTypes));
5050 } 4954 }
5051 if (_findForwardedConstructors( 4955 if (_findForwardedConstructors(
5052 classElement, 4956 classElement, superclassName, superclassType, callback)) {
5053 superclassName,
5054 superclassType,
5055 callback)) {
5056 if (implicitConstructors.isEmpty) { 4957 if (implicitConstructors.isEmpty) {
5057 reportErrorForNode( 4958 reportErrorForNode(CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS,
5058 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, 4959 node, [superclassElement.name]);
5059 node,
5060 [superclassElement.name]);
5061 } else { 4960 } else {
5062 classElement.constructors = implicitConstructors; 4961 classElement.constructors = implicitConstructors;
5063 } 4962 }
5064 } 4963 }
5065 }); 4964 });
5066 } 4965 }
5067 } 4966 }
5068 return null; 4967 return null;
5069 } 4968 }
5070 4969
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
5126 * Find all the constructors that should be forwarded from the superclass 5025 * Find all the constructors that should be forwarded from the superclass
5127 * named [superclassName], having type [superclassType], to the class or 5026 * named [superclassName], having type [superclassType], to the class or
5128 * mixin application [classElement], and pass information about them to 5027 * mixin application [classElement], and pass information about them to
5129 * [callback]. 5028 * [callback].
5130 * 5029 *
5131 * Return true if some constructors were considered. (A false return value 5030 * Return true if some constructors were considered. (A false return value
5132 * can only happen if the supeclass is a built-in type, in which case it 5031 * can only happen if the supeclass is a built-in type, in which case it
5133 * can't be used as a mixin anyway). 5032 * can't be used as a mixin anyway).
5134 */ 5033 */
5135 bool _findForwardedConstructors(ClassElementImpl classElement, 5034 bool _findForwardedConstructors(ClassElementImpl classElement,
5136 TypeName superclassName, InterfaceType superclassType, void 5035 TypeName superclassName, InterfaceType superclassType, void callback(
5137 callback(ConstructorElement explicitConstructor, List<DartType> parameterT ypes, 5036 ConstructorElement explicitConstructor, List<DartType> parameterTypes,
5138 List<DartType> argumentTypes)) { 5037 List<DartType> argumentTypes)) {
5139 ClassElement superclassElement = superclassType.element; 5038 ClassElement superclassElement = superclassType.element;
5140 List<ConstructorElement> constructors = superclassElement.constructors; 5039 List<ConstructorElement> constructors = superclassElement.constructors;
5141 int count = constructors.length; 5040 int count = constructors.length;
5142 if (count == 0) { 5041 if (count == 0) {
5143 return false; 5042 return false;
5144 } 5043 }
5145 List<DartType> parameterTypes = 5044 List<DartType> parameterTypes =
5146 TypeParameterTypeImpl.getTypes(superclassType.typeParameters); 5045 TypeParameterTypeImpl.getTypes(superclassType.typeParameters);
5147 List<DartType> argumentTypes = 5046 List<DartType> argumentTypes =
5148 _getArgumentTypes(superclassName.typeArguments, parameterTypes); 5047 _getArgumentTypes(superclassName.typeArguments, parameterTypes);
5149 for (int i = 0; i < count; i++) { 5048 for (int i = 0; i < count; i++) {
5150 ConstructorElement explicitConstructor = constructors[i]; 5049 ConstructorElement explicitConstructor = constructors[i];
5151 if (!explicitConstructor.isFactory && 5050 if (!explicitConstructor.isFactory &&
5152 classElement.isSuperConstructorAccessible(explicitConstructor)) { 5051 classElement.isSuperConstructorAccessible(explicitConstructor)) {
5153 callback(explicitConstructor, parameterTypes, argumentTypes); 5052 callback(explicitConstructor, parameterTypes, argumentTypes);
5154 } 5053 }
5155 } 5054 }
5156 return true; 5055 return true;
5157 } 5056 }
5158 5057
5159 /** 5058 /**
5160 * Return an array of argument types that corresponds to the array of paramete r types and that are 5059 * Return an array of argument types that corresponds to the array of paramete r types and that are
5161 * derived from the given list of type arguments. 5060 * derived from the given list of type arguments.
5162 * 5061 *
5163 * @param typeArguments the type arguments from which the types will be taken 5062 * @param typeArguments the type arguments from which the types will be taken
5164 * @param parameterTypes the parameter types that must be matched by the type arguments 5063 * @param parameterTypes the parameter types that must be matched by the type arguments
5165 * @return the argument types that correspond to the parameter types 5064 * @return the argument types that correspond to the parameter types
5166 */ 5065 */
5167 List<DartType> _getArgumentTypes(TypeArgumentList typeArguments, 5066 List<DartType> _getArgumentTypes(
5168 List<DartType> parameterTypes) { 5067 TypeArgumentList typeArguments, List<DartType> parameterTypes) {
5169 DynamicTypeImpl dynamic = DynamicTypeImpl.instance; 5068 DynamicTypeImpl dynamic = DynamicTypeImpl.instance;
5170 int parameterCount = parameterTypes.length; 5069 int parameterCount = parameterTypes.length;
5171 List<DartType> types = new List<DartType>(parameterCount); 5070 List<DartType> types = new List<DartType>(parameterCount);
5172 if (typeArguments == null) { 5071 if (typeArguments == null) {
5173 for (int i = 0; i < parameterCount; i++) { 5072 for (int i = 0; i < parameterCount; i++) {
5174 types[i] = dynamic; 5073 types[i] = dynamic;
5175 } 5074 }
5176 } else { 5075 } else {
5177 NodeList<TypeName> arguments = typeArguments.arguments; 5076 NodeList<TypeName> arguments = typeArguments.arguments;
5178 int argumentCount = math.min(arguments.length, parameterCount); 5077 int argumentCount = math.min(arguments.length, parameterCount);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5219 ImplicitConstructorComputer(this.typeProvider); 5118 ImplicitConstructorComputer(this.typeProvider);
5220 5119
5221 /** 5120 /**
5222 * Add the given [unit] to the list of units which need to have implicit 5121 * Add the given [unit] to the list of units which need to have implicit
5223 * constructors built for them. [source] is the source file corresponding to 5122 * constructors built for them. [source] is the source file corresponding to
5224 * the compilation unit, [libraryElement] is the library element containing 5123 * the compilation unit, [libraryElement] is the library element containing
5225 * that source, and [libraryScope] is the scope for the library element. 5124 * that source, and [libraryScope] is the scope for the library element.
5226 */ 5125 */
5227 void add(CompilationUnit unit, Source source, LibraryElement libraryElement, 5126 void add(CompilationUnit unit, Source source, LibraryElement libraryElement,
5228 LibraryScope libraryScope) { 5127 LibraryScope libraryScope) {
5229 unit.accept( 5128 unit.accept(new ImplicitConstructorBuilder(
5230 new ImplicitConstructorBuilder( 5129 source, libraryElement, libraryScope, typeProvider, _defer));
5231 source,
5232 libraryElement,
5233 libraryScope,
5234 typeProvider,
5235 _defer));
5236 } 5130 }
5237 5131
5238 /** 5132 /**
5239 * Compute the implicit constructors for all compilation units that have been 5133 * Compute the implicit constructors for all compilation units that have been
5240 * passed to [add]. 5134 * passed to [add].
5241 */ 5135 */
5242 void compute() { 5136 void compute() {
5243 List<List<ClassElement>> topologicalSort = 5137 List<List<ClassElement>> topologicalSort =
5244 _dependencies.computeTopologicalSort(); 5138 _dependencies.computeTopologicalSort();
5245 for (List<ClassElement> classesInCycle in topologicalSort) { 5139 for (List<ClassElement> classesInCycle in topologicalSort) {
5246 // Note: a cycle could occur if there is a loop in the inheritance graph. 5140 // Note: a cycle could occur if there is a loop in the inheritance graph.
5247 // Such loops are forbidden by Dart but could occur in the analysis of 5141 // Such loops are forbidden by Dart but could occur in the analysis of
5248 // incorrect code. If this happens, we simply visit the classes 5142 // incorrect code. If this happens, we simply visit the classes
5249 // constituting the loop in any order. 5143 // constituting the loop in any order.
5250 for (ClassElement classElement in classesInCycle) { 5144 for (ClassElement classElement in classesInCycle) {
5251 VoidFunction computation = _computations[classElement]; 5145 VoidFunction computation = _computations[classElement];
5252 if (computation != null) { 5146 if (computation != null) {
5253 computation(); 5147 computation();
5254 } 5148 }
5255 } 5149 }
5256 } 5150 }
5257 } 5151 }
5258 5152
5259 /** 5153 /**
5260 * Defer execution of [computation], which builds implicit constructors for 5154 * Defer execution of [computation], which builds implicit constructors for
5261 * [classElement], until after implicit constructors have been built for 5155 * [classElement], until after implicit constructors have been built for
5262 * [superclassElement]. 5156 * [superclassElement].
5263 */ 5157 */
5264 void _defer(ClassElement classElement, ClassElement superclassElement, void 5158 void _defer(ClassElement classElement, ClassElement superclassElement,
5265 computation()) { 5159 void computation()) {
5266 assert(!_computations.containsKey(classElement)); 5160 assert(!_computations.containsKey(classElement));
5267 _computations[classElement] = computation; 5161 _computations[classElement] = computation;
5268 _dependencies.addEdge(classElement, superclassElement); 5162 _dependencies.addEdge(classElement, superclassElement);
5269 } 5163 }
5270 } 5164 }
5271 5165
5272 /** 5166 /**
5273 * Instances of the class `ImplicitLabelScope` represent the scope statements 5167 * Instances of the class `ImplicitLabelScope` represent the scope statements
5274 * that can be the target of unlabeled break and continue statements. 5168 * that can be the target of unlabeled break and continue statements.
5275 */ 5169 */
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
5414 * Any time after the defining compilation unit has been visited by this visit or, this method can 5308 * Any time after the defining compilation unit has been visited by this visit or, this method can
5415 * be called to report an [HintCode.DUPLICATE_IMPORT] hint for each of the imp ort directives 5309 * be called to report an [HintCode.DUPLICATE_IMPORT] hint for each of the imp ort directives
5416 * in the [duplicateImports] list. 5310 * in the [duplicateImports] list.
5417 * 5311 *
5418 * @param errorReporter the error reporter to report the set of [HintCode.DUPL ICATE_IMPORT] 5312 * @param errorReporter the error reporter to report the set of [HintCode.DUPL ICATE_IMPORT]
5419 * hints to 5313 * hints to
5420 */ 5314 */
5421 void generateDuplicateImportHints(ErrorReporter errorReporter) { 5315 void generateDuplicateImportHints(ErrorReporter errorReporter) {
5422 for (ImportDirective duplicateImport in _duplicateImports) { 5316 for (ImportDirective duplicateImport in _duplicateImports) {
5423 errorReporter.reportErrorForNode( 5317 errorReporter.reportErrorForNode(
5424 HintCode.DUPLICATE_IMPORT, 5318 HintCode.DUPLICATE_IMPORT, duplicateImport.uri);
5425 duplicateImport.uri);
5426 } 5319 }
5427 } 5320 }
5428 5321
5429 /** 5322 /**
5430 * After all of the compilation units have been visited by this visitor, this method can be called 5323 * After all of the compilation units have been visited by this visitor, this method can be called
5431 * to report an [HintCode.UNUSED_IMPORT] hint for each of the import directive s in the 5324 * to report an [HintCode.UNUSED_IMPORT] hint for each of the import directive s in the
5432 * [unusedImports] list. 5325 * [unusedImports] list.
5433 * 5326 *
5434 * @param errorReporter the error reporter to report the set of [HintCode.UNUS ED_IMPORT] 5327 * @param errorReporter the error reporter to report the set of [HintCode.UNUS ED_IMPORT]
5435 * hints to 5328 * hints to
5436 */ 5329 */
5437 void generateUnusedImportHints(ErrorReporter errorReporter) { 5330 void generateUnusedImportHints(ErrorReporter errorReporter) {
5438 for (ImportDirective unusedImport in _unusedImports) { 5331 for (ImportDirective unusedImport in _unusedImports) {
5439 // Check that the import isn't dart:core 5332 // Check that the import isn't dart:core
5440 ImportElement importElement = unusedImport.element; 5333 ImportElement importElement = unusedImport.element;
5441 if (importElement != null) { 5334 if (importElement != null) {
5442 LibraryElement libraryElement = importElement.importedLibrary; 5335 LibraryElement libraryElement = importElement.importedLibrary;
5443 if (libraryElement != null && libraryElement.isDartCore) { 5336 if (libraryElement != null && libraryElement.isDartCore) {
5444 continue; 5337 continue;
5445 } 5338 }
5446 } 5339 }
5447 errorReporter.reportErrorForNode( 5340 errorReporter.reportErrorForNode(
5448 HintCode.UNUSED_IMPORT, 5341 HintCode.UNUSED_IMPORT, unusedImport.uri);
5449 unusedImport.uri);
5450 } 5342 }
5451 } 5343 }
5452 5344
5453 @override 5345 @override
5454 Object visitCompilationUnit(CompilationUnit node) { 5346 Object visitCompilationUnit(CompilationUnit node) {
5455 if (_inDefiningCompilationUnit) { 5347 if (_inDefiningCompilationUnit) {
5456 NodeList<Directive> directives = node.directives; 5348 NodeList<Directive> directives = node.directives;
5457 for (Directive directive in directives) { 5349 for (Directive directive in directives) {
5458 if (directive is ImportDirective) { 5350 if (directive is ImportDirective) {
5459 ImportDirective importDirective = directive; 5351 ImportDirective importDirective = directive;
(...skipping 22 matching lines...) Expand all
5482 } 5374 }
5483 // 5375 //
5484 // Initialize libraryMap: libraryElement -> importDirective 5376 // Initialize libraryMap: libraryElement -> importDirective
5485 // 5377 //
5486 _putIntoLibraryMap(libraryElement, importDirective); 5378 _putIntoLibraryMap(libraryElement, importDirective);
5487 // 5379 //
5488 // For this new addition to the libraryMap, also recursively add any 5380 // For this new addition to the libraryMap, also recursively add any
5489 // exports from the libraryElement. 5381 // exports from the libraryElement.
5490 // 5382 //
5491 _addAdditionalLibrariesForExports( 5383 _addAdditionalLibrariesForExports(
5492 libraryElement, 5384 libraryElement, importDirective, new List<LibraryElement>());
5493 importDirective,
5494 new List<LibraryElement>());
5495 } 5385 }
5496 } 5386 }
5497 } 5387 }
5498 } 5388 }
5499 // If there are no imports in this library, don't visit the identifiers in 5389 // If there are no imports in this library, don't visit the identifiers in
5500 // the library- there can be no unused imports. 5390 // the library- there can be no unused imports.
5501 if (_unusedImports.isEmpty) { 5391 if (_unusedImports.isEmpty) {
5502 return null; 5392 return null;
5503 } 5393 }
5504 if (_unusedImports.length > 1) { 5394 if (_unusedImports.length > 1) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
5581 */ 5471 */
5582 void _addAdditionalLibrariesForExports(LibraryElement library, 5472 void _addAdditionalLibrariesForExports(LibraryElement library,
5583 ImportDirective importDirective, List<LibraryElement> exportPath) { 5473 ImportDirective importDirective, List<LibraryElement> exportPath) {
5584 if (exportPath.contains(library)) { 5474 if (exportPath.contains(library)) {
5585 return; 5475 return;
5586 } 5476 }
5587 exportPath.add(library); 5477 exportPath.add(library);
5588 for (LibraryElement exportedLibraryElt in library.exportedLibraries) { 5478 for (LibraryElement exportedLibraryElt in library.exportedLibraries) {
5589 _putIntoLibraryMap(exportedLibraryElt, importDirective); 5479 _putIntoLibraryMap(exportedLibraryElt, importDirective);
5590 _addAdditionalLibrariesForExports( 5480 _addAdditionalLibrariesForExports(
5591 exportedLibraryElt, 5481 exportedLibraryElt, importDirective, exportPath);
5592 importDirective,
5593 exportPath);
5594 } 5482 }
5595 } 5483 }
5596 5484
5597 /** 5485 /**
5598 * Lookup and return the [Namespace] from the [namespaceMap], if the map does not 5486 * Lookup and return the [Namespace] from the [namespaceMap], if the map does not
5599 * have the computed namespace, compute it and cache it in the map. If the imp ort directive is not 5487 * have the computed namespace, compute it and cache it in the map. If the imp ort directive is not
5600 * resolved or is not resolvable, `null` is returned. 5488 * resolved or is not resolvable, `null` is returned.
5601 * 5489 *
5602 * @param importDirective the import directive used to compute the returned na mespace 5490 * @param importDirective the import directive used to compute the returned na mespace
5603 * @return the computed or looked up [Namespace] 5491 * @return the computed or looked up [Namespace]
(...skipping 12 matching lines...) Expand all
5616 } 5504 }
5617 return namespace; 5505 return namespace;
5618 } 5506 }
5619 5507
5620 /** 5508 /**
5621 * The [libraryMap] is a mapping between a library elements and a list of impo rt 5509 * The [libraryMap] is a mapping between a library elements and a list of impo rt
5622 * directives, but when adding these mappings into the [libraryMap], this meth od can be 5510 * directives, but when adding these mappings into the [libraryMap], this meth od can be
5623 * used to simply add the mapping between the library element an an import dir ective without 5511 * used to simply add the mapping between the library element an an import dir ective without
5624 * needing to check to see if a list needs to be created. 5512 * needing to check to see if a list needs to be created.
5625 */ 5513 */
5626 void _putIntoLibraryMap(LibraryElement libraryElement, 5514 void _putIntoLibraryMap(
5627 ImportDirective importDirective) { 5515 LibraryElement libraryElement, ImportDirective importDirective) {
5628 List<ImportDirective> importList = _libraryMap[libraryElement]; 5516 List<ImportDirective> importList = _libraryMap[libraryElement];
5629 if (importList == null) { 5517 if (importList == null) {
5630 importList = new List<ImportDirective>(); 5518 importList = new List<ImportDirective>();
5631 _libraryMap[libraryElement] = importList; 5519 _libraryMap[libraryElement] = importList;
5632 } 5520 }
5633 importList.add(importDirective); 5521 importList.add(importDirective);
5634 } 5522 }
5635 5523
5636 Object _visitIdentifier(Element element, String name) { 5524 Object _visitIdentifier(Element element, String name) {
5637 if (element == null) { 5525 if (element == null) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
5793 * Given some [ClassElement] and some member name, this returns the 5681 * Given some [ClassElement] and some member name, this returns the
5794 * [ExecutableElement] that the class inherits from the mixins, 5682 * [ExecutableElement] that the class inherits from the mixins,
5795 * superclasses or interfaces, that has the member name, if no member is inher ited `null` is 5683 * superclasses or interfaces, that has the member name, if no member is inher ited `null` is
5796 * returned. 5684 * returned.
5797 * 5685 *
5798 * @param classElt the class element to query 5686 * @param classElt the class element to query
5799 * @param memberName the name of the executable element to find and return 5687 * @param memberName the name of the executable element to find and return
5800 * @return the inherited executable element with the member name, or `null` if no such 5688 * @return the inherited executable element with the member name, or `null` if no such
5801 * member exists 5689 * member exists
5802 */ 5690 */
5803 ExecutableElement lookupInheritance(ClassElement classElt, 5691 ExecutableElement lookupInheritance(
5804 String memberName) { 5692 ClassElement classElt, String memberName) {
5805 if (memberName == null || memberName.isEmpty) { 5693 if (memberName == null || memberName.isEmpty) {
5806 return null; 5694 return null;
5807 } 5695 }
5808 ExecutableElement executable = _computeClassChainLookupMap( 5696 ExecutableElement executable = _computeClassChainLookupMap(
5809 classElt, 5697 classElt, new HashSet<ClassElement>()).get(memberName);
5810 new HashSet<ClassElement>()).get(memberName);
5811 if (executable == null) { 5698 if (executable == null) {
5812 return _computeInterfaceLookupMap( 5699 return _computeInterfaceLookupMap(classElt, new HashSet<ClassElement>())
5813 classElt, 5700 .get(memberName);
5814 new HashSet<ClassElement>()).get(memberName);
5815 } 5701 }
5816 return executable; 5702 return executable;
5817 } 5703 }
5818 5704
5819 /** 5705 /**
5820 * Given some [ClassElement] and some member name, this returns the 5706 * Given some [ClassElement] and some member name, this returns the
5821 * [ExecutableElement] that the class either declares itself, or 5707 * [ExecutableElement] that the class either declares itself, or
5822 * inherits, that has the member name, if no member is inherited `null` is ret urned. 5708 * inherits, that has the member name, if no member is inherited `null` is ret urned.
5823 * 5709 *
5824 * @param classElt the class element to query 5710 * @param classElt the class element to query
(...skipping 13 matching lines...) Expand all
5838 * Given some [InterfaceType] and some member name, this returns the 5724 * Given some [InterfaceType] and some member name, this returns the
5839 * [FunctionType] of the [ExecutableElement] that the 5725 * [FunctionType] of the [ExecutableElement] that the
5840 * class either declares itself, or inherits, that has the member name, if no member is inherited 5726 * class either declares itself, or inherits, that has the member name, if no member is inherited
5841 * `null` is returned. The returned [FunctionType] has all type 5727 * `null` is returned. The returned [FunctionType] has all type
5842 * parameters substituted with corresponding type arguments from the given [In terfaceType]. 5728 * parameters substituted with corresponding type arguments from the given [In terfaceType].
5843 * 5729 *
5844 * @param interfaceType the interface type to query 5730 * @param interfaceType the interface type to query
5845 * @param memberName the name of the executable element to find and return 5731 * @param memberName the name of the executable element to find and return
5846 * @return the member's function type, or `null` if no such member exists 5732 * @return the member's function type, or `null` if no such member exists
5847 */ 5733 */
5848 FunctionType lookupMemberType(InterfaceType interfaceType, 5734 FunctionType lookupMemberType(
5849 String memberName) { 5735 InterfaceType interfaceType, String memberName) {
5850 ExecutableElement iteratorMember = 5736 ExecutableElement iteratorMember =
5851 lookupMember(interfaceType.element, memberName); 5737 lookupMember(interfaceType.element, memberName);
5852 if (iteratorMember == null) { 5738 if (iteratorMember == null) {
5853 return null; 5739 return null;
5854 } 5740 }
5855 return substituteTypeArgumentsInMemberFromInheritance( 5741 return substituteTypeArgumentsInMemberFromInheritance(
5856 iteratorMember.type, 5742 iteratorMember.type, memberName, interfaceType);
5857 memberName,
5858 interfaceType);
5859 } 5743 }
5860 5744
5861 /** 5745 /**
5862 * Determine the set of methods which is overridden by the given class member. If no member is 5746 * Determine the set of methods which is overridden by the given class member. If no member is
5863 * inherited, an empty list is returned. If one of the inherited members is a 5747 * inherited, an empty list is returned. If one of the inherited members is a
5864 * [MultiplyInheritedExecutableElement], then it is expanded into its constitu ent inherited 5748 * [MultiplyInheritedExecutableElement], then it is expanded into its constitu ent inherited
5865 * elements. 5749 * elements.
5866 * 5750 *
5867 * @param classElt the class to query 5751 * @param classElt the class to query
5868 * @param memberName the name of the class member to query 5752 * @param memberName the name of the class member to query
5869 * @return a list of overridden methods 5753 * @return a list of overridden methods
5870 */ 5754 */
5871 List<ExecutableElement> lookupOverrides(ClassElement classElt, 5755 List<ExecutableElement> lookupOverrides(
5872 String memberName) { 5756 ClassElement classElt, String memberName) {
5873 List<ExecutableElement> result = new List<ExecutableElement>(); 5757 List<ExecutableElement> result = new List<ExecutableElement>();
5874 if (memberName == null || memberName.isEmpty) { 5758 if (memberName == null || memberName.isEmpty) {
5875 return result; 5759 return result;
5876 } 5760 }
5877 List<MemberMap> interfaceMaps = 5761 List<MemberMap> interfaceMaps =
5878 _gatherInterfaceLookupMaps(classElt, new HashSet<ClassElement>()); 5762 _gatherInterfaceLookupMaps(classElt, new HashSet<ClassElement>());
5879 if (interfaceMaps != null) { 5763 if (interfaceMaps != null) {
5880 for (MemberMap interfaceMap in interfaceMaps) { 5764 for (MemberMap interfaceMap in interfaceMaps) {
5881 ExecutableElement overriddenElement = interfaceMap.get(memberName); 5765 ExecutableElement overriddenElement = interfaceMap.get(memberName);
5882 if (overriddenElement != null) { 5766 if (overriddenElement != null) {
5883 if (overriddenElement is MultiplyInheritedExecutableElement) { 5767 if (overriddenElement is MultiplyInheritedExecutableElement) {
5884 MultiplyInheritedExecutableElement multiplyInheritedElement = 5768 MultiplyInheritedExecutableElement multiplyInheritedElement =
5885 overriddenElement; 5769 overriddenElement;
5886 for (ExecutableElement element in 5770 for (ExecutableElement element
5887 multiplyInheritedElement.inheritedElements) { 5771 in multiplyInheritedElement.inheritedElements) {
5888 result.add(element); 5772 result.add(element);
5889 } 5773 }
5890 } else { 5774 } else {
5891 result.add(overriddenElement); 5775 result.add(overriddenElement);
5892 } 5776 }
5893 } 5777 }
5894 } 5778 }
5895 } 5779 }
5896 return result; 5780 return result;
5897 } 5781 }
5898 5782
5899 /** 5783 /**
5900 * This method takes some inherited [FunctionType], and resolves all the param eterized types 5784 * This method takes some inherited [FunctionType], and resolves all the param eterized types
5901 * in the function type, dependent on the class in which it is being overridde n. 5785 * in the function type, dependent on the class in which it is being overridde n.
5902 * 5786 *
5903 * @param baseFunctionType the function type that is being overridden 5787 * @param baseFunctionType the function type that is being overridden
5904 * @param memberName the name of the member, this is used to lookup the inheri tance path of the 5788 * @param memberName the name of the member, this is used to lookup the inheri tance path of the
5905 * override 5789 * override
5906 * @param definingType the type that is overriding the member 5790 * @param definingType the type that is overriding the member
5907 * @return the passed function type with any parameterized types substituted 5791 * @return the passed function type with any parameterized types substituted
5908 */ 5792 */
5909 FunctionType 5793 FunctionType substituteTypeArgumentsInMemberFromInheritance(
5910 substituteTypeArgumentsInMemberFromInheritance(FunctionType baseFunctionTy pe, 5794 FunctionType baseFunctionType, String memberName,
5911 String memberName, InterfaceType definingType) { 5795 InterfaceType definingType) {
5912 // if the baseFunctionType is null, or does not have any parameters, 5796 // if the baseFunctionType is null, or does not have any parameters,
5913 // return it. 5797 // return it.
5914 if (baseFunctionType == null || 5798 if (baseFunctionType == null ||
5915 baseFunctionType.typeArguments.length == 0) { 5799 baseFunctionType.typeArguments.length == 0) {
5916 return baseFunctionType; 5800 return baseFunctionType;
5917 } 5801 }
5918 // First, generate the path from the defining type to the overridden member 5802 // First, generate the path from the defining type to the overridden member
5919 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); 5803 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>();
5920 _computeInheritancePath(inheritancePath, definingType, memberName); 5804 _computeInheritancePath(inheritancePath, definingType, memberName);
5921 if (inheritancePath == null || inheritancePath.isEmpty) { 5805 if (inheritancePath == null || inheritancePath.isEmpty) {
(...skipping 16 matching lines...) Expand all
5938 * Compute and return a mapping between the set of all string names of the mem bers inherited from 5822 * Compute and return a mapping between the set of all string names of the mem bers inherited from
5939 * the passed [ClassElement] superclass hierarchy, and the associated 5823 * the passed [ClassElement] superclass hierarchy, and the associated
5940 * [ExecutableElement]. 5824 * [ExecutableElement].
5941 * 5825 *
5942 * @param classElt the class element to query 5826 * @param classElt the class element to query
5943 * @param visitedClasses a set of visited classes passed back into this method when it calls 5827 * @param visitedClasses a set of visited classes passed back into this method when it calls
5944 * itself recursively 5828 * itself recursively
5945 * @return a mapping between the set of all string names of the members inheri ted from the passed 5829 * @return a mapping between the set of all string names of the members inheri ted from the passed
5946 * [ClassElement] superclass hierarchy, and the associated [Executable Element] 5830 * [ClassElement] superclass hierarchy, and the associated [Executable Element]
5947 */ 5831 */
5948 MemberMap _computeClassChainLookupMap(ClassElement classElt, 5832 MemberMap _computeClassChainLookupMap(
5949 HashSet<ClassElement> visitedClasses) { 5833 ClassElement classElt, HashSet<ClassElement> visitedClasses) {
5950 MemberMap resultMap = _classLookup[classElt]; 5834 MemberMap resultMap = _classLookup[classElt];
5951 if (resultMap != null) { 5835 if (resultMap != null) {
5952 return resultMap; 5836 return resultMap;
5953 } else { 5837 } else {
5954 resultMap = new MemberMap(); 5838 resultMap = new MemberMap();
5955 } 5839 }
5956 ClassElement superclassElt = null; 5840 ClassElement superclassElt = null;
5957 InterfaceType supertype = classElt.supertype; 5841 InterfaceType supertype = classElt.supertype;
5958 if (supertype != null) { 5842 if (supertype != null) {
5959 superclassElt = supertype.element; 5843 superclassElt = supertype.element;
5960 } else { 5844 } else {
5961 // classElt is Object 5845 // classElt is Object
5962 _classLookup[classElt] = resultMap; 5846 _classLookup[classElt] = resultMap;
5963 return resultMap; 5847 return resultMap;
5964 } 5848 }
5965 if (superclassElt != null) { 5849 if (superclassElt != null) {
5966 if (!visitedClasses.contains(superclassElt)) { 5850 if (!visitedClasses.contains(superclassElt)) {
5967 visitedClasses.add(superclassElt); 5851 visitedClasses.add(superclassElt);
5968 try { 5852 try {
5969 resultMap = 5853 resultMap = new MemberMap.con2(
5970 new MemberMap.con2(_computeClassChainLookupMap(superclassElt, visi tedClasses)); 5854 _computeClassChainLookupMap(superclassElt, visitedClasses));
5971 // 5855 //
5972 // Substitute the super types down the hierarchy. 5856 // Substitute the super types down the hierarchy.
5973 // 5857 //
5974 _substituteTypeParametersDownHierarchy(supertype, resultMap); 5858 _substituteTypeParametersDownHierarchy(supertype, resultMap);
5975 // 5859 //
5976 // Include the members from the superclass in the resultMap. 5860 // Include the members from the superclass in the resultMap.
5977 // 5861 //
5978 _recordMapWithClassMembers(resultMap, supertype, false); 5862 _recordMapWithClassMembers(resultMap, supertype, false);
5979 } finally { 5863 } finally {
5980 visitedClasses.remove(superclassElt); 5864 visitedClasses.remove(superclassElt);
(...skipping 11 matching lines...) Expand all
5992 // multiple mixins, visit them in the order listed so that methods in later 5876 // multiple mixins, visit them in the order listed so that methods in later
5993 // mixins will overwrite identically-named methods in earlier mixins. 5877 // mixins will overwrite identically-named methods in earlier mixins.
5994 // 5878 //
5995 List<InterfaceType> mixins = classElt.mixins; 5879 List<InterfaceType> mixins = classElt.mixins;
5996 for (InterfaceType mixin in mixins) { 5880 for (InterfaceType mixin in mixins) {
5997 ClassElement mixinElement = mixin.element; 5881 ClassElement mixinElement = mixin.element;
5998 if (mixinElement != null) { 5882 if (mixinElement != null) {
5999 if (!visitedClasses.contains(mixinElement)) { 5883 if (!visitedClasses.contains(mixinElement)) {
6000 visitedClasses.add(mixinElement); 5884 visitedClasses.add(mixinElement);
6001 try { 5885 try {
6002 MemberMap map = 5886 MemberMap map = new MemberMap.con2(
6003 new MemberMap.con2(_computeClassChainLookupMap(mixinElement, vis itedClasses)); 5887 _computeClassChainLookupMap(mixinElement, visitedClasses));
6004 // 5888 //
6005 // Substitute the super types down the hierarchy. 5889 // Substitute the super types down the hierarchy.
6006 // 5890 //
6007 _substituteTypeParametersDownHierarchy(mixin, map); 5891 _substituteTypeParametersDownHierarchy(mixin, map);
6008 // 5892 //
6009 // Include the members from the superclass in the resultMap. 5893 // Include the members from the superclass in the resultMap.
6010 // 5894 //
6011 _recordMapWithClassMembers(map, mixin, false); 5895 _recordMapWithClassMembers(map, mixin, false);
6012 // 5896 //
6013 // Add the members from map into result map. 5897 // Add the members from map into result map.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
6106 * Compute and return a mapping between the set of all string names of the mem bers inherited from 5990 * Compute and return a mapping between the set of all string names of the mem bers inherited from
6107 * the passed [ClassElement] interface hierarchy, and the associated 5991 * the passed [ClassElement] interface hierarchy, and the associated
6108 * [ExecutableElement]. 5992 * [ExecutableElement].
6109 * 5993 *
6110 * @param classElt the class element to query 5994 * @param classElt the class element to query
6111 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls 5995 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls
6112 * itself recursively 5996 * itself recursively
6113 * @return a mapping between the set of all string names of the members inheri ted from the passed 5997 * @return a mapping between the set of all string names of the members inheri ted from the passed
6114 * [ClassElement] interface hierarchy, and the associated [ExecutableE lement] 5998 * [ClassElement] interface hierarchy, and the associated [ExecutableE lement]
6115 */ 5999 */
6116 MemberMap _computeInterfaceLookupMap(ClassElement classElt, 6000 MemberMap _computeInterfaceLookupMap(
6117 HashSet<ClassElement> visitedInterfaces) { 6001 ClassElement classElt, HashSet<ClassElement> visitedInterfaces) {
6118 MemberMap resultMap = _interfaceLookup[classElt]; 6002 MemberMap resultMap = _interfaceLookup[classElt];
6119 if (resultMap != null) { 6003 if (resultMap != null) {
6120 return resultMap; 6004 return resultMap;
6121 } 6005 }
6122 List<MemberMap> lookupMaps = 6006 List<MemberMap> lookupMaps =
6123 _gatherInterfaceLookupMaps(classElt, visitedInterfaces); 6007 _gatherInterfaceLookupMaps(classElt, visitedInterfaces);
6124 if (lookupMaps == null) { 6008 if (lookupMaps == null) {
6125 resultMap = new MemberMap(); 6009 resultMap = new MemberMap();
6126 } else { 6010 } else {
6127 HashMap<String, List<ExecutableElement>> unionMap = 6011 HashMap<String, List<ExecutableElement>> unionMap =
(...skipping 11 matching lines...) Expand all
6139 * returned by [computeInterfaceLookupMap] for the corresponding super, except with type 6023 * returned by [computeInterfaceLookupMap] for the corresponding super, except with type
6140 * parameters appropriately substituted. 6024 * parameters appropriately substituted.
6141 * 6025 *
6142 * @param classElt the class element to query 6026 * @param classElt the class element to query
6143 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls 6027 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls
6144 * itself recursively 6028 * itself recursively
6145 * @return `null` if there was a problem (such as a loop in the class hierarch y) or if there 6029 * @return `null` if there was a problem (such as a loop in the class hierarch y) or if there
6146 * are no classes above this one in the class hierarchy. Otherwise, a list of interface 6030 * are no classes above this one in the class hierarchy. Otherwise, a list of interface
6147 * lookup maps. 6031 * lookup maps.
6148 */ 6032 */
6149 List<MemberMap> _gatherInterfaceLookupMaps(ClassElement classElt, 6033 List<MemberMap> _gatherInterfaceLookupMaps(
6150 HashSet<ClassElement> visitedInterfaces) { 6034 ClassElement classElt, HashSet<ClassElement> visitedInterfaces) {
6151 InterfaceType supertype = classElt.supertype; 6035 InterfaceType supertype = classElt.supertype;
6152 ClassElement superclassElement = 6036 ClassElement superclassElement =
6153 supertype != null ? supertype.element : null; 6037 supertype != null ? supertype.element : null;
6154 List<InterfaceType> mixins = classElt.mixins; 6038 List<InterfaceType> mixins = classElt.mixins;
6155 List<InterfaceType> interfaces = classElt.interfaces; 6039 List<InterfaceType> interfaces = classElt.interfaces;
6156 // Recursively collect the list of mappings from all of the interface types 6040 // Recursively collect the list of mappings from all of the interface types
6157 List<MemberMap> lookupMaps = new List<MemberMap>(); 6041 List<MemberMap> lookupMaps = new List<MemberMap>();
6158 // 6042 //
6159 // Superclass element 6043 // Superclass element
6160 // 6044 //
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
6257 6141
6258 /** 6142 /**
6259 * Given some [ClassElement], this method finds and returns the [ExecutableEle ment] of 6143 * Given some [ClassElement], this method finds and returns the [ExecutableEle ment] of
6260 * the passed name in the class element. Static members, members in super type s and members not 6144 * the passed name in the class element. Static members, members in super type s and members not
6261 * accessible from the current library are not considered. 6145 * accessible from the current library are not considered.
6262 * 6146 *
6263 * @param classElt the class element to query 6147 * @param classElt the class element to query
6264 * @param memberName the name of the member to lookup in the class 6148 * @param memberName the name of the member to lookup in the class
6265 * @return the found [ExecutableElement], or `null` if no such member was foun d 6149 * @return the found [ExecutableElement], or `null` if no such member was foun d
6266 */ 6150 */
6267 ExecutableElement _lookupMemberInClass(ClassElement classElt, 6151 ExecutableElement _lookupMemberInClass(
6268 String memberName) { 6152 ClassElement classElt, String memberName) {
6269 List<MethodElement> methods = classElt.methods; 6153 List<MethodElement> methods = classElt.methods;
6270 for (MethodElement method in methods) { 6154 for (MethodElement method in methods) {
6271 if (memberName == method.name && 6155 if (memberName == method.name &&
6272 method.isAccessibleIn(_library) && 6156 method.isAccessibleIn(_library) &&
6273 !method.isStatic) { 6157 !method.isStatic) {
6274 return method; 6158 return method;
6275 } 6159 }
6276 } 6160 }
6277 List<PropertyAccessorElement> accessors = classElt.accessors; 6161 List<PropertyAccessorElement> accessors = classElt.accessors;
6278 for (PropertyAccessorElement accessor in accessors) { 6162 for (PropertyAccessorElement accessor in accessors) {
6279 if (memberName == accessor.name && 6163 if (memberName == accessor.name &&
6280 accessor.isAccessibleIn(_library) && 6164 accessor.isAccessibleIn(_library) &&
6281 !accessor.isStatic) { 6165 !accessor.isStatic) {
6282 return accessor; 6166 return accessor;
6283 } 6167 }
6284 } 6168 }
6285 return null; 6169 return null;
6286 } 6170 }
6287 6171
6288 /** 6172 /**
6289 * Record the passed map with the set of all members (methods, getters and set ters) in the type 6173 * Record the passed map with the set of all members (methods, getters and set ters) in the type
6290 * into the passed map. 6174 * into the passed map.
6291 * 6175 *
6292 * @param map some non-`null` map to put the methods and accessors from the pa ssed 6176 * @param map some non-`null` map to put the methods and accessors from the pa ssed
6293 * [ClassElement] into 6177 * [ClassElement] into
6294 * @param type the type that will be recorded into the passed map 6178 * @param type the type that will be recorded into the passed map
6295 * @param doIncludeAbstract `true` if abstract members will be put into the ma p 6179 * @param doIncludeAbstract `true` if abstract members will be put into the ma p
6296 */ 6180 */
6297 void _recordMapWithClassMembers(MemberMap map, InterfaceType type, 6181 void _recordMapWithClassMembers(
6298 bool doIncludeAbstract) { 6182 MemberMap map, InterfaceType type, bool doIncludeAbstract) {
6299 List<MethodElement> methods = type.methods; 6183 List<MethodElement> methods = type.methods;
6300 for (MethodElement method in methods) { 6184 for (MethodElement method in methods) {
6301 if (method.isAccessibleIn(_library) && 6185 if (method.isAccessibleIn(_library) &&
6302 !method.isStatic && 6186 !method.isStatic &&
6303 (doIncludeAbstract || !method.isAbstract)) { 6187 (doIncludeAbstract || !method.isAbstract)) {
6304 map.put(method.name, method); 6188 map.put(method.name, method);
6305 } 6189 }
6306 } 6190 }
6307 List<PropertyAccessorElement> accessors = type.accessors; 6191 List<PropertyAccessorElement> accessors = type.accessors;
6308 for (PropertyAccessorElement accessor in accessors) { 6192 for (PropertyAccessorElement accessor in accessors) {
(...skipping 16 matching lines...) Expand all
6325 * @param errorCode the error code to be associated with this error 6209 * @param errorCode the error code to be associated with this error
6326 * @param arguments the arguments used to build the error message 6210 * @param arguments the arguments used to build the error message
6327 */ 6211 */
6328 void _reportError(ClassElement classElt, int offset, int length, 6212 void _reportError(ClassElement classElt, int offset, int length,
6329 ErrorCode errorCode, List<Object> arguments) { 6213 ErrorCode errorCode, List<Object> arguments) {
6330 HashSet<AnalysisError> errorSet = _errorsInClassElement[classElt]; 6214 HashSet<AnalysisError> errorSet = _errorsInClassElement[classElt];
6331 if (errorSet == null) { 6215 if (errorSet == null) {
6332 errorSet = new HashSet<AnalysisError>(); 6216 errorSet = new HashSet<AnalysisError>();
6333 _errorsInClassElement[classElt] = errorSet; 6217 _errorsInClassElement[classElt] = errorSet;
6334 } 6218 }
6335 errorSet.add( 6219 errorSet.add(new AnalysisError.con2(
6336 new AnalysisError.con2(classElt.source, offset, length, errorCode, argum ents)); 6220 classElt.source, offset, length, errorCode, arguments));
6337 } 6221 }
6338 6222
6339 /** 6223 /**
6340 * Given the set of methods defined by classes above [classElt] in the class h ierarchy, 6224 * Given the set of methods defined by classes above [classElt] in the class h ierarchy,
6341 * apply the appropriate inheritance rules to determine those methods inherite d by or overridden 6225 * apply the appropriate inheritance rules to determine those methods inherite d by or overridden
6342 * by [classElt]. Also report static warnings 6226 * by [classElt]. Also report static warnings
6343 * [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE] and 6227 * [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE] and
6344 * [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD] if ap propriate. 6228 * [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD] if ap propriate.
6345 * 6229 *
6346 * @param classElt the class element to query. 6230 * @param classElt the class element to query.
6347 * @param unionMap a mapping from method name to the set of unique (in terms o f signature) methods 6231 * @param unionMap a mapping from method name to the set of unique (in terms o f signature) methods
6348 * defined in superclasses of [classElt]. 6232 * defined in superclasses of [classElt].
6349 * @return the inheritance lookup map for [classElt]. 6233 * @return the inheritance lookup map for [classElt].
6350 */ 6234 */
6351 MemberMap _resolveInheritanceLookup(ClassElement classElt, HashMap<String, 6235 MemberMap _resolveInheritanceLookup(ClassElement classElt,
6352 List<ExecutableElement>> unionMap) { 6236 HashMap<String, List<ExecutableElement>> unionMap) {
6353 MemberMap resultMap = new MemberMap(); 6237 MemberMap resultMap = new MemberMap();
6354 unionMap.forEach((String key, List<ExecutableElement> list) { 6238 unionMap.forEach((String key, List<ExecutableElement> list) {
6355 int numOfEltsWithMatchingNames = list.length; 6239 int numOfEltsWithMatchingNames = list.length;
6356 if (numOfEltsWithMatchingNames == 1) { 6240 if (numOfEltsWithMatchingNames == 1) {
6357 // 6241 //
6358 // Example: class A inherits only 1 method named 'm'. 6242 // Example: class A inherits only 1 method named 'm'.
6359 // Since it is the only such method, it is inherited. 6243 // Since it is the only such method, it is inherited.
6360 // Another example: class A inherits 2 methods named 'm' from 2 6244 // Another example: class A inherits 2 methods named 'm' from 2
6361 // different interfaces, but they both have the same signature, so it is 6245 // different interfaces, but they both have the same signature, so it is
6362 // the method inherited. 6246 // the method inherited.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
6397 for (int i = 0; i < numOfEltsWithMatchingNames; i++) { 6281 for (int i = 0; i < numOfEltsWithMatchingNames; i++) {
6398 executableElementTypes[i] = elements[i].type; 6282 executableElementTypes[i] = elements[i].type;
6399 } 6283 }
6400 List<int> subtypesOfAllOtherTypesIndexes = new List<int>(); 6284 List<int> subtypesOfAllOtherTypesIndexes = new List<int>();
6401 for (int i = 0; i < numOfEltsWithMatchingNames; i++) { 6285 for (int i = 0; i < numOfEltsWithMatchingNames; i++) {
6402 FunctionType subtype = executableElementTypes[i]; 6286 FunctionType subtype = executableElementTypes[i];
6403 if (subtype == null) { 6287 if (subtype == null) {
6404 continue; 6288 continue;
6405 } 6289 }
6406 bool subtypeOfAllTypes = true; 6290 bool subtypeOfAllTypes = true;
6407 for (int j = 6291 for (int j = 0;
6408 0; j < numOfEltsWithMatchingNames && subtypeOfAllTypes; j++) { 6292 j < numOfEltsWithMatchingNames && subtypeOfAllTypes;
6293 j++) {
6409 if (i != j) { 6294 if (i != j) {
6410 if (!subtype.isSubtypeOf(executableElementTypes[j])) { 6295 if (!subtype.isSubtypeOf(executableElementTypes[j])) {
6411 subtypeOfAllTypes = false; 6296 subtypeOfAllTypes = false;
6412 break; 6297 break;
6413 } 6298 }
6414 } 6299 }
6415 } 6300 }
6416 if (subtypeOfAllTypes) { 6301 if (subtypeOfAllTypes) {
6417 subtypesOfAllOtherTypesIndexes.add(i); 6302 subtypesOfAllOtherTypesIndexes.add(i);
6418 } 6303 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
6451 } 6336 }
6452 // 6337 //
6453 // Example: class A inherited only 2 method named 'm'. 6338 // Example: class A inherited only 2 method named 'm'.
6454 // One has the function type '() -> int' and one has the function 6339 // One has the function type '() -> int' and one has the function
6455 // type '() -> String'. Since neither is a subtype of the other, 6340 // type '() -> String'. Since neither is a subtype of the other,
6456 // we create a warning, and have this class inherit nothing. 6341 // we create a warning, and have this class inherit nothing.
6457 // 6342 //
6458 if (!classHasMember) { 6343 if (!classHasMember) {
6459 String firstTwoFuntionTypesStr = 6344 String firstTwoFuntionTypesStr =
6460 "${executableElementTypes[0]}, ${executableElementTypes[1]}" ; 6345 "${executableElementTypes[0]}, ${executableElementTypes[1]}" ;
6461 _reportError( 6346 _reportError(classElt, classElt.nameOffset,
6462 classElt,
6463 classElt.nameOffset,
6464 classElt.displayName.length, 6347 classElt.displayName.length,
6465 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, 6348 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, [
6466 [key, firstTwoFuntionTypesStr]); 6349 key,
6350 firstTwoFuntionTypesStr
6351 ]);
6467 } 6352 }
6468 } else { 6353 } else {
6469 // 6354 //
6470 // Example: class A inherits 2 methods named 'm'. 6355 // Example: class A inherits 2 methods named 'm'.
6471 // One has the function type '(int) -> dynamic' and one has the 6356 // One has the function type '(int) -> dynamic' and one has the
6472 // function type '(num) -> dynamic'. Since they are both a subtype 6357 // function type '(num) -> dynamic'. Since they are both a subtype
6473 // of the other, a synthetic function '(dynamic) -> dynamic' is 6358 // of the other, a synthetic function '(dynamic) -> dynamic' is
6474 // inherited. 6359 // inherited.
6475 // Tests: test_getMapOfMembersInheritedFromInterfaces_ 6360 // Tests: test_getMapOfMembersInheritedFromInterfaces_
6476 // union_multipleSubtypes_* 6361 // union_multipleSubtypes_*
6477 // 6362 //
6478 List<ExecutableElement> elementArrayToMerge = 6363 List<ExecutableElement> elementArrayToMerge =
6479 new List<ExecutableElement>(subtypesOfAllOtherTypesIndexes.len gth); 6364 new List<ExecutableElement>(
6365 subtypesOfAllOtherTypesIndexes.length);
6480 for (int i = 0; i < elementArrayToMerge.length; i++) { 6366 for (int i = 0; i < elementArrayToMerge.length; i++) {
6481 elementArrayToMerge[i] = 6367 elementArrayToMerge[i] =
6482 elements[subtypesOfAllOtherTypesIndexes[i]]; 6368 elements[subtypesOfAllOtherTypesIndexes[i]];
6483 } 6369 }
6484 ExecutableElement mergedExecutableElement = 6370 ExecutableElement mergedExecutableElement =
6485 _computeMergedExecutableElement(elementArrayToMerge); 6371 _computeMergedExecutableElement(elementArrayToMerge);
6486 resultMap.put(key, mergedExecutableElement); 6372 resultMap.put(key, mergedExecutableElement);
6487 } 6373 }
6488 } 6374 }
6489 } else { 6375 } else {
6490 _reportError( 6376 _reportError(classElt, classElt.nameOffset,
6491 classElt,
6492 classElt.nameOffset,
6493 classElt.displayName.length, 6377 classElt.displayName.length,
6494 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHO D, 6378 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHO D,
6495 [key]); 6379 [key]);
6496 } 6380 }
6497 } 6381 }
6498 }); 6382 });
6499 return resultMap; 6383 return resultMap;
6500 } 6384 }
6501 6385
6502 /** 6386 /**
6503 * Loop through all of the members in some [MemberMap], performing type parame ter 6387 * Loop through all of the members in some [MemberMap], performing type parame ter
6504 * substitutions using a passed supertype. 6388 * substitutions using a passed supertype.
6505 * 6389 *
6506 * @param superType the supertype to substitute into the members of the [Membe rMap] 6390 * @param superType the supertype to substitute into the members of the [Membe rMap]
6507 * @param map the MemberMap to perform the substitutions on 6391 * @param map the MemberMap to perform the substitutions on
6508 */ 6392 */
6509 void _substituteTypeParametersDownHierarchy(InterfaceType superType, 6393 void _substituteTypeParametersDownHierarchy(
6510 MemberMap map) { 6394 InterfaceType superType, MemberMap map) {
6511 for (int i = 0; i < map.size; i++) { 6395 for (int i = 0; i < map.size; i++) {
6512 ExecutableElement executableElement = map.getValue(i); 6396 ExecutableElement executableElement = map.getValue(i);
6513 if (executableElement is MethodMember) { 6397 if (executableElement is MethodMember) {
6514 executableElement = 6398 executableElement =
6515 MethodMember.from(executableElement as MethodMember, superType); 6399 MethodMember.from(executableElement as MethodMember, superType);
6516 map.setValue(i, executableElement); 6400 map.setValue(i, executableElement);
6517 } else if (executableElement is PropertyAccessorMember) { 6401 } else if (executableElement is PropertyAccessorMember) {
6518 executableElement = PropertyAccessorMember.from( 6402 executableElement = PropertyAccessorMember.from(
6519 executableElement as PropertyAccessorMember, 6403 executableElement as PropertyAccessorMember, superType);
6520 superType);
6521 map.setValue(i, executableElement); 6404 map.setValue(i, executableElement);
6522 } 6405 }
6523 } 6406 }
6524 } 6407 }
6525 6408
6526 /** 6409 /**
6527 * Union all of the [lookupMaps] together into a single map, grouping the Exec utableElements 6410 * Union all of the [lookupMaps] together into a single map, grouping the Exec utableElements
6528 * into a list where none of the elements are equal where equality is determin ed by having equal 6411 * into a list where none of the elements are equal where equality is determin ed by having equal
6529 * function types. (We also take note too of the kind of the element: ()->int and () -> int may 6412 * function types. (We also take note too of the kind of the element: ()->int and () -> int may
6530 * not be equal if one is a getter and the other is a method.) 6413 * not be equal if one is a getter and the other is a method.)
6531 * 6414 *
6532 * @param lookupMaps the maps to be unioned together. 6415 * @param lookupMaps the maps to be unioned together.
6533 * @return the resulting union map. 6416 * @return the resulting union map.
6534 */ 6417 */
6535 HashMap<String, List<ExecutableElement>> 6418 HashMap<String, List<ExecutableElement>> _unionInterfaceLookupMaps(
6536 _unionInterfaceLookupMaps(List<MemberMap> lookupMaps) { 6419 List<MemberMap> lookupMaps) {
6537 HashMap<String, List<ExecutableElement>> unionMap = 6420 HashMap<String, List<ExecutableElement>> unionMap =
6538 new HashMap<String, List<ExecutableElement>>(); 6421 new HashMap<String, List<ExecutableElement>>();
6539 for (MemberMap lookupMap in lookupMaps) { 6422 for (MemberMap lookupMap in lookupMaps) {
6540 int lookupMapSize = lookupMap.size; 6423 int lookupMapSize = lookupMap.size;
6541 for (int i = 0; i < lookupMapSize; i++) { 6424 for (int i = 0; i < lookupMapSize; i++) {
6542 // Get the string key, if null, break. 6425 // Get the string key, if null, break.
6543 String key = lookupMap.getKey(i); 6426 String key = lookupMap.getKey(i);
6544 if (key == null) { 6427 if (key == null) {
6545 break; 6428 break;
6546 } 6429 }
(...skipping 12 matching lines...) Expand all
6559 list.add(newExecutableElementEntry); 6442 list.add(newExecutableElementEntry);
6560 } else { 6443 } else {
6561 // Otherwise, only add the newExecutableElementEntry if it isn't 6444 // Otherwise, only add the newExecutableElementEntry if it isn't
6562 // already in the list, this covers situation where a class inherits 6445 // already in the list, this covers situation where a class inherits
6563 // two methods (or two getters) that are identical. 6446 // two methods (or two getters) that are identical.
6564 bool alreadyInList = false; 6447 bool alreadyInList = false;
6565 bool isMethod1 = newExecutableElementEntry is MethodElement; 6448 bool isMethod1 = newExecutableElementEntry is MethodElement;
6566 for (ExecutableElement executableElementInList in list) { 6449 for (ExecutableElement executableElementInList in list) {
6567 bool isMethod2 = executableElementInList is MethodElement; 6450 bool isMethod2 = executableElementInList is MethodElement;
6568 if (isMethod1 == isMethod2 && 6451 if (isMethod1 == isMethod2 &&
6569 executableElementInList.type == newExecutableElementEntry.type) { 6452 executableElementInList.type ==
6453 newExecutableElementEntry.type) {
6570 alreadyInList = true; 6454 alreadyInList = true;
6571 break; 6455 break;
6572 } 6456 }
6573 } 6457 }
6574 if (!alreadyInList) { 6458 if (!alreadyInList) {
6575 list.add(newExecutableElementEntry); 6459 list.add(newExecutableElementEntry);
6576 } 6460 }
6577 } 6461 }
6578 } 6462 }
6579 } 6463 }
6580 return unionMap; 6464 return unionMap;
6581 } 6465 }
6582 6466
6583 /** 6467 /**
6584 * Given some array of [ExecutableElement]s, this method creates a synthetic e lement as 6468 * Given some array of [ExecutableElement]s, this method creates a synthetic e lement as
6585 * described in 8.1.1: 6469 * described in 8.1.1:
6586 * 6470 *
6587 * Let <i>numberOfPositionals</i>(<i>f</i>) denote the number of positional pa rameters of a 6471 * Let <i>numberOfPositionals</i>(<i>f</i>) denote the number of positional pa rameters of a
6588 * function <i>f</i>, and let <i>numberOfRequiredParams</i>(<i>f</i>) denote t he number of 6472 * function <i>f</i>, and let <i>numberOfRequiredParams</i>(<i>f</i>) denote t he number of
6589 * required parameters of a function <i>f</i>. Furthermore, let <i>s</i> denot e the set of all 6473 * required parameters of a function <i>f</i>. Furthermore, let <i>s</i> denot e the set of all
6590 * named parameters of the <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i>. Then let 6474 * named parameters of the <i>m<sub>1</sub>, &hellip;, m<sub>k</sub></i>. Then let
6591 * * <i>h = max(numberOfPositionals(m<sub>i</sub>)),</i> 6475 * * <i>h = max(numberOfPositionals(m<sub>i</sub>)),</i>
6592 * * <i>r = min(numberOfRequiredParams(m<sub>i</sub>)), for all <i>i</i>, 1 <= i <= k.</i> 6476 * * <i>r = min(numberOfRequiredParams(m<sub>i</sub>)), for all <i>i</i>, 1 <= i <= k.</i>
6593 * Then <i>I</i> has a method named <i>n</i>, with <i>r</i> required parameter s of type 6477 * Then <i>I</i> has a method named <i>n</i>, with <i>r</i> required parameter s of type
6594 * <b>dynamic</b>, <i>h</i> positional parameters of type <b>dynamic</b>, name d parameters 6478 * <b>dynamic</b>, <i>h</i> positional parameters of type <b>dynamic</b>, name d parameters
6595 * <i>s</i> of type <b>dynamic</b> and return type <b>dynamic</b>. 6479 * <i>s</i> of type <b>dynamic</b> and return type <b>dynamic</b>.
6596 * 6480 *
6597 */ 6481 */
6598 static ExecutableElement 6482 static ExecutableElement _computeMergedExecutableElement(
6599 _computeMergedExecutableElement(List<ExecutableElement> elementArrayToMerg e) { 6483 List<ExecutableElement> elementArrayToMerge) {
6600 int h = _getNumOfPositionalParameters(elementArrayToMerge[0]); 6484 int h = _getNumOfPositionalParameters(elementArrayToMerge[0]);
6601 int r = _getNumOfRequiredParameters(elementArrayToMerge[0]); 6485 int r = _getNumOfRequiredParameters(elementArrayToMerge[0]);
6602 Set<String> namedParametersList = new HashSet<String>(); 6486 Set<String> namedParametersList = new HashSet<String>();
6603 for (int i = 1; i < elementArrayToMerge.length; i++) { 6487 for (int i = 1; i < elementArrayToMerge.length; i++) {
6604 ExecutableElement element = elementArrayToMerge[i]; 6488 ExecutableElement element = elementArrayToMerge[i];
6605 int numOfPositionalParams = _getNumOfPositionalParameters(element); 6489 int numOfPositionalParams = _getNumOfPositionalParameters(element);
6606 if (h < numOfPositionalParams) { 6490 if (h < numOfPositionalParams) {
6607 h = numOfPositionalParams; 6491 h = numOfPositionalParams;
6608 } 6492 }
6609 int numOfRequiredParams = _getNumOfRequiredParameters(element); 6493 int numOfRequiredParams = _getNumOfRequiredParameters(element);
6610 if (r > numOfRequiredParams) { 6494 if (r > numOfRequiredParams) {
6611 r = numOfRequiredParams; 6495 r = numOfRequiredParams;
6612 } 6496 }
6613 namedParametersList.addAll(_getNamedParameterNames(element)); 6497 namedParametersList.addAll(_getNamedParameterNames(element));
6614 } 6498 }
6615 return _createSyntheticExecutableElement( 6499 return _createSyntheticExecutableElement(elementArrayToMerge,
6616 elementArrayToMerge, 6500 elementArrayToMerge[0].displayName, r, h - r,
6617 elementArrayToMerge[0].displayName,
6618 r,
6619 h - r,
6620 new List.from(namedParametersList)); 6501 new List.from(namedParametersList));
6621 } 6502 }
6622 6503
6623 /** 6504 /**
6624 * Used by [computeMergedExecutableElement] to actually create the 6505 * Used by [computeMergedExecutableElement] to actually create the
6625 * synthetic element. 6506 * synthetic element.
6626 * 6507 *
6627 * @param elementArrayToMerge the array used to create the synthetic element 6508 * @param elementArrayToMerge the array used to create the synthetic element
6628 * @param name the name of the method, getter or setter 6509 * @param name the name of the method, getter or setter
6629 * @param numOfRequiredParameters the number of required parameters 6510 * @param numOfRequiredParameters the number of required parameters
6630 * @param numOfPositionalParameters the number of positional parameters 6511 * @param numOfPositionalParameters the number of positional parameters
6631 * @param namedParameters the list of [String]s that are the named parameters 6512 * @param namedParameters the list of [String]s that are the named parameters
6632 * @return the created synthetic element 6513 * @return the created synthetic element
6633 */ 6514 */
6634 static ExecutableElement 6515 static ExecutableElement _createSyntheticExecutableElement(
6635 _createSyntheticExecutableElement(List<ExecutableElement> elementArrayToMe rge, 6516 List<ExecutableElement> elementArrayToMerge, String name,
6636 String name, int numOfRequiredParameters, int numOfPositionalParameters, 6517 int numOfRequiredParameters, int numOfPositionalParameters,
6637 List<String> namedParameters) { 6518 List<String> namedParameters) {
6638 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; 6519 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance;
6639 SimpleIdentifier nameIdentifier = 6520 SimpleIdentifier nameIdentifier = new SimpleIdentifier(
6640 new SimpleIdentifier(new sc.StringToken(sc.TokenType.IDENTIFIER, name, 0 )); 6521 new sc.StringToken(sc.TokenType.IDENTIFIER, name, 0));
6641 ExecutableElementImpl executable; 6522 ExecutableElementImpl executable;
6642 if (elementArrayToMerge[0] is MethodElement) { 6523 if (elementArrayToMerge[0] is MethodElement) {
6643 MultiplyInheritedMethodElementImpl unionedMethod = 6524 MultiplyInheritedMethodElementImpl unionedMethod =
6644 new MultiplyInheritedMethodElementImpl(nameIdentifier); 6525 new MultiplyInheritedMethodElementImpl(nameIdentifier);
6645 unionedMethod.inheritedElements = elementArrayToMerge; 6526 unionedMethod.inheritedElements = elementArrayToMerge;
6646 executable = unionedMethod; 6527 executable = unionedMethod;
6647 } else { 6528 } else {
6648 MultiplyInheritedPropertyAccessorElementImpl unionedPropertyAccessor = 6529 MultiplyInheritedPropertyAccessorElementImpl unionedPropertyAccessor =
6649 new MultiplyInheritedPropertyAccessorElementImpl(nameIdentifier); 6530 new MultiplyInheritedPropertyAccessorElementImpl(nameIdentifier);
6650 unionedPropertyAccessor.getter = 6531 unionedPropertyAccessor.getter =
6651 (elementArrayToMerge[0] as PropertyAccessorElement).isGetter; 6532 (elementArrayToMerge[0] as PropertyAccessorElement).isGetter;
6652 unionedPropertyAccessor.setter = 6533 unionedPropertyAccessor.setter =
6653 (elementArrayToMerge[0] as PropertyAccessorElement).isSetter; 6534 (elementArrayToMerge[0] as PropertyAccessorElement).isSetter;
6654 unionedPropertyAccessor.inheritedElements = elementArrayToMerge; 6535 unionedPropertyAccessor.inheritedElements = elementArrayToMerge;
6655 executable = unionedPropertyAccessor; 6536 executable = unionedPropertyAccessor;
6656 } 6537 }
6657 int numOfParameters = 6538 int numOfParameters = numOfRequiredParameters +
6658 numOfRequiredParameters +
6659 numOfPositionalParameters + 6539 numOfPositionalParameters +
6660 namedParameters.length; 6540 namedParameters.length;
6661 List<ParameterElement> parameters = 6541 List<ParameterElement> parameters =
6662 new List<ParameterElement>(numOfParameters); 6542 new List<ParameterElement>(numOfParameters);
6663 int i = 0; 6543 int i = 0;
6664 for (int j = 0; j < numOfRequiredParameters; j++, i++) { 6544 for (int j = 0; j < numOfRequiredParameters; j++, i++) {
6665 ParameterElementImpl parameter = new ParameterElementImpl("", 0); 6545 ParameterElementImpl parameter = new ParameterElementImpl("", 0);
6666 parameter.type = dynamicType; 6546 parameter.type = dynamicType;
6667 parameter.parameterKind = ParameterKind.REQUIRED; 6547 parameter.parameterKind = ParameterKind.REQUIRED;
6668 parameters[i] = parameter; 6548 parameters[i] = parameter;
(...skipping 14 matching lines...) Expand all
6683 executable.returnType = dynamicType; 6563 executable.returnType = dynamicType;
6684 executable.parameters = parameters; 6564 executable.parameters = parameters;
6685 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(executable); 6565 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(executable);
6686 executable.type = methodType; 6566 executable.type = methodType;
6687 return executable; 6567 return executable;
6688 } 6568 }
6689 6569
6690 /** 6570 /**
6691 * Given some [ExecutableElement], return the list of named parameters. 6571 * Given some [ExecutableElement], return the list of named parameters.
6692 */ 6572 */
6693 static List<String> 6573 static List<String> _getNamedParameterNames(
6694 _getNamedParameterNames(ExecutableElement executableElement) { 6574 ExecutableElement executableElement) {
6695 List<String> namedParameterNames = new List<String>(); 6575 List<String> namedParameterNames = new List<String>();
6696 List<ParameterElement> parameters = executableElement.parameters; 6576 List<ParameterElement> parameters = executableElement.parameters;
6697 for (int i = 0; i < parameters.length; i++) { 6577 for (int i = 0; i < parameters.length; i++) {
6698 ParameterElement parameterElement = parameters[i]; 6578 ParameterElement parameterElement = parameters[i];
6699 if (parameterElement.parameterKind == ParameterKind.NAMED) { 6579 if (parameterElement.parameterKind == ParameterKind.NAMED) {
6700 namedParameterNames.add(parameterElement.name); 6580 namedParameterNames.add(parameterElement.name);
6701 } 6581 }
6702 } 6582 }
6703 return namedParameterNames; 6583 return namedParameterNames;
6704 } 6584 }
6705 6585
6706 /** 6586 /**
6707 * Given some [ExecutableElement] return the number of parameters of the speci fied kind. 6587 * Given some [ExecutableElement] return the number of parameters of the speci fied kind.
6708 */ 6588 */
6709 static int _getNumOfParameters(ExecutableElement executableElement, 6589 static int _getNumOfParameters(
6710 ParameterKind parameterKind) { 6590 ExecutableElement executableElement, ParameterKind parameterKind) {
6711 int parameterCount = 0; 6591 int parameterCount = 0;
6712 List<ParameterElement> parameters = executableElement.parameters; 6592 List<ParameterElement> parameters = executableElement.parameters;
6713 for (int i = 0; i < parameters.length; i++) { 6593 for (int i = 0; i < parameters.length; i++) {
6714 ParameterElement parameterElement = parameters[i]; 6594 ParameterElement parameterElement = parameters[i];
6715 if (parameterElement.parameterKind == parameterKind) { 6595 if (parameterElement.parameterKind == parameterKind) {
6716 parameterCount++; 6596 parameterCount++;
6717 } 6597 }
6718 } 6598 }
6719 return parameterCount; 6599 return parameterCount;
6720 } 6600 }
6721 6601
6722 /** 6602 /**
6723 * Given some [ExecutableElement] return the number of positional parameters. 6603 * Given some [ExecutableElement] return the number of positional parameters.
6724 * 6604 *
6725 * Note: by positional we mean [ParameterKind.REQUIRED] or [ParameterKind.POSI TIONAL]. 6605 * Note: by positional we mean [ParameterKind.REQUIRED] or [ParameterKind.POSI TIONAL].
6726 */ 6606 */
6727 static int 6607 static int _getNumOfPositionalParameters(
6728 _getNumOfPositionalParameters(ExecutableElement executableElement) => 6608 ExecutableElement executableElement) =>
6729 _getNumOfParameters(executableElement, ParameterKind.REQUIRED) + 6609 _getNumOfParameters(executableElement, ParameterKind.REQUIRED) +
6730 _getNumOfParameters(executableElement, ParameterKind.POSITIONAL); 6610 _getNumOfParameters(executableElement, ParameterKind.POSITIONAL);
6731 6611
6732 /** 6612 /**
6733 * Given some [ExecutableElement] return the number of required parameters. 6613 * Given some [ExecutableElement] return the number of required parameters.
6734 */ 6614 */
6735 static int _getNumOfRequiredParameters(ExecutableElement executableElement) => 6615 static int _getNumOfRequiredParameters(ExecutableElement executableElement) =>
6736 _getNumOfParameters(executableElement, ParameterKind.REQUIRED); 6616 _getNumOfParameters(executableElement, ParameterKind.REQUIRED);
6737 6617
6738 /** 6618 /**
(...skipping 24 matching lines...) Expand all
6763 static const INIT_STATE INIT_IN_DECLARATION = 6643 static const INIT_STATE INIT_IN_DECLARATION =
6764 const INIT_STATE('INIT_IN_DECLARATION', 1); 6644 const INIT_STATE('INIT_IN_DECLARATION', 1);
6765 6645
6766 static const INIT_STATE INIT_IN_FIELD_FORMAL = 6646 static const INIT_STATE INIT_IN_FIELD_FORMAL =
6767 const INIT_STATE('INIT_IN_FIELD_FORMAL', 2); 6647 const INIT_STATE('INIT_IN_FIELD_FORMAL', 2);
6768 6648
6769 static const INIT_STATE INIT_IN_INITIALIZERS = 6649 static const INIT_STATE INIT_IN_INITIALIZERS =
6770 const INIT_STATE('INIT_IN_INITIALIZERS', 3); 6650 const INIT_STATE('INIT_IN_INITIALIZERS', 3);
6771 6651
6772 static const List<INIT_STATE> values = const [ 6652 static const List<INIT_STATE> values = const [
6773 NOT_INIT, 6653 NOT_INIT,
6774 INIT_IN_DECLARATION, 6654 INIT_IN_DECLARATION,
6775 INIT_IN_FIELD_FORMAL, 6655 INIT_IN_FIELD_FORMAL,
6776 INIT_IN_INITIALIZERS]; 6656 INIT_IN_INITIALIZERS
6657 ];
6777 6658
6778 const INIT_STATE(String name, int ordinal) : super(name, ordinal); 6659 const INIT_STATE(String name, int ordinal) : super(name, ordinal);
6779 } 6660 }
6780 6661
6781 /** 6662 /**
6782 * Instances of the class `LabelScope` represent a scope in which a single label is defined. 6663 * Instances of the class `LabelScope` represent a scope in which a single label is defined.
6783 */ 6664 */
6784 class LabelScope { 6665 class LabelScope {
6785 /** 6666 /**
6786 * The label scope enclosing this label scope. 6667 * The label scope enclosing this label scope.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
7008 } 6889 }
7009 6890
7010 /** 6891 /**
7011 * Return the library element representing this library, creating it if necess ary. 6892 * Return the library element representing this library, creating it if necess ary.
7012 * 6893 *
7013 * @return the library element representing this library 6894 * @return the library element representing this library
7014 */ 6895 */
7015 LibraryElementImpl get libraryElement { 6896 LibraryElementImpl get libraryElement {
7016 if (_libraryElement == null) { 6897 if (_libraryElement == null) {
7017 try { 6898 try {
7018 _libraryElement = 6899 _libraryElement = _analysisContext
7019 _analysisContext.computeLibraryElement(librarySource) as LibraryElem entImpl; 6900 .computeLibraryElement(librarySource) as LibraryElementImpl;
7020 } on AnalysisException catch (exception, stackTrace) { 6901 } on AnalysisException catch (exception, stackTrace) {
7021 AnalysisEngine.instance.logger.logError( 6902 AnalysisEngine.instance.logger.logError(
7022 "Could not compute library element for ${librarySource.fullName}", 6903 "Could not compute library element for ${librarySource.fullName}",
7023 new CaughtException(exception, stackTrace)); 6904 new CaughtException(exception, stackTrace));
7024 } 6905 }
7025 } 6906 }
7026 return _libraryElement; 6907 return _libraryElement;
7027 } 6908 }
7028 6909
7029 /** 6910 /**
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7069 /** 6950 /**
7070 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 6951 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
7071 * library, or `null` if the URI is not valid. If the URI is not valid, report the error. 6952 * library, or `null` if the URI is not valid. If the URI is not valid, report the error.
7072 * 6953 *
7073 * @param directive the directive which URI should be resolved 6954 * @param directive the directive which URI should be resolved
7074 * @return the result of resolving the URI against the URI of the library 6955 * @return the result of resolving the URI against the URI of the library
7075 */ 6956 */
7076 Source getSource(UriBasedDirective directive) { 6957 Source getSource(UriBasedDirective directive) {
7077 StringLiteral uriLiteral = directive.uri; 6958 StringLiteral uriLiteral = directive.uri;
7078 if (uriLiteral is StringInterpolation) { 6959 if (uriLiteral is StringInterpolation) {
7079 _errorListener.onError( 6960 _errorListener.onError(new AnalysisError.con2(librarySource,
7080 new AnalysisError.con2( 6961 uriLiteral.offset, uriLiteral.length,
7081 librarySource, 6962 CompileTimeErrorCode.URI_WITH_INTERPOLATION));
7082 uriLiteral.offset,
7083 uriLiteral.length,
7084 CompileTimeErrorCode.URI_WITH_INTERPOLATION));
7085 return null; 6963 return null;
7086 } 6964 }
7087 String uriContent = uriLiteral.stringValue.trim(); 6965 String uriContent = uriLiteral.stringValue.trim();
7088 _directiveUris[directive] = uriContent; 6966 _directiveUris[directive] = uriContent;
7089 uriContent = Uri.encodeFull(uriContent); 6967 uriContent = Uri.encodeFull(uriContent);
7090 if (directive is ImportDirective && 6968 if (directive is ImportDirective &&
7091 uriContent.startsWith(_DART_EXT_SCHEME)) { 6969 uriContent.startsWith(_DART_EXT_SCHEME)) {
7092 _libraryElement.hasExtUri = true; 6970 _libraryElement.hasExtUri = true;
7093 return null; 6971 return null;
7094 } 6972 }
7095 try { 6973 try {
7096 parseUriWithException(uriContent); 6974 parseUriWithException(uriContent);
7097 Source source = 6975 Source source =
7098 _analysisContext.sourceFactory.resolveUri(librarySource, uriContent); 6976 _analysisContext.sourceFactory.resolveUri(librarySource, uriContent);
7099 if (!_analysisContext.exists(source)) { 6977 if (!_analysisContext.exists(source)) {
7100 _errorListener.onError( 6978 _errorListener.onError(new AnalysisError.con2(librarySource,
7101 new AnalysisError.con2( 6979 uriLiteral.offset, uriLiteral.length,
7102 librarySource, 6980 CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent]));
7103 uriLiteral.offset,
7104 uriLiteral.length,
7105 CompileTimeErrorCode.URI_DOES_NOT_EXIST,
7106 [uriContent]));
7107 } 6981 }
7108 return source; 6982 return source;
7109 } on URISyntaxException catch (exception) { 6983 } on URISyntaxException catch (exception) {
7110 _errorListener.onError( 6984 _errorListener.onError(new AnalysisError.con2(librarySource,
7111 new AnalysisError.con2( 6985 uriLiteral.offset, uriLiteral.length,
7112 librarySource, 6986 CompileTimeErrorCode.INVALID_URI, [uriContent]));
7113 uriLiteral.offset,
7114 uriLiteral.length,
7115 CompileTimeErrorCode.INVALID_URI,
7116 [uriContent]));
7117 } 6987 }
7118 return null; 6988 return null;
7119 } 6989 }
7120 6990
7121 /** 6991 /**
7122 * Returns the URI value of the given directive. 6992 * Returns the URI value of the given directive.
7123 */ 6993 */
7124 String getUri(UriBasedDirective directive) => _directiveUris[directive]; 6994 String getUri(UriBasedDirective directive) => _directiveUris[directive];
7125 6995
7126 /** 6996 /**
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
7210 part.uriOffset = partUri.offset; 7080 part.uriOffset = partUri.offset;
7211 part.uriEnd = partUri.end; 7081 part.uriEnd = partUri.end;
7212 part.uri = partDirective.uriContent; 7082 part.uri = partDirective.uriContent;
7213 // 7083 //
7214 // Validate that the part contains a part-of directive with the same 7084 // Validate that the part contains a part-of directive with the same
7215 // name as the library. 7085 // name as the library.
7216 // 7086 //
7217 String partLibraryName = 7087 String partLibraryName =
7218 _getPartLibraryName(partSource, partUnit, directivesToResolve); 7088 _getPartLibraryName(partSource, partUnit, directivesToResolve);
7219 if (partLibraryName == null) { 7089 if (partLibraryName == null) {
7220 _errorListener.onError( 7090 _errorListener.onError(new AnalysisError.con2(librarySource,
7221 new AnalysisError.con2( 7091 partUri.offset, partUri.length,
7222 librarySource, 7092 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()]));
7223 partUri.offset,
7224 partUri.length,
7225 CompileTimeErrorCode.PART_OF_NON_PART,
7226 [partUri.toSource()]));
7227 } else if (libraryNameNode == null) { 7093 } else if (libraryNameNode == null) {
7228 // TODO(brianwilkerson) Collect the names declared by the part. 7094 // TODO(brianwilkerson) Collect the names declared by the part.
7229 // If they are all the same then we can use that name as the 7095 // If they are all the same then we can use that name as the
7230 // inferred name of the library and present it in a quick-fix. 7096 // inferred name of the library and present it in a quick-fix.
7231 // partLibraryNames.add(partLibraryName); 7097 // partLibraryNames.add(partLibraryName);
7232 } else if (libraryNameNode.name != partLibraryName) { 7098 } else if (libraryNameNode.name != partLibraryName) {
7233 _errorListener.onError( 7099 _errorListener.onError(new AnalysisError.con2(librarySource,
7234 new AnalysisError.con2( 7100 partUri.offset, partUri.length,
7235 librarySource, 7101 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
7236 partUri.offset, 7102 libraryNameNode.name,
7237 partUri.length, 7103 partLibraryName
7238 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, 7104 ]));
7239 [libraryNameNode.name, partLibraryName]));
7240 } 7105 }
7241 if (entryPoint == null) { 7106 if (entryPoint == null) {
7242 entryPoint = _findEntryPoint(part); 7107 entryPoint = _findEntryPoint(part);
7243 } 7108 }
7244 directive.element = part; 7109 directive.element = part;
7245 sourcedCompilationUnits.add(part); 7110 sourcedCompilationUnits.add(part);
7246 } 7111 }
7247 } 7112 }
7248 } 7113 }
7249 if (hasPartDirective && libraryNameNode == null) { 7114 if (hasPartDirective && libraryNameNode == null) {
7250 _errorListener.onError( 7115 _errorListener.onError(new AnalysisError.con1(librarySource,
7251 new AnalysisError.con1( 7116 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7252 librarySource,
7253 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7254 } 7117 }
7255 // 7118 //
7256 // Create and populate the library element. 7119 // Create and populate the library element.
7257 // 7120 //
7258 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode( 7121 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
7259 _analysisContext.getContextFor(librarySource), 7122 _analysisContext.getContextFor(librarySource), libraryNameNode);
7260 libraryNameNode);
7261 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 7123 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
7262 if (entryPoint != null) { 7124 if (entryPoint != null) {
7263 libraryElement.entryPoint = entryPoint; 7125 libraryElement.entryPoint = entryPoint;
7264 } 7126 }
7265 int sourcedUnitCount = sourcedCompilationUnits.length; 7127 int sourcedUnitCount = sourcedCompilationUnits.length;
7266 libraryElement.parts = sourcedCompilationUnits; 7128 libraryElement.parts = sourcedCompilationUnits;
7267 for (Directive directive in directivesToResolve) { 7129 for (Directive directive in directivesToResolve) {
7268 directive.element = libraryElement; 7130 directive.element = libraryElement;
7269 } 7131 }
7270 library.libraryElement = libraryElement; 7132 library.libraryElement = libraryElement;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
7321 part.uriOffset = partUri.offset; 7183 part.uriOffset = partUri.offset;
7322 part.uriEnd = partUri.end; 7184 part.uriEnd = partUri.end;
7323 part.uri = partDirective.uriContent; 7185 part.uri = partDirective.uriContent;
7324 // 7186 //
7325 // Validate that the part contains a part-of directive with the same 7187 // Validate that the part contains a part-of directive with the same
7326 // name as the library. 7188 // name as the library.
7327 // 7189 //
7328 String partLibraryName = 7190 String partLibraryName =
7329 _getPartLibraryName(partSource, partUnit, directivesToResolve); 7191 _getPartLibraryName(partSource, partUnit, directivesToResolve);
7330 if (partLibraryName == null) { 7192 if (partLibraryName == null) {
7331 _errorListener.onError( 7193 _errorListener.onError(new AnalysisError.con2(librarySource,
7332 new AnalysisError.con2( 7194 partUri.offset, partUri.length,
7333 librarySource, 7195 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()]));
7334 partUri.offset,
7335 partUri.length,
7336 CompileTimeErrorCode.PART_OF_NON_PART,
7337 [partUri.toSource()]));
7338 } else if (libraryNameNode == null) { 7196 } else if (libraryNameNode == null) {
7339 // TODO(brianwilkerson) Collect the names declared by the part. 7197 // TODO(brianwilkerson) Collect the names declared by the part.
7340 // If they are all the same then we can use that name as the 7198 // If they are all the same then we can use that name as the
7341 // inferred name of the library and present it in a quick-fix. 7199 // inferred name of the library and present it in a quick-fix.
7342 // partLibraryNames.add(partLibraryName); 7200 // partLibraryNames.add(partLibraryName);
7343 } else if (libraryNameNode.name != partLibraryName) { 7201 } else if (libraryNameNode.name != partLibraryName) {
7344 _errorListener.onError( 7202 _errorListener.onError(new AnalysisError.con2(librarySource,
7345 new AnalysisError.con2( 7203 partUri.offset, partUri.length,
7346 librarySource, 7204 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
7347 partUri.offset, 7205 libraryNameNode.name,
7348 partUri.length, 7206 partLibraryName
7349 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, 7207 ]));
7350 [libraryNameNode.name, partLibraryName]));
7351 } 7208 }
7352 if (entryPoint == null) { 7209 if (entryPoint == null) {
7353 entryPoint = _findEntryPoint(part); 7210 entryPoint = _findEntryPoint(part);
7354 } 7211 }
7355 directive.element = part; 7212 directive.element = part;
7356 sourcedCompilationUnits.add(part); 7213 sourcedCompilationUnits.add(part);
7357 } 7214 }
7358 } 7215 }
7359 } 7216 }
7360 } 7217 }
7361 if (hasPartDirective && libraryNameNode == null) { 7218 if (hasPartDirective && libraryNameNode == null) {
7362 _errorListener.onError( 7219 _errorListener.onError(new AnalysisError.con1(librarySource,
7363 new AnalysisError.con1( 7220 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7364 librarySource,
7365 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7366 } 7221 }
7367 // 7222 //
7368 // Create and populate the library element. 7223 // Create and populate the library element.
7369 // 7224 //
7370 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode( 7225 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
7371 _analysisContext.getContextFor(librarySource), 7226 _analysisContext.getContextFor(librarySource), libraryNameNode);
7372 libraryNameNode);
7373 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 7227 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
7374 if (entryPoint != null) { 7228 if (entryPoint != null) {
7375 libraryElement.entryPoint = entryPoint; 7229 libraryElement.entryPoint = entryPoint;
7376 } 7230 }
7377 int sourcedUnitCount = sourcedCompilationUnits.length; 7231 int sourcedUnitCount = sourcedCompilationUnits.length;
7378 libraryElement.parts = sourcedCompilationUnits; 7232 libraryElement.parts = sourcedCompilationUnits;
7379 for (Directive directive in directivesToResolve) { 7233 for (Directive directive in directivesToResolve) {
7380 directive.element = libraryElement; 7234 directive.element = libraryElement;
7381 } 7235 }
7382 library.libraryElement = libraryElement; 7236 library.libraryElement = libraryElement;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
7517 @override 7371 @override
7518 Source getSource(AstNode node) { 7372 Source getSource(AstNode node) {
7519 Source source = super.getSource(node); 7373 Source source = super.getSource(node);
7520 if (source == null) { 7374 if (source == null) {
7521 source = _definingLibrary.definingCompilationUnit.source; 7375 source = _definingLibrary.definingCompilationUnit.source;
7522 } 7376 }
7523 return source; 7377 return source;
7524 } 7378 }
7525 7379
7526 @override 7380 @override
7527 Element internalLookup(Identifier identifier, String name, 7381 Element internalLookup(
7528 LibraryElement referencingLibrary) { 7382 Identifier identifier, String name, LibraryElement referencingLibrary) {
7529 Element foundElement = localLookup(name, referencingLibrary); 7383 Element foundElement = localLookup(name, referencingLibrary);
7530 if (foundElement != null) { 7384 if (foundElement != null) {
7531 return foundElement; 7385 return foundElement;
7532 } 7386 }
7533 for (int i = 0; i < _importedNamespaces.length; i++) { 7387 for (int i = 0; i < _importedNamespaces.length; i++) {
7534 Namespace nameSpace = _importedNamespaces[i]; 7388 Namespace nameSpace = _importedNamespaces[i];
7535 Element element = nameSpace.get(name); 7389 Element element = nameSpace.get(name);
7536 if (element != null) { 7390 if (element != null) {
7537 if (foundElement == null) { 7391 if (foundElement == null) {
7538 foundElement = element; 7392 foundElement = element;
7539 } else if (!identical(foundElement, element)) { 7393 } else if (!identical(foundElement, element)) {
7540 foundElement = MultiplyDefinedElementImpl.fromElements( 7394 foundElement = MultiplyDefinedElementImpl.fromElements(
7541 _definingLibrary.context, 7395 _definingLibrary.context, foundElement, element);
7542 foundElement,
7543 element);
7544 } 7396 }
7545 } 7397 }
7546 } 7398 }
7547 if (foundElement is MultiplyDefinedElementImpl) { 7399 if (foundElement is MultiplyDefinedElementImpl) {
7548 foundElement = _removeSdkElements( 7400 foundElement = _removeSdkElements(
7549 identifier, 7401 identifier, name, foundElement as MultiplyDefinedElementImpl);
7550 name,
7551 foundElement as MultiplyDefinedElementImpl);
7552 } 7402 }
7553 if (foundElement is MultiplyDefinedElementImpl) { 7403 if (foundElement is MultiplyDefinedElementImpl) {
7554 String foundEltName = foundElement.displayName; 7404 String foundEltName = foundElement.displayName;
7555 List<Element> conflictingMembers = 7405 List<Element> conflictingMembers =
7556 (foundElement as MultiplyDefinedElementImpl).conflictingElements; 7406 (foundElement as MultiplyDefinedElementImpl).conflictingElements;
7557 int count = conflictingMembers.length; 7407 int count = conflictingMembers.length;
7558 List<String> libraryNames = new List<String>(count); 7408 List<String> libraryNames = new List<String>(count);
7559 for (int i = 0; i < count; i++) { 7409 for (int i = 0; i < count; i++) {
7560 libraryNames[i] = _getLibraryName(conflictingMembers[i]); 7410 libraryNames[i] = _getLibraryName(conflictingMembers[i]);
7561 } 7411 }
7562 libraryNames.sort(); 7412 libraryNames.sort();
7563 errorListener.onError( 7413 errorListener.onError(new AnalysisError.con2(getSource(identifier),
7564 new AnalysisError.con2( 7414 identifier.offset, identifier.length,
7565 getSource(identifier), 7415 StaticWarningCode.AMBIGUOUS_IMPORT, [
7566 identifier.offset, 7416 foundEltName,
7567 identifier.length, 7417 StringUtilities.printListOfQuotedNames(libraryNames)
7568 StaticWarningCode.AMBIGUOUS_IMPORT, 7418 ]));
7569 [foundEltName, StringUtilities.printListOfQuotedNames(libraryNames )]));
7570 return foundElement; 7419 return foundElement;
7571 } 7420 }
7572 if (foundElement != null) { 7421 if (foundElement != null) {
7573 defineNameWithoutChecking(name, foundElement); 7422 defineNameWithoutChecking(name, foundElement);
7574 } 7423 }
7575 return foundElement; 7424 return foundElement;
7576 } 7425 }
7577 7426
7578 /** 7427 /**
7579 * Create all of the namespaces associated with the libraries imported into th is library. The 7428 * Create all of the namespaces associated with the libraries imported into th is library. The
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
7611 int count = imports.length; 7460 int count = imports.length;
7612 for (int i = 0; i < count; i++) { 7461 for (int i = 0; i < count; i++) {
7613 if (identical(imports[i].importedLibrary, library)) { 7462 if (identical(imports[i].importedLibrary, library)) {
7614 return library.definingCompilationUnit.displayName; 7463 return library.definingCompilationUnit.displayName;
7615 } 7464 }
7616 } 7465 }
7617 List<String> indirectSources = new List<String>(); 7466 List<String> indirectSources = new List<String>();
7618 for (int i = 0; i < count; i++) { 7467 for (int i = 0; i < count; i++) {
7619 LibraryElement importedLibrary = imports[i].importedLibrary; 7468 LibraryElement importedLibrary = imports[i].importedLibrary;
7620 if (importedLibrary != null) { 7469 if (importedLibrary != null) {
7621 for (LibraryElement exportedLibrary in 7470 for (LibraryElement exportedLibrary
7622 importedLibrary.exportedLibraries) { 7471 in importedLibrary.exportedLibraries) {
7623 if (identical(exportedLibrary, library)) { 7472 if (identical(exportedLibrary, library)) {
7624 indirectSources.add( 7473 indirectSources
7625 importedLibrary.definingCompilationUnit.displayName); 7474 .add(importedLibrary.definingCompilationUnit.displayName);
7626 } 7475 }
7627 } 7476 }
7628 } 7477 }
7629 } 7478 }
7630 int indirectCount = indirectSources.length; 7479 int indirectCount = indirectSources.length;
7631 StringBuffer buffer = new StringBuffer(); 7480 StringBuffer buffer = new StringBuffer();
7632 buffer.write(library.definingCompilationUnit.displayName); 7481 buffer.write(library.definingCompilationUnit.displayName);
7633 if (indirectCount > 0) { 7482 if (indirectCount > 0) {
7634 buffer.write(" (via "); 7483 buffer.write(" (via ");
7635 if (indirectCount > 1) { 7484 if (indirectCount > 1) {
(...skipping 26 matching lines...) Expand all
7662 for (Element member in conflictingMembers) { 7511 for (Element member in conflictingMembers) {
7663 if (member.library.isInSdk) { 7512 if (member.library.isInSdk) {
7664 sdkElement = member; 7513 sdkElement = member;
7665 } else { 7514 } else {
7666 conflictingMembers[to++] = member; 7515 conflictingMembers[to++] = member;
7667 } 7516 }
7668 } 7517 }
7669 if (sdkElement != null && to > 0) { 7518 if (sdkElement != null && to > 0) {
7670 String sdkLibName = _getLibraryName(sdkElement); 7519 String sdkLibName = _getLibraryName(sdkElement);
7671 String otherLibName = _getLibraryName(conflictingMembers[0]); 7520 String otherLibName = _getLibraryName(conflictingMembers[0]);
7672 errorListener.onError( 7521 errorListener.onError(new AnalysisError.con2(getSource(identifier),
7673 new AnalysisError.con2( 7522 identifier.offset, identifier.length,
7674 getSource(identifier), 7523 StaticWarningCode.CONFLICTING_DART_IMPORT, [
7675 identifier.offset, 7524 name,
7676 identifier.length, 7525 sdkLibName,
7677 StaticWarningCode.CONFLICTING_DART_IMPORT, 7526 otherLibName
7678 [name, sdkLibName, otherLibName])); 7527 ]));
7679 } 7528 }
7680 if (to == length) { 7529 if (to == length) {
7681 // None of the members were removed 7530 // None of the members were removed
7682 return foundElement; 7531 return foundElement;
7683 } else if (to == 1) { 7532 } else if (to == 1) {
7684 // All but one member was removed 7533 // All but one member was removed
7685 return conflictingMembers[0]; 7534 return conflictingMembers[0];
7686 } else if (to == 0) { 7535 } else if (to == 0) {
7687 // All members were removed 7536 // All members were removed
7688 AnalysisEngine.instance.logger.logInformation( 7537 AnalysisEngine.instance.logger
7689 "Multiply defined SDK element: $foundElement"); 7538 .logInformation("Multiply defined SDK element: $foundElement");
7690 return foundElement; 7539 return foundElement;
7691 } 7540 }
7692 List<Element> remaining = new List<Element>(to); 7541 List<Element> remaining = new List<Element>(to);
7693 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to); 7542 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to);
7694 return new MultiplyDefinedElementImpl(_definingLibrary.context, remaining); 7543 return new MultiplyDefinedElementImpl(_definingLibrary.context, remaining);
7695 } 7544 }
7696 } 7545 }
7697 7546
7698 /** 7547 /**
7699 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent 7548 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
7793 * Resolve the library specified by the given source in the given context. The library is assumed 7642 * Resolve the library specified by the given source in the given context. The library is assumed
7794 * to be embedded in the given source. 7643 * to be embedded in the given source.
7795 * 7644 *
7796 * @param librarySource the source specifying the defining compilation unit of the library to be 7645 * @param librarySource the source specifying the defining compilation unit of the library to be
7797 * resolved 7646 * resolved
7798 * @param unit the compilation unit representing the embedded library 7647 * @param unit the compilation unit representing the embedded library
7799 * @param fullAnalysis `true` if a full analysis should be performed 7648 * @param fullAnalysis `true` if a full analysis should be performed
7800 * @return the element representing the resolved library 7649 * @return the element representing the resolved library
7801 * @throws AnalysisException if the library could not be resolved for some rea son 7650 * @throws AnalysisException if the library could not be resolved for some rea son
7802 */ 7651 */
7803 LibraryElement resolveEmbeddedLibrary(Source librarySource, 7652 LibraryElement resolveEmbeddedLibrary(
7804 CompilationUnit unit, bool fullAnalysis) { 7653 Source librarySource, CompilationUnit unit, bool fullAnalysis) {
7805 // 7654 //
7806 // Create the objects representing the library being resolved and the core 7655 // Create the objects representing the library being resolved and the core
7807 // library. 7656 // library.
7808 // 7657 //
7809 Library targetLibrary = _createLibraryWithUnit(librarySource, unit); 7658 Library targetLibrary = _createLibraryWithUnit(librarySource, unit);
7810 _coreLibrary = _libraryMap[_coreLibrarySource]; 7659 _coreLibrary = _libraryMap[_coreLibrarySource];
7811 if (_coreLibrary == null) { 7660 if (_coreLibrary == null) {
7812 // This will only happen if the library being analyzed is the core 7661 // This will only happen if the library being analyzed is the core
7813 // library. 7662 // library.
7814 _coreLibrary = createLibrary(_coreLibrarySource); 7663 _coreLibrary = createLibrary(_coreLibrarySource);
7815 if (_coreLibrary == null) { 7664 if (_coreLibrary == null) {
7816 LibraryResolver2.missingCoreLibrary( 7665 LibraryResolver2.missingCoreLibrary(
7817 analysisContext, 7666 analysisContext, _coreLibrarySource);
7818 _coreLibrarySource);
7819 } 7667 }
7820 } 7668 }
7821 _asyncLibrary = _libraryMap[_asyncLibrarySource]; 7669 _asyncLibrary = _libraryMap[_asyncLibrarySource];
7822 if (_asyncLibrary == null) { 7670 if (_asyncLibrary == null) {
7823 // This will only happen if the library being analyzed is the async 7671 // This will only happen if the library being analyzed is the async
7824 // library. 7672 // library.
7825 _asyncLibrary = createLibrary(_asyncLibrarySource); 7673 _asyncLibrary = createLibrary(_asyncLibrarySource);
7826 if (_asyncLibrary == null) { 7674 if (_asyncLibrary == null) {
7827 LibraryResolver2.missingAsyncLibrary( 7675 LibraryResolver2.missingAsyncLibrary(
7828 analysisContext, 7676 analysisContext, _asyncLibrarySource);
7829 _asyncLibrarySource);
7830 } 7677 }
7831 } 7678 }
7832 // 7679 //
7833 // Compute the set of libraries that need to be resolved together. 7680 // Compute the set of libraries that need to be resolved together.
7834 // 7681 //
7835 _computeEmbeddedLibraryDependencies(targetLibrary, unit); 7682 _computeEmbeddedLibraryDependencies(targetLibrary, unit);
7836 _librariesInCycles = _computeLibrariesInCycles(targetLibrary); 7683 _librariesInCycles = _computeLibrariesInCycles(targetLibrary);
7837 // 7684 //
7838 // Build the element models representing the libraries being resolved. 7685 // Build the element models representing the libraries being resolved.
7839 // This is done in three steps: 7686 // This is done in three steps:
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
7991 * @param dependencyMap a table mapping libraries to the collection of librari es from which those 7838 * @param dependencyMap a table mapping libraries to the collection of librari es from which those
7992 * libraries are referenced 7839 * libraries are referenced
7993 */ 7840 */
7994 void _addLibrariesInCycle(Library library, Set<Library> librariesInCycle, 7841 void _addLibrariesInCycle(Library library, Set<Library> librariesInCycle,
7995 HashMap<Library, List<Library>> dependencyMap) { 7842 HashMap<Library, List<Library>> dependencyMap) {
7996 if (librariesInCycle.add(library)) { 7843 if (librariesInCycle.add(library)) {
7997 List<Library> dependentLibraries = dependencyMap[library]; 7844 List<Library> dependentLibraries = dependencyMap[library];
7998 if (dependentLibraries != null) { 7845 if (dependentLibraries != null) {
7999 for (Library dependentLibrary in dependentLibraries) { 7846 for (Library dependentLibrary in dependentLibraries) {
8000 _addLibrariesInCycle( 7847 _addLibrariesInCycle(
8001 dependentLibrary, 7848 dependentLibrary, librariesInCycle, dependencyMap);
8002 librariesInCycle,
8003 dependencyMap);
8004 } 7849 }
8005 } 7850 }
8006 } 7851 }
8007 } 7852 }
8008 7853
8009 /** 7854 /**
8010 * Add the given library, and all libraries reachable from it that have not al ready been visited, 7855 * Add the given library, and all libraries reachable from it that have not al ready been visited,
8011 * to the given dependency map. 7856 * to the given dependency map.
8012 * 7857 *
8013 * @param library the library currently being added to the dependency map 7858 * @param library the library currently being added to the dependency map
8014 * @param dependencyMap the dependency map being computed 7859 * @param dependencyMap the dependency map being computed
8015 * @param visitedLibraries the libraries that have already been visited, used to prevent infinite 7860 * @param visitedLibraries the libraries that have already been visited, used to prevent infinite
8016 * recursion 7861 * recursion
8017 */ 7862 */
8018 void _addToDependencyMap(Library library, HashMap<Library, 7863 void _addToDependencyMap(Library library,
8019 List<Library>> dependencyMap, Set<Library> visitedLibraries) { 7864 HashMap<Library, List<Library>> dependencyMap,
7865 Set<Library> visitedLibraries) {
8020 if (visitedLibraries.add(library)) { 7866 if (visitedLibraries.add(library)) {
8021 bool asyncFound = false; 7867 bool asyncFound = false;
8022 for (Library referencedLibrary in library.importsAndExports) { 7868 for (Library referencedLibrary in library.importsAndExports) {
8023 _addDependencyToMap(dependencyMap, library, referencedLibrary); 7869 _addDependencyToMap(dependencyMap, library, referencedLibrary);
8024 _addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); 7870 _addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries);
8025 if (identical(referencedLibrary, _asyncLibrary)) { 7871 if (identical(referencedLibrary, _asyncLibrary)) {
8026 asyncFound = true; 7872 asyncFound = true;
8027 } 7873 }
8028 } 7874 }
8029 if (!library.explicitlyImportsCore && !identical(library, _coreLibrary)) { 7875 if (!library.explicitlyImportsCore && !identical(library, _coreLibrary)) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
8109 prefix = new PrefixElementImpl.forNode(prefixNode); 7955 prefix = new PrefixElementImpl.forNode(prefixNode);
8110 nameToPrefixMap[prefixName] = prefix; 7956 nameToPrefixMap[prefixName] = prefix;
8111 } 7957 }
8112 importElement.prefix = prefix; 7958 importElement.prefix = prefix;
8113 prefixNode.staticElement = prefix; 7959 prefixNode.staticElement = prefix;
8114 } 7960 }
8115 directive.element = importElement; 7961 directive.element = importElement;
8116 imports.add(importElement); 7962 imports.add(importElement);
8117 if (analysisContext.computeKindOf(importedSource) != 7963 if (analysisContext.computeKindOf(importedSource) !=
8118 SourceKind.LIBRARY) { 7964 SourceKind.LIBRARY) {
8119 ErrorCode errorCode = (importElement.isDeferred ? 7965 ErrorCode errorCode = (importElement.isDeferred
8120 StaticWarningCode.IMPORT_OF_NON_LIBRARY : 7966 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
8121 CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); 7967 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
8122 _errorListener.onError( 7968 _errorListener.onError(new AnalysisError.con2(
8123 new AnalysisError.con2( 7969 library.librarySource, uriLiteral.offset, uriLiteral.length,
8124 library.librarySource, 7970 errorCode, [uriLiteral.toSource()]));
8125 uriLiteral.offset,
8126 uriLiteral.length,
8127 errorCode,
8128 [uriLiteral.toSource()]));
8129 } 7971 }
8130 } 7972 }
8131 } 7973 }
8132 } else if (directive is ExportDirective) { 7974 } else if (directive is ExportDirective) {
8133 ExportDirective exportDirective = directive; 7975 ExportDirective exportDirective = directive;
8134 Source exportedSource = exportDirective.source; 7976 Source exportedSource = exportDirective.source;
8135 if (exportedSource != null) { 7977 if (exportedSource != null) {
8136 // The exported source will be null if the URI in the export 7978 // The exported source will be null if the URI in the export
8137 // directive was invalid. 7979 // directive was invalid.
8138 Library exportedLibrary = _libraryMap[exportedSource]; 7980 Library exportedLibrary = _libraryMap[exportedSource];
8139 if (exportedLibrary != null) { 7981 if (exportedLibrary != null) {
8140 ExportElementImpl exportElement = new ExportElementImpl(); 7982 ExportElementImpl exportElement = new ExportElementImpl();
8141 StringLiteral uriLiteral = exportDirective.uri; 7983 StringLiteral uriLiteral = exportDirective.uri;
8142 exportElement.uriOffset = uriLiteral.offset; 7984 exportElement.uriOffset = uriLiteral.offset;
8143 exportElement.uriEnd = uriLiteral.end; 7985 exportElement.uriEnd = uriLiteral.end;
8144 exportElement.uri = exportDirective.uriContent; 7986 exportElement.uri = exportDirective.uriContent;
8145 exportElement.combinators = _buildCombinators(exportDirective); 7987 exportElement.combinators = _buildCombinators(exportDirective);
8146 LibraryElement exportedLibraryElement = 7988 LibraryElement exportedLibraryElement =
8147 exportedLibrary.libraryElement; 7989 exportedLibrary.libraryElement;
8148 if (exportedLibraryElement != null) { 7990 if (exportedLibraryElement != null) {
8149 exportElement.exportedLibrary = exportedLibraryElement; 7991 exportElement.exportedLibrary = exportedLibraryElement;
8150 } 7992 }
8151 directive.element = exportElement; 7993 directive.element = exportElement;
8152 exports.add(exportElement); 7994 exports.add(exportElement);
8153 if (analysisContext.computeKindOf(exportedSource) != 7995 if (analysisContext.computeKindOf(exportedSource) !=
8154 SourceKind.LIBRARY) { 7996 SourceKind.LIBRARY) {
8155 _errorListener.onError( 7997 _errorListener.onError(new AnalysisError.con2(
8156 new AnalysisError.con2( 7998 library.librarySource, uriLiteral.offset, uriLiteral.length,
8157 library.librarySource, 7999 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, [
8158 uriLiteral.offset, 8000 uriLiteral.toSource()
8159 uriLiteral.length, 8001 ]));
8160 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
8161 [uriLiteral.toSource()]));
8162 } 8002 }
8163 } 8003 }
8164 } 8004 }
8165 } 8005 }
8166 } 8006 }
8167 Source librarySource = library.librarySource; 8007 Source librarySource = library.librarySource;
8168 if (!library.explicitlyImportsCore && 8008 if (!library.explicitlyImportsCore &&
8169 _coreLibrarySource != librarySource) { 8009 _coreLibrarySource != librarySource) {
8170 ImportElementImpl importElement = new ImportElementImpl(-1); 8010 ImportElementImpl importElement = new ImportElementImpl(-1);
8171 importElement.importedLibrary = _coreLibrary.libraryElement; 8011 importElement.importedLibrary = _coreLibrary.libraryElement;
8172 importElement.synthetic = true; 8012 importElement.synthetic = true;
8173 imports.add(importElement); 8013 imports.add(importElement);
8174 } 8014 }
8175 LibraryElementImpl libraryElement = library.libraryElement; 8015 LibraryElementImpl libraryElement = library.libraryElement;
8176 libraryElement.imports = imports; 8016 libraryElement.imports = imports;
8177 libraryElement.exports = exports; 8017 libraryElement.exports = exports;
8178 if (libraryElement.entryPoint == null) { 8018 if (libraryElement.entryPoint == null) {
8179 Namespace namespace = 8019 Namespace namespace = new NamespaceBuilder()
8180 new NamespaceBuilder().createExportNamespaceForLibrary(libraryElemen t); 8020 .createExportNamespaceForLibrary(libraryElement);
8181 Element element = namespace.get(LibraryElementBuilder.ENTRY_POINT_NAME); 8021 Element element = namespace.get(LibraryElementBuilder.ENTRY_POINT_NAME);
8182 if (element is FunctionElement) { 8022 if (element is FunctionElement) {
8183 libraryElement.entryPoint = element; 8023 libraryElement.entryPoint = element;
8184 } 8024 }
8185 } 8025 }
8186 } 8026 }
8187 } 8027 }
8188 8028
8189 /** 8029 /**
8190 * Build element models for all of the libraries in the current cycle. 8030 * Build element models for all of the libraries in the current cycle.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
8223 * [ImplicitConstructorBuilder]. 8063 * [ImplicitConstructorBuilder].
8224 * 8064 *
8225 * @throws AnalysisException if any of the type hierarchies could not be resol ved 8065 * @throws AnalysisException if any of the type hierarchies could not be resol ved
8226 */ 8066 */
8227 void _buildImplicitConstructors() { 8067 void _buildImplicitConstructors() {
8228 PerformanceStatistics.resolve.makeCurrentWhile(() { 8068 PerformanceStatistics.resolve.makeCurrentWhile(() {
8229 ImplicitConstructorComputer computer = 8069 ImplicitConstructorComputer computer =
8230 new ImplicitConstructorComputer(_typeProvider); 8070 new ImplicitConstructorComputer(_typeProvider);
8231 for (Library library in _librariesInCycles) { 8071 for (Library library in _librariesInCycles) {
8232 for (Source source in library.compilationUnitSources) { 8072 for (Source source in library.compilationUnitSources) {
8233 computer.add( 8073 computer.add(library.getAST(source), source, library.libraryElement,
8234 library.getAST(source),
8235 source,
8236 library.libraryElement,
8237 library.libraryScope); 8074 library.libraryScope);
8238 } 8075 }
8239 } 8076 }
8240 computer.compute(); 8077 computer.compute();
8241 }); 8078 });
8242 } 8079 }
8243 8080
8244 /** 8081 /**
8245 * Resolve the types referenced by function type aliases across all of the fun ction type aliases 8082 * Resolve the types referenced by function type aliases across all of the fun ction type aliases
8246 * defined in the current cycle. 8083 * defined in the current cycle.
(...skipping 11 matching lines...) Expand all
8258 if (member is FunctionTypeAlias) { 8095 if (member is FunctionTypeAlias) {
8259 typeAliases.add( 8096 typeAliases.add(
8260 new LibraryResolver_TypeAliasInfo(library, source, member)); 8097 new LibraryResolver_TypeAliasInfo(library, source, member));
8261 } 8098 }
8262 } 8099 }
8263 } 8100 }
8264 } 8101 }
8265 // TODO(brianwilkerson) We need to sort the type aliases such that all 8102 // TODO(brianwilkerson) We need to sort the type aliases such that all
8266 // aliases referenced by an alias T are resolved before we resolve T. 8103 // aliases referenced by an alias T are resolved before we resolve T.
8267 for (LibraryResolver_TypeAliasInfo info in typeAliases) { 8104 for (LibraryResolver_TypeAliasInfo info in typeAliases) {
8268 TypeResolverVisitor visitor = 8105 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(
8269 new TypeResolverVisitor.con1(info._library, info._source, _typeProvi der); 8106 info._library, info._source, _typeProvider);
8270 info._typeAlias.accept(visitor); 8107 info._typeAlias.accept(visitor);
8271 } 8108 }
8272 }); 8109 });
8273 } 8110 }
8274 8111
8275 /** 8112 /**
8276 * Resolve the type hierarchy across all of the types declared in the librarie s in the current 8113 * Resolve the type hierarchy across all of the types declared in the librarie s in the current
8277 * cycle. 8114 * cycle.
8278 * 8115 *
8279 * @throws AnalysisException if any of the type hierarchies could not be resol ved 8116 * @throws AnalysisException if any of the type hierarchies could not be resol ved
8280 */ 8117 */
8281 void _buildTypeHierarchies() { 8118 void _buildTypeHierarchies() {
8282 PerformanceStatistics.resolve.makeCurrentWhile(() { 8119 PerformanceStatistics.resolve.makeCurrentWhile(() {
8283 for (Library library in _librariesInCycles) { 8120 for (Library library in _librariesInCycles) {
8284 for (Source source in library.compilationUnitSources) { 8121 for (Source source in library.compilationUnitSources) {
8285 TypeResolverVisitorFactory typeResolverVisitorFactory = 8122 TypeResolverVisitorFactory typeResolverVisitorFactory =
8286 analysisContext.typeResolverVisitorFactory; 8123 analysisContext.typeResolverVisitorFactory;
8287 TypeResolverVisitor visitor = (typeResolverVisitorFactory == null) ? 8124 TypeResolverVisitor visitor = (typeResolverVisitorFactory == null)
8288 new TypeResolverVisitor.con1(library, source, _typeProvider) : 8125 ? new TypeResolverVisitor.con1(library, source, _typeProvider)
8289 typeResolverVisitorFactory(library, source, _typeProvider); 8126 : typeResolverVisitorFactory(library, source, _typeProvider);
8290 library.getAST(source).accept(visitor); 8127 library.getAST(source).accept(visitor);
8291 } 8128 }
8292 } 8129 }
8293 }); 8130 });
8294 } 8131 }
8295 8132
8296 /** 8133 /**
8297 * Compute a dependency map of libraries reachable from the given library. A d ependency map is a 8134 * Compute a dependency map of libraries reachable from the given library. A d ependency map is a
8298 * table that maps individual libraries to a list of the libraries that either import or export 8135 * table that maps individual libraries to a list of the libraries that either import or export
8299 * those libraries. 8136 * those libraries.
(...skipping 11 matching lines...) Expand all
8311 return dependencyMap; 8148 return dependencyMap;
8312 } 8149 }
8313 8150
8314 /** 8151 /**
8315 * Recursively traverse the libraries reachable from the given library, creati ng instances of the 8152 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
8316 * class [Library] to represent them, and record the references in the library objects. 8153 * class [Library] to represent them, and record the references in the library objects.
8317 * 8154 *
8318 * @param library the library to be processed to find libraries that have not yet been traversed 8155 * @param library the library to be processed to find libraries that have not yet been traversed
8319 * @throws AnalysisException if some portion of the library graph could not be traversed 8156 * @throws AnalysisException if some portion of the library graph could not be traversed
8320 */ 8157 */
8321 void _computeEmbeddedLibraryDependencies(Library library, 8158 void _computeEmbeddedLibraryDependencies(
8322 CompilationUnit unit) { 8159 Library library, CompilationUnit unit) {
8323 Source librarySource = library.librarySource; 8160 Source librarySource = library.librarySource;
8324 HashSet<Source> exportedSources = new HashSet<Source>(); 8161 HashSet<Source> exportedSources = new HashSet<Source>();
8325 HashSet<Source> importedSources = new HashSet<Source>(); 8162 HashSet<Source> importedSources = new HashSet<Source>();
8326 for (Directive directive in unit.directives) { 8163 for (Directive directive in unit.directives) {
8327 if (directive is ExportDirective) { 8164 if (directive is ExportDirective) {
8328 Source exportSource = _resolveSource(librarySource, directive); 8165 Source exportSource = _resolveSource(librarySource, directive);
8329 if (exportSource != null) { 8166 if (exportSource != null) {
8330 exportedSources.add(exportSource); 8167 exportedSources.add(exportSource);
8331 } 8168 }
8332 } else if (directive is ImportDirective) { 8169 } else if (directive is ImportDirective) {
8333 Source importSource = _resolveSource(librarySource, directive); 8170 Source importSource = _resolveSource(librarySource, directive);
8334 if (importSource != null) { 8171 if (importSource != null) {
8335 importedSources.add(importSource); 8172 importedSources.add(importSource);
8336 } 8173 }
8337 } 8174 }
8338 } 8175 }
8339 _computeLibraryDependenciesFromDirectives( 8176 _computeLibraryDependenciesFromDirectives(library,
8340 library, 8177 new List.from(importedSources), new List.from(exportedSources));
8341 new List.from(importedSources),
8342 new List.from(exportedSources));
8343 } 8178 }
8344 8179
8345 /** 8180 /**
8346 * Return a collection containing all of the libraries reachable from the give n library that are 8181 * Return a collection containing all of the libraries reachable from the give n library that are
8347 * contained in a cycle that includes the given library. 8182 * contained in a cycle that includes the given library.
8348 * 8183 *
8349 * @param library the library that must be included in any cycles whose member s are to be returned 8184 * @param library the library that must be included in any cycles whose member s are to be returned
8350 * @return all of the libraries referenced by the given library that have a ci rcular reference 8185 * @return all of the libraries referenced by the given library that have a ci rcular reference
8351 * back to the given library 8186 * back to the given library
8352 */ 8187 */
8353 Set<Library> _computeLibrariesInCycles(Library library) { 8188 Set<Library> _computeLibrariesInCycles(Library library) {
8354 HashMap<Library, List<Library>> dependencyMap = 8189 HashMap<Library, List<Library>> dependencyMap =
8355 _computeDependencyMap(library); 8190 _computeDependencyMap(library);
8356 Set<Library> librariesInCycle = new HashSet<Library>(); 8191 Set<Library> librariesInCycle = new HashSet<Library>();
8357 _addLibrariesInCycle(library, librariesInCycle, dependencyMap); 8192 _addLibrariesInCycle(library, librariesInCycle, dependencyMap);
8358 return librariesInCycle; 8193 return librariesInCycle;
8359 } 8194 }
8360 8195
8361 /** 8196 /**
8362 * Recursively traverse the libraries reachable from the given library, creati ng instances of the 8197 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
8363 * class [Library] to represent them, and record the references in the library objects. 8198 * class [Library] to represent them, and record the references in the library objects.
8364 * 8199 *
8365 * @param library the library to be processed to find libraries that have not yet been traversed 8200 * @param library the library to be processed to find libraries that have not yet been traversed
8366 * @throws AnalysisException if some portion of the library graph could not be traversed 8201 * @throws AnalysisException if some portion of the library graph could not be traversed
8367 */ 8202 */
8368 void _computeLibraryDependencies(Library library) { 8203 void _computeLibraryDependencies(Library library) {
8369 Source librarySource = library.librarySource; 8204 Source librarySource = library.librarySource;
8370 _computeLibraryDependenciesFromDirectives( 8205 _computeLibraryDependenciesFromDirectives(library,
8371 library,
8372 analysisContext.computeImportedLibraries(librarySource), 8206 analysisContext.computeImportedLibraries(librarySource),
8373 analysisContext.computeExportedLibraries(librarySource)); 8207 analysisContext.computeExportedLibraries(librarySource));
8374 } 8208 }
8375 8209
8376 /** 8210 /**
8377 * Recursively traverse the libraries reachable from the given library, creati ng instances of the 8211 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
8378 * class [Library] to represent them, and record the references in the library objects. 8212 * class [Library] to represent them, and record the references in the library objects.
8379 * 8213 *
8380 * @param library the library to be processed to find libraries that have not yet been traversed 8214 * @param library the library to be processed to find libraries that have not yet been traversed
8381 * @param importedSources an array containing the sources that are imported in to the given library 8215 * @param importedSources an array containing the sources that are imported in to the given library
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
8489 identifiers[i] = names[i].name; 8323 identifiers[i] = names[i].name;
8490 } 8324 }
8491 return identifiers; 8325 return identifiers;
8492 } 8326 }
8493 8327
8494 /** 8328 /**
8495 * Compute a value for all of the constants in the libraries being analyzed. 8329 * Compute a value for all of the constants in the libraries being analyzed.
8496 */ 8330 */
8497 void _performConstantEvaluation() { 8331 void _performConstantEvaluation() {
8498 PerformanceStatistics.resolve.makeCurrentWhile(() { 8332 PerformanceStatistics.resolve.makeCurrentWhile(() {
8499 ConstantValueComputer computer = 8333 ConstantValueComputer computer = new ConstantValueComputer(
8500 new ConstantValueComputer(_typeProvider, analysisContext.declaredVaria bles); 8334 _typeProvider, analysisContext.declaredVariables);
8501 for (Library library in _librariesInCycles) { 8335 for (Library library in _librariesInCycles) {
8502 for (Source source in library.compilationUnitSources) { 8336 for (Source source in library.compilationUnitSources) {
8503 try { 8337 try {
8504 CompilationUnit unit = library.getAST(source); 8338 CompilationUnit unit = library.getAST(source);
8505 if (unit != null) { 8339 if (unit != null) {
8506 computer.add(unit); 8340 computer.add(unit);
8507 } 8341 }
8508 } on AnalysisException catch (exception, stackTrace) { 8342 } on AnalysisException catch (exception, stackTrace) {
8509 AnalysisEngine.instance.logger.logError( 8343 AnalysisEngine.instance.logger.logError(
8510 "Internal Error: Could not access AST for ${source.fullName} dur ing constant evaluation", 8344 "Internal Error: Could not access AST for ${source.fullName} dur ing constant evaluation",
8511 new CaughtException(exception, stackTrace)); 8345 new CaughtException(exception, stackTrace));
8512 } 8346 }
8513 } 8347 }
8514 } 8348 }
8515 computer.computeValues(); 8349 computer.computeValues();
8516 // As a temporary workaround for issue 21572, run ConstantVerifier now. 8350 // As a temporary workaround for issue 21572, run ConstantVerifier now.
8517 // TODO(paulberry): remove this workaround once issue 21572 is fixed. 8351 // TODO(paulberry): remove this workaround once issue 21572 is fixed.
8518 for (Library library in _librariesInCycles) { 8352 for (Library library in _librariesInCycles) {
8519 for (Source source in library.compilationUnitSources) { 8353 for (Source source in library.compilationUnitSources) {
8520 try { 8354 try {
8521 CompilationUnit unit = library.getAST(source); 8355 CompilationUnit unit = library.getAST(source);
8522 ErrorReporter errorReporter = 8356 ErrorReporter errorReporter =
8523 new ErrorReporter(_errorListener, source); 8357 new ErrorReporter(_errorListener, source);
8524 ConstantVerifier constantVerifier = 8358 ConstantVerifier constantVerifier = new ConstantVerifier(
8525 new ConstantVerifier(errorReporter, library.libraryElement, _typ eProvider); 8359 errorReporter, library.libraryElement, _typeProvider);
8526 unit.accept(constantVerifier); 8360 unit.accept(constantVerifier);
8527 } on AnalysisException catch (exception, stackTrace) { 8361 } on AnalysisException catch (exception, stackTrace) {
8528 AnalysisEngine.instance.logger.logError( 8362 AnalysisEngine.instance.logger.logError(
8529 "Internal Error: Could not access AST for ${source.fullName} " 8363 "Internal Error: Could not access AST for ${source.fullName} "
8530 "during constant verification", 8364 "during constant verification",
8531 new CaughtException(exception, stackTrace)); 8365 new CaughtException(exception, stackTrace));
8532 } 8366 }
8533 } 8367 }
8534 } 8368 }
8535 }); 8369 });
8536 } 8370 }
8537 8371
8538 /** 8372 /**
8539 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle. 8373 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle.
8540 * 8374 *
(...skipping 14 matching lines...) Expand all
8555 * the library cannot be analyzed 8389 * the library cannot be analyzed
8556 */ 8390 */
8557 void _resolveReferencesAndTypesInLibrary(Library library) { 8391 void _resolveReferencesAndTypesInLibrary(Library library) {
8558 PerformanceStatistics.resolve.makeCurrentWhile(() { 8392 PerformanceStatistics.resolve.makeCurrentWhile(() {
8559 for (Source source in library.compilationUnitSources) { 8393 for (Source source in library.compilationUnitSources) {
8560 CompilationUnit ast = library.getAST(source); 8394 CompilationUnit ast = library.getAST(source);
8561 ast.accept( 8395 ast.accept(
8562 new VariableResolverVisitor.con1(library, source, _typeProvider)); 8396 new VariableResolverVisitor.con1(library, source, _typeProvider));
8563 ResolverVisitorFactory visitorFactory = 8397 ResolverVisitorFactory visitorFactory =
8564 analysisContext.resolverVisitorFactory; 8398 analysisContext.resolverVisitorFactory;
8565 ResolverVisitor visitor = visitorFactory != null ? 8399 ResolverVisitor visitor = visitorFactory != null
8566 visitorFactory(library, source, _typeProvider) : 8400 ? visitorFactory(library, source, _typeProvider)
8567 new ResolverVisitor.con1(library, source, _typeProvider); 8401 : new ResolverVisitor.con1(library, source, _typeProvider);
8568 ast.accept(visitor); 8402 ast.accept(visitor);
8569 } 8403 }
8570 }); 8404 });
8571 } 8405 }
8572 8406
8573 /** 8407 /**
8574 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 8408 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
8575 * given library, or `null` if the URI is not valid. 8409 * given library, or `null` if the URI is not valid.
8576 * 8410 *
8577 * @param librarySource the source representing the library containing the dir ective 8411 * @param librarySource the source representing the library containing the dir ective
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
8678 * Note that because Dart allows circular imports between libraries, it is pos sible that more than 8512 * Note that because Dart allows circular imports between libraries, it is pos sible that more than
8679 * one library will need to be resolved. In such cases the error listener can receive errors from 8513 * one library will need to be resolved. In such cases the error listener can receive errors from
8680 * multiple libraries. 8514 * multiple libraries.
8681 * 8515 *
8682 * @param librarySource the source specifying the defining compilation unit of the library to be 8516 * @param librarySource the source specifying the defining compilation unit of the library to be
8683 * resolved 8517 * resolved
8684 * @param fullAnalysis `true` if a full analysis should be performed 8518 * @param fullAnalysis `true` if a full analysis should be performed
8685 * @return the element representing the resolved library 8519 * @return the element representing the resolved library
8686 * @throws AnalysisException if the library could not be resolved for some rea son 8520 * @throws AnalysisException if the library could not be resolved for some rea son
8687 */ 8521 */
8688 LibraryElement resolveLibrary(Source librarySource, 8522 LibraryElement resolveLibrary(
8689 List<ResolvableLibrary> librariesInCycle) { 8523 Source librarySource, List<ResolvableLibrary> librariesInCycle) {
8690 // 8524 //
8691 // Build the map of libraries that are known. 8525 // Build the map of libraries that are known.
8692 // 8526 //
8693 this._librariesInCycle = librariesInCycle; 8527 this._librariesInCycle = librariesInCycle;
8694 _libraryMap = _buildLibraryMap(); 8528 _libraryMap = _buildLibraryMap();
8695 ResolvableLibrary targetLibrary = _libraryMap[librarySource]; 8529 ResolvableLibrary targetLibrary = _libraryMap[librarySource];
8696 _coreLibrary = _libraryMap[_coreLibrarySource]; 8530 _coreLibrary = _libraryMap[_coreLibrarySource];
8697 _asyncLibrary = _libraryMap[_asyncLibrarySource]; 8531 _asyncLibrary = _libraryMap[_asyncLibrarySource];
8698 // 8532 //
8699 // Build the element models representing the libraries being resolved. 8533 // Build the element models representing the libraries being resolved.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
8824 prefix = new PrefixElementImpl.forNode(prefixNode); 8658 prefix = new PrefixElementImpl.forNode(prefixNode);
8825 nameToPrefixMap[prefixName] = prefix; 8659 nameToPrefixMap[prefixName] = prefix;
8826 } 8660 }
8827 importElement.prefix = prefix; 8661 importElement.prefix = prefix;
8828 prefixNode.staticElement = prefix; 8662 prefixNode.staticElement = prefix;
8829 } 8663 }
8830 directive.element = importElement; 8664 directive.element = importElement;
8831 imports.add(importElement); 8665 imports.add(importElement);
8832 if (analysisContext.computeKindOf(importedSource) != 8666 if (analysisContext.computeKindOf(importedSource) !=
8833 SourceKind.LIBRARY) { 8667 SourceKind.LIBRARY) {
8834 ErrorCode errorCode = (importElement.isDeferred ? 8668 ErrorCode errorCode = (importElement.isDeferred
8835 StaticWarningCode.IMPORT_OF_NON_LIBRARY : 8669 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
8836 CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); 8670 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
8837 _errorListener.onError( 8671 _errorListener.onError(new AnalysisError.con2(
8838 new AnalysisError.con2( 8672 library.librarySource, uriLiteral.offset, uriLiteral.length,
8839 library.librarySource, 8673 errorCode, [uriLiteral.toSource()]));
8840 uriLiteral.offset,
8841 uriLiteral.length,
8842 errorCode,
8843 [uriLiteral.toSource()]));
8844 } 8674 }
8845 } 8675 }
8846 } 8676 }
8847 } else if (directive is ExportDirective) { 8677 } else if (directive is ExportDirective) {
8848 ExportDirective exportDirective = directive; 8678 ExportDirective exportDirective = directive;
8849 Source exportedSource = exportDirective.source; 8679 Source exportedSource = exportDirective.source;
8850 if (exportedSource != null && 8680 if (exportedSource != null &&
8851 analysisContext.exists(exportedSource)) { 8681 analysisContext.exists(exportedSource)) {
8852 // The exported source will be null if the URI in the export 8682 // The exported source will be null if the URI in the export
8853 // directive was invalid. 8683 // directive was invalid.
8854 ResolvableLibrary exportedLibrary = _libraryMap[exportedSource]; 8684 ResolvableLibrary exportedLibrary = _libraryMap[exportedSource];
8855 if (exportedLibrary != null) { 8685 if (exportedLibrary != null) {
8856 ExportElementImpl exportElement = new ExportElementImpl(); 8686 ExportElementImpl exportElement = new ExportElementImpl();
8857 StringLiteral uriLiteral = exportDirective.uri; 8687 StringLiteral uriLiteral = exportDirective.uri;
8858 if (uriLiteral != null) { 8688 if (uriLiteral != null) {
8859 exportElement.uriOffset = uriLiteral.offset; 8689 exportElement.uriOffset = uriLiteral.offset;
8860 exportElement.uriEnd = uriLiteral.end; 8690 exportElement.uriEnd = uriLiteral.end;
8861 } 8691 }
8862 exportElement.uri = exportDirective.uriContent; 8692 exportElement.uri = exportDirective.uriContent;
8863 exportElement.combinators = _buildCombinators(exportDirective); 8693 exportElement.combinators = _buildCombinators(exportDirective);
8864 LibraryElement exportedLibraryElement = 8694 LibraryElement exportedLibraryElement =
8865 exportedLibrary.libraryElement; 8695 exportedLibrary.libraryElement;
8866 if (exportedLibraryElement != null) { 8696 if (exportedLibraryElement != null) {
8867 exportElement.exportedLibrary = exportedLibraryElement; 8697 exportElement.exportedLibrary = exportedLibraryElement;
8868 } 8698 }
8869 directive.element = exportElement; 8699 directive.element = exportElement;
8870 exports.add(exportElement); 8700 exports.add(exportElement);
8871 if (analysisContext.computeKindOf(exportedSource) != 8701 if (analysisContext.computeKindOf(exportedSource) !=
8872 SourceKind.LIBRARY) { 8702 SourceKind.LIBRARY) {
8873 _errorListener.onError( 8703 _errorListener.onError(new AnalysisError.con2(
8874 new AnalysisError.con2( 8704 library.librarySource, uriLiteral.offset, uriLiteral.length,
8875 library.librarySource, 8705 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, [
8876 uriLiteral.offset, 8706 uriLiteral.toSource()
8877 uriLiteral.length, 8707 ]));
8878 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
8879 [uriLiteral.toSource()]));
8880 } 8708 }
8881 } 8709 }
8882 } 8710 }
8883 } 8711 }
8884 } 8712 }
8885 Source librarySource = library.librarySource; 8713 Source librarySource = library.librarySource;
8886 if (!library.explicitlyImportsCore && 8714 if (!library.explicitlyImportsCore &&
8887 _coreLibrarySource != librarySource) { 8715 _coreLibrarySource != librarySource) {
8888 ImportElementImpl importElement = new ImportElementImpl(-1); 8716 ImportElementImpl importElement = new ImportElementImpl(-1);
8889 importElement.importedLibrary = _coreLibrary.libraryElement; 8717 importElement.importedLibrary = _coreLibrary.libraryElement;
8890 importElement.synthetic = true; 8718 importElement.synthetic = true;
8891 imports.add(importElement); 8719 imports.add(importElement);
8892 } 8720 }
8893 LibraryElementImpl libraryElement = library.libraryElement; 8721 LibraryElementImpl libraryElement = library.libraryElement;
8894 libraryElement.imports = imports; 8722 libraryElement.imports = imports;
8895 libraryElement.exports = exports; 8723 libraryElement.exports = exports;
8896 if (libraryElement.entryPoint == null) { 8724 if (libraryElement.entryPoint == null) {
8897 Namespace namespace = 8725 Namespace namespace = new NamespaceBuilder()
8898 new NamespaceBuilder().createExportNamespaceForLibrary(libraryElemen t); 8726 .createExportNamespaceForLibrary(libraryElement);
8899 Element element = namespace.get(LibraryElementBuilder.ENTRY_POINT_NAME); 8727 Element element = namespace.get(LibraryElementBuilder.ENTRY_POINT_NAME);
8900 if (element is FunctionElement) { 8728 if (element is FunctionElement) {
8901 libraryElement.entryPoint = element; 8729 libraryElement.entryPoint = element;
8902 } 8730 }
8903 } 8731 }
8904 } 8732 }
8905 } 8733 }
8906 8734
8907 /** 8735 /**
8908 * Build element models for all of the libraries in the current cycle. 8736 * Build element models for all of the libraries in the current cycle.
(...skipping 30 matching lines...) Expand all
8939 * Finish steps that the [buildTypeHierarchies] could not perform, see 8767 * Finish steps that the [buildTypeHierarchies] could not perform, see
8940 * [ImplicitConstructorBuilder]. 8768 * [ImplicitConstructorBuilder].
8941 * 8769 *
8942 * @throws AnalysisException if any of the type hierarchies could not be resol ved 8770 * @throws AnalysisException if any of the type hierarchies could not be resol ved
8943 */ 8771 */
8944 void _buildImplicitConstructors() { 8772 void _buildImplicitConstructors() {
8945 PerformanceStatistics.resolve.makeCurrentWhile(() { 8773 PerformanceStatistics.resolve.makeCurrentWhile(() {
8946 ImplicitConstructorComputer computer = 8774 ImplicitConstructorComputer computer =
8947 new ImplicitConstructorComputer(_typeProvider); 8775 new ImplicitConstructorComputer(_typeProvider);
8948 for (ResolvableLibrary library in _librariesInCycle) { 8776 for (ResolvableLibrary library in _librariesInCycle) {
8949 for (ResolvableCompilationUnit unit in 8777 for (ResolvableCompilationUnit unit
8950 library.resolvableCompilationUnits) { 8778 in library.resolvableCompilationUnits) {
8951 Source source = unit.source; 8779 Source source = unit.source;
8952 CompilationUnit ast = unit.compilationUnit; 8780 CompilationUnit ast = unit.compilationUnit;
8953 computer.add( 8781 computer
8954 ast, 8782 .add(ast, source, library.libraryElement, library.libraryScope);
8955 source,
8956 library.libraryElement,
8957 library.libraryScope);
8958 } 8783 }
8959 } 8784 }
8960 computer.compute(); 8785 computer.compute();
8961 }); 8786 });
8962 } 8787 }
8963 8788
8964 HashMap<Source, ResolvableLibrary> _buildLibraryMap() { 8789 HashMap<Source, ResolvableLibrary> _buildLibraryMap() {
8965 HashMap<Source, ResolvableLibrary> libraryMap = 8790 HashMap<Source, ResolvableLibrary> libraryMap =
8966 new HashMap<Source, ResolvableLibrary>(); 8791 new HashMap<Source, ResolvableLibrary>();
8967 int libraryCount = _librariesInCycle.length; 8792 int libraryCount = _librariesInCycle.length;
(...skipping 16 matching lines...) Expand all
8984 * Resolve the types referenced by function type aliases across all of the fun ction type aliases 8809 * Resolve the types referenced by function type aliases across all of the fun ction type aliases
8985 * defined in the current cycle. 8810 * defined in the current cycle.
8986 * 8811 *
8987 * @throws AnalysisException if any of the function type aliases could not be resolved 8812 * @throws AnalysisException if any of the function type aliases could not be resolved
8988 */ 8813 */
8989 void _buildTypeAliases() { 8814 void _buildTypeAliases() {
8990 PerformanceStatistics.resolve.makeCurrentWhile(() { 8815 PerformanceStatistics.resolve.makeCurrentWhile(() {
8991 List<LibraryResolver2_TypeAliasInfo> typeAliases = 8816 List<LibraryResolver2_TypeAliasInfo> typeAliases =
8992 new List<LibraryResolver2_TypeAliasInfo>(); 8817 new List<LibraryResolver2_TypeAliasInfo>();
8993 for (ResolvableLibrary library in _librariesInCycle) { 8818 for (ResolvableLibrary library in _librariesInCycle) {
8994 for (ResolvableCompilationUnit unit in 8819 for (ResolvableCompilationUnit unit
8995 library.resolvableCompilationUnits) { 8820 in library.resolvableCompilationUnits) {
8996 for (CompilationUnitMember member in 8821 for (CompilationUnitMember member
8997 unit.compilationUnit.declarations) { 8822 in unit.compilationUnit.declarations) {
8998 if (member is FunctionTypeAlias) { 8823 if (member is FunctionTypeAlias) {
8999 typeAliases.add( 8824 typeAliases.add(new LibraryResolver2_TypeAliasInfo(
9000 new LibraryResolver2_TypeAliasInfo(library, unit.source, membe r)); 8825 library, unit.source, member));
9001 } 8826 }
9002 } 8827 }
9003 } 8828 }
9004 } 8829 }
9005 // TODO(brianwilkerson) We need to sort the type aliases such that all 8830 // TODO(brianwilkerson) We need to sort the type aliases such that all
9006 // aliases referenced by an alias T are resolved before we resolve T. 8831 // aliases referenced by an alias T are resolved before we resolve T.
9007 for (LibraryResolver2_TypeAliasInfo info in typeAliases) { 8832 for (LibraryResolver2_TypeAliasInfo info in typeAliases) {
9008 TypeResolverVisitor visitor = 8833 TypeResolverVisitor visitor = new TypeResolverVisitor.con4(
9009 new TypeResolverVisitor.con4(info._library, info._source, _typeProvi der); 8834 info._library, info._source, _typeProvider);
9010 info._typeAlias.accept(visitor); 8835 info._typeAlias.accept(visitor);
9011 } 8836 }
9012 }); 8837 });
9013 } 8838 }
9014 8839
9015 /** 8840 /**
9016 * Resolve the type hierarchy across all of the types declared in the librarie s in the current 8841 * Resolve the type hierarchy across all of the types declared in the librarie s in the current
9017 * cycle. 8842 * cycle.
9018 * 8843 *
9019 * @throws AnalysisException if any of the type hierarchies could not be resol ved 8844 * @throws AnalysisException if any of the type hierarchies could not be resol ved
9020 */ 8845 */
9021 void _buildTypeHierarchies() { 8846 void _buildTypeHierarchies() {
9022 PerformanceStatistics.resolve.makeCurrentWhile(() { 8847 PerformanceStatistics.resolve.makeCurrentWhile(() {
9023 for (ResolvableLibrary library in _librariesInCycle) { 8848 for (ResolvableLibrary library in _librariesInCycle) {
9024 for (ResolvableCompilationUnit unit in 8849 for (ResolvableCompilationUnit unit
9025 library.resolvableCompilationUnits) { 8850 in library.resolvableCompilationUnits) {
9026 Source source = unit.source; 8851 Source source = unit.source;
9027 CompilationUnit ast = unit.compilationUnit; 8852 CompilationUnit ast = unit.compilationUnit;
9028 TypeResolverVisitor visitor = 8853 TypeResolverVisitor visitor =
9029 new TypeResolverVisitor.con4(library, source, _typeProvider); 8854 new TypeResolverVisitor.con4(library, source, _typeProvider);
9030 ast.accept(visitor); 8855 ast.accept(visitor);
9031 } 8856 }
9032 } 8857 }
9033 }); 8858 });
9034 } 8859 }
9035 8860
(...skipping 10 matching lines...) Expand all
9046 identifiers[i] = names[i].name; 8871 identifiers[i] = names[i].name;
9047 } 8872 }
9048 return identifiers; 8873 return identifiers;
9049 } 8874 }
9050 8875
9051 /** 8876 /**
9052 * Compute a value for all of the constants in the libraries being analyzed. 8877 * Compute a value for all of the constants in the libraries being analyzed.
9053 */ 8878 */
9054 void _performConstantEvaluation() { 8879 void _performConstantEvaluation() {
9055 PerformanceStatistics.resolve.makeCurrentWhile(() { 8880 PerformanceStatistics.resolve.makeCurrentWhile(() {
9056 ConstantValueComputer computer = 8881 ConstantValueComputer computer = new ConstantValueComputer(
9057 new ConstantValueComputer(_typeProvider, analysisContext.declaredVaria bles); 8882 _typeProvider, analysisContext.declaredVariables);
9058 for (ResolvableLibrary library in _librariesInCycle) { 8883 for (ResolvableLibrary library in _librariesInCycle) {
9059 for (ResolvableCompilationUnit unit in 8884 for (ResolvableCompilationUnit unit
9060 library.resolvableCompilationUnits) { 8885 in library.resolvableCompilationUnits) {
9061 CompilationUnit ast = unit.compilationUnit; 8886 CompilationUnit ast = unit.compilationUnit;
9062 if (ast != null) { 8887 if (ast != null) {
9063 computer.add(ast); 8888 computer.add(ast);
9064 } 8889 }
9065 } 8890 }
9066 } 8891 }
9067 computer.computeValues(); 8892 computer.computeValues();
9068 // As a temporary workaround for issue 21572, run ConstantVerifier now. 8893 // As a temporary workaround for issue 21572, run ConstantVerifier now.
9069 // TODO(paulberry): remove this workaround once issue 21572 is fixed. 8894 // TODO(paulberry): remove this workaround once issue 21572 is fixed.
9070 for (ResolvableLibrary library in _librariesInCycle) { 8895 for (ResolvableLibrary library in _librariesInCycle) {
9071 for (ResolvableCompilationUnit unit in 8896 for (ResolvableCompilationUnit unit
9072 library.resolvableCompilationUnits) { 8897 in library.resolvableCompilationUnits) {
9073 CompilationUnit ast = unit.compilationUnit; 8898 CompilationUnit ast = unit.compilationUnit;
9074 ErrorReporter errorReporter = 8899 ErrorReporter errorReporter =
9075 new ErrorReporter(_errorListener, unit.source); 8900 new ErrorReporter(_errorListener, unit.source);
9076 ConstantVerifier constantVerifier = 8901 ConstantVerifier constantVerifier = new ConstantVerifier(
9077 new ConstantVerifier(errorReporter, library.libraryElement, _typeP rovider); 8902 errorReporter, library.libraryElement, _typeProvider);
9078 ast.accept(constantVerifier); 8903 ast.accept(constantVerifier);
9079 } 8904 }
9080 } 8905 }
9081 }); 8906 });
9082 } 8907 }
9083 8908
9084 /** 8909 /**
9085 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle. 8910 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle.
9086 * 8911 *
9087 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the 8912 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the
9088 * libraries could not have their types analyzed 8913 * libraries could not have their types analyzed
9089 */ 8914 */
9090 void _resolveReferencesAndTypes() { 8915 void _resolveReferencesAndTypes() {
9091 for (ResolvableLibrary library in _librariesInCycle) { 8916 for (ResolvableLibrary library in _librariesInCycle) {
9092 _resolveReferencesAndTypesInLibrary(library); 8917 _resolveReferencesAndTypesInLibrary(library);
9093 } 8918 }
9094 } 8919 }
9095 8920
9096 /** 8921 /**
9097 * Resolve the identifiers and perform type analysis in the given library. 8922 * Resolve the identifiers and perform type analysis in the given library.
9098 * 8923 *
9099 * @param library the library to be resolved 8924 * @param library the library to be resolved
9100 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 8925 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
9101 * the library cannot be analyzed 8926 * the library cannot be analyzed
9102 */ 8927 */
9103 void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) { 8928 void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) {
9104 PerformanceStatistics.resolve.makeCurrentWhile(() { 8929 PerformanceStatistics.resolve.makeCurrentWhile(() {
9105 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnits) 8930 for (ResolvableCompilationUnit unit
9106 { 8931 in library.resolvableCompilationUnits) {
9107 Source source = unit.source; 8932 Source source = unit.source;
9108 CompilationUnit ast = unit.compilationUnit; 8933 CompilationUnit ast = unit.compilationUnit;
9109 ast.accept( 8934 ast.accept(
9110 new VariableResolverVisitor.con3(library, source, _typeProvider)); 8935 new VariableResolverVisitor.con3(library, source, _typeProvider));
9111 ResolverVisitor visitor = 8936 ResolverVisitor visitor =
9112 new ResolverVisitor.con4(library, source, _typeProvider); 8937 new ResolverVisitor.con4(library, source, _typeProvider);
9113 ast.accept(visitor); 8938 ast.accept(visitor);
9114 } 8939 }
9115 }); 8940 });
9116 } 8941 }
9117 8942
9118 /** 8943 /**
9119 * Report that the async library could not be resolved in the given 8944 * Report that the async library could not be resolved in the given
9120 * [analysisContext] and throw an exception. [asyncLibrarySource] is the sour ce 8945 * [analysisContext] and throw an exception. [asyncLibrarySource] is the sour ce
9121 * representing the async library. 8946 * representing the async library.
9122 */ 8947 */
9123 static void missingAsyncLibrary(AnalysisContext analysisContext, 8948 static void missingAsyncLibrary(
9124 Source asyncLibrarySource) { 8949 AnalysisContext analysisContext, Source asyncLibrarySource) {
9125 throw new AnalysisException("Could not resolve dart:async"); 8950 throw new AnalysisException("Could not resolve dart:async");
9126 } 8951 }
9127 8952
9128 /** 8953 /**
9129 * Report that the core library could not be resolved in the given analysis co ntext and throw an 8954 * Report that the core library could not be resolved in the given analysis co ntext and throw an
9130 * exception. 8955 * exception.
9131 * 8956 *
9132 * @param analysisContext the analysis context in which the failure occurred 8957 * @param analysisContext the analysis context in which the failure occurred
9133 * @param coreLibrarySource the source representing the core library 8958 * @param coreLibrarySource the source representing the core library
9134 * @throws AnalysisException always 8959 * @throws AnalysisException always
9135 */ 8960 */
9136 static void missingCoreLibrary(AnalysisContext analysisContext, 8961 static void missingCoreLibrary(
9137 Source coreLibrarySource) { 8962 AnalysisContext analysisContext, Source coreLibrarySource) {
9138 throw new AnalysisException("Could not resolve dart:core"); 8963 throw new AnalysisException("Could not resolve dart:core");
9139 } 8964 }
9140 } 8965 }
9141 8966
9142
9143 /** 8967 /**
9144 * Instances of the class `TypeAliasInfo` hold information about a [TypeAlias]. 8968 * Instances of the class `TypeAliasInfo` hold information about a [TypeAlias].
9145 */ 8969 */
9146 class LibraryResolver2_TypeAliasInfo { 8970 class LibraryResolver2_TypeAliasInfo {
9147 final ResolvableLibrary _library; 8971 final ResolvableLibrary _library;
9148 8972
9149 final Source _source; 8973 final Source _source;
9150 8974
9151 final FunctionTypeAlias _typeAlias; 8975 final FunctionTypeAlias _typeAlias;
9152 8976
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
9184 * Instances of the class `LibraryScope` implement a scope containing all of the names defined 9008 * Instances of the class `LibraryScope` implement a scope containing all of the names defined
9185 * in a given library. 9009 * in a given library.
9186 */ 9010 */
9187 class LibraryScope extends EnclosedScope { 9011 class LibraryScope extends EnclosedScope {
9188 /** 9012 /**
9189 * Initialize a newly created scope representing the names defined in the give n library. 9013 * Initialize a newly created scope representing the names defined in the give n library.
9190 * 9014 *
9191 * @param definingLibrary the element representing the library represented by this scope 9015 * @param definingLibrary the element representing the library represented by this scope
9192 * @param errorListener the listener that is to be informed when an error is e ncountered 9016 * @param errorListener the listener that is to be informed when an error is e ncountered
9193 */ 9017 */
9194 LibraryScope(LibraryElement definingLibrary, 9018 LibraryScope(
9195 AnalysisErrorListener errorListener) 9019 LibraryElement definingLibrary, AnalysisErrorListener errorListener)
9196 : super(new LibraryImportScope(definingLibrary, errorListener)) { 9020 : super(new LibraryImportScope(definingLibrary, errorListener)) {
9197 _defineTopLevelNames(definingLibrary); 9021 _defineTopLevelNames(definingLibrary);
9198 } 9022 }
9199 9023
9200 @override 9024 @override
9201 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 9025 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
9202 if (existing is PrefixElement) { 9026 if (existing is PrefixElement) {
9203 // TODO(scheglov) consider providing actual 'nameOffset' from the 9027 // TODO(scheglov) consider providing actual 'nameOffset' from the
9204 // synthetic accessor 9028 // synthetic accessor
9205 int offset = duplicate.nameOffset; 9029 int offset = duplicate.nameOffset;
9206 if (duplicate is PropertyAccessorElement) { 9030 if (duplicate is PropertyAccessorElement) {
9207 PropertyAccessorElement accessor = duplicate; 9031 PropertyAccessorElement accessor = duplicate;
9208 if (accessor.isSynthetic) { 9032 if (accessor.isSynthetic) {
9209 offset = accessor.variable.nameOffset; 9033 offset = accessor.variable.nameOffset;
9210 } 9034 }
9211 } 9035 }
9212 return new AnalysisError.con2( 9036 return new AnalysisError.con2(duplicate.source, offset,
9213 duplicate.source,
9214 offset,
9215 duplicate.displayName.length, 9037 duplicate.displayName.length,
9216 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, 9038 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [
9217 [existing.displayName]); 9039 existing.displayName
9040 ]);
9218 } 9041 }
9219 return super.getErrorForDuplicate(existing, duplicate); 9042 return super.getErrorForDuplicate(existing, duplicate);
9220 } 9043 }
9221 9044
9222 /** 9045 /**
9223 * Add to this scope all of the public top-level names that are defined in the given compilation 9046 * Add to this scope all of the public top-level names that are defined in the given compilation
9224 * unit. 9047 * unit.
9225 * 9048 *
9226 * @param compilationUnit the compilation unit defining the top-level names to be added to this 9049 * @param compilationUnit the compilation unit defining the top-level names to be added to this
9227 * scope 9050 * scope
9228 */ 9051 */
9229 void _defineLocalNames(CompilationUnitElement compilationUnit) { 9052 void _defineLocalNames(CompilationUnitElement compilationUnit) {
9230 for (PropertyAccessorElement element in compilationUnit.accessors) { 9053 for (PropertyAccessorElement element in compilationUnit.accessors) {
9231 define(element); 9054 define(element);
9232 } 9055 }
9233 for (ClassElement element in compilationUnit.enums) { 9056 for (ClassElement element in compilationUnit.enums) {
9234 define(element); 9057 define(element);
9235 } 9058 }
9236 for (FunctionElement element in compilationUnit.functions) { 9059 for (FunctionElement element in compilationUnit.functions) {
9237 define(element); 9060 define(element);
9238 } 9061 }
9239 for (FunctionTypeAliasElement element in 9062 for (FunctionTypeAliasElement element
9240 compilationUnit.functionTypeAliases) { 9063 in compilationUnit.functionTypeAliases) {
9241 define(element); 9064 define(element);
9242 } 9065 }
9243 for (ClassElement element in compilationUnit.types) { 9066 for (ClassElement element in compilationUnit.types) {
9244 define(element); 9067 define(element);
9245 } 9068 }
9246 } 9069 }
9247 9070
9248 /** 9071 /**
9249 * Add to this scope all of the names that are explicitly defined in the given library. 9072 * Add to this scope all of the names that are explicitly defined in the given library.
9250 * 9073 *
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
9495 return new Namespace(definedNames); 9318 return new Namespace(definedNames);
9496 } 9319 }
9497 9320
9498 /** 9321 /**
9499 * Create a namespace representing the export namespace of the given library. 9322 * Create a namespace representing the export namespace of the given library.
9500 * 9323 *
9501 * @param library the library whose export namespace is to be created 9324 * @param library the library whose export namespace is to be created
9502 * @return the export namespace that was created 9325 * @return the export namespace that was created
9503 */ 9326 */
9504 Namespace createExportNamespaceForLibrary(LibraryElement library) => 9327 Namespace createExportNamespaceForLibrary(LibraryElement library) =>
9505 new Namespace(_createExportMapping(library, new HashSet<LibraryElement>()) ); 9328 new Namespace(
9329 _createExportMapping(library, new HashSet<LibraryElement>()));
9506 9330
9507 /** 9331 /**
9508 * Create a namespace representing the import namespace of the given library. 9332 * Create a namespace representing the import namespace of the given library.
9509 * 9333 *
9510 * @param library the library whose import namespace is to be created 9334 * @param library the library whose import namespace is to be created
9511 * @return the import namespace that was created 9335 * @return the import namespace that was created
9512 */ 9336 */
9513 Namespace createImportNamespaceForDirective(ImportElement element) { 9337 Namespace createImportNamespaceForDirective(ImportElement element) {
9514 LibraryElement importedLibrary = element.importedLibrary; 9338 LibraryElement importedLibrary = element.importedLibrary;
9515 if (importedLibrary == null) { 9339 if (importedLibrary == null) {
(...skipping 24 matching lines...) Expand all
9540 } 9364 }
9541 return new Namespace(definedNames); 9365 return new Namespace(definedNames);
9542 } 9366 }
9543 9367
9544 /** 9368 /**
9545 * Add all of the names in the given namespace to the given mapping table. 9369 * Add all of the names in the given namespace to the given mapping table.
9546 * 9370 *
9547 * @param definedNames the mapping table to which the names in the given names pace are to be added 9371 * @param definedNames the mapping table to which the names in the given names pace are to be added
9548 * @param namespace the namespace containing the names to be added to this nam espace 9372 * @param namespace the namespace containing the names to be added to this nam espace
9549 */ 9373 */
9550 void _addAllFromMap(Map<String, Element> definedNames, Map<String, 9374 void _addAllFromMap(
9551 Element> newNames) { 9375 Map<String, Element> definedNames, Map<String, Element> newNames) {
9552 newNames.forEach((String name, Element element) { 9376 newNames.forEach((String name, Element element) {
9553 definedNames[name] = element; 9377 definedNames[name] = element;
9554 }); 9378 });
9555 } 9379 }
9556 9380
9557 /** 9381 /**
9558 * Add all of the names in the given namespace to the given mapping table. 9382 * Add all of the names in the given namespace to the given mapping table.
9559 * 9383 *
9560 * @param definedNames the mapping table to which the names in the given names pace are to be added 9384 * @param definedNames the mapping table to which the names in the given names pace are to be added
9561 * @param namespace the namespace containing the names to be added to this nam espace 9385 * @param namespace the namespace containing the names to be added to this nam espace
9562 */ 9386 */
9563 void _addAllFromNamespace(Map<String, Element> definedNames, 9387 void _addAllFromNamespace(
9564 Namespace namespace) { 9388 Map<String, Element> definedNames, Namespace namespace) {
9565 if (namespace != null) { 9389 if (namespace != null) {
9566 _addAllFromMap(definedNames, namespace.definedNames); 9390 _addAllFromMap(definedNames, namespace.definedNames);
9567 } 9391 }
9568 } 9392 }
9569 9393
9570 /** 9394 /**
9571 * Add the given element to the given mapping table if it has a publicly visib le name. 9395 * Add the given element to the given mapping table if it has a publicly visib le name.
9572 * 9396 *
9573 * @param definedNames the mapping table to which the public name is to be add ed 9397 * @param definedNames the mapping table to which the public name is to be add ed
9574 * @param element the element to be added 9398 * @param element the element to be added
(...skipping 17 matching lines...) Expand all
9592 CompilationUnitElement compilationUnit) { 9416 CompilationUnitElement compilationUnit) {
9593 for (PropertyAccessorElement element in compilationUnit.accessors) { 9417 for (PropertyAccessorElement element in compilationUnit.accessors) {
9594 _addIfPublic(definedNames, element); 9418 _addIfPublic(definedNames, element);
9595 } 9419 }
9596 for (ClassElement element in compilationUnit.enums) { 9420 for (ClassElement element in compilationUnit.enums) {
9597 _addIfPublic(definedNames, element); 9421 _addIfPublic(definedNames, element);
9598 } 9422 }
9599 for (FunctionElement element in compilationUnit.functions) { 9423 for (FunctionElement element in compilationUnit.functions) {
9600 _addIfPublic(definedNames, element); 9424 _addIfPublic(definedNames, element);
9601 } 9425 }
9602 for (FunctionTypeAliasElement element in 9426 for (FunctionTypeAliasElement element
9603 compilationUnit.functionTypeAliases) { 9427 in compilationUnit.functionTypeAliases) {
9604 _addIfPublic(definedNames, element); 9428 _addIfPublic(definedNames, element);
9605 } 9429 }
9606 for (ClassElement element in compilationUnit.types) { 9430 for (ClassElement element in compilationUnit.types) {
9607 _addIfPublic(definedNames, element); 9431 _addIfPublic(definedNames, element);
9608 } 9432 }
9609 } 9433 }
9610 9434
9611 /** 9435 /**
9612 * Apply the given combinators to all of the names in the given mapping table. 9436 * Apply the given combinators to all of the names in the given mapping table.
9613 * 9437 *
9614 * @param definedNames the mapping table to which the namespace operations are to be applied 9438 * @param definedNames the mapping table to which the namespace operations are to be applied
9615 * @param combinators the combinators to be applied 9439 * @param combinators the combinators to be applied
9616 */ 9440 */
9617 HashMap<String, Element> _applyCombinators(HashMap<String, 9441 HashMap<String, Element> _applyCombinators(
9618 Element> definedNames, List<NamespaceCombinator> combinators) { 9442 HashMap<String, Element> definedNames,
9443 List<NamespaceCombinator> combinators) {
9619 for (NamespaceCombinator combinator in combinators) { 9444 for (NamespaceCombinator combinator in combinators) {
9620 if (combinator is HideElementCombinator) { 9445 if (combinator is HideElementCombinator) {
9621 _hide(definedNames, combinator.hiddenNames); 9446 _hide(definedNames, combinator.hiddenNames);
9622 } else if (combinator is ShowElementCombinator) { 9447 } else if (combinator is ShowElementCombinator) {
9623 definedNames = _show(definedNames, combinator.shownNames); 9448 definedNames = _show(definedNames, combinator.shownNames);
9624 } else { 9449 } else {
9625 // Internal error. 9450 // Internal error.
9626 AnalysisEngine.instance.logger.logError( 9451 AnalysisEngine.instance.logger
9627 "Unknown type of combinator: ${combinator.runtimeType}"); 9452 .logError("Unknown type of combinator: ${combinator.runtimeType}");
9628 } 9453 }
9629 } 9454 }
9630 return definedNames; 9455 return definedNames;
9631 } 9456 }
9632 9457
9633 /** 9458 /**
9634 * Apply the given prefix to all of the names in the table of defined names. 9459 * Apply the given prefix to all of the names in the table of defined names.
9635 * 9460 *
9636 * @param definedNames the names that were defined before this operation 9461 * @param definedNames the names that were defined before this operation
9637 * @param prefixElement the element defining the prefix to be added to the nam es 9462 * @param prefixElement the element defining the prefix to be added to the nam es
9638 */ 9463 */
9639 HashMap<String, Element> _applyPrefix(HashMap<String, Element> definedNames, 9464 HashMap<String, Element> _applyPrefix(
9640 PrefixElement prefixElement) { 9465 HashMap<String, Element> definedNames, PrefixElement prefixElement) {
9641 if (prefixElement != null) { 9466 if (prefixElement != null) {
9642 String prefix = prefixElement.name; 9467 String prefix = prefixElement.name;
9643 HashMap<String, Element> newNames = new HashMap<String, Element>(); 9468 HashMap<String, Element> newNames = new HashMap<String, Element>();
9644 definedNames.forEach((String name, Element element) { 9469 definedNames.forEach((String name, Element element) {
9645 newNames["$prefix.$name"] = element; 9470 newNames["$prefix.$name"] = element;
9646 }); 9471 });
9647 return newNames; 9472 return newNames;
9648 } else { 9473 } else {
9649 return definedNames; 9474 return definedNames;
9650 } 9475 }
9651 } 9476 }
9652 9477
9653 /** 9478 /**
9654 * Create a mapping table representing the export namespace of the given libra ry. 9479 * Create a mapping table representing the export namespace of the given libra ry.
9655 * 9480 *
9656 * @param library the library whose public namespace is to be created 9481 * @param library the library whose public namespace is to be created
9657 * @param visitedElements a set of libraries that do not need to be visited wh en processing the 9482 * @param visitedElements a set of libraries that do not need to be visited wh en processing the
9658 * export directives of the given library because all of the names de fined by them will 9483 * export directives of the given library because all of the names de fined by them will
9659 * be added by another library 9484 * be added by another library
9660 * @return the mapping table that was created 9485 * @return the mapping table that was created
9661 */ 9486 */
9662 HashMap<String, Element> _createExportMapping(LibraryElement library, 9487 HashMap<String, Element> _createExportMapping(
9663 HashSet<LibraryElement> visitedElements) { 9488 LibraryElement library, HashSet<LibraryElement> visitedElements) {
9664 visitedElements.add(library); 9489 visitedElements.add(library);
9665 try { 9490 try {
9666 HashMap<String, Element> definedNames = new HashMap<String, Element>(); 9491 HashMap<String, Element> definedNames = new HashMap<String, Element>();
9667 for (ExportElement element in library.exports) { 9492 for (ExportElement element in library.exports) {
9668 LibraryElement exportedLibrary = element.exportedLibrary; 9493 LibraryElement exportedLibrary = element.exportedLibrary;
9669 if (exportedLibrary != null && 9494 if (exportedLibrary != null &&
9670 !visitedElements.contains(exportedLibrary)) { 9495 !visitedElements.contains(exportedLibrary)) {
9671 // 9496 //
9672 // The exported library will be null if the URI does not reference a 9497 // The exported library will be null if the URI does not reference a
9673 // valid library. 9498 // valid library.
9674 // 9499 //
9675 HashMap<String, Element> exportedNames = 9500 HashMap<String, Element> exportedNames =
9676 _createExportMapping(exportedLibrary, visitedElements); 9501 _createExportMapping(exportedLibrary, visitedElements);
9677 exportedNames = _applyCombinators(exportedNames, element.combinators); 9502 exportedNames = _applyCombinators(exportedNames, element.combinators);
9678 _addAllFromMap(definedNames, exportedNames); 9503 _addAllFromMap(definedNames, exportedNames);
9679 } 9504 }
9680 } 9505 }
9681 _addAllFromNamespace( 9506 _addAllFromNamespace(definedNames,
9682 definedNames, 9507 (library.context as InternalAnalysisContext)
9683 (library.context as InternalAnalysisContext).getPublicNamespace(librar y)); 9508 .getPublicNamespace(library));
9684 return definedNames; 9509 return definedNames;
9685 } finally { 9510 } finally {
9686 visitedElements.remove(library); 9511 visitedElements.remove(library);
9687 } 9512 }
9688 } 9513 }
9689 9514
9690 /** 9515 /**
9691 * Hide all of the given names by removing them from the given collection of d efined names. 9516 * Hide all of the given names by removing them from the given collection of d efined names.
9692 * 9517 *
9693 * @param definedNames the names that were defined before this operation 9518 * @param definedNames the names that were defined before this operation
9694 * @param hiddenNames the names to be hidden 9519 * @param hiddenNames the names to be hidden
9695 */ 9520 */
9696 void _hide(HashMap<String, Element> definedNames, List<String> hiddenNames) { 9521 void _hide(HashMap<String, Element> definedNames, List<String> hiddenNames) {
9697 for (String name in hiddenNames) { 9522 for (String name in hiddenNames) {
9698 definedNames.remove(name); 9523 definedNames.remove(name);
9699 definedNames.remove("$name="); 9524 definedNames.remove("$name=");
9700 } 9525 }
9701 } 9526 }
9702 9527
9703 /** 9528 /**
9704 * Show only the given names by removing all other names from the given collec tion of defined 9529 * Show only the given names by removing all other names from the given collec tion of defined
9705 * names. 9530 * names.
9706 * 9531 *
9707 * @param definedNames the names that were defined before this operation 9532 * @param definedNames the names that were defined before this operation
9708 * @param shownNames the names to be shown 9533 * @param shownNames the names to be shown
9709 */ 9534 */
9710 HashMap<String, Element> _show(HashMap<String, Element> definedNames, 9535 HashMap<String, Element> _show(
9711 List<String> shownNames) { 9536 HashMap<String, Element> definedNames, List<String> shownNames) {
9712 HashMap<String, Element> newNames = new HashMap<String, Element>(); 9537 HashMap<String, Element> newNames = new HashMap<String, Element>();
9713 for (String name in shownNames) { 9538 for (String name in shownNames) {
9714 Element element = definedNames[name]; 9539 Element element = definedNames[name];
9715 if (element != null) { 9540 if (element != null) {
9716 newNames[name] = element; 9541 newNames[name] = element;
9717 } 9542 }
9718 String setterName = "$name="; 9543 String setterName = "$name=";
9719 element = definedNames[setterName]; 9544 element = definedNames[setterName];
9720 if (element != null) { 9545 if (element != null) {
9721 newNames[setterName] = element; 9546 newNames[setterName] = element;
(...skipping 26 matching lines...) Expand all
9748 */ 9573 */
9749 OverrideVerifier(this._manager, this._errorReporter); 9574 OverrideVerifier(this._manager, this._errorReporter);
9750 9575
9751 @override 9576 @override
9752 Object visitMethodDeclaration(MethodDeclaration node) { 9577 Object visitMethodDeclaration(MethodDeclaration node) {
9753 ExecutableElement element = node.element; 9578 ExecutableElement element = node.element;
9754 if (_isOverride(element)) { 9579 if (_isOverride(element)) {
9755 if (_getOverriddenMember(element) == null) { 9580 if (_getOverriddenMember(element) == null) {
9756 if (element is MethodElement) { 9581 if (element is MethodElement) {
9757 _errorReporter.reportErrorForNode( 9582 _errorReporter.reportErrorForNode(
9758 HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD, 9583 HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD, node.name);
9759 node.name);
9760 } else if (element is PropertyAccessorElement) { 9584 } else if (element is PropertyAccessorElement) {
9761 if (element.isGetter) { 9585 if (element.isGetter) {
9762 _errorReporter.reportErrorForNode( 9586 _errorReporter.reportErrorForNode(
9763 HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER, 9587 HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER, node.name);
9764 node.name);
9765 } else { 9588 } else {
9766 _errorReporter.reportErrorForNode( 9589 _errorReporter.reportErrorForNode(
9767 HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER, 9590 HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER, node.name);
9768 node.name);
9769 } 9591 }
9770 } 9592 }
9771 } 9593 }
9772 } 9594 }
9773 return super.visitMethodDeclaration(node); 9595 return super.visitMethodDeclaration(node);
9774 } 9596 }
9775 9597
9776 /** 9598 /**
9777 * Return the member that overrides the given member. 9599 * Return the member that overrides the given member.
9778 * 9600 *
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
10280 10102
10281 /** 10103 /**
10282 * The enumeration `ResolverErrorCode` defines the error codes used for errors 10104 * The enumeration `ResolverErrorCode` defines the error codes used for errors
10283 * detected by the resolver. The convention for this class is for the name of 10105 * detected by the resolver. The convention for this class is for the name of
10284 * the error code to indicate the problem that caused the error to be generated 10106 * the error code to indicate the problem that caused the error to be generated
10285 * and for the error message to explain what is wrong and, when appropriate, how 10107 * and for the error message to explain what is wrong and, when appropriate, how
10286 * the problem can be corrected. 10108 * the problem can be corrected.
10287 */ 10109 */
10288 class ResolverErrorCode extends ErrorCode { 10110 class ResolverErrorCode extends ErrorCode {
10289 static const ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = 10111 static const ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER =
10290 const ResolverErrorCode( 10112 const ResolverErrorCode('BREAK_LABEL_ON_SWITCH_MEMBER',
10291 'BREAK_LABEL_ON_SWITCH_MEMBER',
10292 "Break label resolves to case or default statement"); 10113 "Break label resolves to case or default statement");
10293 10114
10294 static const ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = 10115 static const ResolverErrorCode CONTINUE_LABEL_ON_SWITCH =
10295 const ResolverErrorCode( 10116 const ResolverErrorCode('CONTINUE_LABEL_ON_SWITCH',
10296 'CONTINUE_LABEL_ON_SWITCH',
10297 "A continue label resolves to switch, must be loop or switch member"); 10117 "A continue label resolves to switch, must be loop or switch member");
10298 10118
10299 static const ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = 10119 static const ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART =
10300 const ResolverErrorCode( 10120 const ResolverErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART',
10301 'MISSING_LIBRARY_DIRECTIVE_WITH_PART',
10302 "Libraries that have parts must have a library directive"); 10121 "Libraries that have parts must have a library directive");
10303 10122
10304 /** 10123 /**
10305 * Initialize a newly created error code to have the given [name]. The message 10124 * Initialize a newly created error code to have the given [name]. The message
10306 * associated with the error will be created from the given [message] 10125 * associated with the error will be created from the given [message]
10307 * template. The correction associated with the error will be created from the 10126 * template. The correction associated with the error will be created from the
10308 * given [correction] template. 10127 * given [correction] template.
10309 */ 10128 */
10310 const ResolverErrorCode(String name, String message, [String correction]) 10129 const ResolverErrorCode(String name, String message, [String correction])
10311 : super(name, message, correction); 10130 : super(name, message, correction);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
10387 */ 10206 */
10388 bool resolveOnlyCommentInFunctionBody = false; 10207 bool resolveOnlyCommentInFunctionBody = false;
10389 10208
10390 /** 10209 /**
10391 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10210 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10392 * 10211 *
10393 * @param library the library containing the compilation unit being resolved 10212 * @param library the library containing the compilation unit being resolved
10394 * @param source the source representing the compilation unit being visited 10213 * @param source the source representing the compilation unit being visited
10395 * @param typeProvider the object used to access the types from the core libra ry 10214 * @param typeProvider the object used to access the types from the core libra ry
10396 */ 10215 */
10397 ResolverVisitor.con1(Library library, Source source, 10216 ResolverVisitor.con1(
10398 TypeProvider typeProvider, {StaticTypeAnalyzer typeAnalyzer, 10217 Library library, Source source, TypeProvider typeProvider,
10218 {StaticTypeAnalyzer typeAnalyzer,
10399 StaticTypeAnalyzerFactory typeAnalyzerFactory}) 10219 StaticTypeAnalyzerFactory typeAnalyzerFactory})
10400 : super.con1(library, source, typeProvider) { 10220 : super.con1(library, source, typeProvider) {
10401 this._inheritanceManager = library.inheritanceManager; 10221 this._inheritanceManager = library.inheritanceManager;
10402 this._elementResolver = new ElementResolver(this); 10222 this._elementResolver = new ElementResolver(this);
10403 this._typeAnalyzer = typeAnalyzer != null ? 10223 this._typeAnalyzer = typeAnalyzer != null
10404 typeAnalyzer : 10224 ? typeAnalyzer
10405 (typeAnalyzerFactory != null ? 10225 : (typeAnalyzerFactory != null
10406 typeAnalyzerFactory(this) : 10226 ? typeAnalyzerFactory(this)
10407 new StaticTypeAnalyzer(this)); 10227 : new StaticTypeAnalyzer(this));
10408 } 10228 }
10409 10229
10410
10411 /** 10230 /**
10412 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10231 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10413 * 10232 *
10414 * @param definingLibrary the element for the library containing the compilati on unit being 10233 * @param definingLibrary the element for the library containing the compilati on unit being
10415 * visited 10234 * visited
10416 * @param source the source representing the compilation unit being visited 10235 * @param source the source representing the compilation unit being visited
10417 * @param typeProvider the object used to access the types from the core libra ry 10236 * @param typeProvider the object used to access the types from the core libra ry
10418 * @param errorListener the error listener that will be informed of any errors that are found 10237 * @param errorListener the error listener that will be informed of any errors that are found
10419 * during resolution 10238 * during resolution
10420 */ 10239 */
(...skipping 10 matching lines...) Expand all
10431 * Initialize a newly created visitor to resolve the nodes in an AST node. 10250 * Initialize a newly created visitor to resolve the nodes in an AST node.
10432 * 10251 *
10433 * @param definingLibrary the element for the library containing the node bein g visited 10252 * @param definingLibrary the element for the library containing the node bein g visited
10434 * @param source the source representing the compilation unit containing the n ode being visited 10253 * @param source the source representing the compilation unit containing the n ode being visited
10435 * @param typeProvider the object used to access the types from the core libra ry 10254 * @param typeProvider the object used to access the types from the core libra ry
10436 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited 10255 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
10437 * @param errorListener the error listener that will be informed of any errors that are found 10256 * @param errorListener the error listener that will be informed of any errors that are found
10438 * during resolution 10257 * during resolution
10439 */ 10258 */
10440 ResolverVisitor.con3(LibraryElement definingLibrary, Source source, 10259 ResolverVisitor.con3(LibraryElement definingLibrary, Source source,
10441 TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorLis tener) 10260 TypeProvider typeProvider, Scope nameScope,
10261 AnalysisErrorListener errorListener)
10442 : super.con3( 10262 : super.con3(
10443 definingLibrary, 10263 definingLibrary, source, typeProvider, nameScope, errorListener) {
10444 source,
10445 typeProvider,
10446 nameScope,
10447 errorListener) {
10448 this._inheritanceManager = new InheritanceManager(definingLibrary); 10264 this._inheritanceManager = new InheritanceManager(definingLibrary);
10449 this._elementResolver = new ElementResolver(this); 10265 this._elementResolver = new ElementResolver(this);
10450 this._typeAnalyzer = new StaticTypeAnalyzer(this); 10266 this._typeAnalyzer = new StaticTypeAnalyzer(this);
10451 } 10267 }
10452 10268
10453 /** 10269 /**
10454 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10270 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10455 * 10271 *
10456 * @param library the library containing the compilation unit being resolved 10272 * @param library the library containing the compilation unit being resolved
10457 * @param source the source representing the compilation unit being visited 10273 * @param source the source representing the compilation unit being visited
10458 * @param typeProvider the object used to access the types from the core libra ry 10274 * @param typeProvider the object used to access the types from the core libra ry
10459 */ 10275 */
10460 ResolverVisitor.con4(ResolvableLibrary library, Source source, 10276 ResolverVisitor.con4(
10461 TypeProvider typeProvider) 10277 ResolvableLibrary library, Source source, TypeProvider typeProvider)
10462 : super.con4(library, source, typeProvider) { 10278 : super.con4(library, source, typeProvider) {
10463 this._inheritanceManager = library.inheritanceManager; 10279 this._inheritanceManager = library.inheritanceManager;
10464 this._elementResolver = new ElementResolver(this); 10280 this._elementResolver = new ElementResolver(this);
10465 this._typeAnalyzer = new StaticTypeAnalyzer(this); 10281 this._typeAnalyzer = new StaticTypeAnalyzer(this);
10466 } 10282 }
10467 10283
10468 get elementResolver_J2DAccessor => _elementResolver; 10284 get elementResolver_J2DAccessor => _elementResolver;
10469 10285
10470 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; 10286 set elementResolver_J2DAccessor(__v) => _elementResolver = __v;
10471 10287
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
10586 /** 10402 /**
10587 * If it is appropriate to do so, override the current type of the static and propagated elements 10403 * If it is appropriate to do so, override the current type of the static and propagated elements
10588 * associated with the given expression with the given type. Generally speakin g, it is appropriate 10404 * associated with the given expression with the given type. Generally speakin g, it is appropriate
10589 * if the given type is more specific than the current type. 10405 * if the given type is more specific than the current type.
10590 * 10406 *
10591 * @param expression the expression used to access the static and propagated e lements whose types 10407 * @param expression the expression used to access the static and propagated e lements whose types
10592 * might be overridden 10408 * might be overridden
10593 * @param potentialType the potential type of the elements 10409 * @param potentialType the potential type of the elements
10594 * @param allowPrecisionLoss see @{code overrideVariable} docs 10410 * @param allowPrecisionLoss see @{code overrideVariable} docs
10595 */ 10411 */
10596 void overrideExpression(Expression expression, DartType potentialType, 10412 void overrideExpression(
10597 bool allowPrecisionLoss) { 10413 Expression expression, DartType potentialType, bool allowPrecisionLoss) {
10598 VariableElement element = getOverridableStaticElement(expression); 10414 VariableElement element = getOverridableStaticElement(expression);
10599 if (element != null) { 10415 if (element != null) {
10600 overrideVariable(element, potentialType, allowPrecisionLoss); 10416 overrideVariable(element, potentialType, allowPrecisionLoss);
10601 } 10417 }
10602 element = getOverridablePropagatedElement(expression); 10418 element = getOverridablePropagatedElement(expression);
10603 if (element != null) { 10419 if (element != null) {
10604 overrideVariable(element, potentialType, allowPrecisionLoss); 10420 overrideVariable(element, potentialType, allowPrecisionLoss);
10605 } 10421 }
10606 } 10422 }
10607 10423
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
11297 // We visit the target, but do not visit the property name because it needs 11113 // We visit the target, but do not visit the property name because it needs
11298 // to be visited in the context of the property access node. 11114 // to be visited in the context of the property access node.
11299 // 11115 //
11300 safelyVisit(node.target); 11116 safelyVisit(node.target);
11301 node.accept(_elementResolver); 11117 node.accept(_elementResolver);
11302 node.accept(_typeAnalyzer); 11118 node.accept(_typeAnalyzer);
11303 return null; 11119 return null;
11304 } 11120 }
11305 11121
11306 @override 11122 @override
11307 Object 11123 Object visitRedirectingConstructorInvocation(
11308 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation nod e) { 11124 RedirectingConstructorInvocation node) {
11309 // 11125 //
11310 // We visit the argument list, but do not visit the optional identifier 11126 // We visit the argument list, but do not visit the optional identifier
11311 // because it needs to be visited in the context of the constructor 11127 // because it needs to be visited in the context of the constructor
11312 // invocation. 11128 // invocation.
11313 // 11129 //
11314 safelyVisit(node.argumentList); 11130 safelyVisit(node.argumentList);
11315 node.accept(_elementResolver); 11131 node.accept(_elementResolver);
11316 node.accept(_typeAnalyzer); 11132 node.accept(_typeAnalyzer);
11317 return null; 11133 return null;
11318 } 11134 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
11401 return null; 11217 return null;
11402 } 11218 }
11403 11219
11404 /** 11220 /**
11405 * Checks each promoted variable in the current scope for compliance with the following 11221 * Checks each promoted variable in the current scope for compliance with the following
11406 * specification statement: 11222 * specification statement:
11407 * 11223 *
11408 * If the variable <i>v</i> is accessed by a closure in <i>s<sub>1</sub></i> t hen the variable 11224 * If the variable <i>v</i> is accessed by a closure in <i>s<sub>1</sub></i> t hen the variable
11409 * <i>v</i> is not potentially mutated anywhere in the scope of <i>v</i>. 11225 * <i>v</i> is not potentially mutated anywhere in the scope of <i>v</i>.
11410 */ 11226 */
11411 void 11227 void _clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(
11412 _clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(AstNode targ et) { 11228 AstNode target) {
11413 for (Element element in _promoteManager.promotedElements) { 11229 for (Element element in _promoteManager.promotedElements) {
11414 if ((element as VariableElementImpl).isPotentiallyMutatedInScope) { 11230 if ((element as VariableElementImpl).isPotentiallyMutatedInScope) {
11415 if (_isVariableAccessedInClosure(element, target)) { 11231 if (_isVariableAccessedInClosure(element, target)) {
11416 _promoteManager.setType(element, null); 11232 _promoteManager.setType(element, null);
11417 } 11233 }
11418 } 11234 }
11419 } 11235 }
11420 } 11236 }
11421 11237
11422 /** 11238 /**
(...skipping 24 matching lines...) Expand all
11447 InterfaceType interfaceType = expressionType; 11263 InterfaceType interfaceType = expressionType;
11448 FunctionType iteratorFunction = 11264 FunctionType iteratorFunction =
11449 _inheritanceManager.lookupMemberType(interfaceType, "iterator"); 11265 _inheritanceManager.lookupMemberType(interfaceType, "iterator");
11450 if (iteratorFunction == null) { 11266 if (iteratorFunction == null) {
11451 // TODO(brianwilkerson) Should we report this error? 11267 // TODO(brianwilkerson) Should we report this error?
11452 return null; 11268 return null;
11453 } 11269 }
11454 DartType iteratorType = iteratorFunction.returnType; 11270 DartType iteratorType = iteratorFunction.returnType;
11455 if (iteratorType is InterfaceType) { 11271 if (iteratorType is InterfaceType) {
11456 InterfaceType iteratorInterfaceType = iteratorType; 11272 InterfaceType iteratorInterfaceType = iteratorType;
11457 FunctionType currentFunction = 11273 FunctionType currentFunction = _inheritanceManager.lookupMemberType(
11458 _inheritanceManager.lookupMemberType(iteratorInterfaceType, "current "); 11274 iteratorInterfaceType, "current");
11459 if (currentFunction == null) { 11275 if (currentFunction == null) {
11460 // TODO(brianwilkerson) Should we report this error? 11276 // TODO(brianwilkerson) Should we report this error?
11461 return null; 11277 return null;
11462 } 11278 }
11463 return currentFunction.returnType; 11279 return currentFunction.returnType;
11464 } 11280 }
11465 } 11281 }
11466 return null; 11282 return null;
11467 } 11283 }
11468 11284
11469 /** 11285 /**
11470 * If given "mayBeClosure" is [FunctionExpression] without explicit parameters types and its 11286 * If given "mayBeClosure" is [FunctionExpression] without explicit parameters types and its
11471 * required type is [FunctionType], then infer parameters types from [Function Type]. 11287 * required type is [FunctionType], then infer parameters types from [Function Type].
11472 */ 11288 */
11473 void _inferFunctionExpressionParametersTypes(Expression mayBeClosure, 11289 void _inferFunctionExpressionParametersTypes(
11474 DartType mayByFunctionType) { 11290 Expression mayBeClosure, DartType mayByFunctionType) {
11475 // prepare closure 11291 // prepare closure
11476 if (mayBeClosure is! FunctionExpression) { 11292 if (mayBeClosure is! FunctionExpression) {
11477 return; 11293 return;
11478 } 11294 }
11479 FunctionExpression closure = mayBeClosure as FunctionExpression; 11295 FunctionExpression closure = mayBeClosure as FunctionExpression;
11480 // prepare expected closure type 11296 // prepare expected closure type
11481 if (mayByFunctionType is! FunctionType) { 11297 if (mayByFunctionType is! FunctionType) {
11482 return; 11298 return;
11483 } 11299 }
11484 FunctionType expectedClosureType = mayByFunctionType as FunctionType; 11300 FunctionType expectedClosureType = mayByFunctionType as FunctionType;
11485 // If the expectedClosureType is not more specific than the static type, 11301 // If the expectedClosureType is not more specific than the static type,
11486 // return. 11302 // return.
11487 DartType staticClosureType = 11303 DartType staticClosureType =
11488 (closure.element != null ? closure.element.type : null) as DartType; 11304 (closure.element != null ? closure.element.type : null) as DartType;
11489 if (staticClosureType != null && 11305 if (staticClosureType != null &&
11490 !expectedClosureType.isMoreSpecificThan(staticClosureType)) { 11306 !expectedClosureType.isMoreSpecificThan(staticClosureType)) {
11491 return; 11307 return;
11492 } 11308 }
11493 // set propagated type for the closure 11309 // set propagated type for the closure
11494 closure.propagatedType = expectedClosureType; 11310 closure.propagatedType = expectedClosureType;
11495 // set inferred types for parameters 11311 // set inferred types for parameters
11496 NodeList<FormalParameter> parameters = closure.parameters.parameters; 11312 NodeList<FormalParameter> parameters = closure.parameters.parameters;
11497 List<ParameterElement> expectedParameters = expectedClosureType.parameters; 11313 List<ParameterElement> expectedParameters = expectedClosureType.parameters;
11498 for (int i = 11314 for (int i = 0;
11499 0; i < parameters.length && i < expectedParameters.length; i++) { 11315 i < parameters.length && i < expectedParameters.length;
11316 i++) {
11500 FormalParameter parameter = parameters[i]; 11317 FormalParameter parameter = parameters[i];
11501 ParameterElement element = parameter.element; 11318 ParameterElement element = parameter.element;
11502 DartType currentType = _overrideManager.getBestType(element); 11319 DartType currentType = _overrideManager.getBestType(element);
11503 // may be override the type 11320 // may be override the type
11504 DartType expectedType = expectedParameters[i].type; 11321 DartType expectedType = expectedParameters[i].type;
11505 if (currentType == null || expectedType.isMoreSpecificThan(currentType)) { 11322 if (currentType == null || expectedType.isMoreSpecificThan(currentType)) {
11506 _overrideManager.setType(element, expectedType); 11323 _overrideManager.setType(element, expectedType);
11507 } 11324 }
11508 } 11325 }
11509 } 11326 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
11566 return true; 11383 return true;
11567 } else if (statement is ExpressionStatement) { 11384 } else if (statement is ExpressionStatement) {
11568 return _isAbruptTerminationExpression(statement.expression); 11385 return _isAbruptTerminationExpression(statement.expression);
11569 } else if (statement is Block) { 11386 } else if (statement is Block) {
11570 NodeList<Statement> statements = statement.statements; 11387 NodeList<Statement> statements = statement.statements;
11571 int size = statements.length; 11388 int size = statements.length;
11572 if (size == 0) { 11389 if (size == 0) {
11573 return false; 11390 return false;
11574 } 11391 }
11575 11392
11576
11577 // This last-statement-is-return heuristic is unsound for adversarial 11393 // This last-statement-is-return heuristic is unsound for adversarial
11578 // code, but probably works well in the common case: 11394 // code, but probably works well in the common case:
11579 // 11395 //
11580 // var x = 123; 11396 // var x = 123;
11581 // var c = true; 11397 // var c = true;
11582 // L: if (c) { 11398 // L: if (c) {
11583 // x = "hello"; 11399 // x = "hello";
11584 // c = false; 11400 // c = false;
11585 // break L; 11401 // break L;
11586 // return; 11402 // return;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
11824 * in this scope, then an error will be generated and the original element wil l continue to be 11640 * in this scope, then an error will be generated and the original element wil l continue to be
11825 * mapped to the name. If there is an element with the given name in an enclos ing scope, then a 11641 * mapped to the name. If there is an element with the given name in an enclos ing scope, then a
11826 * warning will be generated but the given element will hide the inherited ele ment. 11642 * warning will be generated but the given element will hide the inherited ele ment.
11827 * 11643 *
11828 * @param element the element to be added to this scope 11644 * @param element the element to be added to this scope
11829 */ 11645 */
11830 void define(Element element) { 11646 void define(Element element) {
11831 String name = _getName(element); 11647 String name = _getName(element);
11832 if (name != null && !name.isEmpty) { 11648 if (name != null && !name.isEmpty) {
11833 if (_definedNames.containsKey(name)) { 11649 if (_definedNames.containsKey(name)) {
11834 errorListener.onError( 11650 errorListener
11835 getErrorForDuplicate(_definedNames[name], element)); 11651 .onError(getErrorForDuplicate(_definedNames[name], element));
11836 } else { 11652 } else {
11837 _definedNames[name] = element; 11653 _definedNames[name] = element;
11838 _hasName = true; 11654 _hasName = true;
11839 } 11655 }
11840 } 11656 }
11841 } 11657 }
11842 11658
11843 /** 11659 /**
11844 * Add the given element to this scope without checking for duplication or hid ing. 11660 * Add the given element to this scope without checking for duplication or hid ing.
11845 * 11661 *
(...skipping 22 matching lines...) Expand all
11868 * @param existing the first element to be declared with the conflicting name 11684 * @param existing the first element to be declared with the conflicting name
11869 * @param duplicate another element declared with the conflicting name 11685 * @param duplicate another element declared with the conflicting name
11870 * @return the error code used to report duplicate names within a scope 11686 * @return the error code used to report duplicate names within a scope
11871 */ 11687 */
11872 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 11688 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
11873 // TODO(brianwilkerson) Customize the error message based on the types of 11689 // TODO(brianwilkerson) Customize the error message based on the types of
11874 // elements that share the same name. 11690 // elements that share the same name.
11875 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being 11691 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being
11876 // generated. 11692 // generated.
11877 Source source = duplicate.source; 11693 Source source = duplicate.source;
11878 return new AnalysisError.con2( 11694 return new AnalysisError.con2(source, duplicate.nameOffset,
11879 source, 11695 duplicate.displayName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION,
11880 duplicate.nameOffset,
11881 duplicate.displayName.length,
11882 CompileTimeErrorCode.DUPLICATE_DEFINITION,
11883 [existing.displayName]); 11696 [existing.displayName]);
11884 } 11697 }
11885 11698
11886 /** 11699 /**
11887 * Return the source that contains the given identifier, or the source associa ted with this scope 11700 * Return the source that contains the given identifier, or the source associa ted with this scope
11888 * if the source containing the identifier could not be determined. 11701 * if the source containing the identifier could not be determined.
11889 * 11702 *
11890 * @param identifier the identifier whose source is to be returned 11703 * @param identifier the identifier whose source is to be returned
11891 * @return the source that contains the given identifier 11704 * @return the source that contains the given identifier
11892 */ 11705 */
(...skipping 12 matching lines...) Expand all
11905 * Return the element with which the given name is associated, or `null` if th e name is not 11718 * Return the element with which the given name is associated, or `null` if th e name is not
11906 * defined within this scope. 11719 * defined within this scope.
11907 * 11720 *
11908 * @param identifier the identifier node to lookup element for, used to report correct kind of a 11721 * @param identifier the identifier node to lookup element for, used to report correct kind of a
11909 * problem and associate problem with 11722 * problem and associate problem with
11910 * @param name the name associated with the element to be returned 11723 * @param name the name associated with the element to be returned
11911 * @param referencingLibrary the library that contains the reference to the na me, used to 11724 * @param referencingLibrary the library that contains the reference to the na me, used to
11912 * implement library-level privacy 11725 * implement library-level privacy
11913 * @return the element with which the given name is associated 11726 * @return the element with which the given name is associated
11914 */ 11727 */
11915 Element internalLookup(Identifier identifier, String name, 11728 Element internalLookup(
11916 LibraryElement referencingLibrary); 11729 Identifier identifier, String name, LibraryElement referencingLibrary);
11917 11730
11918 /** 11731 /**
11919 * Return the element with which the given name is associated, or `null` if th e name is not 11732 * Return the element with which the given name is associated, or `null` if th e name is not
11920 * defined within this scope. This method only returns elements that are direc tly defined within 11733 * defined within this scope. This method only returns elements that are direc tly defined within
11921 * this scope, not elements that are defined in an enclosing scope. 11734 * this scope, not elements that are defined in an enclosing scope.
11922 * 11735 *
11923 * @param name the name associated with the element to be returned 11736 * @param name the name associated with the element to be returned
11924 * @param referencingLibrary the library that contains the reference to the na me, used to 11737 * @param referencingLibrary the library that contains the reference to the na me, used to
11925 * implement library-level privacy 11738 * implement library-level privacy
11926 * @return the element with which the given name is associated 11739 * @return the element with which the given name is associated
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
12066 this._nameScope = nameScope; 11879 this._nameScope = nameScope;
12067 } 11880 }
12068 11881
12069 /** 11882 /**
12070 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 11883 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
12071 * 11884 *
12072 * @param library the library containing the compilation unit being resolved 11885 * @param library the library containing the compilation unit being resolved
12073 * @param source the source representing the compilation unit being visited 11886 * @param source the source representing the compilation unit being visited
12074 * @param typeProvider the object used to access the types from the core libra ry 11887 * @param typeProvider the object used to access the types from the core libra ry
12075 */ 11888 */
12076 ScopedVisitor.con4(ResolvableLibrary library, this.source, this.typeProvider) 11889 ScopedVisitor.con4(
12077 { 11890 ResolvableLibrary library, this.source, this.typeProvider) {
12078 this._definingLibrary = library.libraryElement; 11891 this._definingLibrary = library.libraryElement;
12079 LibraryScope libraryScope = library.libraryScope; 11892 LibraryScope libraryScope = library.libraryScope;
12080 this._errorListener = libraryScope.errorListener; 11893 this._errorListener = libraryScope.errorListener;
12081 this._nameScope = libraryScope; 11894 this._nameScope = libraryScope;
12082 } 11895 }
12083 11896
12084 /** 11897 /**
12085 * Return the library element for the library containing the compilation unit being resolved. 11898 * Return the library element for the library containing the compilation unit being resolved.
12086 * 11899 *
12087 * @return the library element for the library containing the compilation unit being resolved 11900 * @return the library element for the library containing the compilation unit being resolved
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
12131 11944
12132 /** 11945 /**
12133 * Report an error with the given error code and arguments. 11946 * Report an error with the given error code and arguments.
12134 * 11947 *
12135 * @param errorCode the error code of the error to be reported 11948 * @param errorCode the error code of the error to be reported
12136 * @param node the node specifying the location of the error 11949 * @param node the node specifying the location of the error
12137 * @param arguments the arguments to the error, used to compose the error mess age 11950 * @param arguments the arguments to the error, used to compose the error mess age
12138 */ 11951 */
12139 void reportErrorForNode(ErrorCode errorCode, AstNode node, 11952 void reportErrorForNode(ErrorCode errorCode, AstNode node,
12140 [List<Object> arguments]) { 11953 [List<Object> arguments]) {
12141 _errorListener.onError( 11954 _errorListener.onError(new AnalysisError.con2(
12142 new AnalysisError.con2(source, node.offset, node.length, errorCode, argu ments)); 11955 source, node.offset, node.length, errorCode, arguments));
12143 } 11956 }
12144 11957
12145 /** 11958 /**
12146 * Report an error with the given error code and arguments. 11959 * Report an error with the given error code and arguments.
12147 * 11960 *
12148 * @param errorCode the error code of the error to be reported 11961 * @param errorCode the error code of the error to be reported
12149 * @param offset the offset of the location of the error 11962 * @param offset the offset of the location of the error
12150 * @param length the length of the location of the error 11963 * @param length the length of the location of the error
12151 * @param arguments the arguments to the error, used to compose the error mess age 11964 * @param arguments the arguments to the error, used to compose the error mess age
12152 */ 11965 */
12153 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, 11966 void reportErrorForOffset(ErrorCode errorCode, int offset, int length,
12154 [List<Object> arguments]) { 11967 [List<Object> arguments]) {
12155 _errorListener.onError( 11968 _errorListener.onError(
12156 new AnalysisError.con2(source, offset, length, errorCode, arguments)); 11969 new AnalysisError.con2(source, offset, length, errorCode, arguments));
12157 } 11970 }
12158 11971
12159 /** 11972 /**
12160 * Report an error with the given error code and arguments. 11973 * Report an error with the given error code and arguments.
12161 * 11974 *
12162 * @param errorCode the error code of the error to be reported 11975 * @param errorCode the error code of the error to be reported
12163 * @param token the token specifying the location of the error 11976 * @param token the token specifying the location of the error
12164 * @param arguments the arguments to the error, used to compose the error mess age 11977 * @param arguments the arguments to the error, used to compose the error mess age
12165 */ 11978 */
12166 void reportErrorForToken(ErrorCode errorCode, sc.Token token, 11979 void reportErrorForToken(ErrorCode errorCode, sc.Token token,
12167 [List<Object> arguments]) { 11980 [List<Object> arguments]) {
12168 _errorListener.onError( 11981 _errorListener.onError(new AnalysisError.con2(
12169 new AnalysisError.con2( 11982 source, token.offset, token.length, errorCode, arguments));
12170 source,
12171 token.offset,
12172 token.length,
12173 errorCode,
12174 arguments));
12175 } 11983 }
12176 11984
12177 /** 11985 /**
12178 * Visit the given AST node if it is not null. 11986 * Visit the given AST node if it is not null.
12179 * 11987 *
12180 * @param node the node to be visited 11988 * @param node the node to be visited
12181 */ 11989 */
12182 void safelyVisit(AstNode node) { 11990 void safelyVisit(AstNode node) {
12183 if (node != null) { 11991 if (node != null) {
12184 node.accept(this); 11992 node.accept(this);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
12298 if (constructorElement == null) { 12106 if (constructorElement == null) {
12299 StringBuffer buffer = new StringBuffer(); 12107 StringBuffer buffer = new StringBuffer();
12300 buffer.write("Missing element for constructor "); 12108 buffer.write("Missing element for constructor ");
12301 buffer.write(node.returnType.name); 12109 buffer.write(node.returnType.name);
12302 if (node.name != null) { 12110 if (node.name != null) {
12303 buffer.write("."); 12111 buffer.write(".");
12304 buffer.write(node.name.name); 12112 buffer.write(node.name.name);
12305 } 12113 }
12306 buffer.write(" in "); 12114 buffer.write(" in ");
12307 buffer.write(definingLibrary.source.fullName); 12115 buffer.write(definingLibrary.source.fullName);
12308 AnalysisEngine.instance.logger.logInformation( 12116 AnalysisEngine.instance.logger.logInformation(buffer.toString(),
12309 buffer.toString(),
12310 new CaughtException(new AnalysisException(), null)); 12117 new CaughtException(new AnalysisException(), null));
12311 } else { 12118 } else {
12312 _nameScope = new FunctionScope(_nameScope, constructorElement); 12119 _nameScope = new FunctionScope(_nameScope, constructorElement);
12313 } 12120 }
12314 super.visitConstructorDeclaration(node); 12121 super.visitConstructorDeclaration(node);
12315 } finally { 12122 } finally {
12316 _nameScope = outerScope; 12123 _nameScope = outerScope;
12317 } 12124 }
12318 return null; 12125 return null;
12319 } 12126 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
12450 Scope outerScope = _nameScope; 12257 Scope outerScope = _nameScope;
12451 try { 12258 try {
12452 ExecutableElement functionElement = node.element; 12259 ExecutableElement functionElement = node.element;
12453 if (functionElement == null) { 12260 if (functionElement == null) {
12454 StringBuffer buffer = new StringBuffer(); 12261 StringBuffer buffer = new StringBuffer();
12455 buffer.write("Missing element for function "); 12262 buffer.write("Missing element for function ");
12456 AstNode parent = node.parent; 12263 AstNode parent = node.parent;
12457 while (parent != null) { 12264 while (parent != null) {
12458 if (parent is Declaration) { 12265 if (parent is Declaration) {
12459 Element parentElement = (parent as Declaration).element; 12266 Element parentElement = (parent as Declaration).element;
12460 buffer.write( 12267 buffer.write(parentElement == null
12461 parentElement == null ? "<unknown> " : "${parentElement.name} "); 12268 ? "<unknown> "
12269 : "${parentElement.name} ");
12462 } 12270 }
12463 parent = parent.parent; 12271 parent = parent.parent;
12464 } 12272 }
12465 buffer.write("in "); 12273 buffer.write("in ");
12466 buffer.write(definingLibrary.source.fullName); 12274 buffer.write(definingLibrary.source.fullName);
12467 AnalysisEngine.instance.logger.logInformation( 12275 AnalysisEngine.instance.logger.logInformation(buffer.toString(),
12468 buffer.toString(),
12469 new CaughtException(new AnalysisException(), null)); 12276 new CaughtException(new AnalysisException(), null));
12470 } else { 12277 } else {
12471 _nameScope = new FunctionScope(_nameScope, functionElement); 12278 _nameScope = new FunctionScope(_nameScope, functionElement);
12472 } 12279 }
12473 super.visitFunctionExpression(node); 12280 super.visitFunctionExpression(node);
12474 } finally { 12281 } finally {
12475 _nameScope = outerScope; 12282 _nameScope = outerScope;
12476 } 12283 }
12477 } 12284 }
12478 return null; 12285 return null;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
12688 * 12495 *
12689 * @param classElement the class to recursively return the set of subtypes of 12496 * @param classElement the class to recursively return the set of subtypes of
12690 */ 12497 */
12691 HashSet<ClassElement> computeAllSubtypes(ClassElement classElement) { 12498 HashSet<ClassElement> computeAllSubtypes(ClassElement classElement) {
12692 // Ensure that we have generated the subtype map for the library 12499 // Ensure that we have generated the subtype map for the library
12693 _computeSubtypesInLibrary(classElement.library); 12500 _computeSubtypesInLibrary(classElement.library);
12694 // use the subtypeMap to compute the set of all subtypes and subtype's 12501 // use the subtypeMap to compute the set of all subtypes and subtype's
12695 // subtypes 12502 // subtypes
12696 HashSet<ClassElement> allSubtypes = new HashSet<ClassElement>(); 12503 HashSet<ClassElement> allSubtypes = new HashSet<ClassElement>();
12697 _safelyComputeAllSubtypes( 12504 _safelyComputeAllSubtypes(
12698 classElement, 12505 classElement, new HashSet<ClassElement>(), allSubtypes);
12699 new HashSet<ClassElement>(),
12700 allSubtypes);
12701 return allSubtypes; 12506 return allSubtypes;
12702 } 12507 }
12703 12508
12704 /** 12509 /**
12705 * Given some [LibraryElement], visit all of the types in the library, the pas sed library, 12510 * Given some [LibraryElement], visit all of the types in the library, the pas sed library,
12706 * and any imported libraries, will be in the [visitedLibraries] set. 12511 * and any imported libraries, will be in the [visitedLibraries] set.
12707 * 12512 *
12708 * @param libraryElement the library to visit, it it hasn't been visited alrea dy 12513 * @param libraryElement the library to visit, it it hasn't been visited alrea dy
12709 */ 12514 */
12710 void ensureLibraryVisited(LibraryElement libraryElement) { 12515 void ensureLibraryVisited(LibraryElement libraryElement) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
12782 _computeSubtypesInLibrary(exportElt.library); 12587 _computeSubtypesInLibrary(exportElt.library);
12783 } 12588 }
12784 } 12589 }
12785 12590
12786 /** 12591 /**
12787 * Add some key/ value pair into the [subtypeMap] map. 12592 * Add some key/ value pair into the [subtypeMap] map.
12788 * 12593 *
12789 * @param supertypeElement the key for the [subtypeMap] map 12594 * @param supertypeElement the key for the [subtypeMap] map
12790 * @param subtypeElement the value for the [subtypeMap] map 12595 * @param subtypeElement the value for the [subtypeMap] map
12791 */ 12596 */
12792 void _putInSubtypeMap(ClassElement supertypeElement, 12597 void _putInSubtypeMap(
12793 ClassElement subtypeElement) { 12598 ClassElement supertypeElement, ClassElement subtypeElement) {
12794 HashSet<ClassElement> subtypes = _subtypeMap[supertypeElement]; 12599 HashSet<ClassElement> subtypes = _subtypeMap[supertypeElement];
12795 if (subtypes == null) { 12600 if (subtypes == null) {
12796 subtypes = new HashSet<ClassElement>(); 12601 subtypes = new HashSet<ClassElement>();
12797 _subtypeMap[supertypeElement] = subtypes; 12602 _subtypeMap[supertypeElement] = subtypes;
12798 } 12603 }
12799 subtypes.add(subtypeElement); 12604 subtypes.add(subtypeElement);
12800 } 12605 }
12801 12606
12802 /** 12607 /**
12803 * Given some [ClassElement] and a [HashSet<ClassElement>], this method recurs ively 12608 * Given some [ClassElement] and a [HashSet<ClassElement>], this method recurs ively
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
12873 /** 12678 /**
12874 * Look for user defined tasks in comments and convert them into info level an alysis issues. 12679 * Look for user defined tasks in comments and convert them into info level an alysis issues.
12875 * 12680 *
12876 * @param commentToken the comment token to analyze 12681 * @param commentToken the comment token to analyze
12877 */ 12682 */
12878 void _scrapeTodoComment(sc.Token commentToken) { 12683 void _scrapeTodoComment(sc.Token commentToken) {
12879 JavaPatternMatcher matcher = 12684 JavaPatternMatcher matcher =
12880 new JavaPatternMatcher(TodoCode.TODO_REGEX, commentToken.lexeme); 12685 new JavaPatternMatcher(TodoCode.TODO_REGEX, commentToken.lexeme);
12881 if (matcher.find()) { 12686 if (matcher.find()) {
12882 int offset = 12687 int offset =
12883 commentToken.offset + 12688 commentToken.offset + matcher.start() + matcher.group(1).length;
12884 matcher.start() +
12885 matcher.group(1).length;
12886 int length = matcher.group(2).length; 12689 int length = matcher.group(2).length;
12887 _errorReporter.reportErrorForOffset( 12690 _errorReporter.reportErrorForOffset(
12888 TodoCode.TODO, 12691 TodoCode.TODO, offset, length, [matcher.group(2)]);
12889 offset,
12890 length,
12891 [matcher.group(2)]);
12892 } 12692 }
12893 } 12693 }
12894 } 12694 }
12895 12695
12896 /** 12696 /**
12897 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an 12697 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an
12898 * element within a given context. 12698 * element within a given context.
12899 */ 12699 */
12900 class TypeOverrideManager { 12700 class TypeOverrideManager {
12901 /** 12701 /**
(...skipping 27 matching lines...) Expand all
12929 return _currentScope.captureLocalOverrides(); 12729 return _currentScope.captureLocalOverrides();
12930 } 12730 }
12931 12731
12932 /** 12732 /**
12933 * Return a map from the elements for the variables in the given list that hav e their types 12733 * Return a map from the elements for the variables in the given list that hav e their types
12934 * overridden to the overriding type. 12734 * overridden to the overriding type.
12935 * 12735 *
12936 * @param variableList the list of variables whose overriding types are to be captured 12736 * @param variableList the list of variables whose overriding types are to be captured
12937 * @return a table mapping elements to their overriding types 12737 * @return a table mapping elements to their overriding types
12938 */ 12738 */
12939 Map<VariableElement, DartType> 12739 Map<VariableElement, DartType> captureOverrides(
12940 captureOverrides(VariableDeclarationList variableList) { 12740 VariableDeclarationList variableList) {
12941 if (_currentScope == null) { 12741 if (_currentScope == null) {
12942 throw new IllegalStateException( 12742 throw new IllegalStateException(
12943 "Cannot capture overrides without a scope"); 12743 "Cannot capture overrides without a scope");
12944 } 12744 }
12945 return _currentScope.captureOverrides(variableList); 12745 return _currentScope.captureOverrides(variableList);
12946 } 12746 }
12947 12747
12948 /** 12748 /**
12949 * Enter a new override scope. 12749 * Enter a new override scope.
12950 */ 12750 */
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
13117 */ 12917 */
13118 Map<VariableElement, DartType> captureLocalOverrides() => _overridenTypes; 12918 Map<VariableElement, DartType> captureLocalOverrides() => _overridenTypes;
13119 12919
13120 /** 12920 /**
13121 * Return a map from the elements for the variables in the given list that hav e their types 12921 * Return a map from the elements for the variables in the given list that hav e their types
13122 * overridden to the overriding type. 12922 * overridden to the overriding type.
13123 * 12923 *
13124 * @param variableList the list of variables whose overriding types are to be captured 12924 * @param variableList the list of variables whose overriding types are to be captured
13125 * @return a table mapping elements to their overriding types 12925 * @return a table mapping elements to their overriding types
13126 */ 12926 */
13127 Map<VariableElement, DartType> 12927 Map<VariableElement, DartType> captureOverrides(
13128 captureOverrides(VariableDeclarationList variableList) { 12928 VariableDeclarationList variableList) {
13129 Map<VariableElement, DartType> overrides = 12929 Map<VariableElement, DartType> overrides =
13130 new HashMap<VariableElement, DartType>(); 12930 new HashMap<VariableElement, DartType>();
13131 if (variableList.isConst || variableList.isFinal) { 12931 if (variableList.isConst || variableList.isFinal) {
13132 for (VariableDeclaration variable in variableList.variables) { 12932 for (VariableDeclaration variable in variableList.variables) {
13133 VariableElement element = variable.element; 12933 VariableElement element = variable.element;
13134 if (element != null) { 12934 if (element != null) {
13135 DartType type = _overridenTypes[element]; 12935 DartType type = _overridenTypes[element];
13136 if (type != null) { 12936 if (type != null) {
13137 overrides[element] = type; 12937 overrides[element] = type;
13138 } 12938 }
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
13703 * Return the type with the given name from the given namespace, or `null` if there is no 13503 * Return the type with the given name from the given namespace, or `null` if there is no
13704 * class with the given name. 13504 * class with the given name.
13705 * 13505 *
13706 * @param namespace the namespace in which to search for the given name 13506 * @param namespace the namespace in which to search for the given name
13707 * @param typeName the name of the type being searched for 13507 * @param typeName the name of the type being searched for
13708 * @return the type that was found 13508 * @return the type that was found
13709 */ 13509 */
13710 InterfaceType _getType(Namespace namespace, String typeName) { 13510 InterfaceType _getType(Namespace namespace, String typeName) {
13711 Element element = namespace.get(typeName); 13511 Element element = namespace.get(typeName);
13712 if (element == null) { 13512 if (element == null) {
13713 AnalysisEngine.instance.logger.logInformation( 13513 AnalysisEngine.instance.logger
13714 "No definition of type $typeName"); 13514 .logInformation("No definition of type $typeName");
13715 return null; 13515 return null;
13716 } 13516 }
13717 return (element as ClassElement).type; 13517 return (element as ClassElement).type;
13718 } 13518 }
13719 13519
13720 /** 13520 /**
13721 * Initialize the types provided by this type provider from the given library. 13521 * Initialize the types provided by this type provider from the given library.
13722 * 13522 *
13723 * @param library the library containing the definitions of the core types 13523 * @param library the library containing the definitions of the core types
13724 */ 13524 */
13725 void _initializeFrom(LibraryElement coreLibrary, 13525 void _initializeFrom(
13726 LibraryElement asyncLibrary) { 13526 LibraryElement coreLibrary, LibraryElement asyncLibrary) {
13727 Namespace coreNamespace = 13527 Namespace coreNamespace =
13728 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLibrary); 13528 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLibrary);
13729 Namespace asyncNamespace = 13529 Namespace asyncNamespace =
13730 new NamespaceBuilder().createPublicNamespaceForLibrary(asyncLibrary); 13530 new NamespaceBuilder().createPublicNamespaceForLibrary(asyncLibrary);
13731 _boolType = _getType(coreNamespace, "bool"); 13531 _boolType = _getType(coreNamespace, "bool");
13732 _bottomType = BottomTypeImpl.instance; 13532 _bottomType = BottomTypeImpl.instance;
13733 _deprecatedType = _getType(coreNamespace, "Deprecated"); 13533 _deprecatedType = _getType(coreNamespace, "Deprecated");
13734 _doubleType = _getType(coreNamespace, "double"); 13534 _doubleType = _getType(coreNamespace, "double");
13735 _dynamicType = DynamicTypeImpl.instance; 13535 _dynamicType = DynamicTypeImpl.instance;
13736 _functionType = _getType(coreNamespace, "Function"); 13536 _functionType = _getType(coreNamespace, "Function");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
13777 */ 13577 */
13778 bool _hasReferenceToSuper = false; 13578 bool _hasReferenceToSuper = false;
13779 13579
13780 /** 13580 /**
13781 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 13581 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
13782 * 13582 *
13783 * @param library the library containing the compilation unit being resolved 13583 * @param library the library containing the compilation unit being resolved
13784 * @param source the source representing the compilation unit being visited 13584 * @param source the source representing the compilation unit being visited
13785 * @param typeProvider the object used to access the types from the core libra ry 13585 * @param typeProvider the object used to access the types from the core libra ry
13786 */ 13586 */
13787 TypeResolverVisitor.con1(Library library, Source source, 13587 TypeResolverVisitor.con1(
13788 TypeProvider typeProvider) 13588 Library library, Source source, TypeProvider typeProvider)
13789 : super.con1(library, source, typeProvider) { 13589 : super.con1(library, source, typeProvider) {
13790 _dynamicType = typeProvider.dynamicType; 13590 _dynamicType = typeProvider.dynamicType;
13791 _undefinedType = typeProvider.undefinedType; 13591 _undefinedType = typeProvider.undefinedType;
13792 } 13592 }
13793 13593
13794 /** 13594 /**
13795 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 13595 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
13796 * 13596 *
13797 * @param definingLibrary the element for the library containing the compilati on unit being 13597 * @param definingLibrary the element for the library containing the compilati on unit being
13798 * visited 13598 * visited
(...skipping 13 matching lines...) Expand all
13812 * Initialize a newly created visitor to resolve the nodes in an AST node. 13612 * Initialize a newly created visitor to resolve the nodes in an AST node.
13813 * 13613 *
13814 * @param definingLibrary the element for the library containing the node bein g visited 13614 * @param definingLibrary the element for the library containing the node bein g visited
13815 * @param source the source representing the compilation unit containing the n ode being visited 13615 * @param source the source representing the compilation unit containing the n ode being visited
13816 * @param typeProvider the object used to access the types from the core libra ry 13616 * @param typeProvider the object used to access the types from the core libra ry
13817 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited 13617 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
13818 * @param errorListener the error listener that will be informed of any errors that are found 13618 * @param errorListener the error listener that will be informed of any errors that are found
13819 * during resolution 13619 * during resolution
13820 */ 13620 */
13821 TypeResolverVisitor.con3(LibraryElement definingLibrary, Source source, 13621 TypeResolverVisitor.con3(LibraryElement definingLibrary, Source source,
13822 TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorLis tener) 13622 TypeProvider typeProvider, Scope nameScope,
13623 AnalysisErrorListener errorListener)
13823 : super.con3( 13624 : super.con3(
13824 definingLibrary, 13625 definingLibrary, source, typeProvider, nameScope, errorListener) {
13825 source,
13826 typeProvider,
13827 nameScope,
13828 errorListener) {
13829 _dynamicType = typeProvider.dynamicType; 13626 _dynamicType = typeProvider.dynamicType;
13830 _undefinedType = typeProvider.undefinedType; 13627 _undefinedType = typeProvider.undefinedType;
13831 } 13628 }
13832 13629
13833 /** 13630 /**
13834 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 13631 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
13835 * 13632 *
13836 * @param library the library containing the compilation unit being resolved 13633 * @param library the library containing the compilation unit being resolved
13837 * @param source the source representing the compilation unit being visited 13634 * @param source the source representing the compilation unit being visited
13838 * @param typeProvider the object used to access the types from the core libra ry 13635 * @param typeProvider the object used to access the types from the core libra ry
13839 */ 13636 */
13840 TypeResolverVisitor.con4(ResolvableLibrary library, Source source, 13637 TypeResolverVisitor.con4(
13841 TypeProvider typeProvider) 13638 ResolvableLibrary library, Source source, TypeProvider typeProvider)
13842 : super.con4(library, source, typeProvider) { 13639 : super.con4(library, source, typeProvider) {
13843 _dynamicType = typeProvider.dynamicType; 13640 _dynamicType = typeProvider.dynamicType;
13844 _undefinedType = typeProvider.undefinedType; 13641 _undefinedType = typeProvider.undefinedType;
13845 } 13642 }
13846 13643
13847 @override 13644 @override
13848 Object visitAnnotation(Annotation node) { 13645 Object visitAnnotation(Annotation node) {
13849 // 13646 //
13850 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" 13647 // Visit annotations, if the annotation is @proxy, on a class, and "proxy"
13851 // resolves to the proxy annotation in dart.core, then create create the 13648 // resolves to the proxy annotation in dart.core, then create create the
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
13920 13717
13921 @override 13718 @override
13922 void visitClassDeclarationInScope(ClassDeclaration node) { 13719 void visitClassDeclarationInScope(ClassDeclaration node) {
13923 super.visitClassDeclarationInScope(node); 13720 super.visitClassDeclarationInScope(node);
13924 ExtendsClause extendsClause = node.extendsClause; 13721 ExtendsClause extendsClause = node.extendsClause;
13925 WithClause withClause = node.withClause; 13722 WithClause withClause = node.withClause;
13926 ImplementsClause implementsClause = node.implementsClause; 13723 ImplementsClause implementsClause = node.implementsClause;
13927 ClassElementImpl classElement = _getClassElement(node.name); 13724 ClassElementImpl classElement = _getClassElement(node.name);
13928 InterfaceType superclassType = null; 13725 InterfaceType superclassType = null;
13929 if (extendsClause != null) { 13726 if (extendsClause != null) {
13930 ErrorCode errorCode = (withClause == null ? 13727 ErrorCode errorCode = (withClause == null
13931 CompileTimeErrorCode.EXTENDS_NON_CLASS : 13728 ? CompileTimeErrorCode.EXTENDS_NON_CLASS
13932 CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS); 13729 : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS);
13933 superclassType = _resolveType( 13730 superclassType = _resolveType(extendsClause.superclass, errorCode,
13934 extendsClause.superclass, 13731 CompileTimeErrorCode.EXTENDS_ENUM, errorCode);
13935 errorCode,
13936 CompileTimeErrorCode.EXTENDS_ENUM,
13937 errorCode);
13938 if (!identical(superclassType, typeProvider.objectType)) { 13732 if (!identical(superclassType, typeProvider.objectType)) {
13939 classElement.validMixin = false; 13733 classElement.validMixin = false;
13940 } 13734 }
13941 } 13735 }
13942 if (classElement != null) { 13736 if (classElement != null) {
13943 if (superclassType == null) { 13737 if (superclassType == null) {
13944 InterfaceType objectType = typeProvider.objectType; 13738 InterfaceType objectType = typeProvider.objectType;
13945 if (!identical(classElement.type, objectType)) { 13739 if (!identical(classElement.type, objectType)) {
13946 superclassType = objectType; 13740 superclassType = objectType;
13947 } 13741 }
(...skipping 16 matching lines...) Expand all
13964 int count = nonFields.length; 13758 int count = nonFields.length;
13965 for (int i = 0; i < count; i++) { 13759 for (int i = 0; i < count; i++) {
13966 nonFields[i].accept(this); 13760 nonFields[i].accept(this);
13967 } 13761 }
13968 } 13762 }
13969 13763
13970 @override 13764 @override
13971 Object visitClassTypeAlias(ClassTypeAlias node) { 13765 Object visitClassTypeAlias(ClassTypeAlias node) {
13972 super.visitClassTypeAlias(node); 13766 super.visitClassTypeAlias(node);
13973 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS; 13767 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS;
13974 InterfaceType superclassType = _resolveType( 13768 InterfaceType superclassType = _resolveType(node.superclass, errorCode,
13975 node.superclass, 13769 CompileTimeErrorCode.EXTENDS_ENUM, errorCode);
13976 errorCode,
13977 CompileTimeErrorCode.EXTENDS_ENUM,
13978 errorCode);
13979 if (superclassType == null) { 13770 if (superclassType == null) {
13980 superclassType = typeProvider.objectType; 13771 superclassType = typeProvider.objectType;
13981 } 13772 }
13982 ClassElementImpl classElement = _getClassElement(node.name); 13773 ClassElementImpl classElement = _getClassElement(node.name);
13983 if (classElement != null) { 13774 if (classElement != null) {
13984 classElement.supertype = superclassType; 13775 classElement.supertype = superclassType;
13985 } 13776 }
13986 _resolve(classElement, node.withClause, node.implementsClause); 13777 _resolve(classElement, node.withClause, node.implementsClause);
13987 return null; 13778 return null;
13988 } 13779 }
(...skipping 10 matching lines...) Expand all
13999 buffer.write(node.name == null ? "<unnamed>" : node.name.name); 13790 buffer.write(node.name == null ? "<unnamed>" : node.name.name);
14000 buffer.write(" in "); 13791 buffer.write(" in ");
14001 if (classNode == null) { 13792 if (classNode == null) {
14002 buffer.write("<unknown class>"); 13793 buffer.write("<unknown class>");
14003 } else { 13794 } else {
14004 buffer.write(classNode.name.name); 13795 buffer.write(classNode.name.name);
14005 } 13796 }
14006 buffer.write(" in "); 13797 buffer.write(" in ");
14007 buffer.write(source.fullName); 13798 buffer.write(source.fullName);
14008 buffer.write(" was not set while trying to resolve types."); 13799 buffer.write(" was not set while trying to resolve types.");
14009 AnalysisEngine.instance.logger.logError( 13800 AnalysisEngine.instance.logger.logError(buffer.toString(),
14010 buffer.toString(),
14011 new CaughtException(new AnalysisException(), null)); 13801 new CaughtException(new AnalysisException(), null));
14012 } else { 13802 } else {
14013 ClassElement definingClass = element.enclosingElement as ClassElement; 13803 ClassElement definingClass = element.enclosingElement as ClassElement;
14014 element.returnType = definingClass.type; 13804 element.returnType = definingClass.type;
14015 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 13805 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
14016 type.typeArguments = definingClass.type.typeArguments; 13806 type.typeArguments = definingClass.type.typeArguments;
14017 element.type = type; 13807 element.type = type;
14018 } 13808 }
14019 return null; 13809 return null;
14020 } 13810 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
14070 Object visitFunctionDeclaration(FunctionDeclaration node) { 13860 Object visitFunctionDeclaration(FunctionDeclaration node) {
14071 super.visitFunctionDeclaration(node); 13861 super.visitFunctionDeclaration(node);
14072 ExecutableElementImpl element = node.element as ExecutableElementImpl; 13862 ExecutableElementImpl element = node.element as ExecutableElementImpl;
14073 if (element == null) { 13863 if (element == null) {
14074 StringBuffer buffer = new StringBuffer(); 13864 StringBuffer buffer = new StringBuffer();
14075 buffer.write("The element for the top-level function "); 13865 buffer.write("The element for the top-level function ");
14076 buffer.write(node.name); 13866 buffer.write(node.name);
14077 buffer.write(" in "); 13867 buffer.write(" in ");
14078 buffer.write(source.fullName); 13868 buffer.write(source.fullName);
14079 buffer.write(" was not set while trying to resolve types."); 13869 buffer.write(" was not set while trying to resolve types.");
14080 AnalysisEngine.instance.logger.logError( 13870 AnalysisEngine.instance.logger.logError(buffer.toString(),
14081 buffer.toString(),
14082 new CaughtException(new AnalysisException(), null)); 13871 new CaughtException(new AnalysisException(), null));
14083 } 13872 }
14084 element.returnType = _computeReturnType(node.returnType); 13873 element.returnType = _computeReturnType(node.returnType);
14085 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 13874 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
14086 ClassElement definingClass = 13875 ClassElement definingClass =
14087 element.getAncestor((element) => element is ClassElement); 13876 element.getAncestor((element) => element is ClassElement);
14088 if (definingClass != null) { 13877 if (definingClass != null) {
14089 type.typeArguments = definingClass.type.typeArguments; 13878 type.typeArguments = definingClass.type.typeArguments;
14090 } 13879 }
14091 element.type = type; 13880 element.type = type;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
14128 buffer.write(node.name.name); 13917 buffer.write(node.name.name);
14129 buffer.write(" in "); 13918 buffer.write(" in ");
14130 if (classNode == null) { 13919 if (classNode == null) {
14131 buffer.write("<unknown class>"); 13920 buffer.write("<unknown class>");
14132 } else { 13921 } else {
14133 buffer.write(classNode.name.name); 13922 buffer.write(classNode.name.name);
14134 } 13923 }
14135 buffer.write(" in "); 13924 buffer.write(" in ");
14136 buffer.write(source.fullName); 13925 buffer.write(source.fullName);
14137 buffer.write(" was not set while trying to resolve types."); 13926 buffer.write(" was not set while trying to resolve types.");
14138 AnalysisEngine.instance.logger.logError( 13927 AnalysisEngine.instance.logger.logError(buffer.toString(),
14139 buffer.toString(),
14140 new CaughtException(new AnalysisException(), null)); 13928 new CaughtException(new AnalysisException(), null));
14141 } 13929 }
14142 element.returnType = _computeReturnType(node.returnType); 13930 element.returnType = _computeReturnType(node.returnType);
14143 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 13931 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
14144 ClassElement definingClass = 13932 ClassElement definingClass =
14145 element.getAncestor((element) => element is ClassElement); 13933 element.getAncestor((element) => element is ClassElement);
14146 if (definingClass != null) { 13934 if (definingClass != null) {
14147 type.typeArguments = definingClass.type.typeArguments; 13935 type.typeArguments = definingClass.type.typeArguments;
14148 } 13936 }
14149 element.type = type; 13937 element.type = type;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
14234 if (name.name == null) { 14022 if (name.name == null) {
14235 PrefixedIdentifier prefixedIdentifier = 14023 PrefixedIdentifier prefixedIdentifier =
14236 typeName as PrefixedIdentifier; 14024 typeName as PrefixedIdentifier;
14237 SimpleIdentifier prefix = prefixedIdentifier.prefix; 14025 SimpleIdentifier prefix = prefixedIdentifier.prefix;
14238 element = nameScope.lookup(prefix, definingLibrary); 14026 element = nameScope.lookup(prefix, definingLibrary);
14239 if (element is PrefixElement) { 14027 if (element is PrefixElement) {
14240 if (parent.parent is InstanceCreationExpression && 14028 if (parent.parent is InstanceCreationExpression &&
14241 (parent.parent as InstanceCreationExpression).isConst) { 14029 (parent.parent as InstanceCreationExpression).isConst) {
14242 // If, if this is a const expression, then generate a 14030 // If, if this is a const expression, then generate a
14243 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. 14031 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
14244 reportErrorForNode( 14032 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE,
14245 CompileTimeErrorCode.CONST_WITH_NON_TYPE,
14246 prefixedIdentifier.identifier, 14033 prefixedIdentifier.identifier,
14247 [prefixedIdentifier.identifier.name]); 14034 [prefixedIdentifier.identifier.name]);
14248 } else { 14035 } else {
14249 // Else, if this expression is a new expression, report a 14036 // Else, if this expression is a new expression, report a
14250 // NEW_WITH_NON_TYPE warning. 14037 // NEW_WITH_NON_TYPE warning.
14251 reportErrorForNode( 14038 reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE,
14252 StaticWarningCode.NEW_WITH_NON_TYPE, 14039 prefixedIdentifier.identifier, [
14253 prefixedIdentifier.identifier, 14040 prefixedIdentifier.identifier.name
14254 [prefixedIdentifier.identifier.name]); 14041 ]);
14255 } 14042 }
14256 _setElement(prefix, element); 14043 _setElement(prefix, element);
14257 return null; 14044 return null;
14258 } else if (element != null) { 14045 } else if (element != null) {
14259 // 14046 //
14260 // Rewrite the constructor name. The parser, when it sees a 14047 // Rewrite the constructor name. The parser, when it sees a
14261 // constructor named "a.b", cannot tell whether "a" is a prefix and 14048 // constructor named "a.b", cannot tell whether "a" is a prefix and
14262 // "b" is a class name, or whether "a" is a class name and "b" is a 14049 // "b" is a class name, or whether "a" is a class name and "b" is a
14263 // constructor name. It arbitrarily chooses the former, but in this 14050 // constructor name. It arbitrarily chooses the former, but in this
14264 // case was wrong. 14051 // case was wrong.
(...skipping 10 matching lines...) Expand all
14275 bool elementValid = element is! MultiplyDefinedElement; 14062 bool elementValid = element is! MultiplyDefinedElement;
14276 if (elementValid && 14063 if (elementValid &&
14277 element is! ClassElement && 14064 element is! ClassElement &&
14278 _isTypeNameInInstanceCreationExpression(node)) { 14065 _isTypeNameInInstanceCreationExpression(node)) {
14279 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName); 14066 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName);
14280 InstanceCreationExpression creation = 14067 InstanceCreationExpression creation =
14281 node.parent.parent as InstanceCreationExpression; 14068 node.parent.parent as InstanceCreationExpression;
14282 if (creation.isConst) { 14069 if (creation.isConst) {
14283 if (element == null) { 14070 if (element == null) {
14284 reportErrorForNode( 14071 reportErrorForNode(
14285 CompileTimeErrorCode.UNDEFINED_CLASS, 14072 CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [typeName]);
14286 typeNameSimple,
14287 [typeName]);
14288 } else { 14073 } else {
14289 reportErrorForNode( 14074 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE,
14290 CompileTimeErrorCode.CONST_WITH_NON_TYPE, 14075 typeNameSimple, [typeName]);
14291 typeNameSimple,
14292 [typeName]);
14293 } 14076 }
14294 elementValid = false; 14077 elementValid = false;
14295 } else { 14078 } else {
14296 if (element != null) { 14079 if (element != null) {
14297 reportErrorForNode( 14080 reportErrorForNode(
14298 StaticWarningCode.NEW_WITH_NON_TYPE, 14081 StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typeName]);
14299 typeNameSimple,
14300 [typeName]);
14301 elementValid = false; 14082 elementValid = false;
14302 } 14083 }
14303 } 14084 }
14304 } 14085 }
14305 if (elementValid && element == null) { 14086 if (elementValid && element == null) {
14306 // We couldn't resolve the type name. 14087 // We couldn't resolve the type name.
14307 // TODO(jwren) Consider moving the check for 14088 // TODO(jwren) Consider moving the check for
14308 // CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE from the 14089 // CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE from the
14309 // ErrorVerifier, so that we don't have two errors on a built in 14090 // ErrorVerifier, so that we don't have two errors on a built in
14310 // identifier being used as a class name. 14091 // identifier being used as a class name.
14311 // See CompileTimeErrorCodeTest.test_builtInIdentifierAsType(). 14092 // See CompileTimeErrorCodeTest.test_builtInIdentifierAsType().
14312 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName); 14093 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName);
14313 RedirectingConstructorKind redirectingConstructorKind; 14094 RedirectingConstructorKind redirectingConstructorKind;
14314 if (_isBuiltInIdentifier(node) && _isTypeAnnotation(node)) { 14095 if (_isBuiltInIdentifier(node) && _isTypeAnnotation(node)) {
14315 reportErrorForNode( 14096 reportErrorForNode(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE,
14316 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 14097 typeName, [typeName.name]);
14317 typeName,
14318 [typeName.name]);
14319 } else if (typeNameSimple.name == "boolean") { 14098 } else if (typeNameSimple.name == "boolean") {
14320 reportErrorForNode( 14099 reportErrorForNode(
14321 StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, 14100 StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []);
14322 typeNameSimple,
14323 []);
14324 } else if (_isTypeNameInCatchClause(node)) { 14101 } else if (_isTypeNameInCatchClause(node)) {
14325 reportErrorForNode( 14102 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName,
14326 StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE,
14327 typeName,
14328 [typeName.name]); 14103 [typeName.name]);
14329 } else if (_isTypeNameInAsExpression(node)) { 14104 } else if (_isTypeNameInAsExpression(node)) {
14330 reportErrorForNode( 14105 reportErrorForNode(
14331 StaticWarningCode.CAST_TO_NON_TYPE, 14106 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]);
14332 typeName,
14333 [typeName.name]);
14334 } else if (_isTypeNameInIsExpression(node)) { 14107 } else if (_isTypeNameInIsExpression(node)) {
14335 reportErrorForNode( 14108 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME,
14336 StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME, 14109 typeName, [typeName.name]);
14337 typeName,
14338 [typeName.name]);
14339 } else if ((redirectingConstructorKind = 14110 } else if ((redirectingConstructorKind =
14340 _getRedirectingConstructorKind(node)) != null) { 14111 _getRedirectingConstructorKind(node)) !=
14341 ErrorCode errorCode = 14112 null) {
14342 (redirectingConstructorKind == RedirectingConstructorKind.CONST ? 14113 ErrorCode errorCode = (redirectingConstructorKind ==
14343 CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : 14114 RedirectingConstructorKind.CONST
14344 StaticWarningCode.REDIRECT_TO_NON_CLASS); 14115 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS
14116 : StaticWarningCode.REDIRECT_TO_NON_CLASS);
14345 reportErrorForNode(errorCode, typeName, [typeName.name]); 14117 reportErrorForNode(errorCode, typeName, [typeName.name]);
14346 } else if (_isTypeNameInTypeArgumentList(node)) { 14118 } else if (_isTypeNameInTypeArgumentList(node)) {
14347 reportErrorForNode( 14119 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT,
14348 StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 14120 typeName, [typeName.name]);
14349 typeName,
14350 [typeName.name]);
14351 } else { 14121 } else {
14352 reportErrorForNode( 14122 reportErrorForNode(
14353 StaticWarningCode.UNDEFINED_CLASS, 14123 StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]);
14354 typeName,
14355 [typeName.name]);
14356 } 14124 }
14357 elementValid = false; 14125 elementValid = false;
14358 } 14126 }
14359 if (!elementValid) { 14127 if (!elementValid) {
14360 if (element is MultiplyDefinedElement) { 14128 if (element is MultiplyDefinedElement) {
14361 _setElement(typeName, element); 14129 _setElement(typeName, element);
14362 } else { 14130 } else {
14363 _setElement(typeName, _dynamicType.element); 14131 _setElement(typeName, _dynamicType.element);
14364 } 14132 }
14365 typeName.staticType = _undefinedType; 14133 typeName.staticType = _undefinedType;
(...skipping 19 matching lines...) Expand all
14385 List<Element> elements = 14153 List<Element> elements =
14386 (element as MultiplyDefinedElement).conflictingElements; 14154 (element as MultiplyDefinedElement).conflictingElements;
14387 type = _getTypeWhenMultiplyDefined(elements); 14155 type = _getTypeWhenMultiplyDefined(elements);
14388 if (type != null) { 14156 if (type != null) {
14389 node.type = type; 14157 node.type = type;
14390 } 14158 }
14391 } else { 14159 } else {
14392 // The name does not represent a type. 14160 // The name does not represent a type.
14393 RedirectingConstructorKind redirectingConstructorKind; 14161 RedirectingConstructorKind redirectingConstructorKind;
14394 if (_isTypeNameInCatchClause(node)) { 14162 if (_isTypeNameInCatchClause(node)) {
14395 reportErrorForNode( 14163 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName,
14396 StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE,
14397 typeName,
14398 [typeName.name]); 14164 [typeName.name]);
14399 } else if (_isTypeNameInAsExpression(node)) { 14165 } else if (_isTypeNameInAsExpression(node)) {
14400 reportErrorForNode( 14166 reportErrorForNode(
14401 StaticWarningCode.CAST_TO_NON_TYPE, 14167 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]);
14402 typeName,
14403 [typeName.name]);
14404 } else if (_isTypeNameInIsExpression(node)) { 14168 } else if (_isTypeNameInIsExpression(node)) {
14405 reportErrorForNode( 14169 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_NON_TYPE, typeName,
14406 StaticWarningCode.TYPE_TEST_WITH_NON_TYPE,
14407 typeName,
14408 [typeName.name]); 14170 [typeName.name]);
14409 } else if ((redirectingConstructorKind = 14171 } else if ((redirectingConstructorKind =
14410 _getRedirectingConstructorKind(node)) != null) { 14172 _getRedirectingConstructorKind(node)) !=
14411 ErrorCode errorCode = 14173 null) {
14412 (redirectingConstructorKind == RedirectingConstructorKind.CONST ? 14174 ErrorCode errorCode = (redirectingConstructorKind ==
14413 CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : 14175 RedirectingConstructorKind.CONST
14414 StaticWarningCode.REDIRECT_TO_NON_CLASS); 14176 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS
14177 : StaticWarningCode.REDIRECT_TO_NON_CLASS);
14415 reportErrorForNode(errorCode, typeName, [typeName.name]); 14178 reportErrorForNode(errorCode, typeName, [typeName.name]);
14416 } else if (_isTypeNameInTypeArgumentList(node)) { 14179 } else if (_isTypeNameInTypeArgumentList(node)) {
14417 reportErrorForNode( 14180 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT,
14418 StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 14181 typeName, [typeName.name]);
14419 typeName,
14420 [typeName.name]);
14421 } else { 14182 } else {
14422 AstNode parent = typeName.parent; 14183 AstNode parent = typeName.parent;
14423 while (parent is TypeName) { 14184 while (parent is TypeName) {
14424 parent = parent.parent; 14185 parent = parent.parent;
14425 } 14186 }
14426 if (parent is ExtendsClause || 14187 if (parent is ExtendsClause ||
14427 parent is ImplementsClause || 14188 parent is ImplementsClause ||
14428 parent is WithClause || 14189 parent is WithClause ||
14429 parent is ClassTypeAlias) { 14190 parent is ClassTypeAlias) {
14430 // Ignored. The error will be reported elsewhere. 14191 // Ignored. The error will be reported elsewhere.
14431 } else { 14192 } else {
14432 reportErrorForNode( 14193 reportErrorForNode(
14433 StaticWarningCode.NOT_A_TYPE, 14194 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]);
14434 typeName,
14435 [typeName.name]);
14436 } 14195 }
14437 } 14196 }
14438 _setElement(typeName, _dynamicType.element); 14197 _setElement(typeName, _dynamicType.element);
14439 typeName.staticType = _dynamicType; 14198 typeName.staticType = _dynamicType;
14440 node.type = _dynamicType; 14199 node.type = _dynamicType;
14441 return null; 14200 return null;
14442 } 14201 }
14443 if (argumentList != null) { 14202 if (argumentList != null) {
14444 NodeList<TypeName> arguments = argumentList.arguments; 14203 NodeList<TypeName> arguments = argumentList.arguments;
14445 int argumentCount = arguments.length; 14204 int argumentCount = arguments.length;
14446 List<DartType> parameters = _getTypeArguments(type); 14205 List<DartType> parameters = _getTypeArguments(type);
14447 int parameterCount = parameters.length; 14206 int parameterCount = parameters.length;
14448 List<DartType> typeArguments = new List<DartType>(parameterCount); 14207 List<DartType> typeArguments = new List<DartType>(parameterCount);
14449 if (argumentCount == parameterCount) { 14208 if (argumentCount == parameterCount) {
14450 for (int i = 0; i < parameterCount; i++) { 14209 for (int i = 0; i < parameterCount; i++) {
14451 TypeName argumentTypeName = arguments[i]; 14210 TypeName argumentTypeName = arguments[i];
14452 DartType argumentType = _getType(argumentTypeName); 14211 DartType argumentType = _getType(argumentTypeName);
14453 if (argumentType == null) { 14212 if (argumentType == null) {
14454 argumentType = _dynamicType; 14213 argumentType = _dynamicType;
14455 } 14214 }
14456 typeArguments[i] = argumentType; 14215 typeArguments[i] = argumentType;
14457 } 14216 }
14458 } else { 14217 } else {
14459 reportErrorForNode( 14218 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, [
14460 _getInvalidTypeParametersErrorCode(node), 14219 typeName.name,
14461 node, 14220 parameterCount,
14462 [typeName.name, parameterCount, argumentCount]); 14221 argumentCount
14222 ]);
14463 for (int i = 0; i < parameterCount; i++) { 14223 for (int i = 0; i < parameterCount; i++) {
14464 typeArguments[i] = _dynamicType; 14224 typeArguments[i] = _dynamicType;
14465 } 14225 }
14466 } 14226 }
14467 if (type is InterfaceTypeImpl) { 14227 if (type is InterfaceTypeImpl) {
14468 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl; 14228 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl;
14469 type = interfaceType.substitute4(typeArguments); 14229 type = interfaceType.substitute4(typeArguments);
14470 } else if (type is FunctionTypeImpl) { 14230 } else if (type is FunctionTypeImpl) {
14471 FunctionTypeImpl functionType = type as FunctionTypeImpl; 14231 FunctionTypeImpl functionType = type as FunctionTypeImpl;
14472 type = functionType.substitute3(typeArguments); 14232 type = functionType.substitute3(typeArguments);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
14646 */ 14406 */
14647 RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) { 14407 RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) {
14648 AstNode parent = typeName.parent; 14408 AstNode parent = typeName.parent;
14649 if (parent is ConstructorName) { 14409 if (parent is ConstructorName) {
14650 ConstructorName constructorName = parent as ConstructorName; 14410 ConstructorName constructorName = parent as ConstructorName;
14651 parent = constructorName.parent; 14411 parent = constructorName.parent;
14652 if (parent is ConstructorDeclaration) { 14412 if (parent is ConstructorDeclaration) {
14653 ConstructorDeclaration constructorDeclaration = 14413 ConstructorDeclaration constructorDeclaration =
14654 parent as ConstructorDeclaration; 14414 parent as ConstructorDeclaration;
14655 if (identical( 14415 if (identical(
14656 constructorDeclaration.redirectedConstructor, 14416 constructorDeclaration.redirectedConstructor, constructorName)) {
14657 constructorName)) {
14658 if (constructorDeclaration.constKeyword != null) { 14417 if (constructorDeclaration.constKeyword != null) {
14659 return RedirectingConstructorKind.CONST; 14418 return RedirectingConstructorKind.CONST;
14660 } 14419 }
14661 return RedirectingConstructorKind.NORMAL; 14420 return RedirectingConstructorKind.NORMAL;
14662 } 14421 }
14663 } 14422 }
14664 } 14423 }
14665 return null; 14424 return null;
14666 } 14425 }
14667 14426
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
14820 * given class element. 14579 * given class element.
14821 * 14580 *
14822 * @param classElement the class element with which the mixin and interface ty pes are to be 14581 * @param classElement the class element with which the mixin and interface ty pes are to be
14823 * associated 14582 * associated
14824 * @param withClause the with clause to be resolved 14583 * @param withClause the with clause to be resolved
14825 * @param implementsClause the implements clause to be resolved 14584 * @param implementsClause the implements clause to be resolved
14826 */ 14585 */
14827 void _resolve(ClassElementImpl classElement, WithClause withClause, 14586 void _resolve(ClassElementImpl classElement, WithClause withClause,
14828 ImplementsClause implementsClause) { 14587 ImplementsClause implementsClause) {
14829 if (withClause != null) { 14588 if (withClause != null) {
14830 List<InterfaceType> mixinTypes = _resolveTypes( 14589 List<InterfaceType> mixinTypes = _resolveTypes(withClause.mixinTypes,
14831 withClause.mixinTypes,
14832 CompileTimeErrorCode.MIXIN_OF_NON_CLASS, 14590 CompileTimeErrorCode.MIXIN_OF_NON_CLASS,
14833 CompileTimeErrorCode.MIXIN_OF_ENUM, 14591 CompileTimeErrorCode.MIXIN_OF_ENUM,
14834 CompileTimeErrorCode.MIXIN_OF_NON_CLASS); 14592 CompileTimeErrorCode.MIXIN_OF_NON_CLASS);
14835 if (classElement != null) { 14593 if (classElement != null) {
14836 classElement.mixins = mixinTypes; 14594 classElement.mixins = mixinTypes;
14837 } 14595 }
14838 } 14596 }
14839 if (implementsClause != null) { 14597 if (implementsClause != null) {
14840 NodeList<TypeName> interfaces = implementsClause.interfaces; 14598 NodeList<TypeName> interfaces = implementsClause.interfaces;
14841 List<InterfaceType> interfaceTypes = _resolveTypes( 14599 List<InterfaceType> interfaceTypes = _resolveTypes(interfaces,
14842 interfaces,
14843 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, 14600 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS,
14844 CompileTimeErrorCode.IMPLEMENTS_ENUM, 14601 CompileTimeErrorCode.IMPLEMENTS_ENUM,
14845 CompileTimeErrorCode.IMPLEMENTS_DYNAMIC); 14602 CompileTimeErrorCode.IMPLEMENTS_DYNAMIC);
14846 if (classElement != null) { 14603 if (classElement != null) {
14847 classElement.interfaces = interfaceTypes; 14604 classElement.interfaces = interfaceTypes;
14848 } 14605 }
14849 // TODO(brianwilkerson) Move the following checks to ErrorVerifier. 14606 // TODO(brianwilkerson) Move the following checks to ErrorVerifier.
14850 int count = interfaces.length; 14607 int count = interfaces.length;
14851 List<bool> detectedRepeatOnIndex = new List<bool>.filled(count, false); 14608 List<bool> detectedRepeatOnIndex = new List<bool>.filled(count, false);
14852 for (int i = 0; i < detectedRepeatOnIndex.length; i++) { 14609 for (int i = 0; i < detectedRepeatOnIndex.length; i++) {
14853 detectedRepeatOnIndex[i] = false; 14610 detectedRepeatOnIndex[i] = false;
14854 } 14611 }
14855 for (int i = 0; i < count; i++) { 14612 for (int i = 0; i < count; i++) {
14856 TypeName typeName = interfaces[i]; 14613 TypeName typeName = interfaces[i];
14857 if (!detectedRepeatOnIndex[i]) { 14614 if (!detectedRepeatOnIndex[i]) {
14858 Element element = typeName.name.staticElement; 14615 Element element = typeName.name.staticElement;
14859 for (int j = i + 1; j < count; j++) { 14616 for (int j = i + 1; j < count; j++) {
14860 TypeName typeName2 = interfaces[j]; 14617 TypeName typeName2 = interfaces[j];
14861 Identifier identifier2 = typeName2.name; 14618 Identifier identifier2 = typeName2.name;
14862 String name2 = identifier2.name; 14619 String name2 = identifier2.name;
14863 Element element2 = identifier2.staticElement; 14620 Element element2 = identifier2.staticElement;
14864 if (element != null && element == element2) { 14621 if (element != null && element == element2) {
14865 detectedRepeatOnIndex[j] = true; 14622 detectedRepeatOnIndex[j] = true;
14866 reportErrorForNode( 14623 reportErrorForNode(
14867 CompileTimeErrorCode.IMPLEMENTS_REPEATED, 14624 CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]);
14868 typeName2,
14869 [name2]);
14870 } 14625 }
14871 } 14626 }
14872 } 14627 }
14873 } 14628 }
14874 } 14629 }
14875 } 14630 }
14876 14631
14877 /** 14632 /**
14878 * Return the type specified by the given name. 14633 * Return the type specified by the given name.
14879 * 14634 *
(...skipping 30 matching lines...) Expand all
14910 * Resolve the types in the given list of type names. 14665 * Resolve the types in the given list of type names.
14911 * 14666 *
14912 * @param typeNames the type names to be resolved 14667 * @param typeNames the type names to be resolved
14913 * @param nonTypeError the error to produce if the type name is defined to be something other than 14668 * @param nonTypeError the error to produce if the type name is defined to be something other than
14914 * a type 14669 * a type
14915 * @param enumTypeError the error to produce if the type name is defined to be an enum 14670 * @param enumTypeError the error to produce if the type name is defined to be an enum
14916 * @param dynamicTypeError the error to produce if the type name is "dynamic" 14671 * @param dynamicTypeError the error to produce if the type name is "dynamic"
14917 * @return an array containing all of the types that were resolved. 14672 * @return an array containing all of the types that were resolved.
14918 */ 14673 */
14919 List<InterfaceType> _resolveTypes(NodeList<TypeName> typeNames, 14674 List<InterfaceType> _resolveTypes(NodeList<TypeName> typeNames,
14920 ErrorCode nonTypeError, ErrorCode enumTypeError, ErrorCode dynamicTypeErro r) { 14675 ErrorCode nonTypeError, ErrorCode enumTypeError,
14676 ErrorCode dynamicTypeError) {
14921 List<InterfaceType> types = new List<InterfaceType>(); 14677 List<InterfaceType> types = new List<InterfaceType>();
14922 for (TypeName typeName in typeNames) { 14678 for (TypeName typeName in typeNames) {
14923 InterfaceType type = 14679 InterfaceType type =
14924 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError); 14680 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError);
14925 if (type != null) { 14681 if (type != null) {
14926 types.add(type); 14682 types.add(type);
14927 } 14683 }
14928 } 14684 }
14929 return types; 14685 return types;
14930 } 14686 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
15027 */ 14783 */
15028 ExecutableElement _enclosingFunction; 14784 ExecutableElement _enclosingFunction;
15029 14785
15030 /** 14786 /**
15031 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 14787 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
15032 * 14788 *
15033 * @param library the library containing the compilation unit being resolved 14789 * @param library the library containing the compilation unit being resolved
15034 * @param source the source representing the compilation unit being visited 14790 * @param source the source representing the compilation unit being visited
15035 * @param typeProvider the object used to access the types from the core libra ry 14791 * @param typeProvider the object used to access the types from the core libra ry
15036 */ 14792 */
15037 VariableResolverVisitor.con1(Library library, Source source, 14793 VariableResolverVisitor.con1(
15038 TypeProvider typeProvider) 14794 Library library, Source source, TypeProvider typeProvider)
15039 : super.con1(library, source, typeProvider); 14795 : super.con1(library, source, typeProvider);
15040 14796
15041 /** 14797 /**
15042 * Initialize a newly created visitor to resolve the nodes in an AST node. 14798 * Initialize a newly created visitor to resolve the nodes in an AST node.
15043 * 14799 *
15044 * @param definingLibrary the element for the library containing the node bein g visited 14800 * @param definingLibrary the element for the library containing the node bein g visited
15045 * @param source the source representing the compilation unit containing the n ode being visited 14801 * @param source the source representing the compilation unit containing the n ode being visited
15046 * @param typeProvider the object used to access the types from the core libra ry 14802 * @param typeProvider the object used to access the types from the core libra ry
15047 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited 14803 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
15048 * @param errorListener the error listener that will be informed of any errors that are found 14804 * @param errorListener the error listener that will be informed of any errors that are found
15049 * during resolution 14805 * during resolution
15050 */ 14806 */
15051 VariableResolverVisitor.con2(LibraryElement definingLibrary, Source source, 14807 VariableResolverVisitor.con2(LibraryElement definingLibrary, Source source,
15052 TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorLis tener) 14808 TypeProvider typeProvider, Scope nameScope,
14809 AnalysisErrorListener errorListener)
15053 : super.con3( 14810 : super.con3(
15054 definingLibrary, 14811 definingLibrary, source, typeProvider, nameScope, errorListener);
15055 source,
15056 typeProvider,
15057 nameScope,
15058 errorListener);
15059 14812
15060 /** 14813 /**
15061 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 14814 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
15062 * 14815 *
15063 * @param library the library containing the compilation unit being resolved 14816 * @param library the library containing the compilation unit being resolved
15064 * @param source the source representing the compilation unit being visited 14817 * @param source the source representing the compilation unit being visited
15065 * @param typeProvider the object used to access the types from the core libra ry 14818 * @param typeProvider the object used to access the types from the core libra ry
15066 */ 14819 */
15067 VariableResolverVisitor.con3(ResolvableLibrary library, Source source, 14820 VariableResolverVisitor.con3(
15068 TypeProvider typeProvider) 14821 ResolvableLibrary library, Source source, TypeProvider typeProvider)
15069 : super.con4(library, source, typeProvider); 14822 : super.con4(library, source, typeProvider);
15070 14823
15071 @override 14824 @override
15072 Object visitExportDirective(ExportDirective node) => null; 14825 Object visitExportDirective(ExportDirective node) => null;
15073 14826
15074 @override 14827 @override
15075 Object visitFunctionDeclaration(FunctionDeclaration node) { 14828 Object visitFunctionDeclaration(FunctionDeclaration node) {
15076 ExecutableElement outerFunction = _enclosingFunction; 14829 ExecutableElement outerFunction = _enclosingFunction;
15077 try { 14830 try {
15078 _enclosingFunction = node.element; 14831 _enclosingFunction = node.element;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
15170 14923
15171 @override 14924 @override
15172 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { 14925 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) {
15173 Element element = node.staticElement; 14926 Element element = node.staticElement;
15174 for (ParameterElement parameterElement in parameterElements) { 14927 for (ParameterElement parameterElement in parameterElements) {
15175 if (identical(parameterElement, element) && parameterElement != null) { 14928 if (identical(parameterElement, element) && parameterElement != null) {
15176 DartType type = parameterElement.type; 14929 DartType type = parameterElement.type;
15177 if (type != null) { 14930 if (type != null) {
15178 if (type.isDynamic) { 14931 if (type.isDynamic) {
15179 return new DartObjectImpl( 14932 return new DartObjectImpl(
15180 verifier._typeProvider.objectType, 14933 verifier._typeProvider.objectType, DynamicState.DYNAMIC_STATE);
15181 DynamicState.DYNAMIC_STATE);
15182 } else if (type.isSubtypeOf(verifier._boolType)) { 14934 } else if (type.isSubtypeOf(verifier._boolType)) {
15183 return new DartObjectImpl( 14935 return new DartObjectImpl(
15184 verifier._typeProvider.boolType, 14936 verifier._typeProvider.boolType, BoolState.UNKNOWN_VALUE);
15185 BoolState.UNKNOWN_VALUE);
15186 } else if (type.isSubtypeOf(verifier._typeProvider.doubleType)) { 14937 } else if (type.isSubtypeOf(verifier._typeProvider.doubleType)) {
15187 return new DartObjectImpl( 14938 return new DartObjectImpl(
15188 verifier._typeProvider.doubleType, 14939 verifier._typeProvider.doubleType, DoubleState.UNKNOWN_VALUE);
15189 DoubleState.UNKNOWN_VALUE);
15190 } else if (type.isSubtypeOf(verifier._intType)) { 14940 } else if (type.isSubtypeOf(verifier._intType)) {
15191 return new DartObjectImpl( 14941 return new DartObjectImpl(
15192 verifier._typeProvider.intType, 14942 verifier._typeProvider.intType, IntState.UNKNOWN_VALUE);
15193 IntState.UNKNOWN_VALUE);
15194 } else if (type.isSubtypeOf(verifier._numType)) { 14943 } else if (type.isSubtypeOf(verifier._numType)) {
15195 return new DartObjectImpl( 14944 return new DartObjectImpl(
15196 verifier._typeProvider.numType, 14945 verifier._typeProvider.numType, NumState.UNKNOWN_VALUE);
15197 NumState.UNKNOWN_VALUE);
15198 } else if (type.isSubtypeOf(verifier._stringType)) { 14946 } else if (type.isSubtypeOf(verifier._stringType)) {
15199 return new DartObjectImpl( 14947 return new DartObjectImpl(
15200 verifier._typeProvider.stringType, 14948 verifier._typeProvider.stringType, StringState.UNKNOWN_VALUE);
15201 StringState.UNKNOWN_VALUE);
15202 } 14949 }
15203 // 14950 //
15204 // We don't test for other types of objects (such as List, Map, 14951 // We don't test for other types of objects (such as List, Map,
15205 // Function or Type) because there are no operations allowed on such 14952 // Function or Type) because there are no operations allowed on such
15206 // types other than '==' and '!=', which means that we don't need to 14953 // types other than '==' and '!=', which means that we don't need to
15207 // know the type when there is no specific data about the state of 14954 // know the type when there is no specific data about the state of
15208 // such objects. 14955 // such objects.
15209 // 14956 //
15210 } 14957 }
15211 return new DartObjectImpl( 14958 return new DartObjectImpl(
15212 type is InterfaceType ? type : verifier._typeProvider.objectType, 14959 type is InterfaceType ? type : verifier._typeProvider.objectType,
15213 GenericState.UNKNOWN_VALUE); 14960 GenericState.UNKNOWN_VALUE);
15214 } 14961 }
15215 } 14962 }
15216 return super.visitSimpleIdentifier(node); 14963 return super.visitSimpleIdentifier(node);
15217 } 14964 }
15218 } 14965 }
15219 14966
15220 class _ElementBuilder_visitClassDeclaration extends UnifyingAstVisitor<Object> { 14967 class _ElementBuilder_visitClassDeclaration extends UnifyingAstVisitor<Object> {
15221 final ElementBuilder builder; 14968 final ElementBuilder builder;
15222 14969
15223 List<ClassMember> nonFields; 14970 List<ClassMember> nonFields;
15224 14971
15225 _ElementBuilder_visitClassDeclaration(this.builder, this.nonFields) 14972 _ElementBuilder_visitClassDeclaration(this.builder, this.nonFields) : super();
15226 : super();
15227 14973
15228 @override 14974 @override
15229 Object visitConstructorDeclaration(ConstructorDeclaration node) { 14975 Object visitConstructorDeclaration(ConstructorDeclaration node) {
15230 nonFields.add(node); 14976 nonFields.add(node);
15231 return null; 14977 return null;
15232 } 14978 }
15233 14979
15234 @override 14980 @override
15235 Object visitMethodDeclaration(MethodDeclaration node) { 14981 Object visitMethodDeclaration(MethodDeclaration node) {
15236 nonFields.add(node); 14982 nonFields.add(node);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
15402 // v++; 15148 // v++;
15403 // ++v; 15149 // ++v;
15404 // v += 2; 15150 // v += 2;
15405 return false; 15151 return false;
15406 } 15152 }
15407 // OK 15153 // OK
15408 return true; 15154 return true;
15409 } 15155 }
15410 } 15156 }
15411 15157
15412 class _ResolverVisitor_isVariableAccessedInClosure extends 15158 class _ResolverVisitor_isVariableAccessedInClosure
15413 RecursiveAstVisitor<Object> { 15159 extends RecursiveAstVisitor<Object> {
15414 final Element variable; 15160 final Element variable;
15415 15161
15416 bool result = false; 15162 bool result = false;
15417 15163
15418 bool _inClosure = false; 15164 bool _inClosure = false;
15419 15165
15420 _ResolverVisitor_isVariableAccessedInClosure(this.variable); 15166 _ResolverVisitor_isVariableAccessedInClosure(this.variable);
15421 15167
15422 @override 15168 @override
15423 Object visitFunctionExpression(FunctionExpression node) { 15169 Object visitFunctionExpression(FunctionExpression node) {
(...skipping 11 matching lines...) Expand all
15435 if (result) { 15181 if (result) {
15436 return null; 15182 return null;
15437 } 15183 }
15438 if (_inClosure && identical(node.staticElement, variable)) { 15184 if (_inClosure && identical(node.staticElement, variable)) {
15439 result = true; 15185 result = true;
15440 } 15186 }
15441 return null; 15187 return null;
15442 } 15188 }
15443 } 15189 }
15444 15190
15445 15191 class _ResolverVisitor_isVariablePotentiallyMutatedIn
15446 class _ResolverVisitor_isVariablePotentiallyMutatedIn extends 15192 extends RecursiveAstVisitor<Object> {
15447 RecursiveAstVisitor<Object> {
15448 final Element variable; 15193 final Element variable;
15449 15194
15450 bool result = false; 15195 bool result = false;
15451 15196
15452 _ResolverVisitor_isVariablePotentiallyMutatedIn(this.variable); 15197 _ResolverVisitor_isVariablePotentiallyMutatedIn(this.variable);
15453 15198
15454 @override 15199 @override
15455 Object visitSimpleIdentifier(SimpleIdentifier node) { 15200 Object visitSimpleIdentifier(SimpleIdentifier node) {
15456 if (result) { 15201 if (result) {
15457 return null; 15202 return null;
15458 } 15203 }
15459 if (identical(node.staticElement, variable)) { 15204 if (identical(node.staticElement, variable)) {
15460 if (node.inSetterContext()) { 15205 if (node.inSetterContext()) {
15461 result = true; 15206 result = true;
15462 } 15207 }
15463 } 15208 }
15464 return null; 15209 return null;
15465 } 15210 }
15466 } 15211 }
15467 15212
15468 15213 class _TypeResolverVisitor_visitClassMembersInScope
15469 class _TypeResolverVisitor_visitClassMembersInScope extends 15214 extends UnifyingAstVisitor<Object> {
15470 UnifyingAstVisitor<Object> {
15471 final TypeResolverVisitor TypeResolverVisitor_this; 15215 final TypeResolverVisitor TypeResolverVisitor_this;
15472 15216
15473 List<ClassMember> nonFields; 15217 List<ClassMember> nonFields;
15474 15218
15475 _TypeResolverVisitor_visitClassMembersInScope(this.TypeResolverVisitor_this, 15219 _TypeResolverVisitor_visitClassMembersInScope(
15476 this.nonFields) 15220 this.TypeResolverVisitor_this, this.nonFields)
15477 : super(); 15221 : super();
15478 15222
15479 @override 15223 @override
15480 Object visitConstructorDeclaration(ConstructorDeclaration node) { 15224 Object visitConstructorDeclaration(ConstructorDeclaration node) {
15481 nonFields.add(node); 15225 nonFields.add(node);
15482 return null; 15226 return null;
15483 } 15227 }
15484 15228
15485 @override 15229 @override
15486 Object visitExtendsClause(ExtendsClause node) => null; 15230 Object visitExtendsClause(ExtendsClause node) => null;
15487 15231
15488 @override 15232 @override
15489 Object visitImplementsClause(ImplementsClause node) => null; 15233 Object visitImplementsClause(ImplementsClause node) => null;
15490 15234
15491 @override 15235 @override
15492 Object visitMethodDeclaration(MethodDeclaration node) { 15236 Object visitMethodDeclaration(MethodDeclaration node) {
15493 nonFields.add(node); 15237 nonFields.add(node);
15494 return null; 15238 return null;
15495 } 15239 }
15496 15240
15497 @override 15241 @override
15498 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15242 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15499 15243
15500 @override 15244 @override
15501 Object visitWithClause(WithClause node) => null; 15245 Object visitWithClause(WithClause node) => null;
15502 } 15246 }
15503 15247
15504
15505 /** 15248 /**
15506 * Instances of the class [_UnusedElementsVerifier] traverse an element 15249 * Instances of the class [_UnusedElementsVerifier] traverse an element
15507 * structure looking for cases of [HintCode.UNUSED_ELEMENT] and 15250 * structure looking for cases of [HintCode.UNUSED_ELEMENT] and
15508 * [HintCode.UNUSED_LOCAL_VARIABLE]. 15251 * [HintCode.UNUSED_LOCAL_VARIABLE].
15509 */ 15252 */
15510 class _UnusedElementsVerifier extends RecursiveElementVisitor { 15253 class _UnusedElementsVerifier extends RecursiveElementVisitor {
15511 /** 15254 /**
15512 * The error listener to which errors will be reported. 15255 * The error listener to which errors will be reported.
15513 */ 15256 */
15514 final AnalysisErrorListener _errorListener; 15257 final AnalysisErrorListener _errorListener;
15515 15258
15516 /** 15259 /**
15517 * The elements know to be used. 15260 * The elements know to be used.
15518 */ 15261 */
15519 final _UsedElements _usedElements; 15262 final _UsedElements _usedElements;
15520 15263
15521 /** 15264 /**
15522 * Create a new instance of the [_UnusedElementsVerifier]. 15265 * Create a new instance of the [_UnusedElementsVerifier].
15523 */ 15266 */
15524 _UnusedElementsVerifier(this._errorListener, this._usedElements); 15267 _UnusedElementsVerifier(this._errorListener, this._usedElements);
15525 15268
15526 @override 15269 @override
15527 visitClassElement(ClassElement element) { 15270 visitClassElement(ClassElement element) {
15528 if (!_isUsedElement(element)) { 15271 if (!_isUsedElement(element)) {
15529 _reportErrorForElement( 15272 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [
15530 HintCode.UNUSED_ELEMENT, 15273 element.kind.displayName,
15531 element, 15274 element.displayName
15532 [element.kind.displayName, element.displayName]); 15275 ]);
15533 } 15276 }
15534 super.visitClassElement(element); 15277 super.visitClassElement(element);
15535 } 15278 }
15536 15279
15537 @override 15280 @override
15538 visitFieldElement(FieldElement element) { 15281 visitFieldElement(FieldElement element) {
15539 if (!_isReadMember(element)) { 15282 if (!_isReadMember(element)) {
15540 _reportErrorForElement( 15283 _reportErrorForElement(
15541 HintCode.UNUSED_FIELD, 15284 HintCode.UNUSED_FIELD, element, [element.displayName]);
15542 element,
15543 [element.displayName]);
15544 } 15285 }
15545 super.visitFieldElement(element); 15286 super.visitFieldElement(element);
15546 } 15287 }
15547 15288
15548 @override 15289 @override
15549 visitFunctionElement(FunctionElement element) { 15290 visitFunctionElement(FunctionElement element) {
15550 if (!_isUsedElement(element)) { 15291 if (!_isUsedElement(element)) {
15551 _reportErrorForElement( 15292 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [
15552 HintCode.UNUSED_ELEMENT, 15293 element.kind.displayName,
15553 element, 15294 element.displayName
15554 [element.kind.displayName, element.displayName]); 15295 ]);
15555 } 15296 }
15556 super.visitFunctionElement(element); 15297 super.visitFunctionElement(element);
15557 } 15298 }
15558 15299
15559 @override 15300 @override
15560 visitLocalVariableElement(LocalVariableElement element) { 15301 visitLocalVariableElement(LocalVariableElement element) {
15561 if (!_isUsedElement(element)) { 15302 if (!_isUsedElement(element)) {
15562 _reportErrorForElement( 15303 _reportErrorForElement(
15563 HintCode.UNUSED_LOCAL_VARIABLE, 15304 HintCode.UNUSED_LOCAL_VARIABLE, element, [element.displayName]);
15564 element,
15565 [element.displayName]);
15566 } 15305 }
15567 } 15306 }
15568 15307
15569 @override 15308 @override
15570 visitMethodElement(MethodElement element) { 15309 visitMethodElement(MethodElement element) {
15571 if (!_isUsedMember(element)) { 15310 if (!_isUsedMember(element)) {
15572 _reportErrorForElement( 15311 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [
15573 HintCode.UNUSED_ELEMENT, 15312 element.kind.displayName,
15574 element, 15313 element.displayName
15575 [element.kind.displayName, element.displayName]); 15314 ]);
15576 } 15315 }
15577 super.visitMethodElement(element); 15316 super.visitMethodElement(element);
15578 } 15317 }
15579 15318
15580 @override 15319 @override
15581 visitPropertyAccessorElement(PropertyAccessorElement element) { 15320 visitPropertyAccessorElement(PropertyAccessorElement element) {
15582 if (!_isUsedMember(element)) { 15321 if (!_isUsedMember(element)) {
15583 _reportErrorForElement( 15322 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [
15584 HintCode.UNUSED_ELEMENT, 15323 element.kind.displayName,
15585 element, 15324 element.displayName
15586 [element.kind.displayName, element.displayName]); 15325 ]);
15587 } 15326 }
15588 super.visitPropertyAccessorElement(element); 15327 super.visitPropertyAccessorElement(element);
15589 } 15328 }
15590 15329
15591 bool _isReadMember(Element element) { 15330 bool _isReadMember(Element element) {
15592 if (element.isPublic) { 15331 if (element.isPublic) {
15593 return true; 15332 return true;
15594 } 15333 }
15595 if (element.isSynthetic) { 15334 if (element.isSynthetic) {
15596 return true; 15335 return true;
(...skipping 22 matching lines...) Expand all
15619 } 15358 }
15620 if (element.isSynthetic) { 15359 if (element.isSynthetic) {
15621 return true; 15360 return true;
15622 } 15361 }
15623 if (_usedElements.members.contains(element.displayName)) { 15362 if (_usedElements.members.contains(element.displayName)) {
15624 return true; 15363 return true;
15625 } 15364 }
15626 return _usedElements.elements.contains(element); 15365 return _usedElements.elements.contains(element);
15627 } 15366 }
15628 15367
15629 void _reportErrorForElement(ErrorCode errorCode, Element element, 15368 void _reportErrorForElement(
15630 List<Object> arguments) { 15369 ErrorCode errorCode, Element element, List<Object> arguments) {
15631 if (element != null) { 15370 if (element != null) {
15632 _errorListener.onError( 15371 _errorListener.onError(new AnalysisError.con2(element.source,
15633 new AnalysisError.con2( 15372 element.nameOffset, element.displayName.length, errorCode,
15634 element.source, 15373 arguments));
15635 element.nameOffset,
15636 element.displayName.length,
15637 errorCode,
15638 arguments));
15639 } 15374 }
15640 } 15375 }
15641 } 15376 }
15642 15377
15643
15644 class _UsedElements { 15378 class _UsedElements {
15645 /** 15379 /**
15646 * Resolved, locally defined elements that are used or potentially can be 15380 * Resolved, locally defined elements that are used or potentially can be
15647 * used. 15381 * used.
15648 */ 15382 */
15649 final HashSet<Element> elements = new HashSet<Element>(); 15383 final HashSet<Element> elements = new HashSet<Element>();
15650 15384
15651 /** 15385 /**
15652 * Names of resolved or unresolved class members that are referenced in the 15386 * Names of resolved or unresolved class members that are referenced in the
15653 * library. 15387 * library.
15654 */ 15388 */
15655 final HashSet<String> members = new HashSet<String>(); 15389 final HashSet<String> members = new HashSet<String>();
15656 15390
15657 /** 15391 /**
15658 * Names of resolved or unresolved class members that are read in the 15392 * Names of resolved or unresolved class members that are read in the
15659 * library. 15393 * library.
15660 */ 15394 */
15661 final HashSet<String> readMembers = new HashSet<String>(); 15395 final HashSet<String> readMembers = new HashSet<String>();
15662 } 15396 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698