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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1665683002: Revert "Create ElementAnnotation objects prior to resolution." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.task.dart_test; 5 library analyzer.test.src.task.dart_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 void _performBuildTask(String content) { 235 void _performBuildTask(String content) {
236 source = newSource('/test.dart', content); 236 source = newSource('/test.dart', content);
237 target = new LibrarySpecificUnit(source, source); 237 target = new LibrarySpecificUnit(source, source);
238 computeResult(target, RESOLVED_UNIT1, 238 computeResult(target, RESOLVED_UNIT1,
239 matcher: isBuildCompilationUnitElementTask); 239 matcher: isBuildCompilationUnitElementTask);
240 } 240 }
241 } 241 }
242 242
243 @reflectiveTest 243 @reflectiveTest
244 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { 244 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest {
245 /**
246 * Verify that the given [element] has exactly one annotation, and that its
247 * [ElementAnnotationImpl] is unresolved and points back to [element].
248 */
249 void checkMetadata(Element element) {
250 expect(element.metadata, hasLength(1));
251 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>());
252 ElementAnnotationImpl elementAnnotation = element.metadata[0];
253 expect(elementAnnotation.element, isNull); // Not yet resolved
254 expect(elementAnnotation.annotatedElement, element);
255 }
256
257 test_perform() { 245 test_perform() {
258 List<Source> sources = newSources({ 246 List<Source> sources = newSources({
259 '/libA.dart': ''' 247 '/libA.dart': '''
260 library libA; 248 library libA;
261 import 'libB.dart'; 249 import 'libB.dart';
262 export 'libC.dart'; 250 export 'libC.dart';
263 ''', 251 ''',
264 '/libB.dart': ''' 252 '/libB.dart': '''
265 library libB; 253 library libB;
266 ''', 254 ''',
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 expect(importElementB.prefixOffset, prefixElement.nameOffset); 462 expect(importElementB.prefixOffset, prefixElement.nameOffset);
475 expect(prefixNodeB.staticElement, prefixElement); 463 expect(prefixNodeB.staticElement, prefixElement);
476 // PrefixElement "pref" is shared 464 // PrefixElement "pref" is shared
477 ImportDirective importNodeC = libraryUnitA.directives[2]; 465 ImportDirective importNodeC = libraryUnitA.directives[2];
478 SimpleIdentifier prefixNodeC = importNodeC.prefix; 466 SimpleIdentifier prefixNodeC = importNodeC.prefix;
479 ImportElement importElementC = importNodeC.element; 467 ImportElement importElementC = importNodeC.element;
480 expect(prefixNodeC.staticElement, prefixElement); 468 expect(prefixNodeC.staticElement, prefixElement);
481 expect(importElementC.prefix, prefixElement); 469 expect(importElementC.prefix, prefixElement);
482 } 470 }
483 471
484 test_perform_metadata() {
485 List<Source> sources = newSources({
486 '/libA.dart': '''
487 @a library libA;
488 @b import 'libB.dart';
489 @c export 'libC.dart';
490 @d part 'part.dart';''',
491 '/libB.dart': 'library libB;',
492 '/libC.dart': 'library libC;',
493 '/part.dart': '@e part of libA;'
494 });
495 Source sourceA = sources[0];
496 Source sourceD = sources[3];
497 // perform task
498 computeResult(sourceA, LIBRARY_ELEMENT2,
499 matcher: isBuildDirectiveElementsTask);
500 // Get outputs
501 LibraryElement libraryA =
502 context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2);
503 CompilationUnit part = context
504 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceD))
505 .getValue(RESOLVED_UNIT1);
506 // Validate metadata
507 checkMetadata(libraryA);
508 checkMetadata(libraryA.imports[0]);
509 checkMetadata(libraryA.exports[0]);
510 checkMetadata(libraryA.parts[0]);
511 expect(part.directives[0], new isInstanceOf<PartOfDirective>());
512 checkMetadata(part.directives[0].element);
513 }
514
515 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { 472 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) {
516 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); 473 _fillErrorListener(BUILD_DIRECTIVES_ERRORS);
517 errorListener.assertErrorsWithCodes(expectedErrorCodes); 474 errorListener.assertErrorsWithCodes(expectedErrorCodes);
518 } 475 }
519 476
520 _getExportLibraryInput(Source source) { 477 _getExportLibraryInput(Source source) {
521 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME; 478 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME;
522 return task.inputs[key][source]; 479 return task.inputs[key][source];
523 } 480 }
524 481
(...skipping 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after
4922 /** 4879 /**
4923 * Fill [errorListener] with [result] errors in the current [task]. 4880 * Fill [errorListener] with [result] errors in the current [task].
4924 */ 4881 */
4925 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 4882 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
4926 List<AnalysisError> errors = task.outputs[result]; 4883 List<AnalysisError> errors = task.outputs[result];
4927 expect(errors, isNotNull, reason: result.name); 4884 expect(errors, isNotNull, reason: result.name);
4928 errorListener = new GatheringErrorListener(); 4885 errorListener = new GatheringErrorListener();
4929 errorListener.addAll(errors); 4886 errorListener.addAll(errors);
4930 } 4887 }
4931 } 4888 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698