Chromium Code Reviews| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 unitElement.setAnnotations(unit.directives[1].offset, []); | 212 unitElement.setAnnotations(unit.directives[1].offset, []); |
| 213 expect(unitElement.library.imports[0].metadata, hasLength(1)); | 213 expect(unitElement.library.imports[0].metadata, hasLength(1)); |
| 214 expect(unitElement.library.imports[1].metadata, hasLength(1)); | 214 expect(unitElement.library.imports[1].metadata, hasLength(1)); |
| 215 // DeclarationResolver on the clone should succeed. | 215 // DeclarationResolver on the clone should succeed. |
| 216 CompilationUnit clonedUnit = AstCloner.clone(unit); | 216 CompilationUnit clonedUnit = AstCloner.clone(unit); |
| 217 new DeclarationResolver().resolve(clonedUnit, unit.element); | 217 new DeclarationResolver().resolve(clonedUnit, unit.element); |
| 218 expect(unit.directives[0].metadata.single.name.name, 'a'); | 218 expect(unit.directives[0].metadata.single.name.name, 'a'); |
| 219 expect(unit.directives[1].metadata.single.name.name, 'b'); | 219 expect(unit.directives[1].metadata.single.name.name, 'b'); |
| 220 } | 220 } |
| 221 | 221 |
| 222 solo_test_metadata_partDirective_resynthesized() async { | |
|
Brian Wilkerson
2017/01/31 19:40:07
Remove "solo_".
| |
| 223 addNamedSource('/part_a.dart', 'part of L;'); | |
| 224 addNamedSource('/part_b.dart', 'part of L;'); | |
| 225 | |
| 226 CompilationUnit unit = await resolveSource(r''' | |
| 227 library L; | |
| 228 | |
| 229 @a | |
| 230 part "part_a.dart"; | |
| 231 | |
| 232 @b | |
| 233 part "part_b.dart"; | |
| 234 | |
| 235 const a = null; | |
| 236 const b = null; | |
| 237 '''); | |
| 238 expect(unit.directives[1].metadata.single.name.name, 'a'); | |
| 239 expect(unit.directives[2].metadata.single.name.name, 'b'); | |
| 240 var unitElement = unit.element as CompilationUnitElementImpl; | |
| 241 // Damage the unit element - as if "setAnnotations" were not called. | |
| 242 // The ImportElement(s) still have the metadata, we should use it. | |
| 243 unitElement.setAnnotations(unit.directives[1].offset, []); | |
| 244 unitElement.setAnnotations(unit.directives[2].offset, []); | |
| 245 expect(unitElement.library.parts[0].metadata, hasLength(1)); | |
| 246 expect(unitElement.library.parts[1].metadata, hasLength(1)); | |
| 247 // DeclarationResolver on the clone should succeed. | |
| 248 CompilationUnit clonedUnit = AstCloner.clone(unit); | |
| 249 new DeclarationResolver().resolve(clonedUnit, unit.element); | |
| 250 expect(unit.directives[1].metadata.single.name.name, 'a'); | |
| 251 expect(unit.directives[2].metadata.single.name.name, 'b'); | |
| 252 } | |
| 253 | |
| 222 test_metadata_libraryDirective() async { | 254 test_metadata_libraryDirective() async { |
| 223 await setupCode('@a library L;'); | 255 await setupCode('@a library L;'); |
| 224 checkMetadata('L'); | 256 checkMetadata('L'); |
| 225 } | 257 } |
| 226 | 258 |
| 227 test_metadata_libraryDirective_resynthesized() async { | 259 test_metadata_libraryDirective_resynthesized() async { |
| 228 CompilationUnit unit = | 260 CompilationUnit unit = |
| 229 await resolveSource('@a library L; const a = null;'); | 261 await resolveSource('@a library L; const a = null;'); |
| 230 expect(unit.directives.single.metadata.single.name.name, 'a'); | 262 expect(unit.directives.single.metadata.single.name.name, 'a'); |
| 231 var unitElement = unit.element as CompilationUnitElementImpl; | 263 var unitElement = unit.element as CompilationUnitElementImpl; |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 expect(element.type.toString(), "<T>(T, T) → T"); | 711 expect(element.type.toString(), "<T>(T, T) → T"); |
| 680 expect(t.element, same(tElement)); | 712 expect(t.element, same(tElement)); |
| 681 | 713 |
| 682 // re-resolve | 714 // re-resolve |
| 683 CompilationUnit unit2 = _cloneResolveUnit(unit); | 715 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 684 node = _findSimpleIdentifier(unit2, code, 'max').parent; | 716 node = _findSimpleIdentifier(unit2, code, 'max').parent; |
| 685 t = node.typeParameters.typeParameters[0]; | 717 t = node.typeParameters.typeParameters[0]; |
| 686 expect(t.element, same(tElement)); | 718 expect(t.element, same(tElement)); |
| 687 } | 719 } |
| 688 } | 720 } |
| OLD | NEW |