| 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 |
| 7 /** |
| 8 * Compute the [DefinedNames] for the given [unit]. |
| 9 */ |
| 10 DefinedNames computeDefinedNames(CompilationUnit unit) { |
| 11 DefinedNames names = new DefinedNames(); |
| 12 |
| 13 void appendName(Set<String> names, SimpleIdentifier node) { |
| 14 String name = node?.name; |
| 15 if (name != null && name.length != 0) { |
| 16 names.add(name); |
| 17 } |
| 18 } |
| 19 |
| 20 void appendClassMemberName(ClassMember member) { |
| 21 if (member is MethodDeclaration) { |
| 22 appendName(names.classMemberNames, member.name); |
| 23 } else if (member is FieldDeclaration) { |
| 24 for (VariableDeclaration field in member.fields.variables) { |
| 25 appendName(names.classMemberNames, field.name); |
| 26 } |
| 27 } |
| 28 } |
| 29 |
| 30 void appendTopLevelName(CompilationUnitMember member) { |
| 31 if (member is NamedCompilationUnitMember) { |
| 32 appendName(names.topLevelNames, member.name); |
| 33 if (member is ClassDeclaration) { |
| 34 member.members.forEach(appendClassMemberName); |
| 35 } |
| 36 } else if (member is TopLevelVariableDeclaration) { |
| 37 for (VariableDeclaration variable in member.variables.variables) { |
| 38 appendName(names.topLevelNames, variable.name); |
| 39 } |
| 40 } |
| 41 } |
| 42 |
| 43 unit.declarations.forEach(appendTopLevelName); |
| 44 return names; |
| 45 } |
| 46 |
| 47 /** |
| 48 * Defined top-level and class member names. |
| 49 */ |
| 50 class DefinedNames { |
| 51 final Set<String> topLevelNames = new Set<String>(); |
| 52 final Set<String> classMemberNames = new Set<String>(); |
| 53 } |
| OLD | NEW |