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

Side by Side Diff: pkg/analysis_services/lib/search/element_visitors.dart

Issue 484733003: Import analysis_services.dart into analysis_server.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 library services.search.element_visitors;
6
7 import 'package:analyzer/src/generated/element.dart';
8
9
10 /**
11 * Uses [processor] to visit all of the children of [element].
12 * If [processor] returns `true`, then children of a child are visited too.
13 */
14 void visitChildren(Element element, ElementProcessor processor) {
15 element.visitChildren(new _ElementVisitorAdapter(processor));
16 }
17
18
19 /**
20 * Uses [processor] to visit all of the top-level elements of [library].
21 */
22 void visitLibraryTopLevelElements(LibraryElement library,
23 ElementProcessor processor) {
24 library.visitChildren(new _TopLevelElementsVisitor(processor));
25 }
26
27
28 /**
29 * An [Element] processor function type.
30 * If `true` is returned, children of [element] will be visited.
31 */
32 typedef bool ElementProcessor(Element element);
33
34
35 /**
36 * A [GeneralizingElementVisitor] adapter for [ElementProcessor].
37 */
38 class _ElementVisitorAdapter extends GeneralizingElementVisitor {
39 final ElementProcessor processor;
40
41 _ElementVisitorAdapter(this.processor);
42
43 @override
44 void visitElement(Element element) {
45 bool visitChildren = processor(element);
46 if (visitChildren == true) {
47 element.visitChildren(this);
48 }
49 }
50 }
51
52
53 /**
54 * A [GeneralizingElementVisitor] for visiting top-level elements.
55 */
56 class _TopLevelElementsVisitor extends GeneralizingElementVisitor {
57 final ElementProcessor processor;
58
59 _TopLevelElementsVisitor(this.processor);
60
61 @override
62 void visitElement(Element element) {
63 if (element is CompilationUnitElement) {
64 element.visitChildren(this);
65 } else {
66 processor(element);
67 }
68 }
69 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/refactoring/refactoring.dart ('k') | pkg/analysis_services/lib/search/hierarchy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698