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:analysis_server/src/services/search/search_engine.dart'; | 7 import 'package:analysis_server/src/services/search/search_engine.dart'; |
8 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 8 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 logger = new PerformanceLog(logBuffer); | 44 logger = new PerformanceLog(logBuffer); |
45 scheduler = new AnalysisDriverScheduler(logger); | 45 scheduler = new AnalysisDriverScheduler(logger); |
46 scheduler.start(); | 46 scheduler.start(); |
47 } | 47 } |
48 | 48 |
49 test_membersOfSubtypes_hasMembers() async { | 49 test_membersOfSubtypes_hasMembers() async { |
50 var a = _p('/test/a.dart'); | 50 var a = _p('/test/a.dart'); |
51 var b = _p('/test/b.dart'); | 51 var b = _p('/test/b.dart'); |
52 var c = _p('/test/c.dart'); | 52 var c = _p('/test/c.dart'); |
53 | 53 |
54 provider.newFile( | 54 provider.newFile(a, ''' |
55 a, | |
56 ''' | |
57 class A { | 55 class A { |
58 void a() {} | 56 void a() {} |
59 void b() {} | 57 void b() {} |
60 void c() {} | 58 void c() {} |
61 } | 59 } |
62 '''); | 60 '''); |
63 provider.newFile( | 61 provider.newFile(b, ''' |
64 b, | |
65 ''' | |
66 import 'a.dart'; | 62 import 'a.dart'; |
67 class B extends A { | 63 class B extends A { |
68 void a() {} | 64 void a() {} |
69 } | 65 } |
70 '''); | 66 '''); |
71 provider.newFile( | 67 provider.newFile(c, ''' |
72 c, | |
73 ''' | |
74 import 'a.dart'; | 68 import 'a.dart'; |
75 class C extends A { | 69 class C extends A { |
76 void b() {} | 70 void b() {} |
77 } | 71 } |
78 '''); | 72 '''); |
79 | 73 |
80 var driver1 = _newDriver(); | 74 var driver1 = _newDriver(); |
81 var driver2 = _newDriver(); | 75 var driver2 = _newDriver(); |
82 | 76 |
83 driver1.addFile(a); | 77 driver1.addFile(a); |
84 driver2.addFile(b); | 78 driver2.addFile(b); |
85 driver2.addFile(c); | 79 driver2.addFile(c); |
86 await scheduler.waitForIdle(); | 80 await scheduler.waitForIdle(); |
87 | 81 |
88 var resultA = await driver1.getResult(a); | 82 var resultA = await driver1.getResult(a); |
89 ClassElement elementA = resultA.unit.element.types[0]; | 83 ClassElement elementA = resultA.unit.element.types[0]; |
90 | 84 |
91 var searchEngine = new SearchEngineImpl([driver1, driver2]); | 85 var searchEngine = new SearchEngineImpl([driver1, driver2]); |
92 Set<String> members = await searchEngine.membersOfSubtypes(elementA); | 86 Set<String> members = await searchEngine.membersOfSubtypes(elementA); |
93 expect(members, unorderedEquals(['a', 'b'])); | 87 expect(members, unorderedEquals(['a', 'b'])); |
94 } | 88 } |
95 | 89 |
96 test_membersOfSubtypes_noMembers() async { | 90 test_membersOfSubtypes_noMembers() async { |
97 var a = _p('/test/a.dart'); | 91 var a = _p('/test/a.dart'); |
98 var b = _p('/test/b.dart'); | 92 var b = _p('/test/b.dart'); |
99 | 93 |
100 provider.newFile( | 94 provider.newFile(a, ''' |
101 a, | |
102 ''' | |
103 class A { | 95 class A { |
104 void a() {} | 96 void a() {} |
105 void b() {} | 97 void b() {} |
106 void c() {} | 98 void c() {} |
107 } | 99 } |
108 '''); | 100 '''); |
109 provider.newFile( | 101 provider.newFile(b, ''' |
110 b, | |
111 ''' | |
112 import 'a.dart'; | 102 import 'a.dart'; |
113 class B extends A {} | 103 class B extends A {} |
114 '''); | 104 '''); |
115 | 105 |
116 var driver = _newDriver(); | 106 var driver = _newDriver(); |
117 | 107 |
118 driver.addFile(a); | 108 driver.addFile(a); |
119 driver.addFile(b); | 109 driver.addFile(b); |
120 await scheduler.waitForIdle(); | 110 await scheduler.waitForIdle(); |
121 | 111 |
122 var resultA = await driver.getResult(a); | 112 var resultA = await driver.getResult(a); |
123 ClassElement elementA = resultA.unit.element.types[0]; | 113 ClassElement elementA = resultA.unit.element.types[0]; |
124 | 114 |
125 var searchEngine = new SearchEngineImpl([driver]); | 115 var searchEngine = new SearchEngineImpl([driver]); |
126 Set<String> members = await searchEngine.membersOfSubtypes(elementA); | 116 Set<String> members = await searchEngine.membersOfSubtypes(elementA); |
127 expect(members, isEmpty); | 117 expect(members, isEmpty); |
128 } | 118 } |
129 | 119 |
130 test_membersOfSubtypes_noSubtypes() async { | 120 test_membersOfSubtypes_noSubtypes() async { |
131 var a = _p('/test/a.dart'); | 121 var a = _p('/test/a.dart'); |
132 var b = _p('/test/b.dart'); | 122 var b = _p('/test/b.dart'); |
133 | 123 |
134 provider.newFile( | 124 provider.newFile(a, ''' |
135 a, | |
136 ''' | |
137 class A { | 125 class A { |
138 void a() {} | 126 void a() {} |
139 void b() {} | 127 void b() {} |
140 void c() {} | 128 void c() {} |
141 } | 129 } |
142 '''); | 130 '''); |
143 provider.newFile( | 131 provider.newFile(b, ''' |
144 b, | |
145 ''' | |
146 import 'a.dart'; | 132 import 'a.dart'; |
147 class B { | 133 class B { |
148 void a() {} | 134 void a() {} |
149 } | 135 } |
150 '''); | 136 '''); |
151 | 137 |
152 var driver = _newDriver(); | 138 var driver = _newDriver(); |
153 | 139 |
154 driver.addFile(a); | 140 driver.addFile(a); |
155 driver.addFile(b); | 141 driver.addFile(b); |
156 await scheduler.waitForIdle(); | 142 await scheduler.waitForIdle(); |
157 | 143 |
158 var resultA = await driver.getResult(a); | 144 var resultA = await driver.getResult(a); |
159 ClassElement elementA = resultA.unit.element.types[0]; | 145 ClassElement elementA = resultA.unit.element.types[0]; |
160 | 146 |
161 var searchEngine = new SearchEngineImpl([driver]); | 147 var searchEngine = new SearchEngineImpl([driver]); |
162 Set<String> members = await searchEngine.membersOfSubtypes(elementA); | 148 Set<String> members = await searchEngine.membersOfSubtypes(elementA); |
163 expect(members, isNull); | 149 expect(members, isNull); |
164 } | 150 } |
165 | 151 |
166 test_membersOfSubtypes_private() async { | 152 test_membersOfSubtypes_private() async { |
167 var a = _p('/test/a.dart'); | 153 var a = _p('/test/a.dart'); |
168 var b = _p('/test/b.dart'); | 154 var b = _p('/test/b.dart'); |
169 | 155 |
170 provider.newFile( | 156 provider.newFile(a, ''' |
171 a, | |
172 ''' | |
173 class A { | 157 class A { |
174 void a() {} | 158 void a() {} |
175 void _b() {} | 159 void _b() {} |
176 void _c() {} | 160 void _c() {} |
177 } | 161 } |
178 class B extends A { | 162 class B extends A { |
179 void _b() {} | 163 void _b() {} |
180 } | 164 } |
181 '''); | 165 '''); |
182 provider.newFile( | 166 provider.newFile(b, ''' |
183 b, | |
184 ''' | |
185 import 'a.dart'; | 167 import 'a.dart'; |
186 class C extends A { | 168 class C extends A { |
187 void a() {} | 169 void a() {} |
188 void _c() {} | 170 void _c() {} |
189 } | 171 } |
190 class D extends B { | 172 class D extends B { |
191 void _c() {} | 173 void _c() {} |
192 } | 174 } |
193 '''); | 175 '''); |
194 | 176 |
195 var driver1 = _newDriver(); | 177 var driver1 = _newDriver(); |
196 var driver2 = _newDriver(); | 178 var driver2 = _newDriver(); |
197 | 179 |
198 driver1.addFile(a); | 180 driver1.addFile(a); |
199 driver2.addFile(b); | 181 driver2.addFile(b); |
200 await scheduler.waitForIdle(); | 182 await scheduler.waitForIdle(); |
201 | 183 |
202 var resultA = await driver1.getResult(a); | 184 var resultA = await driver1.getResult(a); |
203 ClassElement elementA = resultA.unit.element.types[0]; | 185 ClassElement elementA = resultA.unit.element.types[0]; |
204 | 186 |
205 var searchEngine = new SearchEngineImpl([driver1, driver2]); | 187 var searchEngine = new SearchEngineImpl([driver1, driver2]); |
206 Set<String> members = await searchEngine.membersOfSubtypes(elementA); | 188 Set<String> members = await searchEngine.membersOfSubtypes(elementA); |
207 expect(members, unorderedEquals(['a', '_b'])); | 189 expect(members, unorderedEquals(['a', '_b'])); |
208 } | 190 } |
209 | 191 |
210 test_searchAllSubtypes() async { | 192 test_searchAllSubtypes() async { |
211 var p = _p('/test.dart'); | 193 var p = _p('/test.dart'); |
212 | 194 |
213 provider.newFile( | 195 provider.newFile(p, ''' |
214 p, | |
215 ''' | |
216 class T {} | 196 class T {} |
217 class A extends T {} | 197 class A extends T {} |
218 class B extends A {} | 198 class B extends A {} |
219 class C implements B {} | 199 class C implements B {} |
220 '''); | 200 '''); |
221 | 201 |
222 var driver = _newDriver(); | 202 var driver = _newDriver(); |
223 driver.addFile(p); | 203 driver.addFile(p); |
224 | 204 |
225 var resultA = await driver.getResult(p); | 205 var resultA = await driver.getResult(p); |
226 ClassElement element = resultA.unit.element.types[0]; | 206 ClassElement element = resultA.unit.element.types[0]; |
227 | 207 |
228 var searchEngine = new SearchEngineImpl([driver]); | 208 var searchEngine = new SearchEngineImpl([driver]); |
229 Set<ClassElement> subtypes = await searchEngine.searchAllSubtypes(element); | 209 Set<ClassElement> subtypes = await searchEngine.searchAllSubtypes(element); |
230 expect(subtypes, hasLength(3)); | 210 expect(subtypes, hasLength(3)); |
231 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'A'))); | 211 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'A'))); |
232 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'B'))); | 212 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'B'))); |
233 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'C'))); | 213 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'C'))); |
234 } | 214 } |
235 | 215 |
236 test_searchAllSubtypes_acrossDrivers() async { | 216 test_searchAllSubtypes_acrossDrivers() async { |
237 var a = _p('/test/a.dart'); | 217 var a = _p('/test/a.dart'); |
238 var b = _p('/test/b.dart'); | 218 var b = _p('/test/b.dart'); |
239 | 219 |
240 provider.newFile( | 220 provider.newFile(a, ''' |
241 a, | |
242 ''' | |
243 class T {} | 221 class T {} |
244 class A extends T {} | 222 class A extends T {} |
245 '''); | 223 '''); |
246 provider.newFile( | 224 provider.newFile(b, ''' |
247 b, | |
248 ''' | |
249 import 'a.dart'; | 225 import 'a.dart'; |
250 class B extends A {} | 226 class B extends A {} |
251 class C extends B {} | 227 class C extends B {} |
252 '''); | 228 '''); |
253 | 229 |
254 var driver1 = _newDriver(); | 230 var driver1 = _newDriver(); |
255 var driver2 = _newDriver(); | 231 var driver2 = _newDriver(); |
256 | 232 |
257 driver1.addFile(a); | 233 driver1.addFile(a); |
258 driver2.addFile(b); | 234 driver2.addFile(b); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 290 } |
315 | 291 |
316 assertHasElement('test', codeA.indexOf('test; // 1')); | 292 assertHasElement('test', codeA.indexOf('test; // 1')); |
317 assertHasElement('test', codeB.indexOf('test() {} // 2')); | 293 assertHasElement('test', codeB.indexOf('test() {} // 2')); |
318 } | 294 } |
319 | 295 |
320 test_searchMemberReferences() async { | 296 test_searchMemberReferences() async { |
321 var a = _p('/test/a.dart'); | 297 var a = _p('/test/a.dart'); |
322 var b = _p('/test/b.dart'); | 298 var b = _p('/test/b.dart'); |
323 | 299 |
324 provider.newFile( | 300 provider.newFile(a, ''' |
325 a, | |
326 ''' | |
327 class A { | 301 class A { |
328 int test; | 302 int test; |
329 } | 303 } |
330 foo(p) { | 304 foo(p) { |
331 p.test; | 305 p.test; |
332 } | 306 } |
333 '''); | 307 '''); |
334 provider.newFile( | 308 provider.newFile(b, ''' |
335 b, | |
336 ''' | |
337 import 'a.dart'; | 309 import 'a.dart'; |
338 bar(p) { | 310 bar(p) { |
339 p.test = 1; | 311 p.test = 1; |
340 } | 312 } |
341 '''); | 313 '''); |
342 | 314 |
343 var driver1 = _newDriver(); | 315 var driver1 = _newDriver(); |
344 var driver2 = _newDriver(); | 316 var driver2 = _newDriver(); |
345 | 317 |
346 driver1.addFile(a); | 318 driver1.addFile(a); |
(...skipping 10 matching lines...) Expand all Loading... |
357 expect( | 329 expect( |
358 matches, | 330 matches, |
359 contains(predicate((SearchMatch m) => | 331 contains(predicate((SearchMatch m) => |
360 m.element.name == 'bar' || m.kind == MatchKind.WRITE))); | 332 m.element.name == 'bar' || m.kind == MatchKind.WRITE))); |
361 } | 333 } |
362 | 334 |
363 test_searchReferences() async { | 335 test_searchReferences() async { |
364 var a = _p('/test/a.dart'); | 336 var a = _p('/test/a.dart'); |
365 var b = _p('/test/b.dart'); | 337 var b = _p('/test/b.dart'); |
366 | 338 |
367 provider.newFile( | 339 provider.newFile(a, ''' |
368 a, | |
369 ''' | |
370 class T {} | 340 class T {} |
371 T a; | 341 T a; |
372 '''); | 342 '''); |
373 provider.newFile( | 343 provider.newFile(b, ''' |
374 b, | |
375 ''' | |
376 import 'a.dart'; | 344 import 'a.dart'; |
377 T b; | 345 T b; |
378 '''); | 346 '''); |
379 | 347 |
380 var driver1 = _newDriver(); | 348 var driver1 = _newDriver(); |
381 var driver2 = _newDriver(); | 349 var driver2 = _newDriver(); |
382 | 350 |
383 driver1.addFile(a); | 351 driver1.addFile(a); |
384 driver2.addFile(b); | 352 driver2.addFile(b); |
385 | 353 |
386 var resultA = await driver1.getResult(a); | 354 var resultA = await driver1.getResult(a); |
387 ClassElement element = resultA.unit.element.types[0]; | 355 ClassElement element = resultA.unit.element.types[0]; |
388 | 356 |
389 var searchEngine = new SearchEngineImpl([driver1, driver2]); | 357 var searchEngine = new SearchEngineImpl([driver1, driver2]); |
390 List<SearchMatch> matches = await searchEngine.searchReferences(element); | 358 List<SearchMatch> matches = await searchEngine.searchReferences(element); |
391 expect(matches, hasLength(2)); | 359 expect(matches, hasLength(2)); |
392 expect( | 360 expect( |
393 matches, contains(predicate((SearchMatch m) => m.element.name == 'a'))); | 361 matches, contains(predicate((SearchMatch m) => m.element.name == 'a'))); |
394 expect( | 362 expect( |
395 matches, contains(predicate((SearchMatch m) => m.element.name == 'b'))); | 363 matches, contains(predicate((SearchMatch m) => m.element.name == 'b'))); |
396 } | 364 } |
397 | 365 |
398 test_searchTopLevelDeclarations() async { | 366 test_searchTopLevelDeclarations() async { |
399 var a = _p('/test/a.dart'); | 367 var a = _p('/test/a.dart'); |
400 var b = _p('/test/b.dart'); | 368 var b = _p('/test/b.dart'); |
401 | 369 |
402 provider.newFile( | 370 provider.newFile(a, ''' |
403 a, | |
404 ''' | |
405 class A {} | 371 class A {} |
406 int a; | 372 int a; |
407 '''); | 373 '''); |
408 provider.newFile( | 374 provider.newFile(b, ''' |
409 b, | |
410 ''' | |
411 class B {} | 375 class B {} |
412 get b => 42; | 376 get b => 42; |
413 '''); | 377 '''); |
414 | 378 |
415 var driver1 = _newDriver(); | 379 var driver1 = _newDriver(); |
416 var driver2 = _newDriver(); | 380 var driver2 = _newDriver(); |
417 | 381 |
418 driver1.addFile(a); | 382 driver1.addFile(a); |
419 driver2.addFile(b); | 383 driver2.addFile(b); |
420 | 384 |
(...skipping 28 matching lines...) Expand all Loading... |
449 contentOverlay, | 413 contentOverlay, |
450 null, | 414 null, |
451 new SourceFactory( | 415 new SourceFactory( |
452 [new DartUriResolver(sdk), new ResourceUriResolver(provider)], | 416 [new DartUriResolver(sdk), new ResourceUriResolver(provider)], |
453 null, | 417 null, |
454 provider), | 418 provider), |
455 new AnalysisOptionsImpl()..strongMode = true); | 419 new AnalysisOptionsImpl()..strongMode = true); |
456 | 420 |
457 String _p(String path) => provider.convertPath(path); | 421 String _p(String path) => provider.convertPath(path); |
458 } | 422 } |
OLD | NEW |