| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.index; | 8 library engine.index; |
| 9 | 9 |
| 10 import 'dart:collection' show Queue; | 10 import 'dart:collection' show Queue; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 * | 43 * |
| 44 * @param indexStore the index store against which this operation is being run | 44 * @param indexStore the index store against which this operation is being run |
| 45 * @param context the [AnalysisContext] to remove source in | 45 * @param context the [AnalysisContext] to remove source in |
| 46 * @param source the [Source] to remove from index | 46 * @param source the [Source] to remove from index |
| 47 */ | 47 */ |
| 48 RemoveSourceOperation(IndexStore indexStore, AnalysisContext context, this.sou
rce) { | 48 RemoveSourceOperation(IndexStore indexStore, AnalysisContext context, this.sou
rce) { |
| 49 this._indexStore = indexStore; | 49 this._indexStore = indexStore; |
| 50 this._context = context; | 50 this._context = context; |
| 51 } | 51 } |
| 52 | 52 |
| 53 @override |
| 53 bool get isQuery => false; | 54 bool get isQuery => false; |
| 54 | 55 |
| 56 @override |
| 55 void performOperation() { | 57 void performOperation() { |
| 56 _indexStore.removeSource(_context, source); | 58 _indexStore.removeSource(_context, source); |
| 57 } | 59 } |
| 58 | 60 |
| 61 @override |
| 59 bool removeWhenSourceRemoved(Source source) => false; | 62 bool removeWhenSourceRemoved(Source source) => false; |
| 60 | 63 |
| 64 @override |
| 61 String toString() => "RemoveSource(${source.fullName})"; | 65 String toString() => "RemoveSource(${source.fullName})"; |
| 62 } | 66 } |
| 63 | 67 |
| 64 /** | 68 /** |
| 65 * The interface [IndexOperation] defines the behavior of objects used to perfor
m operations | 69 * The interface [IndexOperation] defines the behavior of objects used to perfor
m operations |
| 66 * on an index. | 70 * on an index. |
| 67 */ | 71 */ |
| 68 abstract class IndexOperation { | 72 abstract class IndexOperation { |
| 69 /** | 73 /** |
| 70 * Return `true` if this operation returns information from the index. | 74 * Return `true` if this operation returns information from the index. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 * The mapping of unit [Source] to the [Source]s of libraries it is used in. | 157 * The mapping of unit [Source] to the [Source]s of libraries it is used in. |
| 154 */ | 158 */ |
| 155 Map<AnalysisContext, Map<Source, Set<Source>>> _contextToUnitToLibraries = {}; | 159 Map<AnalysisContext, Map<Source, Set<Source>>> _contextToUnitToLibraries = {}; |
| 156 | 160 |
| 157 int _sourceCount = 0; | 161 int _sourceCount = 0; |
| 158 | 162 |
| 159 int _keyCount = 0; | 163 int _keyCount = 0; |
| 160 | 164 |
| 161 int _locationCount = 0; | 165 int _locationCount = 0; |
| 162 | 166 |
| 167 @override |
| 163 bool aboutToIndexDart(AnalysisContext context, CompilationUnitElement unitElem
ent) { | 168 bool aboutToIndexDart(AnalysisContext context, CompilationUnitElement unitElem
ent) { |
| 164 context = unwrapContext(context); | 169 context = unwrapContext(context); |
| 165 // may be already disposed in other thread | 170 // may be already disposed in other thread |
| 166 if (context.isDisposed) { | 171 if (context.isDisposed) { |
| 167 return false; | 172 return false; |
| 168 } | 173 } |
| 169 // validate unit | 174 // validate unit |
| 170 if (unitElement == null) { | 175 if (unitElement == null) { |
| 171 return false; | 176 return false; |
| 172 } | 177 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 bool hadSource = sourceToKeys.remove(source2) != null; | 222 bool hadSource = sourceToKeys.remove(source2) != null; |
| 218 if (hadSource) { | 223 if (hadSource) { |
| 219 _sourceCount--; | 224 _sourceCount--; |
| 220 } | 225 } |
| 221 } | 226 } |
| 222 } | 227 } |
| 223 // OK, we can index | 228 // OK, we can index |
| 224 return true; | 229 return true; |
| 225 } | 230 } |
| 226 | 231 |
| 232 @override |
| 227 bool aboutToIndexHtml(AnalysisContext context, HtmlElement htmlElement) { | 233 bool aboutToIndexHtml(AnalysisContext context, HtmlElement htmlElement) { |
| 228 context = unwrapContext(context); | 234 context = unwrapContext(context); |
| 229 // may be already disposed in other thread | 235 // may be already disposed in other thread |
| 230 if (context.isDisposed) { | 236 if (context.isDisposed) { |
| 231 return false; | 237 return false; |
| 232 } | 238 } |
| 233 // remove locations | 239 // remove locations |
| 234 Source source = htmlElement.source; | 240 Source source = htmlElement.source; |
| 235 _removeLocations(context, null, source); | 241 _removeLocations(context, null, source); |
| 236 // remove keys | 242 // remove keys |
| 237 { | 243 { |
| 238 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelation
Key>> sourceToKeys = _contextToSourceToKeys[context]; | 244 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelation
Key>> sourceToKeys = _contextToSourceToKeys[context]; |
| 239 if (sourceToKeys != null) { | 245 if (sourceToKeys != null) { |
| 240 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2(
null, source); | 246 MemoryIndexStoreImpl_Source2 source2 = new MemoryIndexStoreImpl_Source2(
null, source); |
| 241 bool hadSource = sourceToKeys.remove(source2) != null; | 247 bool hadSource = sourceToKeys.remove(source2) != null; |
| 242 if (hadSource) { | 248 if (hadSource) { |
| 243 _sourceCount--; | 249 _sourceCount--; |
| 244 } | 250 } |
| 245 } | 251 } |
| 246 } | 252 } |
| 247 // remember libraries in which unit is used | 253 // remember libraries in which unit is used |
| 248 _recordUnitInLibrary(context, null, source); | 254 _recordUnitInLibrary(context, null, source); |
| 249 // OK, we can index | 255 // OK, we can index |
| 250 return true; | 256 return true; |
| 251 } | 257 } |
| 252 | 258 |
| 259 @override |
| 253 List<Location> getRelationships(Element element, Relationship relationship) { | 260 List<Location> getRelationships(Element element, Relationship relationship) { |
| 254 MemoryIndexStoreImpl_ElementRelationKey key = new MemoryIndexStoreImpl_Eleme
ntRelationKey(element, relationship); | 261 MemoryIndexStoreImpl_ElementRelationKey key = new MemoryIndexStoreImpl_Eleme
ntRelationKey(element, relationship); |
| 255 Set<Location> locations = _keyToLocations[key]; | 262 Set<Location> locations = _keyToLocations[key]; |
| 256 if (locations != null) { | 263 if (locations != null) { |
| 257 return new List.from(locations); | 264 return new List.from(locations); |
| 258 } | 265 } |
| 259 return Location.EMPTY_ARRAY; | 266 return Location.EMPTY_ARRAY; |
| 260 } | 267 } |
| 261 | 268 |
| 269 @override |
| 262 String get statistics => "${_locationCount} relationships in ${_keyCount} keys
in ${_sourceCount} sources"; | 270 String get statistics => "${_locationCount} relationships in ${_keyCount} keys
in ${_sourceCount} sources"; |
| 263 | 271 |
| 264 int internalGetKeyCount() => _keyToLocations.length; | 272 int internalGetKeyCount() => _keyToLocations.length; |
| 265 | 273 |
| 266 int internalGetLocationCount() { | 274 int internalGetLocationCount() { |
| 267 int count = 0; | 275 int count = 0; |
| 268 for (Set<Location> locations in _keyToLocations.values) { | 276 for (Set<Location> locations in _keyToLocations.values) { |
| 269 count += locations.length; | 277 count += locations.length; |
| 270 } | 278 } |
| 271 return count; | 279 return count; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 288 int count = 0; | 296 int count = 0; |
| 289 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelationKe
y>> sourceToKeys = _contextToSourceToKeys[context]; | 297 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelationKe
y>> sourceToKeys = _contextToSourceToKeys[context]; |
| 290 if (sourceToKeys != null) { | 298 if (sourceToKeys != null) { |
| 291 for (Set<MemoryIndexStoreImpl_ElementRelationKey> keys in sourceToKeys.val
ues) { | 299 for (Set<MemoryIndexStoreImpl_ElementRelationKey> keys in sourceToKeys.val
ues) { |
| 292 count += keys.length; | 300 count += keys.length; |
| 293 } | 301 } |
| 294 } | 302 } |
| 295 return count; | 303 return count; |
| 296 } | 304 } |
| 297 | 305 |
| 306 @override |
| 298 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { | 307 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { |
| 299 if (element == null || location == null) { | 308 if (element == null || location == null) { |
| 300 return; | 309 return; |
| 301 } | 310 } |
| 302 location = location.clone(); | 311 location = location.newClone(); |
| 303 // at the index level we don't care about Member(s) | 312 // at the index level we don't care about Member(s) |
| 304 if (element is Member) { | 313 if (element is Member) { |
| 305 element = (element as Member).baseElement; | 314 element = (element as Member).baseElement; |
| 306 } | 315 } |
| 307 // System.out.println(element + " " + relationship + " " + location); | 316 // System.out.println(element + " " + relationship + " " + location); |
| 308 // prepare information | 317 // prepare information |
| 309 AnalysisContext elementContext = element.context; | 318 AnalysisContext elementContext = element.context; |
| 310 AnalysisContext locationContext = location.element.context; | 319 AnalysisContext locationContext = location.element.context; |
| 311 Source elementSource = element.source; | 320 Source elementSource = element.source; |
| 312 Source locationSource = location.element.source; | 321 Source locationSource = location.element.source; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 385 } |
| 377 List<Location> locations = sourceToLocations[locationSource2]; | 386 List<Location> locations = sourceToLocations[locationSource2]; |
| 378 if (locations == null) { | 387 if (locations == null) { |
| 379 locations = []; | 388 locations = []; |
| 380 sourceToLocations[locationSource2] = locations; | 389 sourceToLocations[locationSource2] = locations; |
| 381 } | 390 } |
| 382 locations.add(location); | 391 locations.add(location); |
| 383 } | 392 } |
| 384 } | 393 } |
| 385 | 394 |
| 395 @override |
| 386 void removeContext(AnalysisContext context) { | 396 void removeContext(AnalysisContext context) { |
| 387 context = unwrapContext(context); | 397 context = unwrapContext(context); |
| 388 if (context == null) { | 398 if (context == null) { |
| 389 return; | 399 return; |
| 390 } | 400 } |
| 391 // remove sources | 401 // remove sources |
| 392 removeSources(context, null); | 402 removeSources(context, null); |
| 393 // remove context | 403 // remove context |
| 394 _contextToSourceToKeys.remove(context); | 404 _contextToSourceToKeys.remove(context); |
| 395 _contextToSourceToLocations.remove(context); | 405 _contextToSourceToLocations.remove(context); |
| 396 _contextToLibraryToUnits.remove(context); | 406 _contextToLibraryToUnits.remove(context); |
| 397 _contextToUnitToLibraries.remove(context); | 407 _contextToUnitToLibraries.remove(context); |
| 398 } | 408 } |
| 399 | 409 |
| 410 @override |
| 400 void removeSource(AnalysisContext context, Source unit) { | 411 void removeSource(AnalysisContext context, Source unit) { |
| 401 context = unwrapContext(context); | 412 context = unwrapContext(context); |
| 402 if (context == null) { | 413 if (context == null) { |
| 403 return; | 414 return; |
| 404 } | 415 } |
| 405 // remove locations defined in source | 416 // remove locations defined in source |
| 406 Map<Source, Set<Source>> unitToLibraries = _contextToUnitToLibraries[context
]; | 417 Map<Source, Set<Source>> unitToLibraries = _contextToUnitToLibraries[context
]; |
| 407 if (unitToLibraries != null) { | 418 if (unitToLibraries != null) { |
| 408 Set<Source> libraries = unitToLibraries.remove(unit); | 419 Set<Source> libraries = unitToLibraries.remove(unit); |
| 409 if (libraries != null) { | 420 if (libraries != null) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 425 } | 436 } |
| 426 } | 437 } |
| 427 _sourceCount--; | 438 _sourceCount--; |
| 428 } | 439 } |
| 429 } | 440 } |
| 430 } | 441 } |
| 431 } | 442 } |
| 432 } | 443 } |
| 433 } | 444 } |
| 434 | 445 |
| 446 @override |
| 435 void removeSources(AnalysisContext context, SourceContainer container) { | 447 void removeSources(AnalysisContext context, SourceContainer container) { |
| 436 context = unwrapContext(context); | 448 context = unwrapContext(context); |
| 437 if (context == null) { | 449 if (context == null) { |
| 438 return; | 450 return; |
| 439 } | 451 } |
| 440 // remove sources #1 | 452 // remove sources #1 |
| 441 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelationKe
y>> sourceToKeys = _contextToSourceToKeys[context]; | 453 Map<MemoryIndexStoreImpl_Source2, Set<MemoryIndexStoreImpl_ElementRelationKe
y>> sourceToKeys = _contextToSourceToKeys[context]; |
| 442 if (sourceToKeys != null) { | 454 if (sourceToKeys != null) { |
| 443 List<MemoryIndexStoreImpl_Source2> sources = []; | 455 List<MemoryIndexStoreImpl_Source2> sources = []; |
| 444 for (MemoryIndexStoreImpl_Source2 source2 in sources) { | 456 for (MemoryIndexStoreImpl_Source2 source2 in sources) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 class MemoryIndexStoreImpl_ElementRelationKey { | 537 class MemoryIndexStoreImpl_ElementRelationKey { |
| 526 Element _element; | 538 Element _element; |
| 527 | 539 |
| 528 Relationship _relationship; | 540 Relationship _relationship; |
| 529 | 541 |
| 530 MemoryIndexStoreImpl_ElementRelationKey(Element element, Relationship relation
ship) { | 542 MemoryIndexStoreImpl_ElementRelationKey(Element element, Relationship relation
ship) { |
| 531 this._element = element; | 543 this._element = element; |
| 532 this._relationship = relationship; | 544 this._relationship = relationship; |
| 533 } | 545 } |
| 534 | 546 |
| 547 @override |
| 535 bool operator ==(Object obj) { | 548 bool operator ==(Object obj) { |
| 536 MemoryIndexStoreImpl_ElementRelationKey other = obj as MemoryIndexStoreImpl_
ElementRelationKey; | 549 MemoryIndexStoreImpl_ElementRelationKey other = obj as MemoryIndexStoreImpl_
ElementRelationKey; |
| 537 Element otherElement = other._element; | 550 Element otherElement = other._element; |
| 538 return identical(other._relationship, _relationship) && otherElement.nameOff
set == _element.nameOffset && identical(otherElement.kind, _element.kind) && oth
erElement.displayName == _element.displayName && otherElement.source == _element
.source; | 551 return identical(other._relationship, _relationship) && otherElement.nameOff
set == _element.nameOffset && identical(otherElement.kind, _element.kind) && oth
erElement.displayName == _element.displayName && otherElement.source == _element
.source; |
| 539 } | 552 } |
| 540 | 553 |
| 554 @override |
| 541 int get hashCode => JavaArrays.makeHashCode([ | 555 int get hashCode => JavaArrays.makeHashCode([ |
| 542 _element.source, | 556 _element.source, |
| 543 _element.nameOffset, | 557 _element.nameOffset, |
| 544 _element.kind, | 558 _element.kind, |
| 545 _element.displayName, | 559 _element.displayName, |
| 546 _relationship]); | 560 _relationship]); |
| 547 | 561 |
| 562 @override |
| 548 String toString() => "${_element} ${_relationship}"; | 563 String toString() => "${_element} ${_relationship}"; |
| 549 } | 564 } |
| 550 | 565 |
| 551 class MemoryIndexStoreImpl_Source2 { | 566 class MemoryIndexStoreImpl_Source2 { |
| 552 Source _librarySource; | 567 Source _librarySource; |
| 553 | 568 |
| 554 Source _unitSource; | 569 Source _unitSource; |
| 555 | 570 |
| 556 MemoryIndexStoreImpl_Source2(Source librarySource, Source unitSource) { | 571 MemoryIndexStoreImpl_Source2(Source librarySource, Source unitSource) { |
| 557 this._librarySource = librarySource; | 572 this._librarySource = librarySource; |
| 558 this._unitSource = unitSource; | 573 this._unitSource = unitSource; |
| 559 } | 574 } |
| 560 | 575 |
| 576 @override |
| 561 bool operator ==(Object obj) { | 577 bool operator ==(Object obj) { |
| 562 if (identical(obj, this)) { | 578 if (identical(obj, this)) { |
| 563 return true; | 579 return true; |
| 564 } | 580 } |
| 565 if (obj is! MemoryIndexStoreImpl_Source2) { | 581 if (obj is! MemoryIndexStoreImpl_Source2) { |
| 566 return false; | 582 return false; |
| 567 } | 583 } |
| 568 MemoryIndexStoreImpl_Source2 other = obj as MemoryIndexStoreImpl_Source2; | 584 MemoryIndexStoreImpl_Source2 other = obj as MemoryIndexStoreImpl_Source2; |
| 569 return other._librarySource == _librarySource && other._unitSource == _unitS
ource; | 585 return other._librarySource == _librarySource && other._unitSource == _unitS
ource; |
| 570 } | 586 } |
| 571 | 587 |
| 588 @override |
| 572 int get hashCode => JavaArrays.makeHashCode([_librarySource, _unitSource]); | 589 int get hashCode => JavaArrays.makeHashCode([_librarySource, _unitSource]); |
| 573 | 590 |
| 591 @override |
| 574 String toString() => "${_librarySource} ${_unitSource}"; | 592 String toString() => "${_librarySource} ${_unitSource}"; |
| 575 } | 593 } |
| 576 | 594 |
| 577 /** | 595 /** |
| 578 * Instances of the [IndexUnitOperation] implement an operation that adds data t
o the index | 596 * Instances of the [IndexUnitOperation] implement an operation that adds data t
o the index |
| 579 * based on the resolved [CompilationUnit]. | 597 * based on the resolved [CompilationUnit]. |
| 580 */ | 598 */ |
| 581 class IndexUnitOperation implements IndexOperation { | 599 class IndexUnitOperation implements IndexOperation { |
| 582 /** | 600 /** |
| 583 * The index store against which this operation is being run. | 601 * The index store against which this operation is being run. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 this._context = context; | 634 this._context = context; |
| 617 this._unitElement = unit.element; | 635 this._unitElement = unit.element; |
| 618 this._source = _unitElement.source; | 636 this._source = _unitElement.source; |
| 619 } | 637 } |
| 620 | 638 |
| 621 /** | 639 /** |
| 622 * @return the [Source] to be indexed. | 640 * @return the [Source] to be indexed. |
| 623 */ | 641 */ |
| 624 Source get source => _source; | 642 Source get source => _source; |
| 625 | 643 |
| 644 @override |
| 626 bool get isQuery => false; | 645 bool get isQuery => false; |
| 627 | 646 |
| 647 @override |
| 628 void performOperation() { | 648 void performOperation() { |
| 629 try { | 649 try { |
| 630 bool mayIndex = _indexStore.aboutToIndexDart(_context, _unitElement); | 650 bool mayIndex = _indexStore.aboutToIndexDart(_context, _unitElement); |
| 631 if (!mayIndex) { | 651 if (!mayIndex) { |
| 632 return; | 652 return; |
| 633 } | 653 } |
| 634 unit.accept(new IndexContributor(_indexStore)); | 654 unit.accept(new IndexContributor(_indexStore)); |
| 635 unit.accept(new AngularDartIndexContributor(_indexStore)); | 655 unit.accept(new AngularDartIndexContributor(_indexStore)); |
| 636 } catch (exception) { | 656 } catch (exception) { |
| 637 AnalysisEngine.instance.logger.logError2("Could not index ${unit.element.l
ocation}", exception); | 657 AnalysisEngine.instance.logger.logError2("Could not index ${unit.element.l
ocation}", exception); |
| 638 } | 658 } |
| 639 } | 659 } |
| 640 | 660 |
| 661 @override |
| 641 bool removeWhenSourceRemoved(Source source) => this._source == source; | 662 bool removeWhenSourceRemoved(Source source) => this._source == source; |
| 642 | 663 |
| 664 @override |
| 643 String toString() => "IndexUnitOperation(${_source.fullName})"; | 665 String toString() => "IndexUnitOperation(${_source.fullName})"; |
| 644 } | 666 } |
| 645 | 667 |
| 646 /** | 668 /** |
| 647 * Recursively visits [HtmlUnit] and every embedded [Expression]. | 669 * Recursively visits [HtmlUnit] and every embedded [Expression]. |
| 648 */ | 670 */ |
| 649 abstract class ExpressionVisitor extends ht.RecursiveXmlVisitor<Object> { | 671 abstract class ExpressionVisitor extends ht.RecursiveXmlVisitor<Object> { |
| 650 /** | 672 /** |
| 651 * Visits the given [Expression]s embedded into tag or attribute. | 673 * Visits the given [Expression]s embedded into tag or attribute. |
| 652 * | 674 * |
| 653 * @param expression the [Expression] to visit, not `null` | 675 * @param expression the [Expression] to visit, not `null` |
| 654 */ | 676 */ |
| 655 void visitExpression(Expression expression); | 677 void visitExpression(Expression expression); |
| 656 | 678 |
| 679 @override |
| 657 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { | 680 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { |
| 658 _visitExpressions(node.expressions); | 681 _visitExpressions(node.expressions); |
| 659 return super.visitXmlAttributeNode(node); | 682 return super.visitXmlAttributeNode(node); |
| 660 } | 683 } |
| 661 | 684 |
| 685 @override |
| 662 Object visitXmlTagNode(ht.XmlTagNode node) { | 686 Object visitXmlTagNode(ht.XmlTagNode node) { |
| 663 _visitExpressions(node.expressions); | 687 _visitExpressions(node.expressions); |
| 664 return super.visitXmlTagNode(node); | 688 return super.visitXmlTagNode(node); |
| 665 } | 689 } |
| 666 | 690 |
| 667 /** | 691 /** |
| 668 * Visits [Expression]s of the given [XmlExpression]s. | 692 * Visits [Expression]s of the given [XmlExpression]s. |
| 669 */ | 693 */ |
| 670 void _visitExpressions(List<ht.XmlExpression> expressions) { | 694 void _visitExpressions(List<ht.XmlExpression> expressions) { |
| 671 for (ht.XmlExpression xmlExpression in expressions) { | 695 for (ht.XmlExpression xmlExpression in expressions) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 this._uniqueId = uniqueId; | 752 this._uniqueId = uniqueId; |
| 729 } | 753 } |
| 730 | 754 |
| 731 /** | 755 /** |
| 732 * Return the unique identifier for this relationship. | 756 * Return the unique identifier for this relationship. |
| 733 * | 757 * |
| 734 * @return the unique identifier for this relationship | 758 * @return the unique identifier for this relationship |
| 735 */ | 759 */ |
| 736 String get identifier => _uniqueId; | 760 String get identifier => _uniqueId; |
| 737 | 761 |
| 762 @override |
| 738 String toString() => _uniqueId; | 763 String toString() => _uniqueId; |
| 739 } | 764 } |
| 740 | 765 |
| 741 /** | 766 /** |
| 742 * Instances of the [RemoveSourcesOperation] implement an operation that removes
from the | 767 * Instances of the [RemoveSourcesOperation] implement an operation that removes
from the |
| 743 * index any data based on the content of source belonging to a [SourceContainer
]. | 768 * index any data based on the content of source belonging to a [SourceContainer
]. |
| 744 */ | 769 */ |
| 745 class RemoveSourcesOperation implements IndexOperation { | 770 class RemoveSourcesOperation implements IndexOperation { |
| 746 /** | 771 /** |
| 747 * The index store against which this operation is being run. | 772 * The index store against which this operation is being run. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 763 * | 788 * |
| 764 * @param indexStore the index store against which this operation is being run | 789 * @param indexStore the index store against which this operation is being run |
| 765 * @param context the [AnalysisContext] to remove container in | 790 * @param context the [AnalysisContext] to remove container in |
| 766 * @param container the [SourceContainer] to remove from index | 791 * @param container the [SourceContainer] to remove from index |
| 767 */ | 792 */ |
| 768 RemoveSourcesOperation(IndexStore indexStore, AnalysisContext context, this.co
ntainer) { | 793 RemoveSourcesOperation(IndexStore indexStore, AnalysisContext context, this.co
ntainer) { |
| 769 this._indexStore = indexStore; | 794 this._indexStore = indexStore; |
| 770 this._context = context; | 795 this._context = context; |
| 771 } | 796 } |
| 772 | 797 |
| 798 @override |
| 773 bool get isQuery => false; | 799 bool get isQuery => false; |
| 774 | 800 |
| 801 @override |
| 775 void performOperation() { | 802 void performOperation() { |
| 776 _indexStore.removeSources(_context, container); | 803 _indexStore.removeSources(_context, container); |
| 777 } | 804 } |
| 778 | 805 |
| 806 @override |
| 779 bool removeWhenSourceRemoved(Source source) => false; | 807 bool removeWhenSourceRemoved(Source source) => false; |
| 780 | 808 |
| 809 @override |
| 781 String toString() => "RemoveSources(${container})"; | 810 String toString() => "RemoveSources(${container})"; |
| 782 } | 811 } |
| 783 | 812 |
| 784 /** | 813 /** |
| 785 * The interface `UniverseElement` defines element to use when we want to reques
t "defines" | 814 * The interface `UniverseElement` defines element to use when we want to reques
t "defines" |
| 786 * relations without specifying exact library. | 815 * relations without specifying exact library. |
| 787 */ | 816 */ |
| 788 abstract class UniverseElement implements Element { | 817 abstract class UniverseElement implements Element { |
| 789 static final UniverseElement INSTANCE = UniverseElementImpl.INSTANCE; | 818 static final UniverseElement INSTANCE = UniverseElementImpl.INSTANCE; |
| 790 } | 819 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 /** | 1012 /** |
| 984 * Initialize a newly created Angular HTML index contributor. | 1013 * Initialize a newly created Angular HTML index contributor. |
| 985 * | 1014 * |
| 986 * @param store the [IndexStore] to record relations into. | 1015 * @param store the [IndexStore] to record relations into. |
| 987 */ | 1016 */ |
| 988 AngularHtmlIndexContributor(IndexStore store) { | 1017 AngularHtmlIndexContributor(IndexStore store) { |
| 989 this._store = store; | 1018 this._store = store; |
| 990 _indexContributor = new IndexContributor_AngularHtmlIndexContributor(store,
this); | 1019 _indexContributor = new IndexContributor_AngularHtmlIndexContributor(store,
this); |
| 991 } | 1020 } |
| 992 | 1021 |
| 1022 @override |
| 993 void visitExpression(Expression expression) { | 1023 void visitExpression(Expression expression) { |
| 994 // NgFilter | 1024 // NgFilter |
| 995 if (expression is SimpleIdentifier) { | 1025 if (expression is SimpleIdentifier) { |
| 996 SimpleIdentifier identifier = expression; | 1026 SimpleIdentifier identifier = expression; |
| 997 Element element = identifier.bestElement; | 1027 Element element = identifier.bestElement; |
| 998 if (element is AngularElement) { | 1028 if (element is AngularElement) { |
| 999 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, _cr
eateLocationForIdentifier(identifier)); | 1029 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, _cr
eateLocationForIdentifier(identifier)); |
| 1000 return; | 1030 return; |
| 1001 } | 1031 } |
| 1002 } | 1032 } |
| 1003 // index as a normal Dart expression | 1033 // index as a normal Dart expression |
| 1004 expression.accept(_indexContributor); | 1034 expression.accept(_indexContributor); |
| 1005 } | 1035 } |
| 1006 | 1036 |
| 1037 @override |
| 1007 Object visitHtmlUnit(ht.HtmlUnit node) { | 1038 Object visitHtmlUnit(ht.HtmlUnit node) { |
| 1008 _htmlUnitElement = node.element; | 1039 _htmlUnitElement = node.element; |
| 1009 CompilationUnitElement dartUnitElement = _htmlUnitElement.angularCompilation
Unit; | 1040 CompilationUnitElement dartUnitElement = _htmlUnitElement.angularCompilation
Unit; |
| 1010 _indexContributor.enterScope(dartUnitElement); | 1041 _indexContributor.enterScope(dartUnitElement); |
| 1011 return super.visitHtmlUnit(node); | 1042 return super.visitHtmlUnit(node); |
| 1012 } | 1043 } |
| 1013 | 1044 |
| 1045 @override |
| 1014 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { | 1046 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { |
| 1015 Element element = node.element; | 1047 Element element = node.element; |
| 1016 if (element != null) { | 1048 if (element != null) { |
| 1017 ht.Token nameToken = node.nameToken; | 1049 ht.Token nameToken = node.nameToken; |
| 1018 Location location = _createLocationForToken(nameToken); | 1050 Location location = _createLocationForToken(nameToken); |
| 1019 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, locat
ion); | 1051 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, locat
ion); |
| 1020 } | 1052 } |
| 1021 return super.visitXmlAttributeNode(node); | 1053 return super.visitXmlAttributeNode(node); |
| 1022 } | 1054 } |
| 1023 | 1055 |
| 1056 @override |
| 1024 Object visitXmlTagNode(ht.XmlTagNode node) { | 1057 Object visitXmlTagNode(ht.XmlTagNode node) { |
| 1025 Element element = node.element; | 1058 Element element = node.element; |
| 1026 if (element != null) { | 1059 if (element != null) { |
| 1027 // tag | 1060 // tag |
| 1028 { | 1061 { |
| 1029 ht.Token tagToken = node.tagToken; | 1062 ht.Token tagToken = node.tagToken; |
| 1030 Location location = _createLocationForToken(tagToken); | 1063 Location location = _createLocationForToken(tagToken); |
| 1031 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, loc
ation); | 1064 _store.recordRelationship(element, IndexConstants.ANGULAR_REFERENCE, loc
ation); |
| 1032 } | 1065 } |
| 1033 // maybe add closing tag range | 1066 // maybe add closing tag range |
| 1034 ht.Token closingTag = node.closingTag; | 1067 ht.Token closingTag = node.closingTag; |
| 1035 if (closingTag != null) { | 1068 if (closingTag != null) { |
| 1036 Location location = _createLocationForToken(closingTag); | 1069 Location location = _createLocationForToken(closingTag); |
| 1037 _store.recordRelationship(element, IndexConstants.ANGULAR_CLOSING_TAG_RE
FERENCE, location); | 1070 _store.recordRelationship(element, IndexConstants.ANGULAR_CLOSING_TAG_RE
FERENCE, location); |
| 1038 } | 1071 } |
| 1039 } | 1072 } |
| 1040 return super.visitXmlTagNode(node); | 1073 return super.visitXmlTagNode(node); |
| 1041 } | 1074 } |
| 1042 | 1075 |
| 1043 Location _createLocationForIdentifier(SimpleIdentifier identifier) => new Loca
tion(_htmlUnitElement, identifier.offset, identifier.length); | 1076 Location _createLocationForIdentifier(SimpleIdentifier identifier) => new Loca
tion(_htmlUnitElement, identifier.offset, identifier.length); |
| 1044 | 1077 |
| 1045 Location _createLocationForToken(ht.Token token) => new Location(_htmlUnitElem
ent, token.offset, token.length); | 1078 Location _createLocationForToken(ht.Token token) => new Location(_htmlUnitElem
ent, token.offset, token.length); |
| 1046 } | 1079 } |
| 1047 | 1080 |
| 1048 class IndexContributor_AngularHtmlIndexContributor extends IndexContributor { | 1081 class IndexContributor_AngularHtmlIndexContributor extends IndexContributor { |
| 1049 final AngularHtmlIndexContributor AngularHtmlIndexContributor_this; | 1082 final AngularHtmlIndexContributor AngularHtmlIndexContributor_this; |
| 1050 | 1083 |
| 1051 IndexContributor_AngularHtmlIndexContributor(IndexStore arg0, this.AngularHtml
IndexContributor_this) : super(arg0); | 1084 IndexContributor_AngularHtmlIndexContributor(IndexStore arg0, this.AngularHtml
IndexContributor_this) : super(arg0); |
| 1052 | 1085 |
| 1086 @override |
| 1053 Element peekElement() => AngularHtmlIndexContributor_this._htmlUnitElement; | 1087 Element peekElement() => AngularHtmlIndexContributor_this._htmlUnitElement; |
| 1054 | 1088 |
| 1089 @override |
| 1055 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { | 1090 void recordRelationship(Element element, Relationship relationship, Location l
ocation) { |
| 1056 AngularElement angularElement = AngularHtmlUnitResolver.getAngularElement(el
ement); | 1091 AngularElement angularElement = AngularHtmlUnitResolver.getAngularElement(el
ement); |
| 1057 if (angularElement != null) { | 1092 if (angularElement != null) { |
| 1058 element = angularElement; | 1093 element = angularElement; |
| 1059 relationship = IndexConstants.ANGULAR_REFERENCE; | 1094 relationship = IndexConstants.ANGULAR_REFERENCE; |
| 1060 } | 1095 } |
| 1061 super.recordRelationship(element, relationship, location); | 1096 super.recordRelationship(element, relationship, location); |
| 1062 } | 1097 } |
| 1063 } | 1098 } |
| 1064 | 1099 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 } | 1297 } |
| 1263 | 1298 |
| 1264 /** | 1299 /** |
| 1265 * Implementation of [UniverseElement]. | 1300 * Implementation of [UniverseElement]. |
| 1266 */ | 1301 */ |
| 1267 class UniverseElementImpl extends ElementImpl implements UniverseElement { | 1302 class UniverseElementImpl extends ElementImpl implements UniverseElement { |
| 1268 static UniverseElementImpl INSTANCE = new UniverseElementImpl(); | 1303 static UniverseElementImpl INSTANCE = new UniverseElementImpl(); |
| 1269 | 1304 |
| 1270 UniverseElementImpl() : super("--universe--", -1); | 1305 UniverseElementImpl() : super("--universe--", -1); |
| 1271 | 1306 |
| 1307 @override |
| 1272 accept(ElementVisitor visitor) => null; | 1308 accept(ElementVisitor visitor) => null; |
| 1273 | 1309 |
| 1310 @override |
| 1274 ElementKind get kind => ElementKind.UNIVERSE; | 1311 ElementKind get kind => ElementKind.UNIVERSE; |
| 1275 } | 1312 } |
| 1276 | 1313 |
| 1277 /** | 1314 /** |
| 1278 * Visits resolved AST and adds relationships into [IndexStore]. | 1315 * Visits resolved AST and adds relationships into [IndexStore]. |
| 1279 */ | 1316 */ |
| 1280 class IndexContributor extends GeneralizingAstVisitor<Object> { | 1317 class IndexContributor extends GeneralizingAstVisitor<Object> { |
| 1281 /** | 1318 /** |
| 1282 * @return the [Location] representing location of the [Element]. | 1319 * @return the [Location] representing location of the [Element]. |
| 1283 */ | 1320 */ |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 */ | 1593 */ |
| 1557 Element peekElement() { | 1594 Element peekElement() { |
| 1558 for (Element element in _elementStack) { | 1595 for (Element element in _elementStack) { |
| 1559 if (element != null) { | 1596 if (element != null) { |
| 1560 return element; | 1597 return element; |
| 1561 } | 1598 } |
| 1562 } | 1599 } |
| 1563 return null; | 1600 return null; |
| 1564 } | 1601 } |
| 1565 | 1602 |
| 1603 @override |
| 1566 Object visitAssignmentExpression(AssignmentExpression node) { | 1604 Object visitAssignmentExpression(AssignmentExpression node) { |
| 1567 _recordOperatorReference(node.operator, node.bestElement); | 1605 _recordOperatorReference(node.operator, node.bestElement); |
| 1568 return super.visitAssignmentExpression(node); | 1606 return super.visitAssignmentExpression(node); |
| 1569 } | 1607 } |
| 1570 | 1608 |
| 1609 @override |
| 1571 Object visitBinaryExpression(BinaryExpression node) { | 1610 Object visitBinaryExpression(BinaryExpression node) { |
| 1572 _recordOperatorReference(node.operator, node.bestElement); | 1611 _recordOperatorReference(node.operator, node.bestElement); |
| 1573 return super.visitBinaryExpression(node); | 1612 return super.visitBinaryExpression(node); |
| 1574 } | 1613 } |
| 1575 | 1614 |
| 1615 @override |
| 1576 Object visitClassDeclaration(ClassDeclaration node) { | 1616 Object visitClassDeclaration(ClassDeclaration node) { |
| 1577 ClassElement element = node.element; | 1617 ClassElement element = node.element; |
| 1578 enterScope(element); | 1618 enterScope(element); |
| 1579 try { | 1619 try { |
| 1580 _recordElementDefinition(element, IndexConstants.DEFINES_CLASS); | 1620 _recordElementDefinition(element, IndexConstants.DEFINES_CLASS); |
| 1581 { | 1621 { |
| 1582 ExtendsClause extendsClause = node.extendsClause; | 1622 ExtendsClause extendsClause = node.extendsClause; |
| 1583 if (extendsClause != null) { | 1623 if (extendsClause != null) { |
| 1584 TypeName superclassNode = extendsClause.superclass; | 1624 TypeName superclassNode = extendsClause.superclass; |
| 1585 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); | 1625 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1606 _recordSuperType(interfaceNode, IndexConstants.IS_IMPLEMENTED_BY); | 1646 _recordSuperType(interfaceNode, IndexConstants.IS_IMPLEMENTED_BY); |
| 1607 } | 1647 } |
| 1608 } | 1648 } |
| 1609 } | 1649 } |
| 1610 return super.visitClassDeclaration(node); | 1650 return super.visitClassDeclaration(node); |
| 1611 } finally { | 1651 } finally { |
| 1612 _exitScope(); | 1652 _exitScope(); |
| 1613 } | 1653 } |
| 1614 } | 1654 } |
| 1615 | 1655 |
| 1656 @override |
| 1616 Object visitClassTypeAlias(ClassTypeAlias node) { | 1657 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 1617 ClassElement element = node.element; | 1658 ClassElement element = node.element; |
| 1618 enterScope(element); | 1659 enterScope(element); |
| 1619 try { | 1660 try { |
| 1620 _recordElementDefinition(element, IndexConstants.DEFINES_CLASS_ALIAS); | 1661 _recordElementDefinition(element, IndexConstants.DEFINES_CLASS_ALIAS); |
| 1621 { | 1662 { |
| 1622 TypeName superclassNode = node.superclass; | 1663 TypeName superclassNode = node.superclass; |
| 1623 if (superclassNode != null) { | 1664 if (superclassNode != null) { |
| 1624 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); | 1665 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); |
| 1625 } | 1666 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1639 _recordSuperType(interfaceNode, IndexConstants.IS_IMPLEMENTED_BY); | 1680 _recordSuperType(interfaceNode, IndexConstants.IS_IMPLEMENTED_BY); |
| 1640 } | 1681 } |
| 1641 } | 1682 } |
| 1642 } | 1683 } |
| 1643 return super.visitClassTypeAlias(node); | 1684 return super.visitClassTypeAlias(node); |
| 1644 } finally { | 1685 } finally { |
| 1645 _exitScope(); | 1686 _exitScope(); |
| 1646 } | 1687 } |
| 1647 } | 1688 } |
| 1648 | 1689 |
| 1690 @override |
| 1649 Object visitCompilationUnit(CompilationUnit node) { | 1691 Object visitCompilationUnit(CompilationUnit node) { |
| 1650 CompilationUnitElement unitElement = node.element; | 1692 CompilationUnitElement unitElement = node.element; |
| 1651 if (unitElement != null) { | 1693 if (unitElement != null) { |
| 1652 _elementStack.add(unitElement); | 1694 _elementStack.add(unitElement); |
| 1653 _libraryElement = unitElement.enclosingElement; | 1695 _libraryElement = unitElement.enclosingElement; |
| 1654 if (_libraryElement != null) { | 1696 if (_libraryElement != null) { |
| 1655 return super.visitCompilationUnit(node); | 1697 return super.visitCompilationUnit(node); |
| 1656 } | 1698 } |
| 1657 } | 1699 } |
| 1658 return null; | 1700 return null; |
| 1659 } | 1701 } |
| 1660 | 1702 |
| 1703 @override |
| 1661 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 1704 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 1662 ConstructorElement element = node.element; | 1705 ConstructorElement element = node.element; |
| 1663 // define | 1706 // define |
| 1664 { | 1707 { |
| 1665 Location location; | 1708 Location location; |
| 1666 if (node.name != null) { | 1709 if (node.name != null) { |
| 1667 int start = node.period.offset; | 1710 int start = node.period.offset; |
| 1668 int end = node.name.end; | 1711 int end = node.name.end; |
| 1669 location = _createLocationFromOffset(start, end - start); | 1712 location = _createLocationFromOffset(start, end - start); |
| 1670 } else { | 1713 } else { |
| 1671 int start = node.returnType.end; | 1714 int start = node.returnType.end; |
| 1672 location = _createLocationFromOffset(start, 0); | 1715 location = _createLocationFromOffset(start, 0); |
| 1673 } | 1716 } |
| 1674 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); | 1717 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); |
| 1675 } | 1718 } |
| 1676 // visit children | 1719 // visit children |
| 1677 enterScope(element); | 1720 enterScope(element); |
| 1678 try { | 1721 try { |
| 1679 return super.visitConstructorDeclaration(node); | 1722 return super.visitConstructorDeclaration(node); |
| 1680 } finally { | 1723 } finally { |
| 1681 _exitScope(); | 1724 _exitScope(); |
| 1682 } | 1725 } |
| 1683 } | 1726 } |
| 1684 | 1727 |
| 1728 @override |
| 1685 Object visitConstructorName(ConstructorName node) { | 1729 Object visitConstructorName(ConstructorName node) { |
| 1686 ConstructorElement element = node.staticElement; | 1730 ConstructorElement element = node.staticElement; |
| 1687 // in 'class B = A;' actually A constructors are invoked | 1731 // in 'class B = A;' actually A constructors are invoked |
| 1688 if (element != null && element.isSynthetic && element.redirectedConstructor
!= null) { | 1732 if (element != null && element.isSynthetic && element.redirectedConstructor
!= null) { |
| 1689 element = element.redirectedConstructor; | 1733 element = element.redirectedConstructor; |
| 1690 } | 1734 } |
| 1691 // prepare location | 1735 // prepare location |
| 1692 Location location; | 1736 Location location; |
| 1693 if (node.name != null) { | 1737 if (node.name != null) { |
| 1694 int start = node.period.offset; | 1738 int start = node.period.offset; |
| 1695 int end = node.name.end; | 1739 int end = node.name.end; |
| 1696 location = _createLocationFromOffset(start, end - start); | 1740 location = _createLocationFromOffset(start, end - start); |
| 1697 } else { | 1741 } else { |
| 1698 int start = node.type.end; | 1742 int start = node.type.end; |
| 1699 location = _createLocationFromOffset(start, 0); | 1743 location = _createLocationFromOffset(start, 0); |
| 1700 } | 1744 } |
| 1701 // record relationship | 1745 // record relationship |
| 1702 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 1746 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
| 1703 return super.visitConstructorName(node); | 1747 return super.visitConstructorName(node); |
| 1704 } | 1748 } |
| 1705 | 1749 |
| 1750 @override |
| 1706 Object visitExportDirective(ExportDirective node) { | 1751 Object visitExportDirective(ExportDirective node) { |
| 1707 ExportElement element = node.element; | 1752 ExportElement element = node.element; |
| 1708 if (element != null) { | 1753 if (element != null) { |
| 1709 LibraryElement expLibrary = element.exportedLibrary; | 1754 LibraryElement expLibrary = element.exportedLibrary; |
| 1710 _recordLibraryReference(node, expLibrary); | 1755 _recordLibraryReference(node, expLibrary); |
| 1711 } | 1756 } |
| 1712 return super.visitExportDirective(node); | 1757 return super.visitExportDirective(node); |
| 1713 } | 1758 } |
| 1714 | 1759 |
| 1760 @override |
| 1715 Object visitFormalParameter(FormalParameter node) { | 1761 Object visitFormalParameter(FormalParameter node) { |
| 1716 ParameterElement element = node.element; | 1762 ParameterElement element = node.element; |
| 1717 enterScope(element); | 1763 enterScope(element); |
| 1718 try { | 1764 try { |
| 1719 return super.visitFormalParameter(node); | 1765 return super.visitFormalParameter(node); |
| 1720 } finally { | 1766 } finally { |
| 1721 _exitScope(); | 1767 _exitScope(); |
| 1722 } | 1768 } |
| 1723 } | 1769 } |
| 1724 | 1770 |
| 1771 @override |
| 1725 Object visitFunctionDeclaration(FunctionDeclaration node) { | 1772 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 1726 Element element = node.element; | 1773 Element element = node.element; |
| 1727 _recordElementDefinition(element, IndexConstants.DEFINES_FUNCTION); | 1774 _recordElementDefinition(element, IndexConstants.DEFINES_FUNCTION); |
| 1728 enterScope(element); | 1775 enterScope(element); |
| 1729 try { | 1776 try { |
| 1730 return super.visitFunctionDeclaration(node); | 1777 return super.visitFunctionDeclaration(node); |
| 1731 } finally { | 1778 } finally { |
| 1732 _exitScope(); | 1779 _exitScope(); |
| 1733 } | 1780 } |
| 1734 } | 1781 } |
| 1735 | 1782 |
| 1783 @override |
| 1736 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 1784 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 1737 Element element = node.element; | 1785 Element element = node.element; |
| 1738 _recordElementDefinition(element, IndexConstants.DEFINES_FUNCTION_TYPE); | 1786 _recordElementDefinition(element, IndexConstants.DEFINES_FUNCTION_TYPE); |
| 1739 return super.visitFunctionTypeAlias(node); | 1787 return super.visitFunctionTypeAlias(node); |
| 1740 } | 1788 } |
| 1741 | 1789 |
| 1790 @override |
| 1742 Object visitImportDirective(ImportDirective node) { | 1791 Object visitImportDirective(ImportDirective node) { |
| 1743 ImportElement element = node.element; | 1792 ImportElement element = node.element; |
| 1744 if (element != null) { | 1793 if (element != null) { |
| 1745 LibraryElement impLibrary = element.importedLibrary; | 1794 LibraryElement impLibrary = element.importedLibrary; |
| 1746 _recordLibraryReference(node, impLibrary); | 1795 _recordLibraryReference(node, impLibrary); |
| 1747 } | 1796 } |
| 1748 return super.visitImportDirective(node); | 1797 return super.visitImportDirective(node); |
| 1749 } | 1798 } |
| 1750 | 1799 |
| 1800 @override |
| 1751 Object visitIndexExpression(IndexExpression node) { | 1801 Object visitIndexExpression(IndexExpression node) { |
| 1752 MethodElement element = node.bestElement; | 1802 MethodElement element = node.bestElement; |
| 1753 if (element is MethodElement) { | 1803 if (element is MethodElement) { |
| 1754 Token operator = node.leftBracket; | 1804 Token operator = node.leftBracket; |
| 1755 Location location = _createLocationFromToken(operator); | 1805 Location location = _createLocationFromToken(operator); |
| 1756 recordRelationship(element, IndexConstants.IS_INVOKED_BY_QUALIFIED, locati
on); | 1806 recordRelationship(element, IndexConstants.IS_INVOKED_BY_QUALIFIED, locati
on); |
| 1757 } | 1807 } |
| 1758 return super.visitIndexExpression(node); | 1808 return super.visitIndexExpression(node); |
| 1759 } | 1809 } |
| 1760 | 1810 |
| 1811 @override |
| 1761 Object visitMethodDeclaration(MethodDeclaration node) { | 1812 Object visitMethodDeclaration(MethodDeclaration node) { |
| 1762 ExecutableElement element = node.element; | 1813 ExecutableElement element = node.element; |
| 1763 enterScope(element); | 1814 enterScope(element); |
| 1764 try { | 1815 try { |
| 1765 return super.visitMethodDeclaration(node); | 1816 return super.visitMethodDeclaration(node); |
| 1766 } finally { | 1817 } finally { |
| 1767 _exitScope(); | 1818 _exitScope(); |
| 1768 } | 1819 } |
| 1769 } | 1820 } |
| 1770 | 1821 |
| 1822 @override |
| 1771 Object visitMethodInvocation(MethodInvocation node) { | 1823 Object visitMethodInvocation(MethodInvocation node) { |
| 1772 SimpleIdentifier name = node.methodName; | 1824 SimpleIdentifier name = node.methodName; |
| 1773 Element element = name.bestElement; | 1825 Element element = name.bestElement; |
| 1774 if (element is MethodElement) { | 1826 if (element is MethodElement) { |
| 1775 Location location = _createLocationFromNode(name); | 1827 Location location = _createLocationFromNode(name); |
| 1776 Relationship relationship; | 1828 Relationship relationship; |
| 1777 if (node.target != null) { | 1829 if (node.target != null) { |
| 1778 relationship = IndexConstants.IS_INVOKED_BY_QUALIFIED; | 1830 relationship = IndexConstants.IS_INVOKED_BY_QUALIFIED; |
| 1779 } else { | 1831 } else { |
| 1780 relationship = IndexConstants.IS_INVOKED_BY_UNQUALIFIED; | 1832 relationship = IndexConstants.IS_INVOKED_BY_UNQUALIFIED; |
| 1781 } | 1833 } |
| 1782 recordRelationship(element, relationship, location); | 1834 recordRelationship(element, relationship, location); |
| 1783 } | 1835 } |
| 1784 if (element is FunctionElement) { | 1836 if (element is FunctionElement) { |
| 1785 Location location = _createLocationFromNode(name); | 1837 Location location = _createLocationFromNode(name); |
| 1786 recordRelationship(element, IndexConstants.IS_INVOKED_BY, location); | 1838 recordRelationship(element, IndexConstants.IS_INVOKED_BY, location); |
| 1787 } | 1839 } |
| 1788 _recordImportElementReferenceWithoutPrefix(name); | 1840 _recordImportElementReferenceWithoutPrefix(name); |
| 1789 return super.visitMethodInvocation(node); | 1841 return super.visitMethodInvocation(node); |
| 1790 } | 1842 } |
| 1791 | 1843 |
| 1844 @override |
| 1792 Object visitPartDirective(PartDirective node) { | 1845 Object visitPartDirective(PartDirective node) { |
| 1793 Element element = node.element; | 1846 Element element = node.element; |
| 1794 Location location = _createLocationFromNode(node.uri); | 1847 Location location = _createLocationFromNode(node.uri); |
| 1795 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 1848 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
| 1796 return super.visitPartDirective(node); | 1849 return super.visitPartDirective(node); |
| 1797 } | 1850 } |
| 1798 | 1851 |
| 1852 @override |
| 1799 Object visitPartOfDirective(PartOfDirective node) { | 1853 Object visitPartOfDirective(PartOfDirective node) { |
| 1800 Location location = _createLocationFromNode(node.libraryName); | 1854 Location location = _createLocationFromNode(node.libraryName); |
| 1801 recordRelationship(node.element, IndexConstants.IS_REFERENCED_BY, location); | 1855 recordRelationship(node.element, IndexConstants.IS_REFERENCED_BY, location); |
| 1802 return null; | 1856 return null; |
| 1803 } | 1857 } |
| 1804 | 1858 |
| 1859 @override |
| 1805 Object visitPostfixExpression(PostfixExpression node) { | 1860 Object visitPostfixExpression(PostfixExpression node) { |
| 1806 _recordOperatorReference(node.operator, node.bestElement); | 1861 _recordOperatorReference(node.operator, node.bestElement); |
| 1807 return super.visitPostfixExpression(node); | 1862 return super.visitPostfixExpression(node); |
| 1808 } | 1863 } |
| 1809 | 1864 |
| 1865 @override |
| 1810 Object visitPrefixExpression(PrefixExpression node) { | 1866 Object visitPrefixExpression(PrefixExpression node) { |
| 1811 _recordOperatorReference(node.operator, node.bestElement); | 1867 _recordOperatorReference(node.operator, node.bestElement); |
| 1812 return super.visitPrefixExpression(node); | 1868 return super.visitPrefixExpression(node); |
| 1813 } | 1869 } |
| 1814 | 1870 |
| 1871 @override |
| 1815 Object visitSimpleIdentifier(SimpleIdentifier node) { | 1872 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 1816 Element nameElement = new NameElementImpl(node.name); | 1873 Element nameElement = new NameElementImpl(node.name); |
| 1817 Location location = _createLocationFromNode(node); | 1874 Location location = _createLocationFromNode(node); |
| 1818 // name in declaration | 1875 // name in declaration |
| 1819 if (node.inDeclarationContext()) { | 1876 if (node.inDeclarationContext()) { |
| 1820 recordRelationship(nameElement, IndexConstants.IS_DEFINED_BY, location); | 1877 recordRelationship(nameElement, IndexConstants.IS_DEFINED_BY, location); |
| 1821 return null; | 1878 return null; |
| 1822 } | 1879 } |
| 1823 // prepare information | 1880 // prepare information |
| 1824 Element element = node.bestElement; | 1881 Element element = node.bestElement; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1857 } else if (inSetterContext) { | 1914 } else if (inSetterContext) { |
| 1858 recordRelationship(element, IndexConstants.IS_WRITTEN_BY, location); | 1915 recordRelationship(element, IndexConstants.IS_WRITTEN_BY, location); |
| 1859 } else { | 1916 } else { |
| 1860 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 1917 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
| 1861 } | 1918 } |
| 1862 } | 1919 } |
| 1863 _recordImportElementReferenceWithoutPrefix(node); | 1920 _recordImportElementReferenceWithoutPrefix(node); |
| 1864 return super.visitSimpleIdentifier(node); | 1921 return super.visitSimpleIdentifier(node); |
| 1865 } | 1922 } |
| 1866 | 1923 |
| 1924 @override |
| 1867 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 1925 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 1868 ConstructorElement element = node.staticElement; | 1926 ConstructorElement element = node.staticElement; |
| 1869 Location location; | 1927 Location location; |
| 1870 if (node.constructorName != null) { | 1928 if (node.constructorName != null) { |
| 1871 int start = node.period.offset; | 1929 int start = node.period.offset; |
| 1872 int end = node.constructorName.end; | 1930 int end = node.constructorName.end; |
| 1873 location = _createLocationFromOffset(start, end - start); | 1931 location = _createLocationFromOffset(start, end - start); |
| 1874 } else { | 1932 } else { |
| 1875 int start = node.keyword.end; | 1933 int start = node.keyword.end; |
| 1876 location = _createLocationFromOffset(start, 0); | 1934 location = _createLocationFromOffset(start, 0); |
| 1877 } | 1935 } |
| 1878 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 1936 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); |
| 1879 return super.visitSuperConstructorInvocation(node); | 1937 return super.visitSuperConstructorInvocation(node); |
| 1880 } | 1938 } |
| 1881 | 1939 |
| 1940 @override |
| 1882 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 1941 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 1883 VariableDeclarationList variables = node.variables; | 1942 VariableDeclarationList variables = node.variables; |
| 1884 for (VariableDeclaration variableDeclaration in variables.variables) { | 1943 for (VariableDeclaration variableDeclaration in variables.variables) { |
| 1885 Element element = variableDeclaration.element; | 1944 Element element = variableDeclaration.element; |
| 1886 _recordElementDefinition(element, IndexConstants.DEFINES_VARIABLE); | 1945 _recordElementDefinition(element, IndexConstants.DEFINES_VARIABLE); |
| 1887 } | 1946 } |
| 1888 return super.visitTopLevelVariableDeclaration(node); | 1947 return super.visitTopLevelVariableDeclaration(node); |
| 1889 } | 1948 } |
| 1890 | 1949 |
| 1950 @override |
| 1891 Object visitTypeParameter(TypeParameter node) { | 1951 Object visitTypeParameter(TypeParameter node) { |
| 1892 TypeParameterElement element = node.element; | 1952 TypeParameterElement element = node.element; |
| 1893 enterScope(element); | 1953 enterScope(element); |
| 1894 try { | 1954 try { |
| 1895 return super.visitTypeParameter(node); | 1955 return super.visitTypeParameter(node); |
| 1896 } finally { | 1956 } finally { |
| 1897 _exitScope(); | 1957 _exitScope(); |
| 1898 } | 1958 } |
| 1899 } | 1959 } |
| 1900 | 1960 |
| 1961 @override |
| 1901 Object visitVariableDeclaration(VariableDeclaration node) { | 1962 Object visitVariableDeclaration(VariableDeclaration node) { |
| 1902 VariableElement element = node.element; | 1963 VariableElement element = node.element; |
| 1903 // record declaration | 1964 // record declaration |
| 1904 { | 1965 { |
| 1905 SimpleIdentifier name = node.name; | 1966 SimpleIdentifier name = node.name; |
| 1906 Location location = _createLocationFromNode(name); | 1967 Location location = _createLocationFromNode(name); |
| 1907 location = _getLocationWithExpressionType(location, node.initializer); | 1968 location = _getLocationWithExpressionType(location, node.initializer); |
| 1908 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); | 1969 recordRelationship(element, IndexConstants.IS_DEFINED_BY, location); |
| 1909 } | 1970 } |
| 1910 // visit | 1971 // visit |
| 1911 enterScope(element); | 1972 enterScope(element); |
| 1912 try { | 1973 try { |
| 1913 return super.visitVariableDeclaration(node); | 1974 return super.visitVariableDeclaration(node); |
| 1914 } finally { | 1975 } finally { |
| 1915 _exitScope(); | 1976 _exitScope(); |
| 1916 } | 1977 } |
| 1917 } | 1978 } |
| 1918 | 1979 |
| 1980 @override |
| 1919 Object visitVariableDeclarationList(VariableDeclarationList node) { | 1981 Object visitVariableDeclarationList(VariableDeclarationList node) { |
| 1920 NodeList<VariableDeclaration> variables = node.variables; | 1982 NodeList<VariableDeclaration> variables = node.variables; |
| 1921 if (variables != null) { | 1983 if (variables != null) { |
| 1922 // use first VariableDeclaration as Element for Location(s) in type | 1984 // use first VariableDeclaration as Element for Location(s) in type |
| 1923 { | 1985 { |
| 1924 TypeName type = node.type; | 1986 TypeName type = node.type; |
| 1925 if (type != null) { | 1987 if (type != null) { |
| 1926 for (VariableDeclaration variableDeclaration in variables) { | 1988 for (VariableDeclaration variableDeclaration in variables) { |
| 1927 enterScope(variableDeclaration.element); | 1989 enterScope(variableDeclaration.element); |
| 1928 try { | 1990 try { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2110 int _periodEnd = 0; | 2172 int _periodEnd = 0; |
| 2111 } | 2173 } |
| 2112 | 2174 |
| 2113 /** | 2175 /** |
| 2114 * Special [Element] which is used to index references to the name without speci
fying concrete | 2176 * Special [Element] which is used to index references to the name without speci
fying concrete |
| 2115 * kind of this name - field, method or something else. | 2177 * kind of this name - field, method or something else. |
| 2116 */ | 2178 */ |
| 2117 class NameElementImpl extends ElementImpl { | 2179 class NameElementImpl extends ElementImpl { |
| 2118 NameElementImpl(String name) : super("name:${name}", -1); | 2180 NameElementImpl(String name) : super("name:${name}", -1); |
| 2119 | 2181 |
| 2182 @override |
| 2120 accept(ElementVisitor visitor) => null; | 2183 accept(ElementVisitor visitor) => null; |
| 2121 | 2184 |
| 2185 @override |
| 2122 ElementKind get kind => ElementKind.NAME; | 2186 ElementKind get kind => ElementKind.NAME; |
| 2123 } | 2187 } |
| 2124 | 2188 |
| 2125 /** | 2189 /** |
| 2126 * Visits resolved [CompilationUnit] and adds Angular specific relationships int
o | 2190 * Visits resolved [CompilationUnit] and adds Angular specific relationships int
o |
| 2127 * [IndexStore]. | 2191 * [IndexStore]. |
| 2128 */ | 2192 */ |
| 2129 class AngularDartIndexContributor extends GeneralizingAstVisitor<Object> { | 2193 class AngularDartIndexContributor extends GeneralizingAstVisitor<Object> { |
| 2130 IndexStore _store; | 2194 IndexStore _store; |
| 2131 | 2195 |
| 2132 AngularDartIndexContributor(IndexStore store) { | 2196 AngularDartIndexContributor(IndexStore store) { |
| 2133 this._store = store; | 2197 this._store = store; |
| 2134 } | 2198 } |
| 2135 | 2199 |
| 2200 @override |
| 2136 Object visitClassDeclaration(ClassDeclaration node) { | 2201 Object visitClassDeclaration(ClassDeclaration node) { |
| 2137 ClassElement classElement = node.element; | 2202 ClassElement classElement = node.element; |
| 2138 if (classElement != null) { | 2203 if (classElement != null) { |
| 2139 List<ToolkitObjectElement> toolkitObjects = classElement.toolkitObjects; | 2204 List<ToolkitObjectElement> toolkitObjects = classElement.toolkitObjects; |
| 2140 for (ToolkitObjectElement object in toolkitObjects) { | 2205 for (ToolkitObjectElement object in toolkitObjects) { |
| 2141 if (object is AngularComponentElement) { | 2206 if (object is AngularComponentElement) { |
| 2142 _indexComponent(object); | 2207 _indexComponent(object); |
| 2143 } | 2208 } |
| 2144 if (object is AngularDirectiveElement) { | 2209 if (object is AngularDirectiveElement) { |
| 2145 AngularDirectiveElement directive = object; | 2210 AngularDirectiveElement directive = object; |
| 2146 _indexDirective(directive); | 2211 _indexDirective(directive); |
| 2147 } | 2212 } |
| 2148 } | 2213 } |
| 2149 } | 2214 } |
| 2150 // stop visiting | 2215 // stop visiting |
| 2151 return null; | 2216 return null; |
| 2152 } | 2217 } |
| 2153 | 2218 |
| 2219 @override |
| 2154 Object visitCompilationUnitMember(CompilationUnitMember node) => null; | 2220 Object visitCompilationUnitMember(CompilationUnitMember node) => null; |
| 2155 | 2221 |
| 2156 void _indexComponent(AngularComponentElement component) { | 2222 void _indexComponent(AngularComponentElement component) { |
| 2157 _indexProperties(component.properties); | 2223 _indexProperties(component.properties); |
| 2158 } | 2224 } |
| 2159 | 2225 |
| 2160 void _indexDirective(AngularDirectiveElement directive) { | 2226 void _indexDirective(AngularDirectiveElement directive) { |
| 2161 _indexProperties(directive.properties); | 2227 _indexProperties(directive.properties); |
| 2162 } | 2228 } |
| 2163 | 2229 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2211 /** | 2277 /** |
| 2212 * Initialize a newly created operation that will remove the specified resourc
e. | 2278 * Initialize a newly created operation that will remove the specified resourc
e. |
| 2213 * | 2279 * |
| 2214 * @param indexStore the index store against which this operation is being run | 2280 * @param indexStore the index store against which this operation is being run |
| 2215 * @param context the [AnalysisContext] to remove | 2281 * @param context the [AnalysisContext] to remove |
| 2216 */ | 2282 */ |
| 2217 RemoveContextOperation(IndexStore indexStore, this.context) { | 2283 RemoveContextOperation(IndexStore indexStore, this.context) { |
| 2218 this._indexStore = indexStore; | 2284 this._indexStore = indexStore; |
| 2219 } | 2285 } |
| 2220 | 2286 |
| 2287 @override |
| 2221 bool get isQuery => false; | 2288 bool get isQuery => false; |
| 2222 | 2289 |
| 2290 @override |
| 2223 void performOperation() { | 2291 void performOperation() { |
| 2224 _indexStore.removeContext(context); | 2292 _indexStore.removeContext(context); |
| 2225 } | 2293 } |
| 2226 | 2294 |
| 2295 @override |
| 2227 bool removeWhenSourceRemoved(Source source) => false; | 2296 bool removeWhenSourceRemoved(Source source) => false; |
| 2228 | 2297 |
| 2298 @override |
| 2229 String toString() => "RemoveContext(${context})"; | 2299 String toString() => "RemoveContext(${context})"; |
| 2230 } | 2300 } |
| 2231 | 2301 |
| 2232 /** | 2302 /** |
| 2233 * Instances of the [IndexHtmlUnitOperation] implement an operation that adds da
ta to the | 2303 * Instances of the [IndexHtmlUnitOperation] implement an operation that adds da
ta to the |
| 2234 * index based on the resolved [HtmlUnit]. | 2304 * index based on the resolved [HtmlUnit]. |
| 2235 */ | 2305 */ |
| 2236 class IndexHtmlUnitOperation implements IndexOperation { | 2306 class IndexHtmlUnitOperation implements IndexOperation { |
| 2237 /** | 2307 /** |
| 2238 * The index store against which this operation is being run. | 2308 * The index store against which this operation is being run. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 this._context = context; | 2341 this._context = context; |
| 2272 this._htmlElement = unit.element; | 2342 this._htmlElement = unit.element; |
| 2273 this._source = _htmlElement.source; | 2343 this._source = _htmlElement.source; |
| 2274 } | 2344 } |
| 2275 | 2345 |
| 2276 /** | 2346 /** |
| 2277 * @return the [Source] to be indexed. | 2347 * @return the [Source] to be indexed. |
| 2278 */ | 2348 */ |
| 2279 Source get source => _source; | 2349 Source get source => _source; |
| 2280 | 2350 |
| 2351 @override |
| 2281 bool get isQuery => false; | 2352 bool get isQuery => false; |
| 2282 | 2353 |
| 2354 @override |
| 2283 void performOperation() { | 2355 void performOperation() { |
| 2284 try { | 2356 try { |
| 2285 bool mayIndex = _indexStore.aboutToIndexHtml(_context, _htmlElement); | 2357 bool mayIndex = _indexStore.aboutToIndexHtml(_context, _htmlElement); |
| 2286 if (!mayIndex) { | 2358 if (!mayIndex) { |
| 2287 return; | 2359 return; |
| 2288 } | 2360 } |
| 2289 AngularHtmlIndexContributor contributor = new AngularHtmlIndexContributor(
_indexStore); | 2361 AngularHtmlIndexContributor contributor = new AngularHtmlIndexContributor(
_indexStore); |
| 2290 unit.accept(contributor); | 2362 unit.accept(contributor); |
| 2291 } catch (exception) { | 2363 } catch (exception) { |
| 2292 AnalysisEngine.instance.logger.logError2("Could not index ${unit.element.l
ocation}", exception); | 2364 AnalysisEngine.instance.logger.logError2("Could not index ${unit.element.l
ocation}", exception); |
| 2293 } | 2365 } |
| 2294 } | 2366 } |
| 2295 | 2367 |
| 2368 @override |
| 2296 bool removeWhenSourceRemoved(Source source) => this._source == source; | 2369 bool removeWhenSourceRemoved(Source source) => this._source == source; |
| 2297 | 2370 |
| 2371 @override |
| 2298 String toString() => "IndexHtmlUnitOperation(${_source.fullName})"; | 2372 String toString() => "IndexHtmlUnitOperation(${_source.fullName})"; |
| 2299 } | 2373 } |
| 2300 | 2374 |
| 2301 /** | 2375 /** |
| 2302 * Instances of the class <code>Location</code> represent a location related to
an element. The | 2376 * Instances of the class <code>Location</code> represent a location related to
an element. The |
| 2303 * location is expressed as an offset and length, but the offset is relative to
the resource | 2377 * location is expressed as an offset and length, but the offset is relative to
the resource |
| 2304 * containing the element rather than the start of the element within that resou
rce. | 2378 * containing the element rather than the start of the element within that resou
rce. |
| 2305 */ | 2379 */ |
| 2306 class Location { | 2380 class Location { |
| 2307 /** | 2381 /** |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2336 * @param element the [Element] containing this location | 2410 * @param element the [Element] containing this location |
| 2337 * @param offset the offset of this location within the resource containing th
e element | 2411 * @param offset the offset of this location within the resource containing th
e element |
| 2338 * @param length the length of this location | 2412 * @param length the length of this location |
| 2339 */ | 2413 */ |
| 2340 Location(this.element, this.offset, this.length) { | 2414 Location(this.element, this.offset, this.length) { |
| 2341 if (element == null) { | 2415 if (element == null) { |
| 2342 throw new IllegalArgumentException("element location cannot be null"); | 2416 throw new IllegalArgumentException("element location cannot be null"); |
| 2343 } | 2417 } |
| 2344 } | 2418 } |
| 2345 | 2419 |
| 2346 Location clone() => new Location(element, offset, length); | 2420 /** |
| 2421 * Returns a clone of this [Location]. |
| 2422 */ |
| 2423 Location newClone() => new Location(element, offset, length); |
| 2347 | 2424 |
| 2425 @override |
| 2348 String toString() => "[${offset} - ${(offset + length)}) in ${element}"; | 2426 String toString() => "[${offset} - ${(offset + length)}) in ${element}"; |
| 2349 } | 2427 } |
| 2350 | 2428 |
| 2351 /** | 2429 /** |
| 2352 * [IndexStore] which keeps all information in memory, but can write it to strea
m and read | 2430 * [IndexStore] which keeps all information in memory, but can write it to strea
m and read |
| 2353 * later. | 2431 * later. |
| 2354 */ | 2432 */ |
| 2355 abstract class MemoryIndexStore implements IndexStore { | 2433 abstract class MemoryIndexStore implements IndexStore { |
| 2356 } | 2434 } |
| 2357 | 2435 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2369 final RelationshipCallback callback; | 2447 final RelationshipCallback callback; |
| 2370 | 2448 |
| 2371 /** | 2449 /** |
| 2372 * Initialize a newly created operation that will access the locations that ha
ve a specified | 2450 * Initialize a newly created operation that will access the locations that ha
ve a specified |
| 2373 * relationship with a specified element. | 2451 * relationship with a specified element. |
| 2374 */ | 2452 */ |
| 2375 GetRelationshipsOperation(IndexStore indexStore, this.element, this.relationsh
ip, this.callback) { | 2453 GetRelationshipsOperation(IndexStore indexStore, this.element, this.relationsh
ip, this.callback) { |
| 2376 this._indexStore = indexStore; | 2454 this._indexStore = indexStore; |
| 2377 } | 2455 } |
| 2378 | 2456 |
| 2457 @override |
| 2379 bool get isQuery => true; | 2458 bool get isQuery => true; |
| 2380 | 2459 |
| 2460 @override |
| 2381 void performOperation() { | 2461 void performOperation() { |
| 2382 List<Location> locations; | 2462 List<Location> locations; |
| 2383 locations = _indexStore.getRelationships(element, relationship); | 2463 locations = _indexStore.getRelationships(element, relationship); |
| 2384 callback.hasRelationships(element, relationship, locations); | 2464 callback.hasRelationships(element, relationship, locations); |
| 2385 } | 2465 } |
| 2386 | 2466 |
| 2467 @override |
| 2387 bool removeWhenSourceRemoved(Source source) => false; | 2468 bool removeWhenSourceRemoved(Source source) => false; |
| 2388 | 2469 |
| 2470 @override |
| 2389 String toString() => "GetRelationships(${element}, ${relationship})"; | 2471 String toString() => "GetRelationships(${element}, ${relationship})"; |
| 2390 } | 2472 } |
| 2391 | 2473 |
| 2392 /** | 2474 /** |
| 2393 * [Location] with attached data. | 2475 * [Location] with attached data. |
| 2394 */ | 2476 */ |
| 2395 class LocationWithData<D> extends Location { | 2477 class LocationWithData<D> extends Location { |
| 2396 final D data; | 2478 final D data; |
| 2397 | 2479 |
| 2398 LocationWithData.con1(Location location, this.data) : super(location.element,
location.offset, location.length); | 2480 LocationWithData.con1(Location location, this.data) : super(location.element,
location.offset, location.length); |
| 2399 | 2481 |
| 2400 LocationWithData.con2(Element element, int offset, int length, this.data) : su
per(element, offset, length); | 2482 LocationWithData.con2(Element element, int offset, int length, this.data) : su
per(element, offset, length); |
| 2401 | 2483 |
| 2402 Location clone() => new LocationWithData<D>.con2(element, offset, length, data
); | 2484 @override |
| 2485 Location newClone() => new LocationWithData<D>.con2(element, offset, length, d
ata); |
| 2403 } | 2486 } |
| 2404 | 2487 |
| 2405 /** | 2488 /** |
| 2406 * The interface <code>RelationshipCallback</code> defines the behavior of objec
ts that are invoked | 2489 * The interface <code>RelationshipCallback</code> defines the behavior of objec
ts that are invoked |
| 2407 * with the results of a query about a given relationship. | 2490 * with the results of a query about a given relationship. |
| 2408 */ | 2491 */ |
| 2409 abstract class RelationshipCallback { | 2492 abstract class RelationshipCallback { |
| 2410 /** | 2493 /** |
| 2411 * This method is invoked when the locations that have a specified relationshi
p with a specified | 2494 * This method is invoked when the locations that have a specified relationshi
p with a specified |
| 2412 * element are available. For example, if the element is a field and the relat
ionship is the | 2495 * element are available. For example, if the element is a field and the relat
ionship is the |
| 2413 * is-referenced-by relationship, then this method will be invoked with each l
ocation at which the | 2496 * is-referenced-by relationship, then this method will be invoked with each l
ocation at which the |
| 2414 * field is referenced. | 2497 * field is referenced. |
| 2415 * | 2498 * |
| 2416 * @param element the [Element] that has the relationship with the locations | 2499 * @param element the [Element] that has the relationship with the locations |
| 2417 * @param relationship the relationship between the given element and the loca
tions | 2500 * @param relationship the relationship between the given element and the loca
tions |
| 2418 * @param locations the locations that were found | 2501 * @param locations the locations that were found |
| 2419 */ | 2502 */ |
| 2420 void hasRelationships(Element element, Relationship relationship, List<Locatio
n> locations); | 2503 void hasRelationships(Element element, Relationship relationship, List<Locatio
n> locations); |
| 2421 } | 2504 } |
| OLD | NEW |