Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/referenced_names.dart

Issue 2961773002: Compute subtyped names. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/referenced_names_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/visitor.dart'; 6 import 'package:analyzer/dart/ast/visitor.dart';
7 7
8 /** 8 /**
9 * Compute the set of external names referenced in the [unit]. 9 * Compute the set of external names referenced in the [unit].
10 */ 10 */
11 Set<String> computeReferencedNames(CompilationUnit unit) { 11 Set<String> computeReferencedNames(CompilationUnit unit) {
12 _ReferencedNamesComputer computer = new _ReferencedNamesComputer(); 12 _ReferencedNamesComputer computer = new _ReferencedNamesComputer();
13 unit.accept(computer); 13 unit.accept(computer);
14 return computer.names; 14 return computer.names;
15 } 15 }
16 16
17 /** 17 /**
18 * Compute the set of names which are used in `extends`, `with` or `implements`
19 * clauses in the file. Import prefixes and type arguments are not included.
20 */
21 Set<String> computeSubtypedNames(CompilationUnit unit) {
22 Set<String> subtypedNames = new Set<String>();
23
24 void _addSubtypedName(TypeName type) {
25 if (type != null) {
26 Identifier name = type.name;
27 if (name is SimpleIdentifier) {
28 subtypedNames.add(name.name);
29 } else if (name is PrefixedIdentifier) {
30 subtypedNames.add(name.identifier.name);
31 }
32 }
33 }
34
35 void _addSubtypedNames(List<TypeName> types) {
36 types?.forEach(_addSubtypedName);
37 }
38
39 for (CompilationUnitMember declaration in unit.declarations) {
40 if (declaration is ClassDeclaration) {
41 _addSubtypedName(declaration.extendsClause?.superclass);
42 _addSubtypedNames(declaration.withClause?.mixinTypes);
43 _addSubtypedNames(declaration.implementsClause?.interfaces);
44 }
45 }
46
47 return subtypedNames;
48 }
49
50 /**
18 * Chained set of local names, that hide corresponding external names. 51 * Chained set of local names, that hide corresponding external names.
19 */ 52 */
20 class _LocalNameScope { 53 class _LocalNameScope {
21 final _LocalNameScope enclosing; 54 final _LocalNameScope enclosing;
22 Set<String> names; 55 Set<String> names;
23 56
24 _LocalNameScope(this.enclosing); 57 _LocalNameScope(this.enclosing);
25 58
26 factory _LocalNameScope.forBlock(_LocalNameScope enclosing, Block node) { 59 factory _LocalNameScope.forBlock(_LocalNameScope enclosing, Block node) {
27 _LocalNameScope scope = new _LocalNameScope(enclosing); 60 _LocalNameScope scope = new _LocalNameScope(enclosing);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 302 }
270 303
271 static bool _isNameExpressionLabel(AstNode parent) { 304 static bool _isNameExpressionLabel(AstNode parent) {
272 if (parent is Label) { 305 if (parent is Label) {
273 AstNode parent2 = parent?.parent; 306 AstNode parent2 = parent?.parent;
274 return parent2 is NamedExpression && parent2.name == parent; 307 return parent2 is NamedExpression && parent2.name == parent;
275 } 308 }
276 return false; 309 return false;
277 } 310 }
278 } 311 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/referenced_names_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698