blob: 9a2b15d983b466836c642d433be28b5c6f6dfc72 [file] [log] [blame]
// Copyright (c) 2017, 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';
/// Search the [unit] for declared [SimpleIdentifier]s with the given [name].
List<SimpleIdentifier> findDeclaredIdentifiersByName(
CompilationUnit unit, String name) {
var finder = _DeclaredIdentifiersByNameFinder(name);
return finder.identifiers;
class _DeclaredIdentifiersByNameFinder extends RecursiveAstVisitor<void> {
final String name;
final List<SimpleIdentifier> identifiers = [];
void visitSimpleIdentifier(SimpleIdentifier node) {
if ( == name && node.inDeclarationContext()) {