OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/visitor.dart'; |
| 7 |
| 8 /** |
| 9 * Search the [unit] for declared [SimpleIdentifier]s with the given [name]. |
| 10 */ |
| 11 List<SimpleIdentifier> findDeclaredIdentifiersByName( |
| 12 CompilationUnit unit, String name) { |
| 13 var finder = new _DeclaredIdentifiersByNameFinder(name); |
| 14 unit.accept(finder); |
| 15 return finder.identifiers; |
| 16 } |
| 17 |
| 18 class _DeclaredIdentifiersByNameFinder extends RecursiveAstVisitor<Null> { |
| 19 final String name; |
| 20 final List<SimpleIdentifier> identifiers = []; |
| 21 |
| 22 _DeclaredIdentifiersByNameFinder(this.name); |
| 23 |
| 24 @override |
| 25 visitSimpleIdentifier(SimpleIdentifier node) { |
| 26 if (node.name == name && node.inDeclarationContext()) { |
| 27 identifiers.add(node); |
| 28 } |
| 29 } |
| 30 } |
OLD | NEW |