| 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 'package:analysis_server/src/services/index/index.dart'; | 5 import 'package:analysis_server/src/services/index/index.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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 List<Location> locations = await index.getDefinedNames( | 115 List<Location> locations = await index.getDefinedNames( |
| 116 new RegExp(r'^[A-E]$'), IndexNameKind.topLevel); | 116 new RegExp(r'^[A-E]$'), IndexNameKind.topLevel); |
| 117 expect(locations, hasLength(5)); | 117 expect(locations, hasLength(5)); |
| 118 _assertHasDefinedName(locations, topA); | 118 _assertHasDefinedName(locations, topA); |
| 119 _assertHasDefinedName(locations, topB); | 119 _assertHasDefinedName(locations, topB); |
| 120 _assertHasDefinedName(locations, topC); | 120 _assertHasDefinedName(locations, topC); |
| 121 _assertHasDefinedName(locations, topD); | 121 _assertHasDefinedName(locations, topD); |
| 122 _assertHasDefinedName(locations, topE); | 122 _assertHasDefinedName(locations, topE); |
| 123 } | 123 } |
| 124 | 124 |
| 125 test_getDefinedNames_topLevel2() async { |
| 126 _indexTestUnit( |
| 127 ''' |
| 128 class A {} // A |
| 129 class B = Object with A; |
| 130 class NoMatchABCDE {} |
| 131 ''', |
| 132 declOnly: true); |
| 133 Element topA = findElement('A'); |
| 134 Element topB = findElement('B'); |
| 135 List<Location> locations = await index.getDefinedNames( |
| 136 new RegExp(r'^[A-E]$'), IndexNameKind.topLevel); |
| 137 expect(locations, hasLength(2)); |
| 138 _assertHasDefinedName(locations, topA); |
| 139 _assertHasDefinedName(locations, topB); |
| 140 } |
| 141 |
| 125 test_getRelations_isExtendedBy() async { | 142 test_getRelations_isExtendedBy() async { |
| 126 _indexTestUnit(r''' | 143 _indexTestUnit(r''' |
| 127 class A {} | 144 class A {} |
| 128 class B extends A {} // B | 145 class B extends A {} // B |
| 129 '''); | 146 '''); |
| 130 Source source2 = _indexUnit( | 147 Source source2 = _indexUnit( |
| 131 '/test2.dart', | 148 '/test2.dart', |
| 132 r''' | 149 r''' |
| 133 import 'test.dart'; | 150 import 'test.dart'; |
| 134 class C extends A {} // C | 151 class C extends A {} // C |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 '''); | 240 '''); |
| 224 List<Location> locations = | 241 List<Location> locations = |
| 225 await index.getUnresolvedMemberReferences('test'); | 242 await index.getUnresolvedMemberReferences('test'); |
| 226 expect(locations, hasLength(4)); | 243 expect(locations, hasLength(4)); |
| 227 findLocationTest(locations, 'test);', false); | 244 findLocationTest(locations, 'test);', false); |
| 228 findLocationTest(locations, 'test = 1;', false); | 245 findLocationTest(locations, 'test = 1;', false); |
| 229 findLocationTest(locations, 'test += 2;', false); | 246 findLocationTest(locations, 'test += 2;', false); |
| 230 findLocationTest(locations, 'test();', false); | 247 findLocationTest(locations, 'test();', false); |
| 231 } | 248 } |
| 232 | 249 |
| 250 test_indexDeclarations_nullUnit() async { |
| 251 index.indexDeclarations(null); |
| 252 } |
| 253 |
| 254 test_indexDeclarations_nullUnitElement() async { |
| 255 resolveTestUnit(''); |
| 256 testUnit.element = null; |
| 257 index.indexDeclarations(testUnit); |
| 258 } |
| 259 |
| 233 test_indexUnit_nullUnit() async { | 260 test_indexUnit_nullUnit() async { |
| 234 index.indexUnit(null); | 261 index.indexUnit(null); |
| 235 } | 262 } |
| 236 | 263 |
| 237 test_indexUnit_nullUnitElement() async { | 264 test_indexUnit_nullUnitElement() async { |
| 238 resolveTestUnit(''); | 265 resolveTestUnit(''); |
| 239 testUnit.element = null; | 266 testUnit.element = null; |
| 240 index.indexUnit(testUnit); | 267 index.indexUnit(testUnit); |
| 241 } | 268 } |
| 242 | 269 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 location.unitUri == unitUri && | 318 location.unitUri == unitUri && |
| 292 location.offset == element.nameOffset && | 319 location.offset == element.nameOffset && |
| 293 location.length == element.nameLength) { | 320 location.length == element.nameLength) { |
| 294 return; | 321 return; |
| 295 } | 322 } |
| 296 } | 323 } |
| 297 fail('No declaration of $element at ${element.nameOffset} in\n' | 324 fail('No declaration of $element at ${element.nameOffset} in\n' |
| 298 '${locations.join('\n')}'); | 325 '${locations.join('\n')}'); |
| 299 } | 326 } |
| 300 | 327 |
| 301 void _indexTestUnit(String code) { | 328 void _indexTestUnit(String code, {bool declOnly: false}) { |
| 302 resolveTestUnit(code); | 329 resolveTestUnit(code); |
| 303 index.indexUnit(testUnit); | 330 if (declOnly) { |
| 331 index.indexDeclarations(testUnit); |
| 332 } else { |
| 333 index.indexUnit(testUnit); |
| 334 } |
| 304 } | 335 } |
| 305 | 336 |
| 306 Source _indexUnit(String path, String code) { | 337 Source _indexUnit(String path, String code) { |
| 307 Source source = addSource(path, code); | 338 Source source = addSource(path, code); |
| 308 CompilationUnit unit = resolveLibraryUnit(source); | 339 CompilationUnit unit = resolveLibraryUnit(source); |
| 309 index.indexUnit(unit); | 340 index.indexUnit(unit); |
| 310 return source; | 341 return source; |
| 311 } | 342 } |
| 312 } | 343 } |
| OLD | NEW |