OLD | NEW |
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'; |
| 11 import 'package:analyzer/src/dart/element/element.dart'; |
11 import 'package:analyzer/src/generated/declaration_resolver.dart'; | 12 import 'package:analyzer/src/generated/declaration_resolver.dart'; |
12 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
14 import 'package:analyzer/src/task/dart.dart'; | 15 import 'package:analyzer/src/task/dart.dart'; |
15 import 'package:analyzer/task/dart.dart'; | 16 import 'package:analyzer/task/dart.dart'; |
16 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
17 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
18 | 19 |
19 import 'resolver_test_case.dart'; | 20 import 'resolver_test_case.dart'; |
20 import 'test_support.dart'; | 21 import 'test_support.dart'; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 unit = analysisContext.computeResult(target, RESOLVED_UNIT1); | 161 unit = analysisContext.computeResult(target, RESOLVED_UNIT1); |
161 unit2 = _cloneResolveUnit(unit); | 162 unit2 = _cloneResolveUnit(unit); |
162 checkMetadata('import'); | 163 checkMetadata('import'); |
163 } | 164 } |
164 | 165 |
165 void test_metadata_libraryDirective() { | 166 void test_metadata_libraryDirective() { |
166 setupCode('@a library L;'); | 167 setupCode('@a library L;'); |
167 checkMetadata('L'); | 168 checkMetadata('L'); |
168 } | 169 } |
169 | 170 |
| 171 void test_metadata_libraryDirective_resynthesized() { |
| 172 CompilationUnit unit = resolveSource('@a library L; const a = null;'); |
| 173 expect(unit.directives.single.metadata.single.name.name, 'a'); |
| 174 var unitElement = unit.element as CompilationUnitElementImpl; |
| 175 // Damage the unit element - as if "setAnnotations" were not called. |
| 176 // The LibraryElement still has the metadata, we should use it. |
| 177 unitElement.setAnnotations(unit.directives.single.offset, []); |
| 178 expect(unitElement.library.metadata, hasLength(1)); |
| 179 // DeclarationResolver on the clone should succeed. |
| 180 CompilationUnit clonedUnit = AstCloner.clone(unit); |
| 181 new DeclarationResolver().resolve(clonedUnit, unit.element); |
| 182 expect(clonedUnit.directives.single.metadata.single.name.name, 'a'); |
| 183 } |
| 184 |
170 void test_metadata_localFunctionDeclaration() { | 185 void test_metadata_localFunctionDeclaration() { |
171 setupCode('f() { @a g() {} }'); | 186 setupCode('f() { @a g() {} }'); |
172 // Note: metadata on local function declarations is ignored by the | 187 // Note: metadata on local function declarations is ignored by the |
173 // analyzer. TODO(paulberry): is this a bug? | 188 // analyzer. TODO(paulberry): is this a bug? |
174 FunctionDeclaration node = EngineTestCase.findNode( | 189 FunctionDeclaration node = EngineTestCase.findNode( |
175 unit, code, 'g', (AstNode n) => n is FunctionDeclaration); | 190 unit, code, 'g', (AstNode n) => n is FunctionDeclaration); |
176 expect((node as FunctionDeclarationImpl).metadata, isEmpty); | 191 expect((node as FunctionDeclarationImpl).metadata, isEmpty); |
177 } | 192 } |
178 | 193 |
179 void test_metadata_localVariableDeclaration() { | 194 void test_metadata_localVariableDeclaration() { |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 expect(element.type.toString(), "<T>(T, T) → T"); | 618 expect(element.type.toString(), "<T>(T, T) → T"); |
604 expect(t.element, same(tElement)); | 619 expect(t.element, same(tElement)); |
605 | 620 |
606 // re-resolve | 621 // re-resolve |
607 CompilationUnit unit2 = _cloneResolveUnit(unit); | 622 CompilationUnit unit2 = _cloneResolveUnit(unit); |
608 node = _findSimpleIdentifier(unit2, code, 'max').parent; | 623 node = _findSimpleIdentifier(unit2, code, 'max').parent; |
609 t = node.typeParameters.typeParameters[0]; | 624 t = node.typeParameters.typeParameters[0]; |
610 expect(t.element, same(tElement)); | 625 expect(t.element, same(tElement)); |
611 } | 626 } |
612 } | 627 } |
OLD | NEW |