OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
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/analysis/driver.dart'; | 9 import 'package:analyzer/src/dart/analysis/driver.dart'; |
10 import 'package:analyzer/src/dart/analysis/search.dart'; | 10 import 'package:analyzer/src/dart/analysis/search.dart'; |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 ExpectedResult(this.enclosingElement, this.kind, this.offset, this.length, | 32 ExpectedResult(this.enclosingElement, this.kind, this.offset, this.length, |
33 {this.isResolved: true, this.isQualified: false}); | 33 {this.isResolved: true, this.isQualified: false}); |
34 | 34 |
35 bool operator ==(Object result) { | 35 bool operator ==(Object result) { |
36 return result is SearchResult && | 36 return result is SearchResult && |
37 result.kind == this.kind && | 37 result.kind == this.kind && |
38 result.isResolved == this.isResolved && | 38 result.isResolved == this.isResolved && |
39 result.isQualified == this.isQualified && | 39 result.isQualified == this.isQualified && |
40 result.offset == this.offset && | 40 result.offset == this.offset && |
| 41 result.length == this.length && |
41 result.enclosingElement == this.enclosingElement; | 42 result.enclosingElement == this.enclosingElement; |
42 } | 43 } |
43 | 44 |
44 @override | 45 @override |
45 String toString() { | 46 String toString() { |
46 StringBuffer buffer = new StringBuffer(); | 47 StringBuffer buffer = new StringBuffer(); |
47 buffer.write("ExpectedResult(kind="); | 48 buffer.write("ExpectedResult(kind="); |
48 buffer.write(kind); | 49 buffer.write(kind); |
49 buffer.write(", enclosingElement="); | 50 buffer.write(", enclosingElement="); |
50 buffer.write(enclosingElement); | 51 buffer.write(enclosingElement); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 var expected = [ | 504 var expected = [ |
504 _expectId(fooElement, SearchResultKind.WRITE, 'p = 1;'), | 505 _expectId(fooElement, SearchResultKind.WRITE, 'p = 1;'), |
505 _expectId(fooElement, SearchResultKind.READ_WRITE, 'p += 2;'), | 506 _expectId(fooElement, SearchResultKind.READ_WRITE, 'p += 2;'), |
506 _expectId(fooElement, SearchResultKind.READ, 'p);'), | 507 _expectId(fooElement, SearchResultKind.READ, 'p);'), |
507 _expectId(fooElement, SearchResultKind.INVOCATION, 'p();'), | 508 _expectId(fooElement, SearchResultKind.INVOCATION, 'p();'), |
508 _expectIdQ(mainElement, SearchResultKind.REFERENCE, 'p: 42') | 509 _expectIdQ(mainElement, SearchResultKind.REFERENCE, 'p: 42') |
509 ]; | 510 ]; |
510 await _verifyReferences(element, expected); | 511 await _verifyReferences(element, expected); |
511 } | 512 } |
512 | 513 |
| 514 test_searchReferences_PrefixElement() async { |
| 515 String partCode = r''' |
| 516 part of my_lib; |
| 517 ppp.Future c; |
| 518 '''; |
| 519 provider.newFile(_p('$testProject/my_part.dart'), partCode); |
| 520 await _resolveTestUnit(''' |
| 521 library my_lib; |
| 522 import 'dart:async' as ppp; |
| 523 part 'my_part.dart'; |
| 524 main() { |
| 525 ppp.Future a; |
| 526 ppp.Stream b; |
| 527 } |
| 528 '''); |
| 529 PrefixElement element = _findElementAtString('ppp;'); |
| 530 Element a = _findElement('a'); |
| 531 Element b = _findElement('b'); |
| 532 Element c = findChildElement(testLibraryElement, 'c'); |
| 533 var expected = [ |
| 534 _expectId(a, SearchResultKind.REFERENCE, 'ppp.Future'), |
| 535 _expectId(b, SearchResultKind.REFERENCE, 'ppp.Stream'), |
| 536 new ExpectedResult(c, SearchResultKind.REFERENCE, |
| 537 partCode.indexOf('ppp.Future c'), 'ppp'.length) |
| 538 ]; |
| 539 await _verifyReferences(element, expected); |
| 540 } |
| 541 |
513 test_searchReferences_PropertyAccessorElement_getter() async { | 542 test_searchReferences_PropertyAccessorElement_getter() async { |
514 await _resolveTestUnit(''' | 543 await _resolveTestUnit(''' |
515 class A { | 544 class A { |
516 get ggg => null; | 545 get ggg => null; |
517 main() { | 546 main() { |
518 print(ggg); // ref-nq | 547 print(ggg); // ref-nq |
519 print(this.ggg); // ref-q | 548 print(this.ggg); // ref-q |
520 ggg(); // inv-nq | 549 ggg(); // inv-nq |
521 this.ggg(); // inv-q | 550 this.ggg(); // inv-q |
522 } | 551 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 List<SearchResult> results = await driver.search.references(element); | 729 List<SearchResult> results = await driver.search.references(element); |
701 _assertResults(results, expectedMatches); | 730 _assertResults(results, expectedMatches); |
702 expect(results, hasLength(expectedMatches.length)); | 731 expect(results, hasLength(expectedMatches.length)); |
703 } | 732 } |
704 | 733 |
705 static void _assertResults( | 734 static void _assertResults( |
706 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { | 735 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { |
707 expect(matches, unorderedEquals(expectedMatches)); | 736 expect(matches, unorderedEquals(expectedMatches)); |
708 } | 737 } |
709 } | 738 } |
OLD | NEW |