| OLD | NEW |
| (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_common.dart' |
| 8 hide AnalysisError; |
| 9 import 'package:analyzer_plugin/utilities/outline/outline.dart'; |
| 10 |
| 11 /** |
| 12 * A concrete implementation of [DartOutlineRequest]. |
| 13 */ |
| 14 class DartOutlineRequestImpl implements DartOutlineRequest { |
| 15 @override |
| 16 final ResourceProvider resourceProvider; |
| 17 |
| 18 @override |
| 19 final ResolveResult result; |
| 20 |
| 21 /** |
| 22 * Initialize a newly create request with the given data. |
| 23 */ |
| 24 DartOutlineRequestImpl(this.resourceProvider, this.result); |
| 25 |
| 26 @override |
| 27 String get path => result.path; |
| 28 } |
| 29 |
| 30 /** |
| 31 * A concrete implementation of [OutlineCollector]. |
| 32 */ |
| 33 class OutlineCollectorImpl implements OutlineCollector { |
| 34 /** |
| 35 * A list containing the top-level outline nodes. |
| 36 */ |
| 37 List<Outline> outlines = <Outline>[]; |
| 38 |
| 39 /** |
| 40 * A stack keeping track of the outline nodes that have been started but not |
| 41 * yet ended. |
| 42 */ |
| 43 List<Outline> outlineStack = <Outline>[]; |
| 44 |
| 45 @override |
| 46 void endElement() { |
| 47 outlineStack.removeLast(); |
| 48 } |
| 49 |
| 50 @override |
| 51 void startElement(Element element, int offset, int length) { |
| 52 Outline outline = new Outline(element, offset, length); |
| 53 if (outlineStack.isEmpty) { |
| 54 outlines.add(outline); |
| 55 } else { |
| 56 List<Outline> children = outlineStack.last.children; |
| 57 if (children == null) { |
| 58 children = <Outline>[]; |
| 59 outlineStack.last.children = children; |
| 60 } |
| 61 children.add(outline); |
| 62 } |
| 63 outlineStack.add(outline); |
| 64 } |
| 65 } |
| OLD | NEW |