Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 2229603003: Extract unresolved AST parsing (PARSED_UNIT1) from full parsing, which includes UriBasedDirective(s… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update task graph. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
158 Future test_applyChanges_change() { 195 Future test_applyChanges_change() {
159 SourcesChangedListener listener = new SourcesChangedListener(); 196 SourcesChangedListener listener = new SourcesChangedListener();
160 context.onSourcesChanged.listen(listener.onData); 197 context.onSourcesChanged.listen(listener.onData);
161 expect(context.sourcesNeedingProcessing, isEmpty); 198 expect(context.sourcesNeedingProcessing, isEmpty);
162 Source source = newSource('/test.dart'); 199 Source source = newSource('/test.dart');
163 ChangeSet changeSet1 = new ChangeSet(); 200 ChangeSet changeSet1 = new ChangeSet();
164 changeSet1.addedSource(source); 201 changeSet1.addedSource(source);
165 context.applyChanges(changeSet1); 202 context.applyChanges(changeSet1);
166 expect(context.sourcesNeedingProcessing, contains(source)); 203 expect(context.sourcesNeedingProcessing, contains(source));
167 Source source2 = newSource('/test2.dart'); 204 Source source2 = newSource('/test2.dart');
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // The reason is that a.dart adds dependencies on (not existing) b.dart 517 // The reason is that a.dart adds dependencies on (not existing) b.dart
481 // results in cache. 518 // results in cache.
482 // Now a.dart does not have errors. 519 // Now a.dart does not have errors.
483 addSource('/b.dart', codeB); 520 addSource('/b.dart', codeB);
484 expect(getErrorsState(a), CacheState.INVALID); 521 expect(getErrorsState(a), CacheState.INVALID);
485 _performPendingAnalysisTasks(); 522 _performPendingAnalysisTasks();
486 expect(getErrorsState(a), CacheState.VALID); 523 expect(getErrorsState(a), CacheState.VALID);
487 expect(context.getErrors(a).errors, hasLength(0)); 524 expect(context.getErrors(a).errors, hasLength(0));
488 } 525 }
489 526
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 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 Set<String> libraryElementUris = new Set<String>(); 2292 Set<String> libraryElementUris = new Set<String>();
2293 Set<String> parsedUnitUris = new Set<String>(); 2293 Set<String> parsedUnitUris = new Set<String>();
2294 Set<String> resolvedUnitUris = new Set<String>(); 2294 Set<String> resolvedUnitUris = new Set<String>();
2295 // listen 2295 // listen
2296 context.onResultChanged(LIBRARY_ELEMENT).listen((event) { 2296 context.onResultChanged(LIBRARY_ELEMENT).listen((event) {
2297 expect(event.wasComputed, isTrue); 2297 expect(event.wasComputed, isTrue);
2298 expect(event.wasInvalidated, isFalse); 2298 expect(event.wasInvalidated, isFalse);
2299 Source librarySource = event.target; 2299 Source librarySource = event.target;
2300 libraryElementUris.add(librarySource.uri.toString()); 2300 libraryElementUris.add(librarySource.uri.toString());
2301 }); 2301 });
2302 context.onResultChanged(PARSED_UNIT).listen((event) { 2302 context.onResultChanged(PARSED_UNIT1).listen((event) {
2303 expect(event.wasComputed, isTrue); 2303 expect(event.wasComputed, isTrue);
2304 expect(event.wasInvalidated, isFalse); 2304 expect(event.wasInvalidated, isFalse);
2305 Source source = event.target; 2305 Source source = event.target;
2306 parsedUnitUris.add(source.uri.toString()); 2306 parsedUnitUris.add(source.uri.toString());
2307 }); 2307 });
2308 context.onResultChanged(RESOLVED_UNIT).listen((event) { 2308 context.onResultChanged(RESOLVED_UNIT).listen((event) {
2309 expect(event.wasComputed, isTrue); 2309 expect(event.wasComputed, isTrue);
2310 expect(event.wasInvalidated, isFalse); 2310 expect(event.wasInvalidated, isFalse);
2311 LibrarySpecificUnit target = event.target; 2311 LibrarySpecificUnit target = event.target;
2312 Source librarySource = target.library; 2312 Source librarySource = target.library;
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
3753 { 3754 {
3754 Expression argument = find42(); 3755 Expression argument = find42();
3755 expect(argument.staticParameterElement, isNull); 3756 expect(argument.staticParameterElement, isNull);
3756 expect(argument.propagatedParameterElement, isNotNull); 3757 expect(argument.propagatedParameterElement, isNotNull);
3757 } 3758 }
3758 // Update a.dart: add type annotation for 'a'. 3759 // Update a.dart: add type annotation for 'a'.
3759 // '42' has 'staticParameterElement', but not 'propagatedParameterElement'. 3760 // '42' has 'staticParameterElement', but not 'propagatedParameterElement'.
3760 context.setContents( 3761 context.setContents(
3761 a, 3762 a,
3762 r''' 3763 r'''
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
4976 _assertValidUnits(unit, null); 4977 _assertValidUnits(unit, null);
4977 _assertUnitValidTaskResults(unit, ResolveUnitTypeNamesTask.DESCRIPTOR); 4978 _assertUnitValidTaskResults(unit, ResolveUnitTypeNamesTask.DESCRIPTOR);
4978 _assertUnitValidTaskResults(unit, ResolveUnitTask.DESCRIPTOR); 4979 _assertUnitValidTaskResults(unit, ResolveUnitTask.DESCRIPTOR);
4979 _assertValidTaskResults(unit, ResolveLibraryReferencesTask.DESCRIPTOR); 4980 _assertValidTaskResults(unit, ResolveLibraryReferencesTask.DESCRIPTOR);
4980 _assertValidTaskResults(unit, ResolveLibraryTask.DESCRIPTOR); 4981 _assertValidTaskResults(unit, ResolveLibraryTask.DESCRIPTOR);
4981 } 4982 }
4982 4983
4983 void _assertValidForAnyLibrary(Source source) { 4984 void _assertValidForAnyLibrary(Source source) {
4984 // Source results. 4985 // Source results.
4985 _assertValidTaskResults(source, ScanDartTask.DESCRIPTOR); 4986 _assertValidTaskResults(source, ScanDartTask.DESCRIPTOR);
4987 _assertValidTaskResults(source, ParseDartTask.DESCRIPTOR);
4988 _assertValidTaskResults(source, ResolveDirectivesTask.DESCRIPTOR);
4986 // Library results. 4989 // Library results.
4987 _assertValidTaskResults(source, BuildLibraryElementTask.DESCRIPTOR); 4990 _assertValidTaskResults(source, BuildLibraryElementTask.DESCRIPTOR);
4988 _assertValidTaskResults(source, BuildDirectiveElementsTask.DESCRIPTOR); 4991 _assertValidTaskResults(source, BuildDirectiveElementsTask.DESCRIPTOR);
4989 _assertValidTaskResults(source, BuildSourceExportClosureTask.DESCRIPTOR); 4992 _assertValidTaskResults(source, BuildSourceExportClosureTask.DESCRIPTOR);
4990 _assertValidTaskResults(source, ReadyLibraryElement2Task.DESCRIPTOR); 4993 _assertValidTaskResults(source, ReadyLibraryElement2Task.DESCRIPTOR);
4991 _assertValidTaskResults(source, ComputeLibraryCycleTask.DESCRIPTOR); 4994 _assertValidTaskResults(source, ComputeLibraryCycleTask.DESCRIPTOR);
4992 // Unit results. 4995 // Unit results.
4993 _assertUnitValidTaskResults( 4996 _assertUnitValidTaskResults(
4994 source, BuildCompilationUnitElementTask.DESCRIPTOR); 4997 source, BuildCompilationUnitElementTask.DESCRIPTOR);
4995 _assertUnitValidTaskResults( 4998 _assertUnitValidTaskResults(
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
5181 * Initialize the visitor. 5184 * Initialize the visitor.
5182 */ 5185 */
5183 _ElementGatherer(); 5186 _ElementGatherer();
5184 5187
5185 @override 5188 @override
5186 void visitElement(Element element) { 5189 void visitElement(Element element) {
5187 elements[element] = element; 5190 elements[element] = element;
5188 super.visitElement(element); 5191 super.visitElement(element);
5189 } 5192 }
5190 } 5193 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/incremental_resolver_test.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698