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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
7 | 7 |
8 library engine.all_the_rest_test; | 8 library engine.all_the_rest_test; |
9 | 9 |
10 import 'dart:collection'; | |
11 | |
12 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
13 import 'package:analyzer/file_system/memory_file_system.dart'; | 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
14 import 'package:analyzer/file_system/physical_file_system.dart'; | 12 import 'package:analyzer/file_system/physical_file_system.dart'; |
15 import 'package:analyzer/source/package_map_resolver.dart'; | 13 import 'package:analyzer/source/package_map_resolver.dart'; |
16 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 14 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
17 import 'package:analyzer/src/generated/constant.dart'; | 15 import 'package:analyzer/src/generated/constant.dart'; |
18 import 'package:analyzer/src/generated/element.dart'; | 16 import 'package:analyzer/src/generated/element.dart'; |
19 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
20 import 'package:analyzer/src/generated/error.dart'; | 18 import 'package:analyzer/src/generated/error.dart'; |
21 import 'package:analyzer/src/generated/html.dart' as ht; | 19 import 'package:analyzer/src/generated/html.dart' as ht; |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 466 |
469 /** | 467 /** |
470 * Implementation of [ConstantEvaluationValidator] used during unit tests; | 468 * Implementation of [ConstantEvaluationValidator] used during unit tests; |
471 * verifies that any nodes referenced during constant evaluation are present in | 469 * verifies that any nodes referenced during constant evaluation are present in |
472 * the dependency graph. | 470 * the dependency graph. |
473 */ | 471 */ |
474 class ConstantEvaluationValidator_ForTest | 472 class ConstantEvaluationValidator_ForTest |
475 implements ConstantEvaluationValidator { | 473 implements ConstantEvaluationValidator { |
476 ConstantValueComputer computer; | 474 ConstantValueComputer computer; |
477 | 475 |
478 AstNode _nodeBeingEvaluated; | 476 Element _nodeBeingEvaluated; |
479 | 477 |
480 @override | 478 @override |
481 void beforeComputeValue(AstNode constNode) { | 479 void beforeComputeValue(Element element) { |
482 _nodeBeingEvaluated = constNode; | 480 _nodeBeingEvaluated = element; |
483 } | 481 } |
484 | 482 |
485 @override | 483 @override |
486 void beforeGetConstantInitializers(ConstructorElement constructor) { | 484 void beforeGetConstantInitializers(ConstructorElement constructor) { |
487 // If we are getting the constant initializers for a node in the graph, | 485 // Make sure we properly recorded the dependency. |
488 // make sure we properly recorded the dependency. | 486 expect( |
489 ConstructorDeclaration node = | 487 computer.referenceGraph.containsPath(_nodeBeingEvaluated, constructor), |
490 computer.findConstructorDeclaration(constructor); | 488 isTrue); |
491 if (node != null && computer.referenceGraph.nodes.contains(node)) { | |
492 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, node), | |
493 isTrue); | |
494 } | |
495 } | 489 } |
496 | 490 |
497 @override | 491 @override |
498 void beforeGetEvaluationResult(AstNode node) { | 492 void beforeGetEvaluationResult(Element element) { |
499 // If we are getting the evaluation result for a node in the graph, | 493 // Make sure we properly recorded the dependency. |
500 // make sure we properly recorded the dependency. | 494 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, element), |
501 if (computer.referenceGraph.nodes.contains(node)) { | 495 isTrue); |
502 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, node), | |
503 isTrue); | |
504 } | |
505 } | 496 } |
506 | 497 |
507 @override | 498 @override |
508 void beforeGetFieldEvaluationResult(FieldElementImpl field) { | 499 void beforeGetFieldEvaluationResult(FieldElementImpl field) { |
509 // If we are getting the constant value for a node in the graph, make sure | 500 // Make sure we properly recorded the dependency. |
510 // we properly recorded the dependency. | 501 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, field), |
511 VariableDeclaration node = computer.findVariableDeclaration(field); | 502 isTrue); |
512 if (node != null && computer.referenceGraph.nodes.contains(node)) { | |
513 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, node), | |
514 isTrue); | |
515 } | |
516 } | 503 } |
517 | 504 |
518 @override | 505 @override |
519 void beforeGetParameterDefault(ParameterElement parameter) { | 506 void beforeGetParameterDefault(ParameterElement parameter) { |
520 // Find the ConstructorElement and figure out which | 507 // Make sure we properly recorded the dependency. |
521 // parameter we're talking about. | 508 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, parameter), |
522 ConstructorElement constructor = | 509 isTrue); |
523 parameter.getAncestor((element) => element is ConstructorElement); | |
524 int parameterIndex; | |
525 List<ParameterElement> parameters = constructor.parameters; | |
526 int numParameters = parameters.length; | |
527 for (parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) { | |
528 if (identical(parameters[parameterIndex], parameter)) { | |
529 break; | |
530 } | |
531 } | |
532 expect(parameterIndex < numParameters, isTrue); | |
533 // If we are getting the default parameter for a constructor in the graph, | |
534 // make sure we properly recorded the dependency on the parameter. | |
535 ConstructorDeclaration constructorNode = | |
536 computer.constructorDeclarationMap[constructor]; | |
537 if (constructorNode != null) { | |
538 FormalParameter parameterNode = | |
539 constructorNode.parameters.parameters[parameterIndex]; | |
540 expect(computer.referenceGraph.nodes.contains(parameterNode), isTrue); | |
541 expect(computer.referenceGraph.containsPath( | |
542 _nodeBeingEvaluated, parameterNode), isTrue); | |
543 } | |
544 } | 510 } |
545 } | 511 } |
546 | 512 |
547 @reflectiveTest | 513 @reflectiveTest |
548 class ConstantEvaluatorTest extends ResolverTestCase { | 514 class ConstantEvaluatorTest extends ResolverTestCase { |
549 void fail_constructor() { | 515 void fail_constructor() { |
550 EvaluationResult result = _getExpressionValue("?"); | 516 EvaluationResult result = _getExpressionValue("?"); |
551 expect(result.isValid, isTrue); | 517 expect(result.isValid, isTrue); |
552 DartObject value = result.value; | 518 DartObject value = result.value; |
553 expect(value, null); | 519 expect(value, null); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 * constructor. | 916 * constructor. |
951 */ | 917 */ |
952 void test_visitAnnotation_invocation() { | 918 void test_visitAnnotation_invocation() { |
953 _node = AstFactory.annotation2( | 919 _node = AstFactory.annotation2( |
954 AstFactory.identifier3('A'), null, AstFactory.argumentList()); | 920 AstFactory.identifier3('A'), null, AstFactory.argumentList()); |
955 expect(_findAnnotations(), contains(_node)); | 921 expect(_findAnnotations(), contains(_node)); |
956 } | 922 } |
957 | 923 |
958 void test_visitConstructorDeclaration_const() { | 924 void test_visitConstructorDeclaration_const() { |
959 ConstructorElement element = _setupConstructorDeclaration("A", true); | 925 ConstructorElement element = _setupConstructorDeclaration("A", true); |
960 expect(_findConstantDeclarations()[element], same(_node)); | 926 expect(_findConstants(), contains(element)); |
961 } | 927 } |
962 | 928 |
963 void test_visitConstructorDeclaration_nonConst() { | 929 void test_visitConstructorDeclaration_nonConst() { |
964 _setupConstructorDeclaration("A", false); | 930 _setupConstructorDeclaration("A", false); |
965 expect(_findConstantDeclarations().isEmpty, isTrue); | 931 expect(_findConstants(), isEmpty); |
966 } | 932 } |
967 | 933 |
968 void test_visitVariableDeclaration_const() { | 934 void test_visitVariableDeclaration_const() { |
969 VariableElement element = _setupVariableDeclaration("v", true, true); | 935 VariableElement element = _setupVariableDeclaration("v", true, true); |
970 expect(_findVariableDeclarations()[element], same(_node)); | 936 expect(_findConstants(), contains(element)); |
971 } | 937 } |
972 | 938 |
973 void test_visitVariableDeclaration_final_inClass() { | 939 void test_visitVariableDeclaration_final_inClass() { |
974 _setupFieldDeclaration('C', 'f', Keyword.FINAL); | 940 _setupFieldDeclaration('C', 'f', Keyword.FINAL); |
975 expect(_findVariableDeclarations(), isEmpty); | 941 expect(_findConstants(), isEmpty); |
976 } | 942 } |
977 | 943 |
978 void test_visitVariableDeclaration_final_inClassWithConstConstructor() { | 944 void test_visitVariableDeclaration_final_inClassWithConstConstructor() { |
979 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | 945 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, |
980 hasConstConstructor: true); | 946 hasConstConstructor: true); |
981 expect(_findVariableDeclarations()[field.element], same(field)); | 947 expect(_findConstants(), contains(field.element)); |
982 } | 948 } |
983 | 949 |
984 void test_visitVariableDeclaration_final_outsideClass() { | 950 void test_visitVariableDeclaration_final_outsideClass() { |
985 _setupVariableDeclaration('v', false, true, isFinal: true); | 951 _setupVariableDeclaration('v', false, true, isFinal: true); |
986 expect(_findVariableDeclarations(), isEmpty); | 952 expect(_findConstants(), isEmpty); |
987 } | 953 } |
988 | 954 |
989 void test_visitVariableDeclaration_noInitializer() { | 955 void test_visitVariableDeclaration_noInitializer() { |
990 _setupVariableDeclaration("v", true, false); | 956 _setupVariableDeclaration("v", true, false); |
991 expect(_findVariableDeclarations().isEmpty, isTrue); | 957 expect(_findConstants(), isEmpty); |
992 } | 958 } |
993 | 959 |
994 void test_visitVariableDeclaration_nonConst() { | 960 void test_visitVariableDeclaration_nonConst() { |
995 _setupVariableDeclaration("v", false, true); | 961 _setupVariableDeclaration("v", false, true); |
996 expect(_findVariableDeclarations().isEmpty, isTrue); | 962 expect(_findConstants(), isEmpty); |
997 } | 963 } |
998 | 964 |
999 void test_visitVariableDeclaration_static_const_inClass() { | 965 void test_visitVariableDeclaration_static_const_inClass() { |
1000 VariableDeclaration field = | 966 VariableDeclaration field = |
1001 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); | 967 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); |
1002 expect(_findVariableDeclarations()[field.element], same(field)); | 968 expect(_findConstants(), contains(field.element)); |
1003 } | 969 } |
1004 | 970 |
1005 void test_visitVariableDeclaration_static_const_inClassWithConstConstructor()
{ | 971 void test_visitVariableDeclaration_static_const_inClassWithConstConstructor()
{ |
1006 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, | 972 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, |
1007 isStatic: true, hasConstConstructor: true); | 973 isStatic: true, hasConstConstructor: true); |
1008 expect(_findVariableDeclarations()[field.element], same(field)); | 974 expect(_findConstants(), contains(field.element)); |
1009 } | 975 } |
1010 | 976 |
1011 void test_visitVariableDeclaration_static_final_inClassWithConstConstructor()
{ | 977 void test_visitVariableDeclaration_static_final_inClassWithConstConstructor()
{ |
1012 _setupFieldDeclaration('C', 'f', Keyword.FINAL, | 978 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, |
1013 isStatic: true, hasConstConstructor: true); | 979 isStatic: true, hasConstConstructor: true); |
1014 expect(_findVariableDeclarations(), isEmpty); | 980 expect(_findConstants(), isNot(contains(field.element))); |
1015 } | 981 } |
1016 | 982 |
1017 void test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstru
ctor() { | 983 void test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstru
ctor() { |
1018 _setupFieldDeclaration('C', 'f', Keyword.FINAL, | 984 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, |
1019 isInitialized: false, hasConstConstructor: true); | 985 isInitialized: false, hasConstConstructor: true); |
1020 expect(_findVariableDeclarations(), isEmpty); | 986 expect(_findConstants(), isNot(contains(field.element))); |
1021 } | 987 } |
1022 | 988 |
1023 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { | 989 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { |
1024 _setupFieldDeclaration('C', 'f', Keyword.CONST, | 990 _setupFieldDeclaration('C', 'f', Keyword.CONST, |
1025 isStatic: true, isInitialized: false); | 991 isStatic: true, isInitialized: false); |
1026 expect(_findVariableDeclarations(), isEmpty); | 992 expect(_findConstants(), isEmpty); |
1027 } | 993 } |
1028 | 994 |
1029 List<Annotation> _findAnnotations() { | 995 List<Annotation> _findAnnotations() { |
1030 ConstantFinder finder = new ConstantFinder(); | 996 ConstantFinder finder = new ConstantFinder(); |
1031 _node.accept(finder); | 997 _node.accept(finder); |
1032 List<Annotation> annotations = finder.annotations; | 998 List<Annotation> annotations = finder.annotations; |
1033 expect(annotations, isNotNull); | 999 expect(annotations, isNotNull); |
1034 return annotations; | 1000 return annotations; |
1035 } | 1001 } |
1036 | 1002 |
1037 Map<ConstructorElement, ConstructorDeclaration> _findConstantDeclarations() { | 1003 Set<Element> _findConstants() { |
1038 ConstantFinder finder = new ConstantFinder(); | 1004 ConstantFinder finder = new ConstantFinder(); |
1039 _node.accept(finder); | 1005 _node.accept(finder); |
1040 Map<ConstructorElement, ConstructorDeclaration> constructorMap = | 1006 Set<Element> constants = finder.constantsToCompute; |
1041 finder.constructorMap; | 1007 expect(constants, isNotNull); |
1042 expect(constructorMap, isNotNull); | 1008 return constants; |
1043 return constructorMap; | |
1044 } | |
1045 | |
1046 Map<PotentiallyConstVariableElement, VariableDeclaration> _findVariableDeclara
tions() { | |
1047 ConstantFinder finder = new ConstantFinder(); | |
1048 _node.accept(finder); | |
1049 Map<PotentiallyConstVariableElement, VariableDeclaration> variableMap = | |
1050 finder.variableMap; | |
1051 expect(variableMap, isNotNull); | |
1052 return variableMap; | |
1053 } | 1009 } |
1054 | 1010 |
1055 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { | 1011 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { |
1056 Keyword constKeyword = isConst ? Keyword.CONST : null; | 1012 Keyword constKeyword = isConst ? Keyword.CONST : null; |
1057 ConstructorDeclaration constructorDeclaration = AstFactory | 1013 ConstructorDeclaration constructorDeclaration = AstFactory |
1058 .constructorDeclaration2(constKeyword, null, null, name, | 1014 .constructorDeclaration2(constKeyword, null, null, name, |
1059 AstFactory.formalParameterList(), null, | 1015 AstFactory.formalParameterList(), null, |
1060 AstFactory.blockFunctionBody2()); | 1016 AstFactory.blockFunctionBody2()); |
1061 ClassElement classElement = ElementFactory.classElement2(name); | 1017 ClassElement classElement = ElementFactory.classElement2(name); |
1062 ConstructorElement element = | 1018 ConstructorElement element = |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1331 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
1376 expect(unit, isNotNull); | 1332 expect(unit, isNotNull); |
1377 ConstantValueComputer computer = _makeConstantValueComputer(); | 1333 ConstantValueComputer computer = _makeConstantValueComputer(); |
1378 computer.add(unit); | 1334 computer.add(unit); |
1379 computer.computeValues(); | 1335 computer.computeValues(); |
1380 NodeList<CompilationUnitMember> members = unit.declarations; | 1336 NodeList<CompilationUnitMember> members = unit.declarations; |
1381 expect(members, hasLength(1)); | 1337 expect(members, hasLength(1)); |
1382 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | 1338 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); |
1383 } | 1339 } |
1384 | 1340 |
| 1341 void test_computeValues_value_depends_on_enum() { |
| 1342 Source librarySource = addSource(''' |
| 1343 enum E { id0, id1 } |
| 1344 const E e = E.id0; |
| 1345 '''); |
| 1346 LibraryElement libraryElement = resolve(librarySource); |
| 1347 CompilationUnit unit = |
| 1348 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| 1349 expect(unit, isNotNull); |
| 1350 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 1351 computer.add(unit); |
| 1352 computer.computeValues(); |
| 1353 TopLevelVariableDeclaration declaration = unit.declarations |
| 1354 .firstWhere((member) => member is TopLevelVariableDeclaration); |
| 1355 _validate(true, declaration.variables); |
| 1356 } |
| 1357 |
1385 void test_dependencyOnConstructor() { | 1358 void test_dependencyOnConstructor() { |
1386 // x depends on "const A()" | 1359 // x depends on "const A()" |
1387 _assertProperDependencies(r''' | 1360 _assertProperDependencies(r''' |
1388 class A { | 1361 class A { |
1389 const A(); | 1362 const A(); |
1390 } | 1363 } |
1391 const x = const A();'''); | 1364 const x = const A();'''); |
1392 } | 1365 } |
1393 | 1366 |
1394 void test_dependencyOnConstructorArgument() { | 1367 void test_dependencyOnConstructorArgument() { |
(...skipping 6637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8032 | 8005 |
8033 @override | 8006 @override |
8034 SdkLibrary getSdkLibrary(String dartUri) => null; | 8007 SdkLibrary getSdkLibrary(String dartUri) => null; |
8035 | 8008 |
8036 @override | 8009 @override |
8037 Source mapDartUri(String dartUri) => null; | 8010 Source mapDartUri(String dartUri) => null; |
8038 } | 8011 } |
8039 | 8012 |
8040 @reflectiveTest | 8013 @reflectiveTest |
8041 class ReferenceFinderTest extends EngineTestCase { | 8014 class ReferenceFinderTest extends EngineTestCase { |
8042 DirectedGraph<AstNode> _referenceGraph; | 8015 DirectedGraph<Element> _referenceGraph; |
8043 Map<PotentiallyConstVariableElement, VariableDeclaration> _variableDeclaration
Map; | 8016 VariableElement _head; |
8044 Map<ConstructorElement, ConstructorDeclaration> _constructorDeclarationMap; | 8017 Element _tail; |
8045 VariableDeclaration _head; | |
8046 AstNode _tail; | |
8047 @override | 8018 @override |
8048 void setUp() { | 8019 void setUp() { |
8049 _referenceGraph = new DirectedGraph<AstNode>(); | 8020 _referenceGraph = new DirectedGraph<Element>(); |
8050 _variableDeclarationMap = | 8021 _head = ElementFactory.topLevelVariableElement2("v1"); |
8051 new HashMap<PotentiallyConstVariableElement, VariableDeclaration>(); | |
8052 _constructorDeclarationMap = | |
8053 new HashMap<ConstructorElement, ConstructorDeclaration>(); | |
8054 _head = AstFactory.variableDeclaration("v1"); | |
8055 } | 8022 } |
8056 void test_visitSimpleIdentifier_const() { | 8023 void test_visitSimpleIdentifier_const() { |
8057 _visitNode(_makeTailVariable("v2", true, true)); | 8024 _visitNode(_makeTailVariable("v2", true)); |
8058 _assertOneArc(_tail); | 8025 _assertOneArc(_tail); |
8059 } | 8026 } |
8060 void test_visitSimpleIdentifier_nonConst() { | 8027 void test_visitSimpleIdentifier_nonConst() { |
8061 _visitNode(_makeTailVariable("v2", false, true)); | 8028 _visitNode(_makeTailVariable("v2", false)); |
8062 _assertNoArcs(); | |
8063 } | |
8064 void test_visitSimpleIdentifier_notInMap() { | |
8065 _visitNode(_makeTailVariable("v2", true, false)); | |
8066 _assertNoArcs(); | 8029 _assertNoArcs(); |
8067 } | 8030 } |
8068 void test_visitSuperConstructorInvocation_const() { | 8031 void test_visitSuperConstructorInvocation_const() { |
8069 _visitNode(_makeTailSuperConstructorInvocation("A", true, true)); | 8032 _visitNode(_makeTailSuperConstructorInvocation("A", true)); |
8070 _assertOneArc(_tail); | 8033 _assertOneArc(_tail); |
8071 } | 8034 } |
8072 void test_visitSuperConstructorInvocation_nonConst() { | 8035 void test_visitSuperConstructorInvocation_nonConst() { |
8073 _visitNode(_makeTailSuperConstructorInvocation("A", false, true)); | 8036 _visitNode(_makeTailSuperConstructorInvocation("A", false)); |
8074 _assertNoArcs(); | |
8075 } | |
8076 void test_visitSuperConstructorInvocation_notInMap() { | |
8077 _visitNode(_makeTailSuperConstructorInvocation("A", true, false)); | |
8078 _assertNoArcs(); | 8037 _assertNoArcs(); |
8079 } | 8038 } |
8080 void test_visitSuperConstructorInvocation_unresolved() { | 8039 void test_visitSuperConstructorInvocation_unresolved() { |
8081 SuperConstructorInvocation superConstructorInvocation = | 8040 SuperConstructorInvocation superConstructorInvocation = |
8082 AstFactory.superConstructorInvocation(); | 8041 AstFactory.superConstructorInvocation(); |
8083 _tail = superConstructorInvocation; | |
8084 _visitNode(superConstructorInvocation); | 8042 _visitNode(superConstructorInvocation); |
8085 _assertNoArcs(); | 8043 _assertNoArcs(); |
8086 } | 8044 } |
8087 void _assertNoArcs() { | 8045 void _assertNoArcs() { |
8088 Set<AstNode> tails = _referenceGraph.getTails(_head); | 8046 Set<Element> tails = _referenceGraph.getTails(_head); |
8089 expect(tails, hasLength(0)); | 8047 expect(tails, hasLength(0)); |
8090 } | 8048 } |
8091 void _assertOneArc(AstNode tail) { | 8049 void _assertOneArc(Element tail) { |
8092 Set<AstNode> tails = _referenceGraph.getTails(_head); | 8050 Set<Element> tails = _referenceGraph.getTails(_head); |
8093 expect(tails, hasLength(1)); | 8051 expect(tails, hasLength(1)); |
8094 expect(tails.first, same(tail)); | 8052 expect(tails.first, same(tail)); |
8095 } | 8053 } |
8096 ReferenceFinder _createReferenceFinder(AstNode source) => new ReferenceFinder( | 8054 ReferenceFinder _createReferenceFinder(Element source) => |
8097 source, _referenceGraph, _variableDeclarationMap, | 8055 new ReferenceFinder(source, _referenceGraph); |
8098 _constructorDeclarationMap); | |
8099 SuperConstructorInvocation _makeTailSuperConstructorInvocation( | 8056 SuperConstructorInvocation _makeTailSuperConstructorInvocation( |
8100 String name, bool isConst, bool inMap) { | 8057 String name, bool isConst) { |
8101 List<ConstructorInitializer> initializers = | 8058 List<ConstructorInitializer> initializers = |
8102 new List<ConstructorInitializer>(); | 8059 new List<ConstructorInitializer>(); |
8103 ConstructorDeclaration constructorDeclaration = AstFactory | 8060 ConstructorDeclaration constructorDeclaration = AstFactory |
8104 .constructorDeclaration(AstFactory.identifier3(name), null, | 8061 .constructorDeclaration(AstFactory.identifier3(name), null, |
8105 AstFactory.formalParameterList(), initializers); | 8062 AstFactory.formalParameterList(), initializers); |
8106 _tail = constructorDeclaration; | |
8107 if (isConst) { | 8063 if (isConst) { |
8108 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); | 8064 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); |
8109 } | 8065 } |
8110 ClassElementImpl classElement = ElementFactory.classElement2(name); | 8066 ClassElementImpl classElement = ElementFactory.classElement2(name); |
8111 SuperConstructorInvocation superConstructorInvocation = | 8067 SuperConstructorInvocation superConstructorInvocation = |
8112 AstFactory.superConstructorInvocation(); | 8068 AstFactory.superConstructorInvocation(); |
8113 ConstructorElementImpl constructorElement = | 8069 ConstructorElementImpl constructorElement = |
8114 ElementFactory.constructorElement(classElement, name, isConst); | 8070 ElementFactory.constructorElement(classElement, name, isConst); |
8115 if (inMap) { | 8071 _tail = constructorElement; |
8116 _constructorDeclarationMap[constructorElement] = constructorDeclaration; | |
8117 } | |
8118 superConstructorInvocation.staticElement = constructorElement; | 8072 superConstructorInvocation.staticElement = constructorElement; |
8119 return superConstructorInvocation; | 8073 return superConstructorInvocation; |
8120 } | 8074 } |
8121 SimpleIdentifier _makeTailVariable(String name, bool isConst, bool inMap) { | 8075 SimpleIdentifier _makeTailVariable(String name, bool isConst) { |
8122 VariableDeclaration variableDeclaration = | 8076 VariableDeclaration variableDeclaration = |
8123 AstFactory.variableDeclaration(name); | 8077 AstFactory.variableDeclaration(name); |
8124 _tail = variableDeclaration; | |
8125 ConstLocalVariableElementImpl variableElement = | 8078 ConstLocalVariableElementImpl variableElement = |
8126 ElementFactory.constLocalVariableElement(name); | 8079 ElementFactory.constLocalVariableElement(name); |
| 8080 _tail = variableElement; |
8127 variableElement.const3 = isConst; | 8081 variableElement.const3 = isConst; |
8128 AstFactory.variableDeclarationList2( | 8082 AstFactory.variableDeclarationList2( |
8129 isConst ? Keyword.CONST : Keyword.VAR, [variableDeclaration]); | 8083 isConst ? Keyword.CONST : Keyword.VAR, [variableDeclaration]); |
8130 if (inMap) { | |
8131 _variableDeclarationMap[variableElement] = variableDeclaration; | |
8132 } | |
8133 SimpleIdentifier identifier = AstFactory.identifier3(name); | 8084 SimpleIdentifier identifier = AstFactory.identifier3(name); |
8134 identifier.staticElement = variableElement; | 8085 identifier.staticElement = variableElement; |
8135 return identifier; | 8086 return identifier; |
8136 } | 8087 } |
8137 void _visitNode(AstNode node) { | 8088 void _visitNode(AstNode node) { |
8138 node.accept(_createReferenceFinder(_head)); | 8089 node.accept(_createReferenceFinder(_head)); |
8139 } | 8090 } |
8140 } | 8091 } |
8141 | 8092 |
8142 @reflectiveTest | 8093 @reflectiveTest |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8704 if (_expectedExternalScriptName == null) { | 8655 if (_expectedExternalScriptName == null) { |
8705 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 8656 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
8706 } else { | 8657 } else { |
8707 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 8658 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
8708 String actualExternalScriptName = scriptSource.shortName; | 8659 String actualExternalScriptName = scriptSource.shortName; |
8709 expect(actualExternalScriptName, _expectedExternalScriptName, | 8660 expect(actualExternalScriptName, _expectedExternalScriptName, |
8710 reason: "script $scriptIndex"); | 8661 reason: "script $scriptIndex"); |
8711 } | 8662 } |
8712 } | 8663 } |
8713 } | 8664 } |
OLD | NEW |