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

Unified Diff: pkg/analyzer_plugin/lib/src/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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart
diff --git a/pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart b/pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3329e16fcd476766ee733f456dc35248365b7f1e
--- /dev/null
+++ b/pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// 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/dart/analysis/results.dart';
+import 'package:analyzer/file_system/file_system.dart';
+import 'package:analyzer_plugin/protocol/protocol_common.dart'
+ hide AnalysisError;
+import 'package:analyzer_plugin/utilities/outline/outline.dart';
+
+/**
+ * A concrete implementation of [DartOutlineRequest].
+ */
+class DartOutlineRequestImpl implements DartOutlineRequest {
+ @override
+ final ResourceProvider resourceProvider;
+
+ @override
+ final ResolveResult result;
+
+ /**
+ * Initialize a newly create request with the given data.
+ */
+ DartOutlineRequestImpl(this.resourceProvider, this.result);
+
+ @override
+ String get path => result.path;
+}
+
+/**
+ * A concrete implementation of [OutlineCollector].
+ */
+class OutlineCollectorImpl implements OutlineCollector {
+ /**
+ * A list containing the top-level outline nodes.
+ */
+ List<Outline> outlines = <Outline>[];
+
+ /**
+ * A stack keeping track of the outline nodes that have been started but not
+ * yet ended.
+ */
+ List<Outline> outlineStack = <Outline>[];
+
+ @override
+ void endElement() {
+ outlineStack.removeLast();
+ }
+
+ @override
+ void startElement(Element element, int offset, int length) {
+ Outline outline = new Outline(element, offset, length);
+ if (outlineStack.isEmpty) {
+ outlines.add(outline);
+ } else {
+ List<Outline> children = outlineStack.last.children;
+ if (children == null) {
+ children = <Outline>[];
+ outlineStack.last.children = children;
+ }
+ children.add(outline);
+ }
+ outlineStack.add(outline);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698