| 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 9f283fc048366ef99e316f3560a4d7425d7ab4bf..6ea33959a248e5b6838334b94259e313a5d0cca1 100644
|
| --- a/pkg/analysis_server/lib/src/services/search/search_engine.dart
|
| +++ b/pkg/analysis_server/lib/src/services/search/search_engine.dart
|
| @@ -7,11 +7,7 @@ library services.search_engine;
|
| import 'dart:async';
|
|
|
| import 'package:analyzer/dart/element/element.dart';
|
| -import 'package:analyzer/dart/element/visitor.dart';
|
| -import 'package:analyzer/src/dart/element/element.dart';
|
| -import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
|
| import 'package:analyzer/src/generated/source.dart';
|
| -import 'package:analyzer/src/generated/utilities_general.dart';
|
|
|
| /**
|
| * Instances of the enum [MatchKind] represent the kind of reference that was
|
| @@ -110,138 +106,53 @@ abstract class SearchEngine {
|
| * Instances of the class [SearchMatch] represent a match found by
|
| * [SearchEngine].
|
| */
|
| -class SearchMatch {
|
| +abstract class SearchMatch {
|
| /**
|
| - * The [AnalysisContext] containing the match.
|
| - */
|
| - final AnalysisContext context;
|
| -
|
| - /**
|
| - * The URI of the source of the library containing the match.
|
| - */
|
| - final String libraryUri;
|
| -
|
| - /**
|
| - * The URI of the source of the unit 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.
|
| */
|
| - final String unitUri;
|
| + Element get element;
|
|
|
| /**
|
| - * The kind of the match.
|
| + * The absolute path of the file containing the match.
|
| */
|
| - final MatchKind kind;
|
| + String get file;
|
|
|
| /**
|
| - * The source range that was matched.
|
| + * Is `true` if field or method access is done using qualifier.
|
| */
|
| - final SourceRange sourceRange;
|
| + bool get isQualified;
|
|
|
| /**
|
| * Is `true` if the match is a resolved reference to some [Element].
|
| */
|
| - final bool isResolved;
|
| + bool get isResolved;
|
|
|
| /**
|
| - * Is `true` if field or method access is done using qualifier.
|
| - */
|
| - final bool isQualified;
|
| -
|
| - Source _librarySource;
|
| - Source _unitSource;
|
| - LibraryElement _libraryElement;
|
| - Element _element;
|
| -
|
| - SearchMatch(this.context, this.libraryUri, this.unitUri, this.kind,
|
| - this.sourceRange, this.isResolved, this.isQualified);
|
| -
|
| - /**
|
| - * 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.
|
| + * The kind of the match.
|
| */
|
| - Element get element {
|
| - if (_element == null) {
|
| - CompilationUnitElement unitElement =
|
| - context.getCompilationUnitElement(unitSource, librarySource);
|
| - if (unitElement != null) {
|
| - _ContainingElementFinder finder =
|
| - new _ContainingElementFinder(sourceRange.offset);
|
| - unitElement.accept(finder);
|
| - _element = finder.containingElement;
|
| - }
|
| - }
|
| - return _element;
|
| - }
|
| + MatchKind get kind;
|
|
|
| /**
|
| - * The absolute path of the file containing the match.
|
| + * Return the [LibraryElement] for the [libraryUri] in the [context].
|
| */
|
| - String get file => unitSource.fullName;
|
| -
|
| - @override
|
| - int get hashCode {
|
| - return JenkinsSmiHash.hash4(libraryUri.hashCode, unitUri.hashCode,
|
| - kind.hashCode, sourceRange.hashCode);
|
| - }
|
| + LibraryElement get libraryElement;
|
|
|
| /**
|
| - * Return the [LibraryElement] for the [libraryUri] in the [context].
|
| + * The library [Source] of the reference.
|
| */
|
| - LibraryElement get libraryElement {
|
| - _libraryElement ??= context.getLibraryElement(librarySource);
|
| - return _libraryElement;
|
| - }
|
| + Source get librarySource;
|
|
|
| /**
|
| - * The library [Source] of the reference.
|
| + * The source range that was matched.
|
| */
|
| - Source get librarySource {
|
| - _librarySource ??= context.sourceFactory.forUri(libraryUri);
|
| - return _librarySource;
|
| - }
|
| + SourceRange get sourceRange;
|
|
|
| /**
|
| * The unit [Source] of the reference.
|
| */
|
| - Source get unitSource {
|
| - _unitSource ??= context.sourceFactory.forUri(unitUri);
|
| - return _unitSource;
|
| - }
|
| -
|
| - @override
|
| - bool operator ==(Object object) {
|
| - if (identical(object, this)) {
|
| - return true;
|
| - }
|
| - if (object is SearchMatch) {
|
| - return kind == object.kind &&
|
| - libraryUri == object.libraryUri &&
|
| - unitUri == object.unitUri &&
|
| - isResolved == object.isResolved &&
|
| - isQualified == object.isQualified &&
|
| - sourceRange == object.sourceRange;
|
| - }
|
| - return false;
|
| - }
|
| -
|
| - @override
|
| - String toString() {
|
| - StringBuffer buffer = new StringBuffer();
|
| - buffer.write("SearchMatch(kind=");
|
| - buffer.write(kind);
|
| - buffer.write(", libraryUri=");
|
| - buffer.write(libraryUri);
|
| - buffer.write(", unitUri=");
|
| - buffer.write(unitUri);
|
| - buffer.write(", range=");
|
| - buffer.write(sourceRange);
|
| - buffer.write(", isResolved=");
|
| - buffer.write(isResolved);
|
| - buffer.write(", isQualified=");
|
| - buffer.write(isQualified);
|
| - buffer.write(")");
|
| - return buffer.toString();
|
| - }
|
| + Source get unitSource;
|
|
|
| /**
|
| * Return elements of [matches] which has not-null elements.
|
| @@ -253,24 +164,3 @@ class SearchMatch {
|
| return matches.where((match) => match.element != null).toList();
|
| }
|
| }
|
| -
|
| -/**
|
| - * A visitor that finds the deep-most [Element] that contains the [offset].
|
| - */
|
| -class _ContainingElementFinder extends GeneralizingElementVisitor {
|
| - final int offset;
|
| - Element containingElement;
|
| -
|
| - _ContainingElementFinder(this.offset);
|
| -
|
| - visitElement(Element element) {
|
| - if (element is ElementImpl) {
|
| - if (element.codeOffset != null &&
|
| - element.codeOffset <= offset &&
|
| - offset <= element.codeOffset + element.codeLength) {
|
| - containingElement = element;
|
| - super.visitElement(element);
|
| - }
|
| - }
|
| - }
|
| -}
|
|
|