OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.services.src.index.dart_index_contributor; | 5 library test.services.src.index.dart_index_contributor; |
6 | 6 |
7 import 'package:analysis_server/plugin/index/index_core.dart'; | 7 import 'package:analysis_server/src/provisional/index/index_core.dart'; |
8 import 'package:analysis_server/src/services/index/index.dart'; | 8 import 'package:analysis_server/src/services/index/index.dart'; |
9 import 'package:analysis_server/src/services/index/index_contributor.dart'; | 9 import 'package:analysis_server/src/services/index/index_contributor.dart'; |
10 import 'package:analysis_server/src/services/index/index_store.dart'; | 10 import 'package:analysis_server/src/services/index/index_store.dart'; |
11 import 'package:analysis_server/src/services/index/indexable_element.dart'; | 11 import 'package:analysis_server/src/services/index/indexable_element.dart'; |
12 import 'package:analysis_server/src/services/index/indexable_file.dart'; | 12 import 'package:analysis_server/src/services/index/indexable_file.dart'; |
13 import 'package:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
14 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
17 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 LocationImpl location) { | 87 LocationImpl location) { |
88 recordedRelations | 88 recordedRelations |
89 .add(new RecordedRelation(indexable, relationship, location)); | 89 .add(new RecordedRelation(indexable, relationship, location)); |
90 }); | 90 }); |
91 when(store.recordTopLevelDeclaration(anyObject)) | 91 when(store.recordTopLevelDeclaration(anyObject)) |
92 .thenInvoke((Element element) { | 92 .thenInvoke((Element element) { |
93 recordedTopElements.add(element); | 93 recordedTopElements.add(element); |
94 }); | 94 }); |
95 } | 95 } |
96 | 96 |
97 void test_isReferencedBy_PrefixElement() { | |
98 _indexTestUnit(''' | |
99 import 'dart:async' as ppp; | |
100 main() { | |
101 ppp.Future a; | |
102 ppp.Stream b; | |
103 } | |
104 '''); | |
105 // prepare elements | |
106 PrefixElement element = findNodeElementAtString('ppp;'); | |
107 Element elementA = findElement('a'); | |
108 Element elementB = findElement('b'); | |
109 IndexableElement indexable = new IndexableElement(element); | |
110 // verify | |
111 _assertRecordedRelation(indexable, IndexConstants.IS_REFERENCED_BY, | |
112 _expectedLocation(elementA, 'ppp.Future')); | |
113 _assertRecordedRelation(indexable, IndexConstants.IS_REFERENCED_BY, | |
114 _expectedLocation(elementB, 'ppp.Stream')); | |
115 _assertNoRecordedRelation(indexable, null, _expectedLocation(null, 'ppp;')); | |
116 } | |
117 | |
118 void test_bad_unresolvedFieldFormalParameter() { | 97 void test_bad_unresolvedFieldFormalParameter() { |
119 verifyNoTestUnitErrors = false; | 98 verifyNoTestUnitErrors = false; |
120 _indexTestUnit(''' | 99 _indexTestUnit(''' |
121 class Test { | 100 class Test { |
122 final field; | 101 final field; |
123 Test(this.fie); | 102 Test(this.fie); |
124 }'''); | 103 }'''); |
125 } | 104 } |
126 | 105 |
127 void test_definesClass() { | 106 void test_definesClass() { |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 } | 1395 } |
1417 '''); | 1396 '''); |
1418 // prepare elements | 1397 // prepare elements |
1419 Element mainElement = findElement('main'); | 1398 Element mainElement = findElement('main'); |
1420 Element element = findElement('p'); | 1399 Element element = findElement('p'); |
1421 // verify | 1400 // verify |
1422 _assertRecordedRelationForElement(element, IndexConstants.IS_REFERENCED_BY, | 1401 _assertRecordedRelationForElement(element, IndexConstants.IS_REFERENCED_BY, |
1423 _expectedLocation(mainElement, 'p: 1')); | 1402 _expectedLocation(mainElement, 'p: 1')); |
1424 } | 1403 } |
1425 | 1404 |
| 1405 void test_isReferencedBy_PrefixElement() { |
| 1406 _indexTestUnit(''' |
| 1407 import 'dart:async' as ppp; |
| 1408 main() { |
| 1409 ppp.Future a; |
| 1410 ppp.Stream b; |
| 1411 } |
| 1412 '''); |
| 1413 // prepare elements |
| 1414 PrefixElement element = findNodeElementAtString('ppp;'); |
| 1415 Element elementA = findElement('a'); |
| 1416 Element elementB = findElement('b'); |
| 1417 IndexableElement indexable = new IndexableElement(element); |
| 1418 // verify |
| 1419 _assertRecordedRelation(indexable, IndexConstants.IS_REFERENCED_BY, |
| 1420 _expectedLocation(elementA, 'ppp.Future')); |
| 1421 _assertRecordedRelation(indexable, IndexConstants.IS_REFERENCED_BY, |
| 1422 _expectedLocation(elementB, 'ppp.Stream')); |
| 1423 _assertNoRecordedRelation(indexable, null, _expectedLocation(null, 'ppp;')); |
| 1424 } |
| 1425 |
1426 void test_isReferencedBy_TopLevelVariableElement() { | 1426 void test_isReferencedBy_TopLevelVariableElement() { |
1427 addSource( | 1427 addSource( |
1428 '/lib.dart', | 1428 '/lib.dart', |
1429 ''' | 1429 ''' |
1430 library lib; | 1430 library lib; |
1431 var V; | 1431 var V; |
1432 '''); | 1432 '''); |
1433 _indexTestUnit(''' | 1433 _indexTestUnit(''' |
1434 import 'lib.dart' show V; // imp | 1434 import 'lib.dart' show V; // imp |
1435 import 'lib.dart' as pref; | 1435 import 'lib.dart' as pref; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 RecordedRelation(this.indexable, this.relationship, this.location); | 1796 RecordedRelation(this.indexable, this.relationship, this.location); |
1797 | 1797 |
1798 @override | 1798 @override |
1799 String toString() { | 1799 String toString() { |
1800 return 'RecordedRelation(indexable=$indexable; relationship=$relationship; ' | 1800 return 'RecordedRelation(indexable=$indexable; relationship=$relationship; ' |
1801 'location=$location; flags=' | 1801 'location=$location; flags=' |
1802 '${location.isQualified ? "Q" : ""}' | 1802 '${location.isQualified ? "Q" : ""}' |
1803 '${location.isResolved ? "R" : ""})'; | 1803 '${location.isResolved ? "R" : ""})'; |
1804 } | 1804 } |
1805 } | 1805 } |
OLD | NEW |