| Index: pkg/analysis_server/lib/src/services/search/search_engine.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/search/search_engine.dart b/pkg/analysis_server/lib/src/services/search/search_engine.dart
|
| index 72ca48283123d54ae5faf6f6d77e5f97133adb4e..e9c681d3c3fd945c461d23716d40e4a174aeaf55 100644
|
| --- a/pkg/analysis_server/lib/src/services/search/search_engine.dart
|
| +++ b/pkg/analysis_server/lib/src/services/search/search_engine.dart
|
| @@ -155,16 +155,20 @@ class SearchMatch {
|
| this.sourceRange, this.isResolved, this.isQualified);
|
|
|
| /**
|
| - * Return the [Element] containing the match.
|
| + * Return the [Element] containing the match. Can return `null` if the unit
|
| + * does not exist, or its element was invalidated, or the element cannot be
|
| + * found, etc.
|
| */
|
| Element get element {
|
| if (_element == null) {
|
| CompilationUnitElement unitElement =
|
| context.getCompilationUnitElement(unitSource, librarySource);
|
| - _ContainingElementFinder finder =
|
| - new _ContainingElementFinder(sourceRange.offset);
|
| - unitElement.accept(finder);
|
| - _element = finder.containingElement;
|
| + if (unitElement != null) {
|
| + _ContainingElementFinder finder =
|
| + new _ContainingElementFinder(sourceRange.offset);
|
| + unitElement.accept(finder);
|
| + _element = finder.containingElement;
|
| + }
|
| }
|
| return _element;
|
| }
|
| @@ -237,6 +241,16 @@ class SearchMatch {
|
| buffer.write(")");
|
| return buffer.toString();
|
| }
|
| +
|
| + /**
|
| + * Return elements of [matches] which has not-null elements.
|
| + *
|
| + * When [SearchMatch.element] is not `null` we cache its value, so it cannot
|
| + * become `null` later.
|
| + */
|
| + static List<SearchMatch> withNotNullElement(List<SearchMatch> matches) {
|
| + return matches.where((match) => match.element != null).toList();
|
| + }
|
| }
|
|
|
| /**
|
|
|