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.src.context.context_test; | 5 library analyzer.test.src.context.context_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
12 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
13 import 'package:analyzer/dart/element/visitor.dart'; | 13 import 'package:analyzer/dart/element/visitor.dart'; |
| 14 import 'package:analyzer/file_system/file_system.dart'; |
14 import 'package:analyzer/file_system/memory_file_system.dart'; | 15 import 'package:analyzer/file_system/memory_file_system.dart'; |
15 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
16 import 'package:analyzer/src/cancelable_future.dart'; | 17 import 'package:analyzer/src/cancelable_future.dart'; |
17 import 'package:analyzer/src/context/cache.dart'; | 18 import 'package:analyzer/src/context/cache.dart'; |
18 import 'package:analyzer/src/context/context.dart'; | 19 import 'package:analyzer/src/context/context.dart'; |
19 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 20 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
20 import 'package:analyzer/src/generated/engine.dart'; | 21 import 'package:analyzer/src/generated/engine.dart'; |
21 import 'package:analyzer/src/generated/error.dart'; | 22 import 'package:analyzer/src/generated/error.dart'; |
22 import 'package:analyzer/src/generated/java_engine.dart'; | 23 import 'package:analyzer/src/generated/java_engine.dart'; |
23 import 'package:analyzer/src/generated/resolver.dart'; | 24 import 'package:analyzer/src/generated/resolver.dart'; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 changeSet2.addedSource(source2); | 273 changeSet2.addedSource(source2); |
273 changeSet2.changedRange(source, 'library test;', 0, 0, 13); | 274 changeSet2.changedRange(source, 'library test;', 0, 0, 13); |
274 context.applyChanges(changeSet2); | 275 context.applyChanges(changeSet2); |
275 return pumpEventQueue().then((_) { | 276 return pumpEventQueue().then((_) { |
276 listener.assertEvent(wereSourcesAdded: true); | 277 listener.assertEvent(wereSourcesAdded: true); |
277 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | 278 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
278 listener.assertNoMoreEvents(); | 279 listener.assertNoMoreEvents(); |
279 }); | 280 }); |
280 } | 281 } |
281 | 282 |
| 283 void test_applyChanges_changedSource_updateModificationTime() { |
| 284 String path = '/test.dart'; |
| 285 File file = resourceProvider.newFile(path, 'var V = 1;'); |
| 286 Source source = file.createSource(); |
| 287 context.applyChanges(new ChangeSet()..addedSource(source)); |
| 288 // Analyze all. |
| 289 _analyzeAll_assertFinished(); |
| 290 expect(context.analysisCache.getState(source, RESOLVED_UNIT), |
| 291 CacheState.INVALID); |
| 292 // Update the file and notify the context about the change. |
| 293 resourceProvider.updateFile(path, 'var V = 2;'); |
| 294 context.applyChanges(new ChangeSet()..changedSource(source)); |
| 295 // The analysis results are invalidated. |
| 296 // We have seen the new contents, so 'modificationTime' is also updated. |
| 297 expect(context.analysisCache.getState(source, RESOLVED_UNIT), |
| 298 CacheState.INVALID); |
| 299 expect( |
| 300 context.getCacheEntry(source).modificationTime, file.modificationStamp); |
| 301 } |
| 302 |
282 void test_applyChanges_empty() { | 303 void test_applyChanges_empty() { |
283 context.applyChanges(new ChangeSet()); | 304 context.applyChanges(new ChangeSet()); |
284 expect(context.performAnalysisTask().changeNotices, isNull); | 305 expect(context.performAnalysisTask().changeNotices, isNull); |
285 } | 306 } |
286 | 307 |
287 void test_applyChanges_overriddenSource() { | 308 void test_applyChanges_overriddenSource() { |
288 String content = "library test;"; | 309 String content = "library test;"; |
289 Source source = addSource("/test.dart", content); | 310 Source source = addSource("/test.dart", content); |
290 context.setContents(source, content); | 311 context.setContents(source, content); |
291 context.computeErrors(source); | 312 context.computeErrors(source); |
(...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 TestSource source = _addSourceWithException2("/test.dart", "library test;"); | 2136 TestSource source = _addSourceWithException2("/test.dart", "library test;"); |
2116 source.generateExceptionOnRead = false; | 2137 source.generateExceptionOnRead = false; |
2117 _analyzeAll_assertFinished(); | 2138 _analyzeAll_assertFinished(); |
2118 expect(source.readCount, 2); | 2139 expect(source.readCount, 2); |
2119 _changeSource(source, ""); | 2140 _changeSource(source, ""); |
2120 source.generateExceptionOnRead = true; | 2141 source.generateExceptionOnRead = true; |
2121 _analyzeAll_assertFinished(); | 2142 _analyzeAll_assertFinished(); |
2122 if (context.analysisOptions.finerGrainedInvalidation) { | 2143 if (context.analysisOptions.finerGrainedInvalidation) { |
2123 expect(source.readCount, 7); | 2144 expect(source.readCount, 7); |
2124 } else { | 2145 } else { |
2125 expect(source.readCount, 4); | 2146 expect(source.readCount, 5); |
2126 } | 2147 } |
2127 } | 2148 } |
2128 | 2149 |
2129 void test_performAnalysisTask_missingPart() { | 2150 void test_performAnalysisTask_missingPart() { |
2130 Source source = | 2151 Source source = |
2131 addSource("/test.dart", "library lib; part 'no-such-file.dart';"); | 2152 addSource("/test.dart", "library lib; part 'no-such-file.dart';"); |
2132 _analyzeAll_assertFinished(); | 2153 _analyzeAll_assertFinished(); |
2133 expect(context.getLibraryElement(source), isNotNull, | 2154 expect(context.getLibraryElement(source), isNotNull, |
2134 reason: "performAnalysisTask failed to compute an element model"); | 2155 reason: "performAnalysisTask failed to compute an element model"); |
2135 } | 2156 } |
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3975 * Initialize the visitor. | 3996 * Initialize the visitor. |
3976 */ | 3997 */ |
3977 _ElementGatherer(); | 3998 _ElementGatherer(); |
3978 | 3999 |
3979 @override | 4000 @override |
3980 void visitElement(Element element) { | 4001 void visitElement(Element element) { |
3981 elements[element] = element; | 4002 elements[element] = element; |
3982 super.visitElement(element); | 4003 super.visitElement(element); |
3983 } | 4004 } |
3984 } | 4005 } |
OLD | NEW |