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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/declaration_resolver.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 engine.declaration_resolver_test; 5 library engine.declaration_resolver_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/dart/ast/ast.dart'; 9 import 'package:analyzer/src/dart/ast/ast.dart';
10 import 'package:analyzer/src/dart/ast/utilities.dart'; 10 import 'package:analyzer/src/dart/ast/utilities.dart';
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 setupCode('@a enum E { v }'); 94 setupCode('@a enum E { v }');
95 checkMetadata('E'); 95 checkMetadata('E');
96 } 96 }
97 97
98 void test_metadata_exportDirective() { 98 void test_metadata_exportDirective() {
99 addNamedSource('/foo.dart', 'class C {}'); 99 addNamedSource('/foo.dart', 'class C {}');
100 setupCode('@a export "foo.dart";'); 100 setupCode('@a export "foo.dart";');
101 checkMetadata('export'); 101 checkMetadata('export');
102 } 102 }
103 103
104 void test_metadata_exportDirective_resynthesized() {
105 CompilationUnit unit = resolveSource(r'''
106 @a
107 export "dart:async";
108
109 @b
110 export "dart:math";
111
112 const a = null;
113 const b = null;
114 ''');
115 expect(unit.directives[0].metadata.single.name.name, 'a');
116 expect(unit.directives[1].metadata.single.name.name, 'b');
117 var unitElement = unit.element as CompilationUnitElementImpl;
118 // Damage the unit element - as if "setAnnotations" were not called.
119 // The ImportElement(s) still have the metadata, we should use it.
120 unitElement.setAnnotations(unit.directives[0].offset, []);
121 unitElement.setAnnotations(unit.directives[1].offset, []);
122 expect(unitElement.library.exports[0].metadata, hasLength(1));
123 expect(unitElement.library.exports[1].metadata, hasLength(1));
124 // DeclarationResolver on the clone should succeed.
125 CompilationUnit clonedUnit = AstCloner.clone(unit);
126 new DeclarationResolver().resolve(clonedUnit, unit.element);
127 expect(unit.directives[0].metadata.single.name.name, 'a');
128 expect(unit.directives[1].metadata.single.name.name, 'b');
129 }
130
104 void test_metadata_fieldDeclaration() { 131 void test_metadata_fieldDeclaration() {
105 setupCode('class C { @a int x; }'); 132 setupCode('class C { @a int x; }');
106 checkMetadata('x'); 133 checkMetadata('x');
107 } 134 }
108 135
109 void test_metadata_fieldFormalParameter() { 136 void test_metadata_fieldFormalParameter() {
110 setupCode('class C { var x; C(@a this.x); }'); 137 setupCode('class C { var x; C(@a this.x); }');
111 checkMetadata('this'); 138 checkMetadata('this');
112 } 139 }
113 140
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 addNamedSource('/foo.dart', 'class C {}'); 183 addNamedSource('/foo.dart', 'class C {}');
157 this.code = 'const a = null; @a import "foo.dart";'; 184 this.code = 'const a = null; @a import "foo.dart";';
158 Source source = addNamedSource('/test.dart', code); 185 Source source = addNamedSource('/test.dart', code);
159 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 186 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
160 analysisContext.computeResult(source, LIBRARY_ELEMENT1); 187 analysisContext.computeResult(source, LIBRARY_ELEMENT1);
161 unit = analysisContext.computeResult(target, RESOLVED_UNIT1); 188 unit = analysisContext.computeResult(target, RESOLVED_UNIT1);
162 unit2 = _cloneResolveUnit(unit); 189 unit2 = _cloneResolveUnit(unit);
163 checkMetadata('import'); 190 checkMetadata('import');
164 } 191 }
165 192
193 void test_metadata_importDirective_resynthesized() {
194 CompilationUnit unit = resolveSource(r'''
195 @a
196 import "dart:async";
197
198 @b
199 import "dart:math";
200
201 const a = null;
202 const b = null;
203 ''');
204 expect(unit.directives[0].metadata.single.name.name, 'a');
205 expect(unit.directives[1].metadata.single.name.name, 'b');
206 var unitElement = unit.element as CompilationUnitElementImpl;
207 // Damage the unit element - as if "setAnnotations" were not called.
208 // The ImportElement(s) still have the metadata, we should use it.
209 unitElement.setAnnotations(unit.directives[0].offset, []);
210 unitElement.setAnnotations(unit.directives[1].offset, []);
211 expect(unitElement.library.imports[0].metadata, hasLength(1));
212 expect(unitElement.library.imports[1].metadata, hasLength(1));
213 // DeclarationResolver on the clone should succeed.
214 CompilationUnit clonedUnit = AstCloner.clone(unit);
215 new DeclarationResolver().resolve(clonedUnit, unit.element);
216 expect(unit.directives[0].metadata.single.name.name, 'a');
217 expect(unit.directives[1].metadata.single.name.name, 'b');
218 }
219
166 void test_metadata_libraryDirective() { 220 void test_metadata_libraryDirective() {
167 setupCode('@a library L;'); 221 setupCode('@a library L;');
168 checkMetadata('L'); 222 checkMetadata('L');
169 } 223 }
170 224
171 void test_metadata_libraryDirective_resynthesized() { 225 void test_metadata_libraryDirective_resynthesized() {
172 CompilationUnit unit = resolveSource('@a library L; const a = null;'); 226 CompilationUnit unit = resolveSource('@a library L; const a = null;');
173 expect(unit.directives.single.metadata.single.name.name, 'a'); 227 expect(unit.directives.single.metadata.single.name.name, 'a');
174 var unitElement = unit.element as CompilationUnitElementImpl; 228 var unitElement = unit.element as CompilationUnitElementImpl;
175 // Damage the unit element - as if "setAnnotations" were not called. 229 // Damage the unit element - as if "setAnnotations" were not called.
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 expect(element.type.toString(), "<T>(T, T) → T"); 676 expect(element.type.toString(), "<T>(T, T) → T");
623 expect(t.element, same(tElement)); 677 expect(t.element, same(tElement));
624 678
625 // re-resolve 679 // re-resolve
626 CompilationUnit unit2 = _cloneResolveUnit(unit); 680 CompilationUnit unit2 = _cloneResolveUnit(unit);
627 node = _findSimpleIdentifier(unit2, code, 'max').parent; 681 node = _findSimpleIdentifier(unit2, code, 'max').parent;
628 t = node.typeParameters.typeParameters[0]; 682 t = node.typeParameters.typeParameters[0];
629 expect(t.element, same(tElement)); 683 expect(t.element, same(tElement));
630 } 684 }
631 } 685 }
OLDNEW
« 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