| 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/src/services/index/index.dart'; | 7 import 'package:analysis_server/src/services/index/index.dart'; |
| 8 import 'package:analysis_server/src/services/index/index_contributor.dart'; | 8 import 'package:analysis_server/src/services/index/index_contributor.dart'; |
| 9 import 'package:analysis_server/src/services/index/index_store.dart'; | 9 import 'package:analysis_server/src/services/index/index_store.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 constructorA, | 785 constructorA, |
| 786 IndexConstants.IS_REFERENCED_BY, | 786 IndexConstants.IS_REFERENCED_BY, |
| 787 _expectedLocation(constructorA_foo, '(); // marker', length: 0)); | 787 _expectedLocation(constructorA_foo, '(); // marker', length: 0)); |
| 788 // A.foo() | 788 // A.foo() |
| 789 _assertRecordedRelation( | 789 _assertRecordedRelation( |
| 790 constructorA_bar, | 790 constructorA_bar, |
| 791 IndexConstants.IS_REFERENCED_BY, | 791 IndexConstants.IS_REFERENCED_BY, |
| 792 _expectedLocation(constructorA, '.bar();', length: 4)); | 792 _expectedLocation(constructorA, '.bar();', length: 4)); |
| 793 } | 793 } |
| 794 | 794 |
| 795 void test_isReferencedBy_ConstructorFieldInitializer() { | |
| 796 _indexTestUnit(''' | |
| 797 class A { | |
| 798 int field; | |
| 799 A() : field = 5; | |
| 800 } | |
| 801 '''); | |
| 802 // prepare elements | |
| 803 ConstructorElement constructorElement = | |
| 804 findNodeElementAtString("A()", (node) => node is ConstructorDeclaration)
; | |
| 805 FieldElement fieldElement = findElement("field"); | |
| 806 // verify | |
| 807 _assertRecordedRelation( | |
| 808 fieldElement, | |
| 809 IndexConstants.IS_REFERENCED_BY, | |
| 810 _expectedLocation(constructorElement, 'field = 5')); | |
| 811 } | |
| 812 | |
| 813 void test_isReferencedBy_FieldElement() { | 795 void test_isReferencedBy_FieldElement() { |
| 814 _indexTestUnit(''' | 796 _indexTestUnit(''' |
| 815 class A { | 797 class A { |
| 816 var field; | 798 var field; |
| 817 main() { | 799 A({this.field}); |
| 818 this.field = 5; // q | 800 m() { |
| 819 print(this.field); // q | 801 field = 1; // nq |
| 820 field = 5; // nq | |
| 821 print(field); // nq | 802 print(field); // nq |
| 822 } | 803 } |
| 823 } | 804 } |
| 805 main(A a) { |
| 806 a.field = 2; // q |
| 807 print(a.field); // q |
| 808 new A(field: 3); |
| 809 } |
| 824 '''); | 810 '''); |
| 825 // prepare elements | 811 // prepare elements |
| 812 Element mElement = findElement("m"); |
| 826 Element mainElement = findElement("main"); | 813 Element mainElement = findElement("main"); |
| 827 FieldElement fieldElement = findElement("field"); | 814 FieldElement fieldElement = findElement("field"); |
| 828 PropertyAccessorElement getter = fieldElement.getter; | 815 PropertyAccessorElement getter = fieldElement.getter; |
| 829 PropertyAccessorElement setter = fieldElement.setter; | 816 PropertyAccessorElement setter = fieldElement.setter; |
| 830 // verify | 817 // m() |
| 831 _assertRecordedRelation( | 818 _assertRecordedRelation( |
| 832 setter, | 819 setter, |
| 833 IndexConstants.IS_REFERENCED_BY, | 820 IndexConstants.IS_REFERENCED_BY, |
| 834 _expectedLocationQ(mainElement, 'field = 5; // q')); | 821 _expectedLocation(mElement, 'field = 1; // nq')); |
| 822 _assertRecordedRelation( |
| 823 getter, |
| 824 IndexConstants.IS_REFERENCED_BY, |
| 825 _expectedLocation(mElement, 'field); // nq')); |
| 826 // main() |
| 827 _assertRecordedRelation( |
| 828 setter, |
| 829 IndexConstants.IS_REFERENCED_BY, |
| 830 _expectedLocationQ(mainElement, 'field = 2; // q')); |
| 835 _assertRecordedRelation( | 831 _assertRecordedRelation( |
| 836 getter, | 832 getter, |
| 837 IndexConstants.IS_REFERENCED_BY, | 833 IndexConstants.IS_REFERENCED_BY, |
| 838 _expectedLocationQ(mainElement, 'field); // q')); | 834 _expectedLocationQ(mainElement, 'field); // q')); |
| 839 _assertRecordedRelation( | 835 _assertRecordedRelation( |
| 840 setter, | |
| 841 IndexConstants.IS_REFERENCED_BY, | |
| 842 _expectedLocation(mainElement, 'field = 5; // nq')); | |
| 843 _assertRecordedRelation( | |
| 844 getter, | |
| 845 IndexConstants.IS_REFERENCED_BY, | |
| 846 _expectedLocation(mainElement, 'field); // nq')); | |
| 847 } | |
| 848 | |
| 849 void test_isReferencedBy_FieldFormalParameterElement() { | |
| 850 _indexTestUnit(''' | |
| 851 class A { | |
| 852 int field; | |
| 853 A(this.field); | |
| 854 } | |
| 855 '''); | |
| 856 // prepare elements | |
| 857 FieldElement fieldElement = findElement("field"); | |
| 858 Element fieldParameterElement = findNodeElementAtString("field);"); | |
| 859 // verify | |
| 860 _assertRecordedRelation( | |
| 861 fieldElement, | 836 fieldElement, |
| 862 IndexConstants.IS_REFERENCED_BY, | 837 IndexConstants.IS_REFERENCED_BY, |
| 863 _expectedLocation(fieldParameterElement, 'field);')); | 838 _expectedLocation(mainElement, 'field: 3')); |
| 864 } | 839 } |
| 865 | 840 |
| 866 void test_isReferencedBy_FunctionElement() { | 841 void test_isReferencedBy_FunctionElement() { |
| 867 _indexTestUnit(''' | 842 _indexTestUnit(''' |
| 868 foo() {} | 843 foo() {} |
| 869 main() { | 844 main() { |
| 870 print(foo); | 845 print(foo); |
| 871 print(foo()); | 846 print(foo()); |
| 872 } | 847 } |
| 873 '''); | 848 '''); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 _assertRecordedRelation( | 1271 _assertRecordedRelation( |
| 1297 typeParameterElement, | 1272 typeParameterElement, |
| 1298 IndexConstants.IS_REFERENCED_BY, | 1273 IndexConstants.IS_REFERENCED_BY, |
| 1299 _expectedLocation(parameterElement, 'T p')); | 1274 _expectedLocation(parameterElement, 'T p')); |
| 1300 _assertRecordedRelation( | 1275 _assertRecordedRelation( |
| 1301 typeParameterElement, | 1276 typeParameterElement, |
| 1302 IndexConstants.IS_REFERENCED_BY, | 1277 IndexConstants.IS_REFERENCED_BY, |
| 1303 _expectedLocation(variableElement, 'T v')); | 1278 _expectedLocation(variableElement, 'T v')); |
| 1304 } | 1279 } |
| 1305 | 1280 |
| 1281 void test_isWrittenBy_ConstructorFieldInitializer() { |
| 1282 _indexTestUnit(''' |
| 1283 class A { |
| 1284 int field; |
| 1285 A() : field = 5; |
| 1286 } |
| 1287 '''); |
| 1288 // prepare elements |
| 1289 ClassElement classElement = findElement('A'); |
| 1290 ConstructorElement constructorElement = classElement.constructors[0]; |
| 1291 FieldElement fieldElement = findElement("field"); |
| 1292 // verify |
| 1293 _assertRecordedRelation( |
| 1294 fieldElement, |
| 1295 IndexConstants.IS_WRITTEN_BY, |
| 1296 _expectedLocation(constructorElement, 'field = 5')); |
| 1297 } |
| 1298 |
| 1299 void test_isWrittenBy_FieldElement_fieldFormalParameter() { |
| 1300 _indexTestUnit(''' |
| 1301 class A { |
| 1302 int field; |
| 1303 A(this.field); |
| 1304 } |
| 1305 '''); |
| 1306 // prepare elements |
| 1307 FieldElement fieldElement = findElement("field"); |
| 1308 Element fieldParameterElement = findNodeElementAtString("field);"); |
| 1309 // verify |
| 1310 _assertRecordedRelation( |
| 1311 fieldElement, |
| 1312 IndexConstants.IS_WRITTEN_BY, |
| 1313 _expectedLocation(fieldParameterElement, 'field);')); |
| 1314 } |
| 1315 |
| 1306 void test_isWrittenBy_ParameterElement() { | 1316 void test_isWrittenBy_ParameterElement() { |
| 1307 _indexTestUnit(''' | 1317 _indexTestUnit(''' |
| 1308 main(var p) { | 1318 main(var p) { |
| 1309 p = 1; | 1319 p = 1; |
| 1310 }'''); | 1320 }'''); |
| 1311 // prepare elements | 1321 // prepare elements |
| 1312 Element mainElement = findElement("main"); | 1322 Element mainElement = findElement("main"); |
| 1313 ParameterElement pElement = findElement("p"); | 1323 ParameterElement pElement = findElement("p"); |
| 1314 // verify | 1324 // verify |
| 1315 _assertRecordedRelation( | 1325 _assertRecordedRelation( |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 | 1768 |
| 1759 RecordedRelation(this.element, this.relationship, this.location); | 1769 RecordedRelation(this.element, this.relationship, this.location); |
| 1760 | 1770 |
| 1761 @override | 1771 @override |
| 1762 String toString() { | 1772 String toString() { |
| 1763 return 'RecordedRelation(element=$element; relationship=$relationship; ' | 1773 return 'RecordedRelation(element=$element; relationship=$relationship; ' |
| 1764 'location=$location; flags=' '${location.isQualified ? "Q" : ""}' | 1774 'location=$location; flags=' '${location.isQualified ? "Q" : ""}' |
| 1765 '${location.isResolved ? "R" : ""})'; | 1775 '${location.isResolved ? "R" : ""})'; |
| 1766 } | 1776 } |
| 1767 } | 1777 } |
| OLD | NEW |