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 test.src.context.context_test; | 5 library test.src.context.context_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/src/cancelable_future.dart'; | 9 import 'package:analyzer/src/cancelable_future.dart'; |
10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 ChangeNotice, | 27 ChangeNotice, |
28 ChangeSet, | 28 ChangeSet, |
29 IncrementalAnalysisCache, | 29 IncrementalAnalysisCache, |
30 TimestampedData; | 30 TimestampedData; |
31 import 'package:analyzer/src/generated/error.dart'; | 31 import 'package:analyzer/src/generated/error.dart'; |
32 import 'package:analyzer/src/generated/html.dart' as ht; | 32 import 'package:analyzer/src/generated/html.dart' as ht; |
33 import 'package:analyzer/src/generated/java_engine.dart'; | 33 import 'package:analyzer/src/generated/java_engine.dart'; |
34 import 'package:analyzer/src/generated/resolver.dart'; | 34 import 'package:analyzer/src/generated/resolver.dart'; |
35 import 'package:analyzer/src/generated/scanner.dart'; | 35 import 'package:analyzer/src/generated/scanner.dart'; |
36 import 'package:analyzer/src/generated/source.dart'; | 36 import 'package:analyzer/src/generated/source.dart'; |
| 37 import 'package:analyzer/src/task/dart.dart'; |
37 import 'package:analyzer/task/dart.dart'; | 38 import 'package:analyzer/task/dart.dart'; |
38 import 'package:unittest/unittest.dart'; | 39 import 'package:unittest/unittest.dart'; |
39 import 'package:watcher/src/utils.dart'; | 40 import 'package:watcher/src/utils.dart'; |
40 | 41 |
41 import '../../generated/engine_test.dart'; | 42 import '../../generated/engine_test.dart'; |
42 import '../../generated/test_support.dart'; | 43 import '../../generated/test_support.dart'; |
43 import '../../reflective_tests.dart'; | 44 import '../../reflective_tests.dart'; |
44 import 'abstract_context.dart'; | 45 import 'abstract_context.dart'; |
45 | 46 |
46 main() { | 47 main() { |
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 | 1227 |
1227 void test_dispose() { | 1228 void test_dispose() { |
1228 expect(context.isDisposed, isFalse); | 1229 expect(context.isDisposed, isFalse); |
1229 context.dispose(); | 1230 context.dispose(); |
1230 expect(context.isDisposed, isTrue); | 1231 expect(context.isDisposed, isTrue); |
1231 } | 1232 } |
1232 | 1233 |
1233 void test_ensureResolvedDartUnits_definingUnit_hasResolved() { | 1234 void test_ensureResolvedDartUnits_definingUnit_hasResolved() { |
1234 Source source = addSource('/test.dart', ''); | 1235 Source source = addSource('/test.dart', ''); |
1235 LibrarySpecificUnit libTarget = new LibrarySpecificUnit(source, source); | 1236 LibrarySpecificUnit libTarget = new LibrarySpecificUnit(source, source); |
1236 analysisDriver.computeResult(libTarget, RESOLVED_UNIT); | 1237 analysisDriver.computeResult(libTarget, RESOLVED_UNIT6); |
1237 CompilationUnit unit = | 1238 CompilationUnit unit = |
1238 context.getCacheEntry(libTarget).getValue(RESOLVED_UNIT); | 1239 context.getCacheEntry(libTarget).getValue(RESOLVED_UNIT6); |
1239 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); | 1240 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); |
1240 expect(units, unorderedEquals([unit])); | 1241 expect(units, unorderedEquals([unit])); |
1241 } | 1242 } |
1242 | 1243 |
1243 void test_ensureResolvedDartUnits_definingUnit_notResolved() { | 1244 void test_ensureResolvedDartUnits_definingUnit_notResolved() { |
1244 Source source = addSource('/test.dart', ''); | 1245 Source source = addSource('/test.dart', ''); |
1245 LibrarySpecificUnit libTarget = new LibrarySpecificUnit(source, source); | 1246 LibrarySpecificUnit libTarget = new LibrarySpecificUnit(source, source); |
1246 analysisDriver.computeResult(libTarget, RESOLVED_UNIT); | 1247 analysisDriver.computeResult(libTarget, RESOLVED_UNIT6); |
1247 // flush | 1248 // flush |
1248 context.getCacheEntry(libTarget).setState( | 1249 context.getCacheEntry(libTarget).setState( |
1249 RESOLVED_UNIT, CacheState.FLUSHED); | 1250 RESOLVED_UNIT6, CacheState.FLUSHED); |
1250 // schedule recomputing | 1251 // schedule recomputing |
1251 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); | 1252 List<CompilationUnit> units = context.ensureResolvedDartUnits(source); |
1252 expect(units, isNull); | 1253 expect(units, isNull); |
1253 // should be the next result to compute | 1254 // should be the next result to compute |
1254 TargetedResult nextResult = context.dartWorkManager.getNextResult(); | 1255 TargetedResult nextResult = context.dartWorkManager.getNextResult(); |
1255 expect(nextResult.target, libTarget); | 1256 expect(nextResult.target, libTarget); |
1256 expect(nextResult.result, RESOLVED_UNIT); | 1257 expect(nextResult.result, RESOLVED_UNIT6); |
1257 } | 1258 } |
1258 | 1259 |
1259 void test_ensureResolvedDartUnits_partUnit_notResolved() { | 1260 void test_ensureResolvedDartUnits_partUnit_notResolved() { |
1260 Source libSource1 = addSource('/lib1.dart', r''' | 1261 Source libSource1 = addSource('/lib1.dart', r''' |
1261 library lib; | 1262 library lib; |
1262 part 'part.dart'; | 1263 part 'part.dart'; |
1263 '''); | 1264 '''); |
1264 Source libSource2 = addSource('/lib2.dart', r''' | 1265 Source libSource2 = addSource('/lib2.dart', r''' |
1265 library lib; | 1266 library lib; |
1266 part 'part.dart'; | 1267 part 'part.dart'; |
1267 '''); | 1268 '''); |
1268 Source partSource = addSource('/part.dart', r''' | 1269 Source partSource = addSource('/part.dart', r''' |
1269 part of lib; | 1270 part of lib; |
1270 '''); | 1271 '''); |
1271 LibrarySpecificUnit partTarget1 = | 1272 LibrarySpecificUnit partTarget1 = |
1272 new LibrarySpecificUnit(libSource1, partSource); | 1273 new LibrarySpecificUnit(libSource1, partSource); |
1273 LibrarySpecificUnit partTarget2 = | 1274 LibrarySpecificUnit partTarget2 = |
1274 new LibrarySpecificUnit(libSource2, partSource); | 1275 new LibrarySpecificUnit(libSource2, partSource); |
1275 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT); | 1276 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT6); |
1276 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT); | 1277 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT6); |
1277 // flush | 1278 // flush |
1278 context.getCacheEntry(partTarget1).setState( | 1279 context.getCacheEntry(partTarget1).setState( |
1279 RESOLVED_UNIT, CacheState.FLUSHED); | 1280 RESOLVED_UNIT6, CacheState.FLUSHED); |
1280 context.getCacheEntry(partTarget2).setState( | 1281 context.getCacheEntry(partTarget2).setState( |
1281 RESOLVED_UNIT, CacheState.FLUSHED); | 1282 RESOLVED_UNIT6, CacheState.FLUSHED); |
1282 // schedule recomputing | 1283 // schedule recomputing |
1283 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); | 1284 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); |
1284 expect(units, isNull); | 1285 expect(units, isNull); |
1285 // should be the next result to compute | 1286 // should be the next result to compute |
1286 TargetedResult nextResult = context.dartWorkManager.getNextResult(); | 1287 TargetedResult nextResult = context.dartWorkManager.getNextResult(); |
1287 expect(nextResult.target, anyOf(partTarget1, partTarget2)); | 1288 expect(nextResult.target, anyOf(partTarget1, partTarget2)); |
1288 expect(nextResult.result, RESOLVED_UNIT); | 1289 expect(nextResult.result, RESOLVED_UNIT6); |
1289 } | 1290 } |
1290 | 1291 |
1291 void test_ensureResolvedDartUnits_partUnit_hasResolved() { | 1292 void test_ensureResolvedDartUnits_partUnit_hasResolved() { |
1292 Source libSource1 = addSource('/lib1.dart', r''' | 1293 Source libSource1 = addSource('/lib1.dart', r''' |
1293 library lib; | 1294 library lib; |
1294 part 'part.dart'; | 1295 part 'part.dart'; |
1295 '''); | 1296 '''); |
1296 Source libSource2 = addSource('/lib2.dart', r''' | 1297 Source libSource2 = addSource('/lib2.dart', r''' |
1297 library lib; | 1298 library lib; |
1298 part 'part.dart'; | 1299 part 'part.dart'; |
1299 '''); | 1300 '''); |
1300 Source partSource = addSource('/part.dart', r''' | 1301 Source partSource = addSource('/part.dart', r''' |
1301 part of lib; | 1302 part of lib; |
1302 '''); | 1303 '''); |
1303 LibrarySpecificUnit partTarget1 = | 1304 LibrarySpecificUnit partTarget1 = |
1304 new LibrarySpecificUnit(libSource1, partSource); | 1305 new LibrarySpecificUnit(libSource1, partSource); |
1305 LibrarySpecificUnit partTarget2 = | 1306 LibrarySpecificUnit partTarget2 = |
1306 new LibrarySpecificUnit(libSource2, partSource); | 1307 new LibrarySpecificUnit(libSource2, partSource); |
1307 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT); | 1308 analysisDriver.computeResult(partTarget1, RESOLVED_UNIT6); |
1308 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT); | 1309 analysisDriver.computeResult(partTarget2, RESOLVED_UNIT6); |
1309 CompilationUnit unit1 = | 1310 CompilationUnit unit1 = |
1310 context.getCacheEntry(partTarget1).getValue(RESOLVED_UNIT); | 1311 context.getCacheEntry(partTarget1).getValue(RESOLVED_UNIT6); |
1311 CompilationUnit unit2 = | 1312 CompilationUnit unit2 = |
1312 context.getCacheEntry(partTarget2).getValue(RESOLVED_UNIT); | 1313 context.getCacheEntry(partTarget2).getValue(RESOLVED_UNIT6); |
1313 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); | 1314 List<CompilationUnit> units = context.ensureResolvedDartUnits(partSource); |
1314 expect(units, unorderedEquals([unit1, unit2])); | 1315 expect(units, unorderedEquals([unit1, unit2])); |
1315 } | 1316 } |
1316 | 1317 |
1317 void test_exists_false() { | 1318 void test_exists_false() { |
1318 TestSource source = new TestSource(); | 1319 TestSource source = new TestSource(); |
1319 source.exists2 = false; | 1320 source.exists2 = false; |
1320 expect(context.exists(source), isFalse); | 1321 expect(context.exists(source), isFalse); |
1321 } | 1322 } |
1322 | 1323 |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2027 for (ClassElement classElement in unit.types) { | 2028 for (ClassElement classElement in unit.types) { |
2028 if (classElement.displayName == className) { | 2029 if (classElement.displayName == className) { |
2029 return classElement; | 2030 return classElement; |
2030 } | 2031 } |
2031 } | 2032 } |
2032 return null; | 2033 return null; |
2033 } | 2034 } |
2034 | 2035 |
2035 void _flushAst(Source source) { | 2036 void _flushAst(Source source) { |
2036 CacheEntry entry = context.getReadableSourceEntryOrNull(new LibrarySpecificU
nit(source, source)); | 2037 CacheEntry entry = context.getReadableSourceEntryOrNull(new LibrarySpecificU
nit(source, source)); |
2037 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); | 2038 entry.setState(RESOLVED_UNIT6, CacheState.FLUSHED); |
2038 } | 2039 } |
2039 | 2040 |
2040 IncrementalAnalysisCache _getIncrementalAnalysisCache( | 2041 IncrementalAnalysisCache _getIncrementalAnalysisCache( |
2041 AnalysisContextImpl context2) { | 2042 AnalysisContextImpl context2) { |
2042 return context2.test_incrementalAnalysisCache; | 2043 return context2.test_incrementalAnalysisCache; |
2043 } | 2044 } |
2044 | 2045 |
2045 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { | 2046 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { |
2046 return context2.test_priorityOrder; | 2047 return context2.test_priorityOrder; |
2047 } | 2048 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 : super(name, UriKind.FILE_URI); | 2119 : super(name, UriKind.FILE_URI); |
2119 | 2120 |
2120 @override | 2121 @override |
2121 TimestampedData<String> get contents { | 2122 TimestampedData<String> get contents { |
2122 throw 'Read error'; | 2123 throw 'Read error'; |
2123 } | 2124 } |
2124 | 2125 |
2125 @override | 2126 @override |
2126 bool exists() => true; | 2127 bool exists() => true; |
2127 } | 2128 } |
OLD | NEW |