| 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_services/index/index.dart'; | 7 import 'package:analysis_services/index/index.dart'; |
| 8 import 'package:analysis_services/index/index_store.dart'; | 8 import 'package:analysis_services/index/index_store.dart'; |
| 9 import 'package:analysis_services/src/index/index_contributor.dart'; | 9 import 'package:analysis_services/src/index/index_contributor.dart'; |
| 10 import 'package:analysis_testing/abstract_single_unit.dart'; |
| 10 import 'package:analysis_testing/reflective_tests.dart'; | 11 import 'package:analysis_testing/reflective_tests.dart'; |
| 11 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 12 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:typed_mock/typed_mock.dart'; | 15 import 'package:typed_mock/typed_mock.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 16 import 'package:unittest/unittest.dart'; |
| 16 | 17 |
| 17 import 'abstract_single_unit.dart'; | |
| 18 | |
| 19 | 18 |
| 20 main() { | 19 main() { |
| 21 groupSep = ' | '; | 20 groupSep = ' | '; |
| 22 group('DartUnitContributor', () { | 21 group('DartUnitContributor', () { |
| 23 runReflectiveTests(DartUnitContributorTest); | 22 runReflectiveTests(DartUnitContributorTest); |
| 24 }); | 23 }); |
| 25 } | 24 } |
| 26 | 25 |
| 27 | 26 |
| 28 /** | 27 /** |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 _assertRecordedRelation( | 115 _assertRecordedRelation( |
| 117 nameElement, | 116 nameElement, |
| 118 IndexConstants.IS_READ_BY, | 117 IndexConstants.IS_READ_BY, |
| 119 _expectedLocationQU(mainElement, 'field); // ur')); | 118 _expectedLocationQU(mainElement, 'field); // ur')); |
| 120 _assertNoRecordedRelation( | 119 _assertNoRecordedRelation( |
| 121 nameElement, | 120 nameElement, |
| 122 IndexConstants.IS_READ_BY, | 121 IndexConstants.IS_READ_BY, |
| 123 _expectedLocation(mainElement, 'field); // not a member')); | 122 _expectedLocation(mainElement, 'field); // not a member')); |
| 124 } | 123 } |
| 125 | 124 |
| 125 void test_NameElement_isDefinedBy_localVariable_inForEach() { |
| 126 _indexTestUnit(''' |
| 127 class A { |
| 128 main() { |
| 129 for (int test in []) { |
| 130 } |
| 131 } |
| 132 } |
| 133 '''); |
| 134 // prepare elements |
| 135 Element mainElement = findElement('main'); |
| 136 LocalVariableElement testElement = findElement('test'); |
| 137 Element nameElement = new NameElement('test'); |
| 138 // verify |
| 139 _assertRecordedRelation( |
| 140 nameElement, |
| 141 IndexConstants.NAME_IS_DEFINED_BY, |
| 142 _expectedLocation(testElement, 'test in []')); |
| 143 } |
| 144 |
| 126 void test_NameElement_method() { | 145 void test_NameElement_method() { |
| 127 _indexTestUnit(''' | 146 _indexTestUnit(''' |
| 128 class A { | 147 class A { |
| 129 method() {} | 148 method() {} |
| 130 } | 149 } |
| 131 main(A a, p) { | 150 main(A a, p) { |
| 132 a.method(); // r | 151 a.method(); // r |
| 133 p.method(); // ur | 152 p.method(); // ur |
| 134 } | 153 } |
| 135 '''); | 154 '''); |
| 136 // prepare elements | 155 // prepare elements |
| 137 Element mainElement = findElement('main'); | 156 Element mainElement = findElement('main'); |
| 138 MethodElement methodElement = findElement('method'); | 157 MethodElement methodElement = findElement('method'); |
| 139 Element nameElement = new NameElement('method'); | 158 Element nameElement = new NameElement('method'); |
| 140 // verify | 159 // verify |
| 141 _assertRecordedRelation( | 160 _assertRecordedRelation( |
| 142 nameElement, | 161 nameElement, |
| 143 IndexConstants.NAME_IS_DEFINED_BY, | 162 IndexConstants.NAME_IS_DEFINED_BY, |
| 144 _expectedLocation(methodElement, 'method() {}')); | 163 _expectedLocation(methodElement, 'method() {}')); |
| 145 _assertRecordedRelation( | 164 _assertRecordedRelation( |
| 146 nameElement, | 165 nameElement, |
| 147 IndexConstants.IS_INVOKED_BY, | 166 IndexConstants.IS_INVOKED_BY, |
| 148 _expectedLocationQ(mainElement, 'method(); // r')); | 167 _expectedLocationQ(mainElement, 'method(); // r')); |
| 149 _assertRecordedRelation( | 168 _assertRecordedRelation( |
| 150 nameElement, | 169 nameElement, |
| 151 IndexConstants.IS_INVOKED_BY, | 170 IndexConstants.IS_INVOKED_BY, |
| 152 _expectedLocationQU(mainElement, 'method(); // ur')); | 171 _expectedLocationQU(mainElement, 'method(); // ur')); |
| 153 } | 172 } |
| 154 | 173 |
| 155 void test_NameElement_isDefinedBy_localVariable_inForEach() { | |
| 156 _indexTestUnit(''' | |
| 157 class A { | |
| 158 main() { | |
| 159 for (int test in []) { | |
| 160 } | |
| 161 } | |
| 162 } | |
| 163 '''); | |
| 164 // prepare elements | |
| 165 Element mainElement = findElement('main'); | |
| 166 LocalVariableElement testElement = findElement('test'); | |
| 167 Element nameElement = new NameElement('test'); | |
| 168 // verify | |
| 169 _assertRecordedRelation( | |
| 170 nameElement, | |
| 171 IndexConstants.NAME_IS_DEFINED_BY, | |
| 172 _expectedLocation(testElement, 'test in []')); | |
| 173 } | |
| 174 | |
| 175 void test_NameElement_operator_resolved() { | 174 void test_NameElement_operator_resolved() { |
| 176 _indexTestUnit(''' | 175 _indexTestUnit(''' |
| 177 class A { | 176 class A { |
| 178 operator +(o) {} | 177 operator +(o) {} |
| 179 operator -(o) {} | 178 operator -(o) {} |
| 180 operator ~() {} | 179 operator ~() {} |
| 181 operator ==(o) {} | 180 operator ==(o) {} |
| 182 } | 181 } |
| 183 main(A a) { | 182 main(A a) { |
| 184 a + 5; | 183 a + 5; |
| (...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 | 1721 |
| 1723 RecordedRelation(this.element, this.relationship, this.location); | 1722 RecordedRelation(this.element, this.relationship, this.location); |
| 1724 | 1723 |
| 1725 @override | 1724 @override |
| 1726 String toString() { | 1725 String toString() { |
| 1727 return 'RecordedRelation(element=$element; relationship=$relationship; ' | 1726 return 'RecordedRelation(element=$element; relationship=$relationship; ' |
| 1728 'location=$location; flags=' '${location.isQualified ? "Q" : ""}' | 1727 'location=$location; flags=' '${location.isQualified ? "Q" : ""}' |
| 1729 '${location.isResolved ? "R" : ""})'; | 1728 '${location.isResolved ? "R" : ""})'; |
| 1730 } | 1729 } |
| 1731 } | 1730 } |
| OLD | NEW |