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'; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 CacheEntry entry = context.getCacheEntry(source); | 148 CacheEntry entry = context.getCacheEntry(source); |
149 expect(entry.explicitlyAdded, isFalse); | 149 expect(entry.explicitlyAdded, isFalse); |
150 // add the source | 150 // add the source |
151 ChangeSet changeSet = new ChangeSet(); | 151 ChangeSet changeSet = new ChangeSet(); |
152 changeSet.addedSource(source); | 152 changeSet.addedSource(source); |
153 context.applyChanges(changeSet); | 153 context.applyChanges(changeSet); |
154 // now the entry is explicit | 154 // now the entry is explicit |
155 expect(entry.explicitlyAdded, isTrue); | 155 expect(entry.explicitlyAdded, isTrue); |
156 } | 156 } |
157 | 157 |
158 void test_applyChanges_addNewImport_invalidateLibraryCycle() { | |
159 context.analysisOptions = | |
160 new AnalysisOptionsImpl.from(context.analysisOptions) | |
161 ..strongMode = true; | |
162 Source embedder = addSource( | |
163 '/a.dart', | |
164 r''' | |
165 library a; | |
166 import 'b.dart'; | |
167 //import 'c.dart'; | |
168 '''); | |
169 addSource( | |
170 '/b.dart', | |
171 r''' | |
172 library b; | |
173 import 'a.dart'; | |
174 '''); | |
175 addSource( | |
176 '/c.dart', | |
177 r''' | |
178 library c; | |
179 import 'b.dart'; | |
180 '''); | |
181 _performPendingAnalysisTasks(); | |
182 // Add a new import into a.dart, this should invalidate its library cycle. | |
183 // If it doesn't, we will get a task cycle exception. | |
184 context.setContents( | |
185 embedder, | |
186 r''' | |
187 library a; | |
188 import 'b.dart'; | |
189 import 'c.dart'; | |
190 '''); | |
191 _performPendingAnalysisTasks(); | |
192 expect(context.getCacheEntry(embedder).exception, isNull); | |
193 } | |
194 | |
195 Future test_applyChanges_change() { | 158 Future test_applyChanges_change() { |
196 SourcesChangedListener listener = new SourcesChangedListener(); | 159 SourcesChangedListener listener = new SourcesChangedListener(); |
197 context.onSourcesChanged.listen(listener.onData); | 160 context.onSourcesChanged.listen(listener.onData); |
198 expect(context.sourcesNeedingProcessing, isEmpty); | 161 expect(context.sourcesNeedingProcessing, isEmpty); |
199 Source source = newSource('/test.dart'); | 162 Source source = newSource('/test.dart'); |
200 ChangeSet changeSet1 = new ChangeSet(); | 163 ChangeSet changeSet1 = new ChangeSet(); |
201 changeSet1.addedSource(source); | 164 changeSet1.addedSource(source); |
202 context.applyChanges(changeSet1); | 165 context.applyChanges(changeSet1); |
203 expect(context.sourcesNeedingProcessing, contains(source)); | 166 expect(context.sourcesNeedingProcessing, contains(source)); |
204 Source source2 = newSource('/test2.dart'); | 167 Source source2 = newSource('/test2.dart'); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 // The reason is that a.dart adds dependencies on (not existing) b.dart | 480 // The reason is that a.dart adds dependencies on (not existing) b.dart |
518 // results in cache. | 481 // results in cache. |
519 // Now a.dart does not have errors. | 482 // Now a.dart does not have errors. |
520 addSource('/b.dart', codeB); | 483 addSource('/b.dart', codeB); |
521 expect(getErrorsState(a), CacheState.INVALID); | 484 expect(getErrorsState(a), CacheState.INVALID); |
522 _performPendingAnalysisTasks(); | 485 _performPendingAnalysisTasks(); |
523 expect(getErrorsState(a), CacheState.VALID); | 486 expect(getErrorsState(a), CacheState.VALID); |
524 expect(context.getErrors(a).errors, hasLength(0)); | 487 expect(context.getErrors(a).errors, hasLength(0)); |
525 } | 488 } |
526 | 489 |
| 490 void test_applyChanges_addNewImport_invalidateLibraryCycle() { |
| 491 context.analysisOptions = |
| 492 new AnalysisOptionsImpl.from(context.analysisOptions) |
| 493 ..strongMode = true; |
| 494 Source embedder = addSource( |
| 495 '/a.dart', |
| 496 r''' |
| 497 library a; |
| 498 import 'b.dart'; |
| 499 //import 'c.dart'; |
| 500 '''); |
| 501 addSource( |
| 502 '/b.dart', |
| 503 r''' |
| 504 library b; |
| 505 import 'a.dart'; |
| 506 '''); |
| 507 addSource( |
| 508 '/c.dart', |
| 509 r''' |
| 510 library c; |
| 511 import 'b.dart'; |
| 512 '''); |
| 513 _performPendingAnalysisTasks(); |
| 514 // Add a new import into a.dart, this should invalidate its library cycle. |
| 515 // If it doesn't, we will get a task cycle exception. |
| 516 context.setContents( |
| 517 embedder, |
| 518 r''' |
| 519 library a; |
| 520 import 'b.dart'; |
| 521 import 'c.dart'; |
| 522 '''); |
| 523 _performPendingAnalysisTasks(); |
| 524 expect(context.getCacheEntry(embedder).exception, isNull); |
| 525 } |
| 526 |
527 void test_cacheConsistencyValidator_computed_deleted() { | 527 void test_cacheConsistencyValidator_computed_deleted() { |
528 CacheConsistencyValidator validator = context.cacheConsistencyValidator; | 528 CacheConsistencyValidator validator = context.cacheConsistencyValidator; |
529 var stat = PerformanceStatistics.cacheConsistencyValidationStatistics; | 529 var stat = PerformanceStatistics.cacheConsistencyValidationStatistics; |
530 stat.reset(); | 530 stat.reset(); |
531 // Add sources. | 531 // Add sources. |
532 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 532 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
533 String path1 = '/test1.dart'; | 533 String path1 = '/test1.dart'; |
534 String path2 = '/test2.dart'; | 534 String path2 = '/test2.dart'; |
535 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource(); | 535 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource(); |
536 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource(); | 536 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource(); |
(...skipping 3206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3743 '''); | 3743 '''); |
3744 _performPendingAnalysisTasks(); | 3744 _performPendingAnalysisTasks(); |
3745 Expression find42() { | 3745 Expression find42() { |
3746 CompilationUnit unit = | 3746 CompilationUnit unit = |
3747 context.getResult(new LibrarySpecificUnit(a, a), RESOLVED_UNIT); | 3747 context.getResult(new LibrarySpecificUnit(a, a), RESOLVED_UNIT); |
3748 ExpressionStatement statement = | 3748 ExpressionStatement statement = |
3749 AstFinder.getStatementsInTopLevelFunction(unit, 'main').single; | 3749 AstFinder.getStatementsInTopLevelFunction(unit, 'main').single; |
3750 MethodInvocation invocation = statement.expression; | 3750 MethodInvocation invocation = statement.expression; |
3751 return invocation.argumentList.arguments[0]; | 3751 return invocation.argumentList.arguments[0]; |
3752 } | 3752 } |
3753 | |
3754 { | 3753 { |
3755 Expression argument = find42(); | 3754 Expression argument = find42(); |
3756 expect(argument.staticParameterElement, isNull); | 3755 expect(argument.staticParameterElement, isNull); |
3757 expect(argument.propagatedParameterElement, isNotNull); | 3756 expect(argument.propagatedParameterElement, isNotNull); |
3758 } | 3757 } |
3759 // Update a.dart: add type annotation for 'a'. | 3758 // Update a.dart: add type annotation for 'a'. |
3760 // '42' has 'staticParameterElement', but not 'propagatedParameterElement'. | 3759 // '42' has 'staticParameterElement', but not 'propagatedParameterElement'. |
3761 context.setContents( | 3760 context.setContents( |
3762 a, | 3761 a, |
3763 r''' | 3762 r''' |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4977 _assertValidUnits(unit, null); | 4976 _assertValidUnits(unit, null); |
4978 _assertUnitValidTaskResults(unit, ResolveUnitTypeNamesTask.DESCRIPTOR); | 4977 _assertUnitValidTaskResults(unit, ResolveUnitTypeNamesTask.DESCRIPTOR); |
4979 _assertUnitValidTaskResults(unit, ResolveUnitTask.DESCRIPTOR); | 4978 _assertUnitValidTaskResults(unit, ResolveUnitTask.DESCRIPTOR); |
4980 _assertValidTaskResults(unit, ResolveLibraryReferencesTask.DESCRIPTOR); | 4979 _assertValidTaskResults(unit, ResolveLibraryReferencesTask.DESCRIPTOR); |
4981 _assertValidTaskResults(unit, ResolveLibraryTask.DESCRIPTOR); | 4980 _assertValidTaskResults(unit, ResolveLibraryTask.DESCRIPTOR); |
4982 } | 4981 } |
4983 | 4982 |
4984 void _assertValidForAnyLibrary(Source source) { | 4983 void _assertValidForAnyLibrary(Source source) { |
4985 // Source results. | 4984 // Source results. |
4986 _assertValidTaskResults(source, ScanDartTask.DESCRIPTOR); | 4985 _assertValidTaskResults(source, ScanDartTask.DESCRIPTOR); |
4987 _assertValidTaskResults(source, ParseDartTask.DESCRIPTOR); | |
4988 _assertValidTaskResults(source, ResolveDirectivesTask.DESCRIPTOR); | |
4989 // Library results. | 4986 // Library results. |
4990 _assertValidTaskResults(source, BuildLibraryElementTask.DESCRIPTOR); | 4987 _assertValidTaskResults(source, BuildLibraryElementTask.DESCRIPTOR); |
4991 _assertValidTaskResults(source, BuildDirectiveElementsTask.DESCRIPTOR); | 4988 _assertValidTaskResults(source, BuildDirectiveElementsTask.DESCRIPTOR); |
4992 _assertValidTaskResults(source, BuildSourceExportClosureTask.DESCRIPTOR); | 4989 _assertValidTaskResults(source, BuildSourceExportClosureTask.DESCRIPTOR); |
4993 _assertValidTaskResults(source, ReadyLibraryElement2Task.DESCRIPTOR); | 4990 _assertValidTaskResults(source, ReadyLibraryElement2Task.DESCRIPTOR); |
4994 _assertValidTaskResults(source, ComputeLibraryCycleTask.DESCRIPTOR); | 4991 _assertValidTaskResults(source, ComputeLibraryCycleTask.DESCRIPTOR); |
4995 // Unit results. | 4992 // Unit results. |
4996 _assertUnitValidTaskResults( | 4993 _assertUnitValidTaskResults( |
4997 source, BuildCompilationUnitElementTask.DESCRIPTOR); | 4994 source, BuildCompilationUnitElementTask.DESCRIPTOR); |
4998 _assertUnitValidTaskResults( | 4995 _assertUnitValidTaskResults( |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5184 * Initialize the visitor. | 5181 * Initialize the visitor. |
5185 */ | 5182 */ |
5186 _ElementGatherer(); | 5183 _ElementGatherer(); |
5187 | 5184 |
5188 @override | 5185 @override |
5189 void visitElement(Element element) { | 5186 void visitElement(Element element) { |
5190 elements[element] = element; | 5187 elements[element] = element; |
5191 super.visitElement(element); | 5188 super.visitElement(element); |
5192 } | 5189 } |
5193 } | 5190 } |
OLD | NEW |