| 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 analyzer.test.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 void _performBuildTask(String content) { | 235 void _performBuildTask(String content) { |
| 236 source = newSource('/test.dart', content); | 236 source = newSource('/test.dart', content); |
| 237 target = new LibrarySpecificUnit(source, source); | 237 target = new LibrarySpecificUnit(source, source); |
| 238 computeResult(target, RESOLVED_UNIT1, | 238 computeResult(target, RESOLVED_UNIT1, |
| 239 matcher: isBuildCompilationUnitElementTask); | 239 matcher: isBuildCompilationUnitElementTask); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 @reflectiveTest | 243 @reflectiveTest |
| 244 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 244 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 245 /** |
| 246 * Verify that the given [element] has exactly one annotation, and that its |
| 247 * [ElementAnnotationImpl] is unresolved and points back to [element]. |
| 248 * |
| 249 * The compilation unit stored in the [ElementAnnotationImpl] should be |
| 250 * [compilationUnit]. |
| 251 */ |
| 252 void checkMetadata(Element element, CompilationUnitElement compilationUnit) { |
| 253 expect(element.metadata, hasLength(1)); |
| 254 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>()); |
| 255 ElementAnnotationImpl elementAnnotation = element.metadata[0]; |
| 256 expect(elementAnnotation.element, isNull); // Not yet resolved |
| 257 expect(elementAnnotation.compilationUnit, isNotNull); |
| 258 expect(elementAnnotation.compilationUnit, compilationUnit); |
| 259 } |
| 260 |
| 245 test_perform() { | 261 test_perform() { |
| 246 List<Source> sources = newSources({ | 262 List<Source> sources = newSources({ |
| 247 '/libA.dart': ''' | 263 '/libA.dart': ''' |
| 248 library libA; | 264 library libA; |
| 249 import 'libB.dart'; | 265 import 'libB.dart'; |
| 250 export 'libC.dart'; | 266 export 'libC.dart'; |
| 251 ''', | 267 ''', |
| 252 '/libB.dart': ''' | 268 '/libB.dart': ''' |
| 253 library libB; | 269 library libB; |
| 254 ''', | 270 ''', |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 expect(importElementB.prefixOffset, prefixElement.nameOffset); | 478 expect(importElementB.prefixOffset, prefixElement.nameOffset); |
| 463 expect(prefixNodeB.staticElement, prefixElement); | 479 expect(prefixNodeB.staticElement, prefixElement); |
| 464 // PrefixElement "pref" is shared | 480 // PrefixElement "pref" is shared |
| 465 ImportDirective importNodeC = libraryUnitA.directives[2]; | 481 ImportDirective importNodeC = libraryUnitA.directives[2]; |
| 466 SimpleIdentifier prefixNodeC = importNodeC.prefix; | 482 SimpleIdentifier prefixNodeC = importNodeC.prefix; |
| 467 ImportElement importElementC = importNodeC.element; | 483 ImportElement importElementC = importNodeC.element; |
| 468 expect(prefixNodeC.staticElement, prefixElement); | 484 expect(prefixNodeC.staticElement, prefixElement); |
| 469 expect(importElementC.prefix, prefixElement); | 485 expect(importElementC.prefix, prefixElement); |
| 470 } | 486 } |
| 471 | 487 |
| 488 test_perform_metadata() { |
| 489 List<Source> sources = newSources({ |
| 490 '/libA.dart': ''' |
| 491 @a library libA; |
| 492 @b import 'libB.dart'; |
| 493 @c export 'libC.dart'; |
| 494 @d part 'part.dart';''', |
| 495 '/libB.dart': 'library libB;', |
| 496 '/libC.dart': 'library libC;', |
| 497 '/part.dart': 'part of libA;' |
| 498 }); |
| 499 Source sourceA = sources[0]; |
| 500 Source sourcePart = sources[3]; |
| 501 // perform task |
| 502 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 503 matcher: isBuildDirectiveElementsTask); |
| 504 // Get outputs |
| 505 LibraryElement libraryA = |
| 506 context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2); |
| 507 // Validate metadata |
| 508 checkMetadata(libraryA, libraryA.definingCompilationUnit); |
| 509 checkMetadata(libraryA.imports[0], libraryA.definingCompilationUnit); |
| 510 checkMetadata(libraryA.exports[0], libraryA.definingCompilationUnit); |
| 511 checkMetadata(libraryA.parts[0], libraryA.definingCompilationUnit); |
| 512 } |
| 513 |
| 514 test_perform_metadata_partOf() { |
| 515 // We don't record annotations on `part of` directives because the element |
| 516 // associated with a `part of` directive is the library, and the convention |
| 517 // is to annotate the library at the site of the `library` declaration. |
| 518 List<Source> sources = newSources({ |
| 519 '/libA.dart': ''' |
| 520 library libA; |
| 521 part 'part.dart';''', |
| 522 '/part.dart': '@a part of libA;' |
| 523 }); |
| 524 Source sourceA = sources[0]; |
| 525 Source sourcePart = sources[1]; |
| 526 // perform task |
| 527 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 528 matcher: isBuildDirectiveElementsTask); |
| 529 // Get outputs |
| 530 LibraryElement libraryA = |
| 531 context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2); |
| 532 CompilationUnit part = context |
| 533 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourcePart)) |
| 534 .getValue(RESOLVED_UNIT1); |
| 535 // Validate metadata |
| 536 expect(part.directives[0], new isInstanceOf<PartOfDirective>()); |
| 537 expect(part.directives[0].element, same(libraryA)); |
| 538 expect(part.directives[0].element.metadata, isEmpty); |
| 539 } |
| 540 |
| 472 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 541 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 473 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); | 542 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); |
| 474 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 543 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 475 } | 544 } |
| 476 | 545 |
| 477 _getExportLibraryInput(Source source) { | 546 _getExportLibraryInput(Source source) { |
| 478 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME; | 547 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME; |
| 479 return task.inputs[key][source]; | 548 return task.inputs[key][source]; |
| 480 } | 549 } |
| 481 | 550 |
| (...skipping 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4879 /** | 4948 /** |
| 4880 * Fill [errorListener] with [result] errors in the current [task]. | 4949 * Fill [errorListener] with [result] errors in the current [task]. |
| 4881 */ | 4950 */ |
| 4882 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4951 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4883 List<AnalysisError> errors = task.outputs[result]; | 4952 List<AnalysisError> errors = task.outputs[result]; |
| 4884 expect(errors, isNotNull, reason: result.name); | 4953 expect(errors, isNotNull, reason: result.name); |
| 4885 errorListener = new GatheringErrorListener(); | 4954 errorListener = new GatheringErrorListener(); |
| 4886 errorListener.addAll(errors); | 4955 errorListener.addAll(errors); |
| 4887 } | 4956 } |
| 4888 } | 4957 } |
| OLD | NEW |