| Index: pkg/analyzer_plugin/lib/utilities/navigation/navigation.dart
|
| diff --git a/pkg/analyzer_plugin/lib/utilities/navigation.dart b/pkg/analyzer_plugin/lib/utilities/navigation/navigation.dart
|
| similarity index 50%
|
| rename from pkg/analyzer_plugin/lib/utilities/navigation.dart
|
| rename to pkg/analyzer_plugin/lib/utilities/navigation/navigation.dart
|
| index 4db996a49bbc3fb4274a9e196dc541d289962a9c..a7876195ffa680aeb65dbb0e5cfeda807559c336 100644
|
| --- a/pkg/analyzer_plugin/lib/utilities/navigation.dart
|
| +++ b/pkg/analyzer_plugin/lib/utilities/navigation/navigation.dart
|
| @@ -2,12 +2,14 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -import 'package:analyzer/src/dart/analysis/driver.dart';
|
| +import 'package:analyzer/dart/analysis/results.dart';
|
| +import 'package:analyzer/file_system/file_system.dart';
|
| import 'package:analyzer_plugin/protocol/protocol.dart';
|
| import 'package:analyzer_plugin/protocol/protocol_common.dart'
|
| show ElementKind, Location;
|
| import 'package:analyzer_plugin/protocol/protocol_generated.dart';
|
| -import 'package:analyzer_plugin/src/utilities/navigation.dart';
|
| +import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart';
|
| +import 'package:analyzer_plugin/utilities/generator.dart';
|
|
|
| /**
|
| * An object that [NavigationContributor]s use to record navigation regions.
|
| @@ -30,12 +32,11 @@ abstract class NavigationCollector {
|
| */
|
| abstract class NavigationContributor {
|
| /**
|
| - * Contribute navigation regions for a subset of the content of the given
|
| - * [source] into the given [collector]. The subset is specified by the
|
| - * [offset] and [length]. The [driver] can be used to access analysis results.
|
| + * Contribute navigation regions for the portion of the file specified by the
|
| + * given [request] into the given [collector].
|
| */
|
| - void computeNavigation(NavigationCollector collector,
|
| - AnalysisDriverGeneric driver, String filePath, int offset, int length);
|
| + void computeNavigation(
|
| + NavigationRequest request, NavigationCollector collector);
|
| }
|
|
|
| /**
|
| @@ -45,36 +46,27 @@ abstract class NavigationContributor {
|
| */
|
| class NavigationGenerator {
|
| /**
|
| - * The driver to be passed in to the contributors.
|
| - */
|
| - final AnalysisDriverGeneric driver;
|
| -
|
| - /**
|
| * The contributors to be used to generate the navigation data.
|
| */
|
| final List<NavigationContributor> contributors;
|
|
|
| /**
|
| - * Initialize a newly created navigation generator.
|
| + * Initialize a newly created navigation generator to use the given
|
| + * [contributors].
|
| */
|
| - NavigationGenerator(this.driver, this.contributors);
|
| + NavigationGenerator(this.contributors);
|
|
|
| /**
|
| - * Create an 'analysis.navigation' notification for the file with the given
|
| - * [filePath]. If any of the contributors throws an exception, also create a
|
| - * non-fatal 'plugin.error' notification.
|
| + * Create an 'analysis.navigation' notification for the portion of the file
|
| + * specified by the given [request]. If any of the contributors throws an
|
| + * exception, also create a non-fatal 'plugin.error' notification.
|
| */
|
| - List<Notification> generateNavigationNotification(String filePath) {
|
| - // TODO(brianwilkerson) Consider not passing a driver in (to either the
|
| - // NavigationGenerator constructor or computeNavigation) and replace the
|
| - // filePath with an AnalysisResult that then gets passed in to
|
| - // computeNavigation. That would allow contributors to use previously
|
| - // computed results rather than re-compute them.
|
| + GeneratorResult generateNavigationNotification(NavigationRequest request) {
|
| List<Notification> notifications = <Notification>[];
|
| NavigationCollectorImpl collector = new NavigationCollectorImpl();
|
| for (NavigationContributor contributor in contributors) {
|
| try {
|
| - contributor.computeNavigation(collector, driver, filePath, null, null);
|
| + contributor.computeNavigation(request, collector);
|
| } catch (exception, stackTrace) {
|
| notifications.add(new PluginErrorParams(
|
| false, exception.toString(), stackTrace.toString())
|
| @@ -82,9 +74,39 @@ class NavigationGenerator {
|
| }
|
| }
|
| collector.createRegions();
|
| - notifications.add(new AnalysisNavigationParams(
|
| - filePath, collector.regions, collector.targets, collector.files)
|
| + notifications.add(new AnalysisNavigationParams(request.result.path,
|
| + collector.regions, collector.targets, collector.files)
|
| .toNotification());
|
| - return notifications;
|
| + return new GeneratorResult(null, notifications);
|
| }
|
| }
|
| +
|
| +/**
|
| + * The information about a requested set of navigation information.
|
| + *
|
| + * Clients may not extend, implement or mix-in this class.
|
| + */
|
| +abstract class NavigationRequest {
|
| + /**
|
| + * Return the length of the region within the source for which navigation
|
| + * regions are being requested.
|
| + */
|
| + int get length;
|
| +
|
| + /**
|
| + * Return the offset of the region within the source for which navigation
|
| + * regions are being requested.
|
| + */
|
| + int get offset;
|
| +
|
| + /**
|
| + * Return the resource provider associated with this request.
|
| + */
|
| + ResourceProvider get resourceProvider;
|
| +
|
| + /**
|
| + * The analysis result for the file in which the navigation regions are being
|
| + * requested.
|
| + */
|
| + ResolveResult get result;
|
| +}
|
|
|