Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: pkg/analyzer_plugin/lib/utilities/outline/outline.dart

Issue 3002233002: Add utilities to support the outline notification (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'package:analyzer/dart/analysis/results.dart';
6 import 'package:analyzer/file_system/file_system.dart';
7 import 'package:analyzer_plugin/protocol/protocol.dart';
8 import 'package:analyzer_plugin/protocol/protocol_common.dart'
9 hide AnalysisError;
10 import 'package:analyzer_plugin/protocol/protocol_generated.dart';
11 import 'package:analyzer_plugin/src/utilities/outline/outline.dart';
12 import 'package:analyzer_plugin/utilities/generator.dart';
13
14 /**
15 * The information about a requested set of outline information when
16 * computing outline information in a `.dart` file.
17 *
18 * Clients may not extend, implement or mix-in this class.
19 */
20 abstract class DartOutlineRequest implements OutlineRequest {
21 /**
22 * The analysis result for the file for which the outline is being requested.
23 */
24 ResolveResult get result;
25 }
26
27 /**
28 * An object that [OutlineContributor]s use to record outline information.
29 *
30 * Invocations of the [startElement] and [endElement] methods must be paired.
31 * Any elements started (and ended) between a [startElement] and [endElement]
32 * pair are assumed to be children of the outer pair's element and as such will
33 * automatically be added as children of the outer pair's outline node.
34 *
35 * Clients may not extend, implement or mix-in this class.
36 */
37 abstract class OutlineCollector {
38 /**
39 * Stop recording information about the current element.
40 */
41 void endElement();
42
43 /**
44 * Start recording information about the given [element].
45 */
46 void startElement(Element element, int offset, int length);
47 }
48
49 /**
50 * An object used to produce nodes in an outline.
51 *
52 * Clients may implement this class when implementing plugins.
53 */
54 abstract class OutlineContributor {
55 /**
56 * Contribute outline nodes into the given [collector].
57 */
58 void computeOutline(OutlineRequest request, OutlineCollector collector);
59 }
60
61 /**
62 * A generator that will generate an 'analysis.outline' notification.
63 *
64 * Clients may not extend, implement or mix-in this class.
65 */
66 class OutlineGenerator {
67 /**
68 * The contributors to be used to generate the outline nodes.
69 */
70 final List<OutlineContributor> contributors;
71
72 /**
73 * Initialize a newly created outline generator to use the given
74 * [contributors].
75 */
76 OutlineGenerator(this.contributors);
77
78 /**
79 * Create an 'analysis.outline' notification. If any of the contributors
80 * throws an exception, also create a non-fatal 'plugin.error' notification.
81 */
82 GeneratorResult generateOutlineNotification(OutlineRequest request) {
83 List<Notification> notifications = <Notification>[];
84 OutlineCollectorImpl collector = new OutlineCollectorImpl();
85 for (OutlineContributor contributor in contributors) {
86 try {
87 contributor.computeOutline(request, collector);
88 } catch (exception, stackTrace) {
89 notifications.add(new PluginErrorParams(
90 false, exception.toString(), stackTrace.toString())
91 .toNotification());
92 }
93 }
94 notifications.add(
95 new AnalysisOutlineParams(request.path, collector.outlines)
96 .toNotification());
97 return new GeneratorResult(null, notifications);
98 }
99 }
100
101 /**
102 * The information about a requested set of outline information.
103 *
104 * Clients may not extend, implement or mix-in this class.
105 */
106 abstract class OutlineRequest {
107 /**
108 * Return the path of the file for which an outline is being requested.
109 */
110 String get path;
111
112 /**
113 * Return the resource provider associated with this request.
114 */
115 ResourceProvider get resourceProvider;
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698