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

Unified Diff: pkg/analyzer/test/generated/declaration_resolver_test.dart

Issue 2508223004: Fix for Import/ExportDirective annotations while applying resynthesized element model. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/declaration_resolver.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/declaration_resolver_test.dart
diff --git a/pkg/analyzer/test/generated/declaration_resolver_test.dart b/pkg/analyzer/test/generated/declaration_resolver_test.dart
index 869d7e0e25b4302c00d727cfe5e48d5060fbe7ae..e75079841dbfefcfcf7cca62baa3a5ecad2260b4 100644
--- a/pkg/analyzer/test/generated/declaration_resolver_test.dart
+++ b/pkg/analyzer/test/generated/declaration_resolver_test.dart
@@ -101,6 +101,33 @@ class DeclarationResolverMetadataTest extends ResolverTestCase {
checkMetadata('export');
}
+ void test_metadata_exportDirective_resynthesized() {
+ CompilationUnit unit = resolveSource(r'''
+@a
+export "dart:async";
+
+@b
+export "dart:math";
+
+const a = null;
+const b = null;
+''');
+ expect(unit.directives[0].metadata.single.name.name, 'a');
+ expect(unit.directives[1].metadata.single.name.name, 'b');
+ var unitElement = unit.element as CompilationUnitElementImpl;
+ // Damage the unit element - as if "setAnnotations" were not called.
+ // The ImportElement(s) still have the metadata, we should use it.
+ unitElement.setAnnotations(unit.directives[0].offset, []);
+ unitElement.setAnnotations(unit.directives[1].offset, []);
+ expect(unitElement.library.exports[0].metadata, hasLength(1));
+ expect(unitElement.library.exports[1].metadata, hasLength(1));
+ // DeclarationResolver on the clone should succeed.
+ CompilationUnit clonedUnit = AstCloner.clone(unit);
+ new DeclarationResolver().resolve(clonedUnit, unit.element);
+ expect(unit.directives[0].metadata.single.name.name, 'a');
+ expect(unit.directives[1].metadata.single.name.name, 'b');
+ }
+
void test_metadata_fieldDeclaration() {
setupCode('class C { @a int x; }');
checkMetadata('x');
@@ -163,6 +190,33 @@ class DeclarationResolverMetadataTest extends ResolverTestCase {
checkMetadata('import');
}
+ void test_metadata_importDirective_resynthesized() {
+ CompilationUnit unit = resolveSource(r'''
+@a
+import "dart:async";
+
+@b
+import "dart:math";
+
+const a = null;
+const b = null;
+''');
+ expect(unit.directives[0].metadata.single.name.name, 'a');
+ expect(unit.directives[1].metadata.single.name.name, 'b');
+ var unitElement = unit.element as CompilationUnitElementImpl;
+ // Damage the unit element - as if "setAnnotations" were not called.
+ // The ImportElement(s) still have the metadata, we should use it.
+ unitElement.setAnnotations(unit.directives[0].offset, []);
+ unitElement.setAnnotations(unit.directives[1].offset, []);
+ expect(unitElement.library.imports[0].metadata, hasLength(1));
+ expect(unitElement.library.imports[1].metadata, hasLength(1));
+ // DeclarationResolver on the clone should succeed.
+ CompilationUnit clonedUnit = AstCloner.clone(unit);
+ new DeclarationResolver().resolve(clonedUnit, unit.element);
+ expect(unit.directives[0].metadata.single.name.name, 'a');
+ expect(unit.directives[1].metadata.single.name.name, 'b');
+ }
+
void test_metadata_libraryDirective() {
setupCode('@a library L;');
checkMetadata('L');
« no previous file with comments | « pkg/analyzer/lib/src/generated/declaration_resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698