| 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_server/src/services/index/index.dart'; | 7 import 'package:analysis_server/src/services/index/index.dart'; |
| 8 import 'package:analysis_server/src/services/index/index_contributor.dart'; | 8 import 'package:analysis_server/src/services/index/index_contributor.dart'; |
| 9 import 'package:analysis_server/src/services/index/index_store.dart'; | 9 import 'package:analysis_server/src/services/index/index_store.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 expected.isQualified, | 35 expected.isQualified, |
| 36 expected.isResolved); | 36 expected.isResolved); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Returns `true` if the [actual] location the expected properties. | 41 * Returns `true` if the [actual] location the expected properties. |
| 42 */ | 42 */ |
| 43 bool _equalsLocationProperties(Location actual, Element expectedElement, | 43 bool _equalsLocationProperties(Location actual, Element expectedElement, |
| 44 int expectedOffset, int expectedLength, bool isQualified, bool isResolved) { | 44 int expectedOffset, int expectedLength, bool isQualified, bool isResolved) { |
| 45 return expectedElement == actual.element && | 45 return (expectedElement == null || expectedElement == actual.element) && |
| 46 expectedOffset == actual.offset && | 46 expectedOffset == actual.offset && |
| 47 expectedLength == actual.length && | 47 expectedLength == actual.length && |
| 48 isQualified == actual.isQualified && | 48 isQualified == actual.isQualified && |
| 49 isResolved == actual.isResolved; | 49 isResolved == actual.isResolved; |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 bool _equalsRecordedRelation(RecordedRelation recordedRelation, | 53 bool _equalsRecordedRelation(RecordedRelation recordedRelation, |
| 54 Element expectedElement, Relationship expectedRelationship, | 54 Element expectedElement, Relationship expectedRelationship, |
| 55 ExpectedLocation expectedLocation) { | 55 ExpectedLocation expectedLocation) { |
| 56 return expectedElement == recordedRelation.element && | 56 return expectedElement == recordedRelation.element && |
| 57 expectedRelationship == recordedRelation.relationship && | 57 (expectedRelationship == null || |
| 58 expectedRelationship == recordedRelation.relationship) && |
| 58 (expectedLocation == null || | 59 (expectedLocation == null || |
| 59 _equalsLocation(recordedRelation.location, expectedLocation)); | 60 _equalsLocation(recordedRelation.location, expectedLocation)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 | 63 |
| 63 @ReflectiveTestCase() | 64 @ReflectiveTestCase() |
| 64 class DartUnitContributorTest extends AbstractSingleUnitTest { | 65 class DartUnitContributorTest extends AbstractSingleUnitTest { |
| 65 IndexStore store = new MockIndexStore(); | 66 IndexStore store = new MockIndexStore(); |
| 66 List<RecordedRelation> recordedRelations = <RecordedRelation>[]; | 67 List<RecordedRelation> recordedRelations = <RecordedRelation>[]; |
| 67 | 68 |
| (...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 // prepare elements | 1331 // prepare elements |
| 1331 Element mainElement = findElement('main'); | 1332 Element mainElement = findElement('main'); |
| 1332 Element element = findElement('p'); | 1333 Element element = findElement('p'); |
| 1333 // verify | 1334 // verify |
| 1334 _assertRecordedRelation( | 1335 _assertRecordedRelation( |
| 1335 element, | 1336 element, |
| 1336 IndexConstants.IS_REFERENCED_BY, | 1337 IndexConstants.IS_REFERENCED_BY, |
| 1337 _expectedLocation(mainElement, 'p: 1')); | 1338 _expectedLocation(mainElement, 'p: 1')); |
| 1338 } | 1339 } |
| 1339 | 1340 |
| 1341 void test_isReferencedBy_PrefixElement() { |
| 1342 _indexTestUnit(''' |
| 1343 import 'dart:async' as ppp; |
| 1344 main() { |
| 1345 ppp.Future a; |
| 1346 ppp.Stream b; |
| 1347 } |
| 1348 '''); |
| 1349 // prepare elements |
| 1350 PrefixElement element = findNodeElementAtString('ppp;'); |
| 1351 Element elementA = findElement('a'); |
| 1352 Element elementB = findElement('b'); |
| 1353 // verify |
| 1354 _assertRecordedRelation( |
| 1355 element, |
| 1356 IndexConstants.IS_REFERENCED_BY, |
| 1357 _expectedLocation(elementA, 'ppp.Future')); |
| 1358 _assertRecordedRelation( |
| 1359 element, |
| 1360 IndexConstants.IS_REFERENCED_BY, |
| 1361 _expectedLocation(elementB, 'ppp.Stream')); |
| 1362 _assertNoRecordedRelation(element, null, _expectedLocation(null, 'ppp;')); |
| 1363 } |
| 1364 |
| 1340 void test_isReferencedBy_TopLevelVariableElement() { | 1365 void test_isReferencedBy_TopLevelVariableElement() { |
| 1341 addSource('/lib.dart', ''' | 1366 addSource('/lib.dart', ''' |
| 1342 library lib; | 1367 library lib; |
| 1343 var V; | 1368 var V; |
| 1344 '''); | 1369 '''); |
| 1345 _indexTestUnit(''' | 1370 _indexTestUnit(''' |
| 1346 import 'lib.dart' show V; // imp | 1371 import 'lib.dart' show V; // imp |
| 1347 import 'lib.dart' as pref; | 1372 import 'lib.dart' as pref; |
| 1348 main() { | 1373 main() { |
| 1349 pref.V = 5; // q | 1374 pref.V = 5; // q |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 | 1745 |
| 1721 RecordedRelation(this.element, this.relationship, this.location); | 1746 RecordedRelation(this.element, this.relationship, this.location); |
| 1722 | 1747 |
| 1723 @override | 1748 @override |
| 1724 String toString() { | 1749 String toString() { |
| 1725 return 'RecordedRelation(element=$element; relationship=$relationship; ' | 1750 return 'RecordedRelation(element=$element; relationship=$relationship; ' |
| 1726 'location=$location; flags=' '${location.isQualified ? "Q" : ""}' | 1751 'location=$location; flags=' '${location.isQualified ? "Q" : ""}' |
| 1727 '${location.isResolved ? "R" : ""})'; | 1752 '${location.isResolved ? "R" : ""})'; |
| 1728 } | 1753 } |
| 1729 } | 1754 } |
| OLD | NEW |