blob: 2b7e6d249177c7c12d200a8d080dee44134b1c81 [file] [log] [blame]
// Copyright (c) 2019, 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/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
/// A simple class to find all [Annotation]s and track if they all get visited.
class AnnotationTracker extends RecursiveAstVisitor<void> {
final Set<Annotation> _nodes = {};
void finalize() {
assert(_nodes.isEmpty, 'Annotation nodes not visited: $_nodes');
}
void nodeVisited(Annotation node) {
if (!_nodes.remove(node)) {
throw StateError('Visited unexpected annotation $node');
}
}
@override
void visitAnnotation(Annotation node) {
_nodes.add(node);
}
}