Skip to content

Commit 2f89caf

Browse files
pqCommit Queue
authored andcommitted
[element model] cleanup migrated ast utilities
Change-Id: I52ba518677bd0f60501bf700187a7b0509a59382 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391493 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 98ec623 commit 2f89caf

File tree

3 files changed

+8
-61
lines changed

3 files changed

+8
-61
lines changed

pkg/linter/lib/src/ast.dart

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,9 @@ import 'utils.dart';
2323
final List<String> reservedWords = _collectReservedWords();
2424

2525
/// Returns direct children of [parent].
26-
List<Element> getChildren(Element parent, [String? name]) {
27-
var children = <Element>[];
28-
visitChildren(parent, (Element element) {
29-
if (name == null || element.displayName == name) {
30-
children.add(element);
31-
}
32-
return false;
33-
});
34-
return children;
35-
}
36-
37-
/// Returns direct children of [parent].
38-
List<Element2> getChildren2(Element2 parent, [String? name]) {
26+
List<Element2> getChildren(Element2 parent, [String? name]) {
3927
var children = <Element2>[];
40-
visitChildren2(parent, (Element2 element) {
28+
visitChildren(parent, (Element2 element) {
4129
if (name == null || element.displayName == name) {
4230
children.add(element);
4331
}
@@ -317,14 +305,8 @@ File? locatePubspecFile(CompilationUnit compilationUnit) {
317305

318306
/// Uses [processor] to visit all of the children of [element].
319307
/// If [processor] returns `true`, then children of a child are visited too.
320-
void visitChildren(Element element, ElementProcessor processor) {
321-
element.visitChildren(_ElementVisitorAdapter(processor));
322-
}
323-
324-
/// Uses [processor] to visit all of the children of [element].
325-
/// If [processor] returns `true`, then children of a child are visited too.
326-
void visitChildren2(Element2 element, ElementProcessor2 processor) {
327-
element.visitChildren2(_ElementVisitorAdapter2(processor));
308+
void visitChildren(Element2 element, ElementProcessor processor) {
309+
element.visitChildren2(_ElementVisitorAdapter(processor));
328310
}
329311

330312
bool _checkForSimpleGetter(MethodDeclaration getter, Expression? expression) {
@@ -434,35 +416,16 @@ bool _hasFieldOrMethod(ClassMember element, String name) =>
434416
(element is MethodDeclaration && element.name.lexeme == name) ||
435417
(element is FieldDeclaration && getFieldName(element, name) != null);
436418

437-
/// An [Element] processor function type.
438-
/// If `true` is returned, children of [element] will be visited.
439-
typedef ElementProcessor = bool Function(Element element);
440-
441-
/// An [Element] processor function type.
419+
/// An [Element2] processor function type.
442420
/// If `true` is returned, children of [element] will be visited.
443-
typedef ElementProcessor2 = bool Function(Element2 element);
421+
typedef ElementProcessor = bool Function(Element2 element);
444422

445423
/// A [GeneralizingElementVisitor] adapter for [ElementProcessor].
446-
class _ElementVisitorAdapter extends GeneralizingElementVisitor<void> {
424+
class _ElementVisitorAdapter extends GeneralizingElementVisitor2<void> {
447425
final ElementProcessor processor;
448426

449427
_ElementVisitorAdapter(this.processor);
450428

451-
@override
452-
void visitElement(Element element) {
453-
var visitChildren = processor(element);
454-
if (visitChildren) {
455-
element.visitChildren(this);
456-
}
457-
}
458-
}
459-
460-
/// A [GeneralizingElementVisitor] adapter for [ElementProcessor].
461-
class _ElementVisitorAdapter2 extends GeneralizingElementVisitor2<void> {
462-
final ElementProcessor2 processor;
463-
464-
_ElementVisitorAdapter2(this.processor);
465-
466429
@override
467430
void visitElement(Element2 element) {
468431
var visitChildren = processor(element);
@@ -480,13 +443,3 @@ extension AstNodeExtension on AstNode {
480443
self.argumentList.arguments.isNotEmpty;
481444
}
482445
}
483-
484-
extension ElementExtension on Element? {
485-
// TODO(srawlins): Move to extensions.dart.
486-
bool get isDartCorePrint {
487-
var self = this;
488-
return self is FunctionElement &&
489-
self.name == 'print' &&
490-
self.library.isDartCore;
491-
}
492-
}

pkg/linter/lib/src/extensions.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:analyzer/dart/element/element2.dart';
1010
import 'package:analyzer/dart/element/type.dart';
1111
import 'package:analyzer/file_system/physical_file_system.dart';
1212
import 'package:analyzer/src/dart/ast/ast.dart'; // ignore: implementation_imports
13-
import 'package:analyzer/src/dart/element/element.dart'; // ignore: implementation_imports
1413
import 'package:analyzer/src/dart/element/member.dart'; // ignore: implementation_imports
1514
import 'package:analyzer/src/dart/element/type.dart' // ignore: implementation_imports
1615
show
@@ -393,11 +392,6 @@ extension ElementExtension on Element {
393392
}
394393
return self;
395394
}
396-
397-
bool get isMacro {
398-
var self = this;
399-
return self is ClassElementImpl && self.isMacro;
400-
}
401395
}
402396

403397
extension ElementExtension2 on Element2? {

pkg/linter/lib/src/rules/prefer_is_not_empty.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _Visitor extends SimpleAstVisitor<void> {
6565
// Element should also support "isNotEmpty".
6666
var propertyTarget = propertyElement.enclosingElement2;
6767
if (propertyTarget == null ||
68-
getChildren2(propertyTarget, 'isNotEmpty').isEmpty) {
68+
getChildren(propertyTarget, 'isNotEmpty').isEmpty) {
6969
return;
7070
}
7171

0 commit comments

Comments
 (0)