Skip to content

Commit b7178c2

Browse files
bwilkersonCommit Queue
authored andcommitted
[migration] element_visitors.dart
Change-Id: I85b6e19575a1a8695982bf8349fc88c84ace2645 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410241 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 0c42363 commit b7178c2

File tree

1 file changed

+0
-87
lines changed

1 file changed

+0
-87
lines changed

pkg/analysis_server/lib/src/services/search/element_visitors.dart

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,26 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
7-
import 'package:analyzer/dart/element/element.dart';
85
import 'package:analyzer/dart/element/element2.dart';
96
import 'package:analyzer/dart/element/visitor.dart';
107
import 'package:analyzer/dart/element/visitor2.dart';
118

12-
/// Return the [Element] that is either [root], or one of its direct or
13-
/// indirect children, and has the given [nameOffset].
14-
Element? findElementByNameOffset(Element? root, int nameOffset) {
15-
if (root == null) {
16-
return null;
17-
}
18-
try {
19-
var visitor = _ElementByNameOffsetVisitor(nameOffset);
20-
root.accept(visitor);
21-
} on Element catch (result) {
22-
return result;
23-
}
24-
return null;
25-
}
26-
279
/// Returns the fragment that is either [fragment], or one of its direct or
2810
/// indirect children, and has the given [nameOffset].
2911
Fragment? findFragmentByNameOffset(LibraryFragment fragment, int nameOffset) {
3012
return _FragmentByNameOffsetVisitor(nameOffset).search(fragment);
3113
}
3214

33-
/// Uses [processor] to visit all of the children of [element].
34-
/// If [processor] returns `true`, then children of a child are visited too.
35-
void visitChildren(Element element, BoolElementProcessor processor) {
36-
element.visitChildren(_ElementVisitorAdapter(processor));
37-
}
38-
3915
/// Uses [processor] to visit all of the children of [element].
4016
/// If [processor] returns `true`, then children of a child are visited too.
4117
void visitChildren2(Element2 element, BoolElementProcessor2 processor) {
4218
element.visitChildren2(_ElementVisitorAdapter2(processor));
4319
}
4420

45-
/// Uses [processor] to visit all of the top-level elements of [library].
46-
void visitLibraryTopLevelElements(
47-
LibraryElement library,
48-
VoidElementProcessor processor,
49-
) {
50-
library.visitChildren(_TopLevelElementsVisitor(processor));
51-
}
52-
53-
/// An [Element] processor function type.
54-
/// If `true` is returned, children of [element] will be visited.
55-
typedef BoolElementProcessor = bool Function(Element element);
56-
5721
/// An [Element2] processor function type.
5822
/// If `true` is returned, children of [element] will be visited.
5923
typedef BoolElementProcessor2 = bool Function(Element2 element);
6024

61-
/// An [Element] processor function type.
62-
typedef VoidElementProcessor = void Function(Element element);
63-
64-
/// A visitor that finds the deep-most [Element] that contains the [nameOffset].
65-
class _ElementByNameOffsetVisitor extends GeneralizingElementVisitor<void> {
66-
final int nameOffset;
67-
68-
_ElementByNameOffsetVisitor(this.nameOffset);
69-
70-
@override
71-
void visitElement(Element element) {
72-
if (element.nameOffset != -1 &&
73-
!element.isSynthetic &&
74-
element.nameOffset == nameOffset) {
75-
throw element;
76-
}
77-
super.visitElement(element);
78-
}
79-
}
80-
81-
/// A [GeneralizingElementVisitor] adapter for [BoolElementProcessor].
82-
class _ElementVisitorAdapter extends GeneralizingElementVisitor<void> {
83-
final BoolElementProcessor processor;
84-
85-
_ElementVisitorAdapter(this.processor);
86-
87-
@override
88-
void visitElement(Element element) {
89-
var visitChildren = processor(element);
90-
if (visitChildren == true) {
91-
element.visitChildren(this);
92-
}
93-
}
94-
}
95-
9625
/// A [GeneralizingElementVisitor] adapter for [BoolElementProcessor2].
9726
class _ElementVisitorAdapter2 extends GeneralizingElementVisitor2<void> {
9827
final BoolElementProcessor2 processor;
@@ -129,19 +58,3 @@ class _FragmentByNameOffsetVisitor {
12958
return null;
13059
}
13160
}
132-
133-
/// A [GeneralizingElementVisitor] for visiting top-level elements.
134-
class _TopLevelElementsVisitor extends GeneralizingElementVisitor<void> {
135-
final VoidElementProcessor processor;
136-
137-
_TopLevelElementsVisitor(this.processor);
138-
139-
@override
140-
void visitElement(Element element) {
141-
if (element is CompilationUnitElement) {
142-
element.visitChildren(this);
143-
} else {
144-
processor(element);
145-
}
146-
}
147-
}

0 commit comments

Comments
 (0)