| 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 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 import 'package:analyzer/src/generated/sdk.dart'; | 26 import 'package:analyzer/src/generated/sdk.dart'; |
| 27 import 'package:analyzer/src/generated/sdk_io.dart'; | 27 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 28 import 'package:analyzer/src/generated/source.dart'; | 28 import 'package:analyzer/src/generated/source.dart'; |
| 29 import 'package:analyzer/src/generated/source_io.dart'; | 29 import 'package:analyzer/src/generated/source_io.dart'; |
| 30 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 30 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 31 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 31 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 32 import 'package:analyzer/src/generated/testing/html_factory.dart'; | 32 import 'package:analyzer/src/generated/testing/html_factory.dart'; |
| 33 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 33 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
| 34 import 'package:analyzer/src/generated/utilities_collection.dart'; | 34 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 35 import 'package:analyzer/src/generated/utilities_dart.dart'; | 35 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 36 import 'package:analyzer/src/task/dart.dart'; |
| 36 import 'package:path/src/context.dart'; | 37 import 'package:path/src/context.dart'; |
| 37 import 'package:unittest/unittest.dart'; | 38 import 'package:unittest/unittest.dart'; |
| 38 | 39 |
| 39 import '../reflective_tests.dart'; | 40 import '../reflective_tests.dart'; |
| 41 import 'engine_test.dart'; |
| 40 import 'parser_test.dart'; | 42 import 'parser_test.dart'; |
| 41 import 'resolver_test.dart'; | 43 import 'resolver_test.dart'; |
| 42 import 'test_support.dart'; | 44 import 'test_support.dart'; |
| 43 | 45 |
| 44 main() { | 46 main() { |
| 45 groupSep = ' | '; | 47 groupSep = ' | '; |
| 46 runReflectiveTests(ConstantEvaluatorTest); | 48 runReflectiveTests(ConstantEvaluatorTest); |
| 47 runReflectiveTests(ConstantFinderTest); | 49 runReflectiveTests(ConstantFinderTest); |
| 48 runReflectiveTests(ConstantValueComputerTest); | 50 runReflectiveTests(ConstantValueComputerTest); |
| 49 runReflectiveTests(ConstantVisitorTest); | 51 runReflectiveTests(ConstantVisitorTest); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 468 |
| 467 /** | 469 /** |
| 468 * Implementation of [ConstantEvaluationValidator] used during unit tests; | 470 * Implementation of [ConstantEvaluationValidator] used during unit tests; |
| 469 * verifies that any nodes referenced during constant evaluation are present in | 471 * verifies that any nodes referenced during constant evaluation are present in |
| 470 * the dependency graph. | 472 * the dependency graph. |
| 471 */ | 473 */ |
| 472 class ConstantEvaluationValidator_ForTest | 474 class ConstantEvaluationValidator_ForTest |
| 473 implements ConstantEvaluationValidator { | 475 implements ConstantEvaluationValidator { |
| 474 ConstantValueComputer computer; | 476 ConstantValueComputer computer; |
| 475 | 477 |
| 476 Element _nodeBeingEvaluated; | 478 ConstantEvaluationTarget _nodeBeingEvaluated; |
| 477 | 479 |
| 478 @override | 480 @override |
| 479 void beforeComputeValue(Element element) { | 481 void beforeComputeValue(ConstantEvaluationTarget constant) { |
| 480 _nodeBeingEvaluated = element; | 482 _nodeBeingEvaluated = constant; |
| 481 } | 483 } |
| 482 | 484 |
| 483 @override | 485 @override |
| 484 void beforeGetConstantInitializers(ConstructorElement constructor) { | 486 void beforeGetConstantInitializers(ConstructorElement constructor) { |
| 485 // Make sure we properly recorded the dependency. | 487 // Make sure we properly recorded the dependency. |
| 486 expect( | 488 expect( |
| 487 computer.referenceGraph.containsPath(_nodeBeingEvaluated, constructor), | 489 computer.referenceGraph.containsPath(_nodeBeingEvaluated, constructor), |
| 488 isTrue); | 490 isTrue); |
| 489 } | 491 } |
| 490 | 492 |
| 491 @override | 493 @override |
| 492 void beforeGetEvaluationResult(Element element) { | 494 void beforeGetEvaluationResult(ConstantEvaluationTarget constant) { |
| 493 // Make sure we properly recorded the dependency. | 495 // Make sure we properly recorded the dependency. |
| 494 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, element), | 496 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, constant), |
| 495 isTrue); | 497 isTrue); |
| 496 } | 498 } |
| 497 | 499 |
| 498 @override | 500 @override |
| 499 void beforeGetFieldEvaluationResult(FieldElementImpl field) { | 501 void beforeGetFieldEvaluationResult(FieldElementImpl field) { |
| 500 // Make sure we properly recorded the dependency. | 502 // Make sure we properly recorded the dependency. |
| 501 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, field), | 503 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, field), |
| 502 isTrue); | 504 isTrue); |
| 503 } | 505 } |
| 504 | 506 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 expect(variables, hasLength(1)); | 889 expect(variables, hasLength(1)); |
| 888 ConstantEvaluator evaluator = | 890 ConstantEvaluator evaluator = |
| 889 new ConstantEvaluator(source, analysisContext.typeProvider); | 891 new ConstantEvaluator(source, analysisContext.typeProvider); |
| 890 return evaluator.evaluate(variables[0].initializer); | 892 return evaluator.evaluate(variables[0].initializer); |
| 891 } | 893 } |
| 892 } | 894 } |
| 893 | 895 |
| 894 @reflectiveTest | 896 @reflectiveTest |
| 895 class ConstantFinderTest extends EngineTestCase { | 897 class ConstantFinderTest extends EngineTestCase { |
| 896 AstNode _node; | 898 AstNode _node; |
| 897 | |
| 898 TypeProvider _typeProvider; | 899 TypeProvider _typeProvider; |
| 900 AnalysisContext _context; |
| 901 Source _source; |
| 899 | 902 |
| 900 void setUp() { | 903 void setUp() { |
| 901 super.setUp(); | 904 super.setUp(); |
| 902 _typeProvider = new TestTypeProvider(); | 905 _typeProvider = new TestTypeProvider(); |
| 906 _context = new TestAnalysisContext(); |
| 907 _source = new TestSource(); |
| 903 } | 908 } |
| 904 | 909 |
| 905 /** | 910 /** |
| 906 * Test an annotation that consists solely of an identifier (and hence | 911 * Test an annotation that consists solely of an identifier (and hence |
| 907 * represents a reference to a compile-time constant variable). | 912 * represents a reference to a compile-time constant variable). |
| 908 */ | 913 */ |
| 909 void test_visitAnnotation_constantVariable() { | 914 void test_visitAnnotation_constantVariable() { |
| 910 _node = AstFactory.annotation(AstFactory.identifier3('x')); | 915 _node = AstFactory.annotation(AstFactory.identifier3('x')); |
| 911 expect(_findAnnotations(), contains(_node)); | 916 expect(_findAnnotations(), contains(_node)); |
| 912 } | 917 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 expect(_findConstants(), isNot(contains(field.element))); | 991 expect(_findConstants(), isNot(contains(field.element))); |
| 987 } | 992 } |
| 988 | 993 |
| 989 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { | 994 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { |
| 990 _setupFieldDeclaration('C', 'f', Keyword.CONST, | 995 _setupFieldDeclaration('C', 'f', Keyword.CONST, |
| 991 isStatic: true, isInitialized: false); | 996 isStatic: true, isInitialized: false); |
| 992 expect(_findConstants(), isEmpty); | 997 expect(_findConstants(), isEmpty); |
| 993 } | 998 } |
| 994 | 999 |
| 995 List<Annotation> _findAnnotations() { | 1000 List<Annotation> _findAnnotations() { |
| 996 ConstantFinder finder = new ConstantFinder(); | 1001 Set<Annotation> annotations = new Set<Annotation>(); |
| 997 _node.accept(finder); | 1002 for (ConstantEvaluationTarget target in _findConstants()) { |
| 998 List<Annotation> annotations = finder.annotations; | 1003 if (target is ConstantEvaluationTarget_Annotation) { |
| 999 expect(annotations, isNotNull); | 1004 expect(target.context, same(_context)); |
| 1000 return annotations; | 1005 expect(target.source, same(_source)); |
| 1006 annotations.add(target.annotation); |
| 1007 } |
| 1008 } |
| 1009 return new List<Annotation>.from(annotations); |
| 1001 } | 1010 } |
| 1002 | 1011 |
| 1003 Set<Element> _findConstants() { | 1012 Set<ConstantEvaluationTarget> _findConstants() { |
| 1004 ConstantFinder finder = new ConstantFinder(); | 1013 ConstantFinder finder = new ConstantFinder(_context, _source, _source); |
| 1005 _node.accept(finder); | 1014 _node.accept(finder); |
| 1006 Set<Element> constants = finder.constantsToCompute; | 1015 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute; |
| 1007 expect(constants, isNotNull); | 1016 expect(constants, isNotNull); |
| 1008 return constants; | 1017 return constants; |
| 1009 } | 1018 } |
| 1010 | 1019 |
| 1011 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { | 1020 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { |
| 1012 Keyword constKeyword = isConst ? Keyword.CONST : null; | 1021 Keyword constKeyword = isConst ? Keyword.CONST : null; |
| 1013 ConstructorDeclaration constructorDeclaration = AstFactory | 1022 ConstructorDeclaration constructorDeclaration = AstFactory |
| 1014 .constructorDeclaration2(constKeyword, null, null, name, | 1023 .constructorDeclaration2(constKeyword, null, null, name, |
| 1015 AstFactory.formalParameterList(), null, | 1024 AstFactory.formalParameterList(), null, |
| 1016 AstFactory.blockFunctionBody2()); | 1025 AstFactory.blockFunctionBody2()); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 Source librarySource = addSource(r''' | 1262 Source librarySource = addSource(r''' |
| 1254 const int a = c; | 1263 const int a = c; |
| 1255 const int b = a; | 1264 const int b = a; |
| 1256 const int c = b;'''); | 1265 const int c = b;'''); |
| 1257 LibraryElement libraryElement = resolve(librarySource); | 1266 LibraryElement libraryElement = resolve(librarySource); |
| 1258 CompilationUnit unit = | 1267 CompilationUnit unit = |
| 1259 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1268 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| 1260 analysisContext.computeErrors(librarySource); | 1269 analysisContext.computeErrors(librarySource); |
| 1261 expect(unit, isNotNull); | 1270 expect(unit, isNotNull); |
| 1262 ConstantValueComputer computer = _makeConstantValueComputer(); | 1271 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 1263 computer.add(unit); | 1272 computer.add(unit, librarySource, librarySource); |
| 1264 computer.computeValues(); | 1273 computer.computeValues(); |
| 1265 NodeList<CompilationUnitMember> members = unit.declarations; | 1274 NodeList<CompilationUnitMember> members = unit.declarations; |
| 1266 expect(members, hasLength(3)); | 1275 expect(members, hasLength(3)); |
| 1267 _validate(false, (members[0] as TopLevelVariableDeclaration).variables); | 1276 _validate(false, (members[0] as TopLevelVariableDeclaration).variables); |
| 1268 _validate(false, (members[1] as TopLevelVariableDeclaration).variables); | 1277 _validate(false, (members[1] as TopLevelVariableDeclaration).variables); |
| 1269 _validate(false, (members[2] as TopLevelVariableDeclaration).variables); | 1278 _validate(false, (members[2] as TopLevelVariableDeclaration).variables); |
| 1270 } | 1279 } |
| 1271 | 1280 |
| 1272 void test_computeValues_dependentVariables() { | 1281 void test_computeValues_dependentVariables() { |
| 1273 Source librarySource = addSource(r''' | 1282 Source librarySource = addSource(r''' |
| 1274 const int b = a; | 1283 const int b = a; |
| 1275 const int a = 0;'''); | 1284 const int a = 0;'''); |
| 1276 LibraryElement libraryElement = resolve(librarySource); | 1285 LibraryElement libraryElement = resolve(librarySource); |
| 1277 CompilationUnit unit = | 1286 CompilationUnit unit = |
| 1278 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1287 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| 1279 expect(unit, isNotNull); | 1288 expect(unit, isNotNull); |
| 1280 ConstantValueComputer computer = _makeConstantValueComputer(); | 1289 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 1281 computer.add(unit); | 1290 computer.add(unit, librarySource, librarySource); |
| 1282 computer.computeValues(); | 1291 computer.computeValues(); |
| 1283 NodeList<CompilationUnitMember> members = unit.declarations; | 1292 NodeList<CompilationUnitMember> members = unit.declarations; |
| 1284 expect(members, hasLength(2)); | 1293 expect(members, hasLength(2)); |
| 1285 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | 1294 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); |
| 1286 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); | 1295 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); |
| 1287 } | 1296 } |
| 1288 | 1297 |
| 1289 void test_computeValues_empty() { | 1298 void test_computeValues_empty() { |
| 1290 ConstantValueComputer computer = _makeConstantValueComputer(); | 1299 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 1291 computer.computeValues(); | 1300 computer.computeValues(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1302 const int b = a; | 1311 const int b = a; |
| 1303 const int d = c;'''); | 1312 const int d = c;'''); |
| 1304 LibraryElement libraryElement = resolve(librarySource); | 1313 LibraryElement libraryElement = resolve(librarySource); |
| 1305 CompilationUnit libraryUnit = | 1314 CompilationUnit libraryUnit = |
| 1306 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1315 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| 1307 expect(libraryUnit, isNotNull); | 1316 expect(libraryUnit, isNotNull); |
| 1308 CompilationUnit partUnit = | 1317 CompilationUnit partUnit = |
| 1309 analysisContext.resolveCompilationUnit(partSource, libraryElement); | 1318 analysisContext.resolveCompilationUnit(partSource, libraryElement); |
| 1310 expect(partUnit, isNotNull); | 1319 expect(partUnit, isNotNull); |
| 1311 ConstantValueComputer computer = _makeConstantValueComputer(); | 1320 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 1312 computer.add(libraryUnit); | 1321 computer.add(libraryUnit, librarySource, librarySource); |
| 1313 computer.add(partUnit); | 1322 computer.add(partUnit, partSource, librarySource); |
| 1314 computer.computeValues(); | 1323 computer.computeValues(); |
| 1315 NodeList<CompilationUnitMember> libraryMembers = libraryUnit.declarations; | 1324 NodeList<CompilationUnitMember> libraryMembers = libraryUnit.declarations; |
| 1316 expect(libraryMembers, hasLength(2)); | 1325 expect(libraryMembers, hasLength(2)); |
| 1317 _validate( | 1326 _validate( |
| 1318 true, (libraryMembers[0] as TopLevelVariableDeclaration).variables); | 1327 true, (libraryMembers[0] as TopLevelVariableDeclaration).variables); |
| 1319 _validate( | 1328 _validate( |
| 1320 true, (libraryMembers[1] as TopLevelVariableDeclaration).variables); | 1329 true, (libraryMembers[1] as TopLevelVariableDeclaration).variables); |
| 1321 NodeList<CompilationUnitMember> partMembers = libraryUnit.declarations; | 1330 NodeList<CompilationUnitMember> partMembers = libraryUnit.declarations; |
| 1322 expect(partMembers, hasLength(2)); | 1331 expect(partMembers, hasLength(2)); |
| 1323 _validate(true, (partMembers[0] as TopLevelVariableDeclaration).variables); | 1332 _validate(true, (partMembers[0] as TopLevelVariableDeclaration).variables); |
| 1324 _validate(true, (partMembers[1] as TopLevelVariableDeclaration).variables); | 1333 _validate(true, (partMembers[1] as TopLevelVariableDeclaration).variables); |
| 1325 } | 1334 } |
| 1326 | 1335 |
| 1327 void test_computeValues_singleVariable() { | 1336 void test_computeValues_singleVariable() { |
| 1328 Source librarySource = addSource("const int a = 0;"); | 1337 Source librarySource = addSource("const int a = 0;"); |
| 1329 LibraryElement libraryElement = resolve(librarySource); | 1338 LibraryElement libraryElement = resolve(librarySource); |
| 1330 CompilationUnit unit = | 1339 CompilationUnit unit = |
| 1331 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1340 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| 1332 expect(unit, isNotNull); | 1341 expect(unit, isNotNull); |
| 1333 ConstantValueComputer computer = _makeConstantValueComputer(); | 1342 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 1334 computer.add(unit); | 1343 computer.add(unit, librarySource, librarySource); |
| 1335 computer.computeValues(); | 1344 computer.computeValues(); |
| 1336 NodeList<CompilationUnitMember> members = unit.declarations; | 1345 NodeList<CompilationUnitMember> members = unit.declarations; |
| 1337 expect(members, hasLength(1)); | 1346 expect(members, hasLength(1)); |
| 1338 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | 1347 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); |
| 1339 } | 1348 } |
| 1340 | 1349 |
| 1341 void test_computeValues_value_depends_on_enum() { | 1350 void test_computeValues_value_depends_on_enum() { |
| 1342 Source librarySource = addSource(''' | 1351 Source librarySource = addSource(''' |
| 1343 enum E { id0, id1 } | 1352 enum E { id0, id1 } |
| 1344 const E e = E.id0; | 1353 const E e = E.id0; |
| 1345 '''); | 1354 '''); |
| 1346 LibraryElement libraryElement = resolve(librarySource); | 1355 LibraryElement libraryElement = resolve(librarySource); |
| 1347 CompilationUnit unit = | 1356 CompilationUnit unit = |
| 1348 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 1357 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| 1349 expect(unit, isNotNull); | 1358 expect(unit, isNotNull); |
| 1350 ConstantValueComputer computer = _makeConstantValueComputer(); | 1359 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 1351 computer.add(unit); | 1360 computer.add(unit, librarySource, librarySource); |
| 1352 computer.computeValues(); | 1361 computer.computeValues(); |
| 1353 TopLevelVariableDeclaration declaration = unit.declarations | 1362 TopLevelVariableDeclaration declaration = unit.declarations |
| 1354 .firstWhere((member) => member is TopLevelVariableDeclaration); | 1363 .firstWhere((member) => member is TopLevelVariableDeclaration); |
| 1355 _validate(true, declaration.variables); | 1364 _validate(true, declaration.variables); |
| 1356 } | 1365 } |
| 1357 | 1366 |
| 1358 void test_dependencyOnConstructor() { | 1367 void test_dependencyOnConstructor() { |
| 1359 // x depends on "const A()" | 1368 // x depends on "const A()" |
| 1360 _assertProperDependencies(r''' | 1369 _assertProperDependencies(r''' |
| 1361 class A { | 1370 class A { |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2157 } | 2166 } |
| 2158 | 2167 |
| 2159 void _assertProperDependencies(String sourceText, | 2168 void _assertProperDependencies(String sourceText, |
| 2160 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { | 2169 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { |
| 2161 Source source = addSource(sourceText); | 2170 Source source = addSource(sourceText); |
| 2162 LibraryElement element = resolve(source); | 2171 LibraryElement element = resolve(source); |
| 2163 CompilationUnit unit = | 2172 CompilationUnit unit = |
| 2164 analysisContext.resolveCompilationUnit(source, element); | 2173 analysisContext.resolveCompilationUnit(source, element); |
| 2165 expect(unit, isNotNull); | 2174 expect(unit, isNotNull); |
| 2166 ConstantValueComputer computer = _makeConstantValueComputer(); | 2175 ConstantValueComputer computer = _makeConstantValueComputer(); |
| 2167 computer.add(unit); | 2176 computer.add(unit, source, source); |
| 2168 computer.computeValues(); | 2177 computer.computeValues(); |
| 2169 assertErrors(source, expectedErrorCodes); | 2178 assertErrors(source, expectedErrorCodes); |
| 2170 } | 2179 } |
| 2171 | 2180 |
| 2172 Map<String, DartObjectImpl> _assertType( | 2181 Map<String, DartObjectImpl> _assertType( |
| 2173 EvaluationResultImpl result, String typeName) { | 2182 EvaluationResultImpl result, String typeName) { |
| 2174 expect(result.value, isNotNull); | 2183 expect(result.value, isNotNull); |
| 2175 DartObjectImpl value = result.value; | 2184 DartObjectImpl value = result.value; |
| 2176 expect(value.type.displayName, typeName); | 2185 expect(value.type.displayName, typeName); |
| 2177 return value.fields; | 2186 return value.fields; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2335 CompilationUnit compilationUnit, String name) { | 2344 CompilationUnit compilationUnit, String name) { |
| 2336 VariableDeclaration varDecl = | 2345 VariableDeclaration varDecl = |
| 2337 findTopLevelDeclaration(compilationUnit, name); | 2346 findTopLevelDeclaration(compilationUnit, name); |
| 2338 ConstTopLevelVariableElementImpl varElement = varDecl.element; | 2347 ConstTopLevelVariableElementImpl varElement = varDecl.element; |
| 2339 return varElement.evaluationResult; | 2348 return varElement.evaluationResult; |
| 2340 } | 2349 } |
| 2341 | 2350 |
| 2342 ConstantValueComputer _makeConstantValueComputer() { | 2351 ConstantValueComputer _makeConstantValueComputer() { |
| 2343 ConstantEvaluationValidator_ForTest validator = | 2352 ConstantEvaluationValidator_ForTest validator = |
| 2344 new ConstantEvaluationValidator_ForTest(); | 2353 new ConstantEvaluationValidator_ForTest(); |
| 2345 validator.computer = new ConstantValueComputer( | 2354 validator.computer = new ConstantValueComputer(analysisContext2, |
| 2346 analysisContext2.typeProvider, analysisContext2.declaredVariables, | 2355 analysisContext2.typeProvider, analysisContext2.declaredVariables, |
| 2347 validator); | 2356 validator); |
| 2348 return validator.computer; | 2357 return validator.computer; |
| 2349 } | 2358 } |
| 2350 | 2359 |
| 2351 void _validate(bool shouldBeValid, VariableDeclarationList declarationList) { | 2360 void _validate(bool shouldBeValid, VariableDeclarationList declarationList) { |
| 2352 for (VariableDeclaration declaration in declarationList.variables) { | 2361 for (VariableDeclaration declaration in declarationList.variables) { |
| 2353 VariableElementImpl element = declaration.element as VariableElementImpl; | 2362 VariableElementImpl element = declaration.element as VariableElementImpl; |
| 2354 expect(element, isNotNull); | 2363 expect(element, isNotNull); |
| 2355 EvaluationResultImpl result = element.evaluationResult; | 2364 EvaluationResultImpl result = element.evaluationResult; |
| (...skipping 5649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8005 | 8014 |
| 8006 @override | 8015 @override |
| 8007 SdkLibrary getSdkLibrary(String dartUri) => null; | 8016 SdkLibrary getSdkLibrary(String dartUri) => null; |
| 8008 | 8017 |
| 8009 @override | 8018 @override |
| 8010 Source mapDartUri(String dartUri) => null; | 8019 Source mapDartUri(String dartUri) => null; |
| 8011 } | 8020 } |
| 8012 | 8021 |
| 8013 @reflectiveTest | 8022 @reflectiveTest |
| 8014 class ReferenceFinderTest extends EngineTestCase { | 8023 class ReferenceFinderTest extends EngineTestCase { |
| 8015 DirectedGraph<Element> _referenceGraph; | 8024 DirectedGraph<ConstantEvaluationTarget> _referenceGraph; |
| 8016 VariableElement _head; | 8025 VariableElement _head; |
| 8017 Element _tail; | 8026 Element _tail; |
| 8018 @override | 8027 @override |
| 8019 void setUp() { | 8028 void setUp() { |
| 8020 _referenceGraph = new DirectedGraph<Element>(); | 8029 _referenceGraph = new DirectedGraph<ConstantEvaluationTarget>(); |
| 8021 _head = ElementFactory.topLevelVariableElement2("v1"); | 8030 _head = ElementFactory.topLevelVariableElement2("v1"); |
| 8022 } | 8031 } |
| 8023 void test_visitSimpleIdentifier_const() { | 8032 void test_visitSimpleIdentifier_const() { |
| 8024 _visitNode(_makeTailVariable("v2", true)); | 8033 _visitNode(_makeTailVariable("v2", true)); |
| 8025 _assertOneArc(_tail); | 8034 _assertOneArc(_tail); |
| 8026 } | 8035 } |
| 8027 void test_visitSimpleIdentifier_nonConst() { | 8036 void test_visitSimpleIdentifier_nonConst() { |
| 8028 _visitNode(_makeTailVariable("v2", false)); | 8037 _visitNode(_makeTailVariable("v2", false)); |
| 8029 _assertNoArcs(); | 8038 _assertNoArcs(); |
| 8030 } | 8039 } |
| 8031 void test_visitSuperConstructorInvocation_const() { | 8040 void test_visitSuperConstructorInvocation_const() { |
| 8032 _visitNode(_makeTailSuperConstructorInvocation("A", true)); | 8041 _visitNode(_makeTailSuperConstructorInvocation("A", true)); |
| 8033 _assertOneArc(_tail); | 8042 _assertOneArc(_tail); |
| 8034 } | 8043 } |
| 8035 void test_visitSuperConstructorInvocation_nonConst() { | 8044 void test_visitSuperConstructorInvocation_nonConst() { |
| 8036 _visitNode(_makeTailSuperConstructorInvocation("A", false)); | 8045 _visitNode(_makeTailSuperConstructorInvocation("A", false)); |
| 8037 _assertNoArcs(); | 8046 _assertNoArcs(); |
| 8038 } | 8047 } |
| 8039 void test_visitSuperConstructorInvocation_unresolved() { | 8048 void test_visitSuperConstructorInvocation_unresolved() { |
| 8040 SuperConstructorInvocation superConstructorInvocation = | 8049 SuperConstructorInvocation superConstructorInvocation = |
| 8041 AstFactory.superConstructorInvocation(); | 8050 AstFactory.superConstructorInvocation(); |
| 8042 _visitNode(superConstructorInvocation); | 8051 _visitNode(superConstructorInvocation); |
| 8043 _assertNoArcs(); | 8052 _assertNoArcs(); |
| 8044 } | 8053 } |
| 8045 void _assertNoArcs() { | 8054 void _assertNoArcs() { |
| 8046 Set<Element> tails = _referenceGraph.getTails(_head); | 8055 Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head); |
| 8047 expect(tails, hasLength(0)); | 8056 expect(tails, hasLength(0)); |
| 8048 } | 8057 } |
| 8049 void _assertOneArc(Element tail) { | 8058 void _assertOneArc(Element tail) { |
| 8050 Set<Element> tails = _referenceGraph.getTails(_head); | 8059 Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head); |
| 8051 expect(tails, hasLength(1)); | 8060 expect(tails, hasLength(1)); |
| 8052 expect(tails.first, same(tail)); | 8061 expect(tails.first, same(tail)); |
| 8053 } | 8062 } |
| 8054 ReferenceFinder _createReferenceFinder(Element source) => | 8063 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => |
| 8055 new ReferenceFinder((Element dependency) { | 8064 new ReferenceFinder((ConstantEvaluationTarget dependency) { |
| 8056 _referenceGraph.addEdge(source, dependency); | 8065 _referenceGraph.addEdge(source, dependency); |
| 8057 }); | 8066 }); |
| 8058 SuperConstructorInvocation _makeTailSuperConstructorInvocation( | 8067 SuperConstructorInvocation _makeTailSuperConstructorInvocation( |
| 8059 String name, bool isConst) { | 8068 String name, bool isConst) { |
| 8060 List<ConstructorInitializer> initializers = | 8069 List<ConstructorInitializer> initializers = |
| 8061 new List<ConstructorInitializer>(); | 8070 new List<ConstructorInitializer>(); |
| 8062 ConstructorDeclaration constructorDeclaration = AstFactory | 8071 ConstructorDeclaration constructorDeclaration = AstFactory |
| 8063 .constructorDeclaration(AstFactory.identifier3(name), null, | 8072 .constructorDeclaration(AstFactory.identifier3(name), null, |
| 8064 AstFactory.formalParameterList(), initializers); | 8073 AstFactory.formalParameterList(), initializers); |
| 8065 if (isConst) { | 8074 if (isConst) { |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8657 if (_expectedExternalScriptName == null) { | 8666 if (_expectedExternalScriptName == null) { |
| 8658 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 8667 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
| 8659 } else { | 8668 } else { |
| 8660 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 8669 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
| 8661 String actualExternalScriptName = scriptSource.shortName; | 8670 String actualExternalScriptName = scriptSource.shortName; |
| 8662 expect(actualExternalScriptName, _expectedExternalScriptName, | 8671 expect(actualExternalScriptName, _expectedExternalScriptName, |
| 8663 reason: "script $scriptIndex"); | 8672 reason: "script $scriptIndex"); |
| 8664 } | 8673 } |
| 8665 } | 8674 } |
| 8666 } | 8675 } |
| OLD | NEW |