Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: pkg/analysis_server/test/services/index2/index2_test.dart

Issue 1768353002: Implement SearchEngine.searchMemberReferences(). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'package:analysis_server/src/services/index2/index2.dart'; 5 import 'package:analysis_server/src/services/index2/index2.dart';
6 import 'package:analyzer/dart/ast/ast.dart'; 6 import 'package:analyzer/dart/ast/ast.dart';
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/summary/idl.dart'; 9 import 'package:analyzer/src/summary/idl.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; 10 import 'package:test_reflective_loader/test_reflective_loader.dart';
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 main(int a, int b) { 141 main(int a, int b) {
142 } 142 }
143 '''); 143 ''');
144 ClassElement intElement = context.typeProvider.intType.element; 144 ClassElement intElement = context.typeProvider.intType.element;
145 List<Location> locations = await index.getRelations( 145 List<Location> locations = await index.getRelations(
146 intElement, IndexRelationKind.IS_REFERENCED_BY); 146 intElement, IndexRelationKind.IS_REFERENCED_BY);
147 findLocationTest(locations, 'int a'); 147 findLocationTest(locations, 'int a');
148 findLocationTest(locations, 'int b'); 148 findLocationTest(locations, 'int b');
149 } 149 }
150 150
151 test_getUnresolvedMemberReferences() async {
152 _indexTestUnit('''
153 class A {
154 var test; // A
155 mainA() {
156 test(); // a-inv-r-nq
157 test = 1; // a-ref-r-nq
158 test += 2; // a-ref-r-nq
159 print(test); // a-ref-r-nq
160 }
161 }
162 main(A a, p) {
163 a.test(); // a-inv-r-q
164 a.test = 1; // a-ref-r-q
165 a.test += 2; // a-ref-r-q
166 print(a.test); // a-ref-r-q
167 p.test(); // p-inv-ur-q
168 p.test = 1; // p-ref-ur-q
169 p.test += 2; // p-ref-ur-q
170 print(p.test); // p-ref-ur-q
171 }
172 ''');
173 List<Location> locations =
174 await index.getUnresolvedMemberReferences('test');
175 expect(locations, hasLength(4));
176 findLocationTest(locations, 'test(); // p-inv-ur-q');
177 findLocationTest(locations, 'test = 1; // p-ref-ur-q');
178 findLocationTest(locations, 'test += 2; // p-ref-ur-q');
179 findLocationTest(locations, 'test); // p-ref-ur-q');
180 }
181
151 /** 182 /**
152 * Assert that the given list of [locations] has a [Location] corresponding 183 * Assert that the given list of [locations] has a [Location] corresponding
153 * to the [element]. 184 * to the [element].
154 */ 185 */
155 void _assertHasDefinedName(List<Location> locations, Element element) { 186 void _assertHasDefinedName(List<Location> locations, Element element) {
156 String libraryUri = element.library.source.uri.toString(); 187 String libraryUri = element.library.source.uri.toString();
157 String unitUri = element.source.uri.toString(); 188 String unitUri = element.source.uri.toString();
158 for (Location location in locations) { 189 for (Location location in locations) {
159 if (location.libraryUri == libraryUri && 190 if (location.libraryUri == libraryUri &&
160 location.unitUri == unitUri && 191 location.unitUri == unitUri &&
(...skipping 11 matching lines...) Expand all
172 index.indexUnit(testUnit); 203 index.indexUnit(testUnit);
173 } 204 }
174 205
175 Source _indexUnit(String path, String code) { 206 Source _indexUnit(String path, String code) {
176 Source source = addSource(path, code); 207 Source source = addSource(path, code);
177 CompilationUnit unit = resolveLibraryUnit(source); 208 CompilationUnit unit = resolveLibraryUnit(source);
178 index.indexUnit(unit); 209 index.indexUnit(unit);
179 return source; 210 return source;
180 } 211 }
181 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698