| Index: pkg/analyzer/test/src/task/dart_test.dart
|
| diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart
|
| index e351c39f68421478b60cbed0bc30936a683307f8..74e3ce5ccbcef912f5395ede292de70967fca69e 100644
|
| --- a/pkg/analyzer/test/src/task/dart_test.dart
|
| +++ b/pkg/analyzer/test/src/task/dart_test.dart
|
| @@ -242,6 +242,22 @@ class B = Object with A;
|
|
|
| @reflectiveTest
|
| class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest {
|
| + /**
|
| + * Verify that the given [element] has exactly one annotation, and that its
|
| + * [ElementAnnotationImpl] is unresolved and points back to [element].
|
| + *
|
| + * The compilation unit stored in the [ElementAnnotationImpl] should be
|
| + * [compilationUnit].
|
| + */
|
| + void checkMetadata(Element element, CompilationUnitElement compilationUnit) {
|
| + expect(element.metadata, hasLength(1));
|
| + expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>());
|
| + ElementAnnotationImpl elementAnnotation = element.metadata[0];
|
| + expect(elementAnnotation.element, isNull); // Not yet resolved
|
| + expect(elementAnnotation.compilationUnit, isNotNull);
|
| + expect(elementAnnotation.compilationUnit, compilationUnit);
|
| + }
|
| +
|
| test_perform() {
|
| List<Source> sources = newSources({
|
| '/libA.dart': '''
|
| @@ -469,6 +485,59 @@ library libC;
|
| expect(importElementC.prefix, prefixElement);
|
| }
|
|
|
| + test_perform_metadata() {
|
| + List<Source> sources = newSources({
|
| + '/libA.dart': '''
|
| +@a library libA;
|
| +@b import 'libB.dart';
|
| +@c export 'libC.dart';
|
| +@d part 'part.dart';''',
|
| + '/libB.dart': 'library libB;',
|
| + '/libC.dart': 'library libC;',
|
| + '/part.dart': 'part of libA;'
|
| + });
|
| + Source sourceA = sources[0];
|
| + Source sourcePart = sources[3];
|
| + // perform task
|
| + computeResult(sourceA, LIBRARY_ELEMENT2,
|
| + matcher: isBuildDirectiveElementsTask);
|
| + // Get outputs
|
| + LibraryElement libraryA =
|
| + context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2);
|
| + // Validate metadata
|
| + checkMetadata(libraryA, libraryA.definingCompilationUnit);
|
| + checkMetadata(libraryA.imports[0], libraryA.definingCompilationUnit);
|
| + checkMetadata(libraryA.exports[0], libraryA.definingCompilationUnit);
|
| + checkMetadata(libraryA.parts[0], libraryA.definingCompilationUnit);
|
| + }
|
| +
|
| + test_perform_metadata_partOf() {
|
| + // We don't record annotations on `part of` directives because the element
|
| + // associated with a `part of` directive is the library, and the convention
|
| + // is to annotate the library at the site of the `library` declaration.
|
| + List<Source> sources = newSources({
|
| + '/libA.dart': '''
|
| +library libA;
|
| +part 'part.dart';''',
|
| + '/part.dart': '@a part of libA;'
|
| + });
|
| + Source sourceA = sources[0];
|
| + Source sourcePart = sources[1];
|
| + // perform task
|
| + computeResult(sourceA, LIBRARY_ELEMENT2,
|
| + matcher: isBuildDirectiveElementsTask);
|
| + // Get outputs
|
| + LibraryElement libraryA =
|
| + context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2);
|
| + CompilationUnit part = context
|
| + .getCacheEntry(new LibrarySpecificUnit(sourceA, sourcePart))
|
| + .getValue(RESOLVED_UNIT1);
|
| + // Validate metadata
|
| + expect(part.directives[0], new isInstanceOf<PartOfDirective>());
|
| + expect(part.directives[0].element, same(libraryA));
|
| + expect(part.directives[0].element.metadata, isEmpty);
|
| + }
|
| +
|
| void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) {
|
| _fillErrorListener(BUILD_DIRECTIVES_ERRORS);
|
| errorListener.assertErrorsWithCodes(expectedErrorCodes);
|
|
|