| 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/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/analysis/driver.dart'; | 10 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 468 } |
| 469 | 469 |
| 470 test_searchReferences_FunctionElement_local() async { | 470 test_searchReferences_FunctionElement_local() async { |
| 471 await _resolveTestUnit(''' | 471 await _resolveTestUnit(''' |
| 472 main() { | 472 main() { |
| 473 test() {} | 473 test() {} |
| 474 test(); | 474 test(); |
| 475 print(test); | 475 print(test); |
| 476 } | 476 } |
| 477 '''); | 477 '''); |
| 478 FunctionElement element = _findElement('test'); | 478 FunctionElement element = findElementsByName(testUnit, 'test').single; |
| 479 Element main = _findElement('main'); | 479 Element main = _findElement('main'); |
| 480 var expected = [ | 480 var expected = [ |
| 481 _expectId(main, SearchResultKind.INVOCATION, 'test();'), | 481 _expectId(main, SearchResultKind.INVOCATION, 'test();'), |
| 482 _expectId(main, SearchResultKind.REFERENCE, 'test);') | 482 _expectId(main, SearchResultKind.REFERENCE, 'test);') |
| 483 ]; | 483 ]; |
| 484 await _verifyReferences(element, expected); | 484 await _verifyReferences(element, expected); |
| 485 } | 485 } |
| 486 | 486 |
| 487 test_searchReferences_ImportElement_noPrefix() async { | 487 test_searchReferences_ImportElement_noPrefix() async { |
| 488 await _resolveTestUnit(''' | 488 await _resolveTestUnit(''' |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 main() { | 745 main() { |
| 746 foo(p) { | 746 foo(p) { |
| 747 p = 1; | 747 p = 1; |
| 748 p += 2; | 748 p += 2; |
| 749 print(p); | 749 print(p); |
| 750 p(); | 750 p(); |
| 751 } | 751 } |
| 752 foo(42); | 752 foo(42); |
| 753 } | 753 } |
| 754 '''); | 754 '''); |
| 755 ParameterElement element = _findElement('p'); | 755 Element main = _findElement('main'); |
| 756 Element fooElement = _findElement('foo'); | 756 FunctionElement foo = findElementsByName(testUnit, 'foo').single; |
| 757 ParameterElement element = foo.parameters.single; |
| 757 var expected = [ | 758 var expected = [ |
| 758 _expectId(fooElement, SearchResultKind.WRITE, 'p = 1;'), | 759 _expectId(main, SearchResultKind.WRITE, 'p = 1;'), |
| 759 _expectId(fooElement, SearchResultKind.READ_WRITE, 'p += 2;'), | 760 _expectId(main, SearchResultKind.READ_WRITE, 'p += 2;'), |
| 760 _expectId(fooElement, SearchResultKind.READ, 'p);'), | 761 _expectId(main, SearchResultKind.READ, 'p);'), |
| 761 _expectId(fooElement, SearchResultKind.INVOCATION, 'p();') | 762 _expectId(main, SearchResultKind.INVOCATION, 'p();') |
| 762 ]; | 763 ]; |
| 763 await _verifyReferences(element, expected); | 764 await _verifyReferences(element, expected); |
| 764 } | 765 } |
| 765 | 766 |
| 766 test_searchReferences_ParameterElement_ofMethod() async { | 767 test_searchReferences_ParameterElement_ofMethod() async { |
| 767 await _resolveTestUnit(''' | 768 await _resolveTestUnit(''' |
| 768 class C { | 769 class C { |
| 769 foo(p) { | 770 foo(p) { |
| 770 p = 1; | 771 p = 1; |
| 771 p += 2; | 772 p += 2; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 } | 1017 } |
| 1017 | 1018 |
| 1018 test_searchReferences_TypeParameterElement_ofLocalFunction() async { | 1019 test_searchReferences_TypeParameterElement_ofLocalFunction() async { |
| 1019 await _resolveTestUnit(''' | 1020 await _resolveTestUnit(''' |
| 1020 main() { | 1021 main() { |
| 1021 void foo<T>(T a) { | 1022 void foo<T>(T a) { |
| 1022 void bar(T b) {} | 1023 void bar(T b) {} |
| 1023 } | 1024 } |
| 1024 } | 1025 } |
| 1025 '''); | 1026 '''); |
| 1026 TypeParameterElement element = _findElement('T'); | 1027 Element main = _findElement('main'); |
| 1027 Element a = _findElement('a'); | 1028 FunctionElement foo = findElementsByName(testUnit, 'foo').single; |
| 1028 Element b = _findElement('b'); | 1029 TypeParameterElement element = foo.typeParameters.single; |
| 1029 var expected = [ | 1030 var expected = [ |
| 1030 _expectId(a, SearchResultKind.REFERENCE, 'T a'), | 1031 _expectId(main, SearchResultKind.REFERENCE, 'T a'), |
| 1031 _expectId(b, SearchResultKind.REFERENCE, 'T b'), | 1032 _expectId(main, SearchResultKind.REFERENCE, 'T b'), |
| 1032 ]; | 1033 ]; |
| 1033 await _verifyReferences(element, expected); | 1034 await _verifyReferences(element, expected); |
| 1034 } | 1035 } |
| 1035 | 1036 |
| 1036 test_searchReferences_TypeParameterElement_ofMethod() async { | 1037 test_searchReferences_TypeParameterElement_ofMethod() async { |
| 1037 await _resolveTestUnit(''' | 1038 await _resolveTestUnit(''' |
| 1038 class A { | 1039 class A { |
| 1039 foo<T>(T p) {} | 1040 foo<T>(T p) {} |
| 1040 } | 1041 } |
| 1041 '''); | 1042 '''); |
| 1042 TypeParameterElement element = _findElement('T'); | 1043 TypeParameterElement element = _findElement('T'); |
| 1043 Element p = _findElement('p'); | 1044 Element p = _findElement('p'); |
| 1044 var expected = [ | 1045 var expected = [ |
| 1045 _expectId(p, SearchResultKind.REFERENCE, 'T p'), | 1046 _expectId(p, SearchResultKind.REFERENCE, 'T p'), |
| 1046 ]; | 1047 ]; |
| 1047 await _verifyReferences(element, expected); | 1048 await _verifyReferences(element, expected); |
| 1048 } | 1049 } |
| 1049 | 1050 |
| 1050 test_searchReferences_TypeParameterElement_ofTopLevelFunction() async { | 1051 test_searchReferences_TypeParameterElement_ofTopLevelFunction() async { |
| 1051 await _resolveTestUnit(''' | 1052 await _resolveTestUnit(''' |
| 1052 foo<T>(T a) { | 1053 foo<T>(T a) { |
| 1053 bar(T b) {} | 1054 bar(T b) {} |
| 1054 } | 1055 } |
| 1055 '''); | 1056 '''); |
| 1057 FunctionElement foo = _findElement('foo'); |
| 1056 TypeParameterElement element = _findElement('T'); | 1058 TypeParameterElement element = _findElement('T'); |
| 1057 Element a = _findElement('a'); | 1059 Element a = _findElement('a'); |
| 1058 Element b = _findElement('b'); | |
| 1059 var expected = [ | 1060 var expected = [ |
| 1060 _expectId(a, SearchResultKind.REFERENCE, 'T a'), | 1061 _expectId(a, SearchResultKind.REFERENCE, 'T a'), |
| 1061 _expectId(b, SearchResultKind.REFERENCE, 'T b'), | 1062 _expectId(foo, SearchResultKind.REFERENCE, 'T b'), |
| 1062 ]; | 1063 ]; |
| 1063 await _verifyReferences(element, expected); | 1064 await _verifyReferences(element, expected); |
| 1064 } | 1065 } |
| 1065 | 1066 |
| 1066 test_searchSubtypes() async { | 1067 test_searchSubtypes() async { |
| 1067 await _resolveTestUnit(''' | 1068 await _resolveTestUnit(''' |
| 1068 class T {} | 1069 class T {} |
| 1069 class A extends T {} // A | 1070 class A extends T {} // A |
| 1070 class B = Object with T; // B | 1071 class B = Object with T; // B |
| 1071 class C implements T {} // C | 1072 class C implements T {} // C |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 List<SearchResult> results = await driver.search.references(element); | 1266 List<SearchResult> results = await driver.search.references(element); |
| 1266 _assertResults(results, expectedMatches); | 1267 _assertResults(results, expectedMatches); |
| 1267 expect(results, hasLength(expectedMatches.length)); | 1268 expect(results, hasLength(expectedMatches.length)); |
| 1268 } | 1269 } |
| 1269 | 1270 |
| 1270 static void _assertResults( | 1271 static void _assertResults( |
| 1271 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { | 1272 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { |
| 1272 expect(matches, unorderedEquals(expectedMatches)); | 1273 expect(matches, unorderedEquals(expectedMatches)); |
| 1273 } | 1274 } |
| 1274 } | 1275 } |
| OLD | NEW |