| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 11 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 11 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | |
| 12 import 'package:analyzer/dart/ast/token.dart'; | 12 import 'package:analyzer/dart/ast/token.dart'; |
| 13 import 'package:analyzer/dart/ast/visitor.dart'; | 13 import 'package:analyzer/dart/ast/visitor.dart'; |
| 14 import 'package:analyzer/dart/element/element.dart'; | 14 import 'package:analyzer/dart/element/element.dart'; |
| 15 import 'package:analyzer/dart/element/type.dart'; | 15 import 'package:analyzer/dart/element/type.dart'; |
| 16 import 'package:analyzer/file_system/memory_file_system.dart'; | 16 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 17 import 'package:analyzer/src/dart/element/builder.dart'; | 17 import 'package:analyzer/src/dart/element/builder.dart'; |
| 18 import 'package:analyzer/src/dart/element/element.dart'; | 18 import 'package:analyzer/src/dart/element/element.dart'; |
| 19 import 'package:analyzer/src/dart/element/type.dart'; | 19 import 'package:analyzer/src/dart/element/type.dart'; |
| 20 import 'package:analyzer/src/error/codes.dart'; | 20 import 'package:analyzer/src/error/codes.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart'; | 21 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 */ | 402 */ |
| 403 List<Expression> _unresolvedExpressions = new List<Expression>(); | 403 List<Expression> _unresolvedExpressions = new List<Expression>(); |
| 404 | 404 |
| 405 /** | 405 /** |
| 406 * A list containing all of the AST Expression nodes for which a propagated ty
pe was computed but | 406 * A list containing all of the AST Expression nodes for which a propagated ty
pe was computed but |
| 407 * where that type was not more specific than the static type. | 407 * where that type was not more specific than the static type. |
| 408 */ | 408 */ |
| 409 List<Expression> _invalidlyPropagatedExpressions = new List<Expression>(); | 409 List<Expression> _invalidlyPropagatedExpressions = new List<Expression>(); |
| 410 | 410 |
| 411 /** | 411 /** |
| 412 * A list containing all of the AST TypeName nodes that were not resolved. | 412 * The TypeAnnotation nodes that were not resolved. |
| 413 */ | 413 */ |
| 414 List<TypeName> _unresolvedTypes = new List<TypeName>(); | 414 List<TypeAnnotation> _unresolvedTypes = new List<TypeAnnotation>(); |
| 415 | 415 |
| 416 /** | 416 /** |
| 417 * Counter for the number of Expression nodes visited that are resolved. | 417 * Counter for the number of Expression nodes visited that are resolved. |
| 418 */ | 418 */ |
| 419 int _resolvedExpressionCount = 0; | 419 int _resolvedExpressionCount = 0; |
| 420 | 420 |
| 421 /** | 421 /** |
| 422 * Counter for the number of Expression nodes visited that have propagated typ
e information. | 422 * Counter for the number of Expression nodes visited that have propagated typ
e information. |
| 423 */ | 423 */ |
| 424 int _propagatedExpressionCount = 0; | 424 int _propagatedExpressionCount = 0; |
| 425 | 425 |
| 426 /** | 426 /** |
| 427 * Counter for the number of TypeName nodes visited that are resolved. | 427 * Counter for the number of TypeName nodes visited that are resolved. |
| 428 */ | 428 */ |
| 429 int _resolvedTypeCount = 0; | 429 int _resolvedTypeCount = 0; |
| 430 | 430 |
| 431 /** | 431 /** |
| 432 * Assert that all of the visited nodes have a static type associated with the
m. | 432 * Assert that all of the visited nodes have a static type associated with the
m. |
| 433 */ | 433 */ |
| 434 void assertResolved() { | 434 void assertResolved() { |
| 435 if (!_unresolvedExpressions.isEmpty || !_unresolvedTypes.isEmpty) { | 435 if (!_unresolvedExpressions.isEmpty || !_unresolvedTypes.isEmpty) { |
| 436 StringBuffer buffer = new StringBuffer(); | 436 StringBuffer buffer = new StringBuffer(); |
| 437 int unresolvedTypeCount = _unresolvedTypes.length; | 437 int unresolvedTypeCount = _unresolvedTypes.length; |
| 438 if (unresolvedTypeCount > 0) { | 438 if (unresolvedTypeCount > 0) { |
| 439 buffer.write("Failed to resolve "); | 439 buffer.write("Failed to resolve "); |
| 440 buffer.write(unresolvedTypeCount); | 440 buffer.write(unresolvedTypeCount); |
| 441 buffer.write(" of "); | 441 buffer.write(" of "); |
| 442 buffer.write(_resolvedTypeCount + unresolvedTypeCount); | 442 buffer.write(_resolvedTypeCount + unresolvedTypeCount); |
| 443 buffer.writeln(" type names:"); | 443 buffer.writeln(" type names:"); |
| 444 for (TypeName identifier in _unresolvedTypes) { | 444 for (TypeAnnotation identifier in _unresolvedTypes) { |
| 445 buffer.write(" "); | 445 buffer.write(" "); |
| 446 buffer.write(identifier.toString()); | 446 buffer.write(identifier.toString()); |
| 447 buffer.write(" ("); | 447 buffer.write(" ("); |
| 448 buffer.write(_getFileName(identifier)); | 448 buffer.write(_getFileName(identifier)); |
| 449 buffer.write(" : "); | 449 buffer.write(" : "); |
| 450 buffer.write(identifier.offset); | 450 buffer.write(identifier.offset); |
| 451 buffer.writeln(")"); | 451 buffer.writeln(")"); |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 int unresolvedExpressionCount = _unresolvedExpressions.length; | 454 int unresolvedExpressionCount = _unresolvedExpressions.length; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 identical(node, parent.fieldName)) { | 568 identical(node, parent.fieldName)) { |
| 569 return null; | 569 return null; |
| 570 } else if (node.staticElement is PrefixElement) { | 570 } else if (node.staticElement is PrefixElement) { |
| 571 // Prefixes don't have a type. | 571 // Prefixes don't have a type. |
| 572 return null; | 572 return null; |
| 573 } | 573 } |
| 574 return super.visitSimpleIdentifier(node); | 574 return super.visitSimpleIdentifier(node); |
| 575 } | 575 } |
| 576 | 576 |
| 577 @override | 577 @override |
| 578 Object visitTypeAnnotation(TypeAnnotation node) { |
| 579 if (node.type == null) { |
| 580 _unresolvedTypes.add(node); |
| 581 } else { |
| 582 _resolvedTypeCount++; |
| 583 } |
| 584 return super.visitTypeAnnotation(node); |
| 585 } |
| 586 |
| 587 @override |
| 578 Object visitTypeName(TypeName node) { | 588 Object visitTypeName(TypeName node) { |
| 579 // Note: do not visit children from this node, the child SimpleIdentifier in | 589 // Note: do not visit children from this node, the child SimpleIdentifier in |
| 580 // TypeName (i.e. "String") does not have a static type defined. | 590 // TypeName (i.e. "String") does not have a static type defined. |
| 591 // TODO(brianwilkerson) Not visiting the children means that we won't catch |
| 592 // type arguments that were not resolved. |
| 581 if (node.type == null) { | 593 if (node.type == null) { |
| 582 _unresolvedTypes.add(node); | 594 _unresolvedTypes.add(node); |
| 583 } else { | 595 } else { |
| 584 _resolvedTypeCount++; | 596 _resolvedTypeCount++; |
| 585 } | 597 } |
| 586 return null; | 598 return null; |
| 587 } | 599 } |
| 588 | 600 |
| 589 String _getFileName(AstNode node) { | 601 String _getFileName(AstNode node) { |
| 590 // TODO (jwren) there are two copies of this method, one here and one in | 602 // TODO (jwren) there are two copies of this method, one here and one in |
| (...skipping 3075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3666 */ | 3678 */ |
| 3667 class _StaleElement extends ElementImpl { | 3679 class _StaleElement extends ElementImpl { |
| 3668 _StaleElement() : super("_StaleElement", -1); | 3680 _StaleElement() : super("_StaleElement", -1); |
| 3669 | 3681 |
| 3670 @override | 3682 @override |
| 3671 get kind => throw "_StaleElement's kind shouldn't be accessed"; | 3683 get kind => throw "_StaleElement's kind shouldn't be accessed"; |
| 3672 | 3684 |
| 3673 @override | 3685 @override |
| 3674 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; | 3686 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; |
| 3675 } | 3687 } |
| OLD | NEW |