| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 '''); | 241 '''); |
| 242 List<Location> locations = | 242 List<Location> locations = |
| 243 await index.getUnresolvedMemberReferences('test'); | 243 await index.getUnresolvedMemberReferences('test'); |
| 244 expect(locations, hasLength(4)); | 244 expect(locations, hasLength(4)); |
| 245 findLocationTest(locations, 'test);', false); | 245 findLocationTest(locations, 'test);', false); |
| 246 findLocationTest(locations, 'test = 1;', false); | 246 findLocationTest(locations, 'test = 1;', false); |
| 247 findLocationTest(locations, 'test += 2;', false); | 247 findLocationTest(locations, 'test += 2;', false); |
| 248 findLocationTest(locations, 'test();', false); | 248 findLocationTest(locations, 'test();', false); |
| 249 } | 249 } |
| 250 | 250 |
| 251 test_indexDeclarations_afterIndexUnit() async { |
| 252 resolveTestUnit(''' |
| 253 var a = 0; |
| 254 var b = a + 1; |
| 255 '''); |
| 256 index.indexUnit(testUnit); |
| 257 TopLevelVariableElement a = findElement('a'); |
| 258 // We can find references. |
| 259 { |
| 260 List<Location> locations = await index.getRelations( |
| 261 a.getter, IndexRelationKind.IS_REFERENCED_BY); |
| 262 findLocationTest(locations, 'a + 1', false); |
| 263 } |
| 264 // Attempt to index just declarations - we still can find references. |
| 265 index.indexDeclarations(testUnit); |
| 266 { |
| 267 List<Location> locations = await index.getRelations( |
| 268 a.getter, IndexRelationKind.IS_REFERENCED_BY); |
| 269 findLocationTest(locations, 'a + 1', false); |
| 270 } |
| 271 } |
| 272 |
| 251 test_indexDeclarations_nullUnit() async { | 273 test_indexDeclarations_nullUnit() async { |
| 252 index.indexDeclarations(null); | 274 index.indexDeclarations(null); |
| 253 } | 275 } |
| 254 | 276 |
| 255 test_indexDeclarations_nullUnitElement() async { | 277 test_indexDeclarations_nullUnitElement() async { |
| 256 resolveTestUnit(''); | 278 resolveTestUnit(''); |
| 257 testUnit.element = null; | 279 testUnit.element = null; |
| 258 index.indexDeclarations(testUnit); | 280 index.indexDeclarations(testUnit); |
| 259 } | 281 } |
| 260 | 282 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 Source _indexUnit(String path, String code) { | 368 Source _indexUnit(String path, String code) { |
| 347 Source source = addSource(path, code); | 369 Source source = addSource(path, code); |
| 348 CompilationUnit unit = resolveLibraryUnit(source); | 370 CompilationUnit unit = resolveLibraryUnit(source); |
| 349 index.indexUnit(unit); | 371 index.indexUnit(unit); |
| 350 return source; | 372 return source; |
| 351 } | 373 } |
| 352 } | 374 } |
| 353 | 375 |
| 354 class _CompilationUnitElementMock extends TypedMock | 376 class _CompilationUnitElementMock extends TypedMock |
| 355 implements CompilationUnitElement {} | 377 implements CompilationUnitElement {} |
| OLD | NEW |