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

Side by Side Diff: pkg/analyzer/lib/src/summary/public_namespace_computer.dart

Issue 1585973004: Use constructor args in favor of summary "encode" functions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.src.summary.public_namespace_visitor; 5 library analyzer.src.summary.public_namespace_visitor;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/src/summary/format.dart'; 8 import 'package:analyzer/src/summary/format.dart';
9 9
10 /** 10 /**
11 * Compute the public namespace portion of the summary for the given [unit], 11 * Compute the public namespace portion of the summary for the given [unit],
12 * which is presumed to be an unresolved AST. 12 * which is presumed to be an unresolved AST.
13 */ 13 */
14 UnlinkedPublicNamespaceBuilder computePublicNamespace(CompilationUnit unit) { 14 UnlinkedPublicNamespaceBuilder computePublicNamespace(CompilationUnit unit) {
15 _PublicNamespaceVisitor visitor = new _PublicNamespaceVisitor(); 15 _PublicNamespaceVisitor visitor = new _PublicNamespaceVisitor();
16 unit.accept(visitor); 16 unit.accept(visitor);
17 return encodeUnlinkedPublicNamespace( 17 return new UnlinkedPublicNamespaceBuilder(
18 names: visitor.names, exports: visitor.exports, parts: visitor.parts); 18 names: visitor.names, exports: visitor.exports, parts: visitor.parts);
19 } 19 }
20 20
21 class _CombinatorEncoder extends SimpleAstVisitor<UnlinkedCombinatorBuilder> { 21 class _CombinatorEncoder extends SimpleAstVisitor<UnlinkedCombinatorBuilder> {
22 _CombinatorEncoder(); 22 _CombinatorEncoder();
23 23
24 List<String> encodeNames(NodeList<SimpleIdentifier> names) => 24 List<String> encodeNames(NodeList<SimpleIdentifier> names) =>
25 names.map((SimpleIdentifier id) => id.name).toList(); 25 names.map((SimpleIdentifier id) => id.name).toList();
26 26
27 @override 27 @override
28 UnlinkedCombinatorBuilder visitHideCombinator(HideCombinator node) { 28 UnlinkedCombinatorBuilder visitHideCombinator(HideCombinator node) {
29 return encodeUnlinkedCombinator(hides: encodeNames(node.hiddenNames)); 29 return new UnlinkedCombinatorBuilder(hides: encodeNames(node.hiddenNames));
30 } 30 }
31 31
32 @override 32 @override
33 UnlinkedCombinatorBuilder visitShowCombinator(ShowCombinator node) { 33 UnlinkedCombinatorBuilder visitShowCombinator(ShowCombinator node) {
34 return encodeUnlinkedCombinator(shows: encodeNames(node.shownNames)); 34 return new UnlinkedCombinatorBuilder(shows: encodeNames(node.shownNames));
35 } 35 }
36 } 36 }
37 37
38 class _PublicNamespaceVisitor extends RecursiveAstVisitor { 38 class _PublicNamespaceVisitor extends RecursiveAstVisitor {
39 final List<UnlinkedPublicNameBuilder> names = <UnlinkedPublicNameBuilder>[]; 39 final List<UnlinkedPublicNameBuilder> names = <UnlinkedPublicNameBuilder>[];
40 final List<UnlinkedExportPublicBuilder> exports = 40 final List<UnlinkedExportPublicBuilder> exports =
41 <UnlinkedExportPublicBuilder>[]; 41 <UnlinkedExportPublicBuilder>[];
42 final List<String> parts = <String>[]; 42 final List<String> parts = <String>[];
43 43
44 _PublicNamespaceVisitor(); 44 _PublicNamespaceVisitor();
45 45
46 void addNameIfPublic( 46 void addNameIfPublic(
47 String name, PrelinkedReferenceKind kind, int numTypeParameters) { 47 String name, PrelinkedReferenceKind kind, int numTypeParameters) {
48 if (isPublic(name)) { 48 if (isPublic(name)) {
49 names.add(encodeUnlinkedPublicName( 49 names.add(new UnlinkedPublicNameBuilder(
50 name: name, kind: kind, numTypeParameters: numTypeParameters)); 50 name: name, kind: kind, numTypeParameters: numTypeParameters));
51 } 51 }
52 } 52 }
53 53
54 bool isPublic(String name) => !name.startsWith('_'); 54 bool isPublic(String name) => !name.startsWith('_');
55 55
56 @override 56 @override
57 visitClassDeclaration(ClassDeclaration node) { 57 visitClassDeclaration(ClassDeclaration node) {
58 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, 58 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum,
59 node.typeParameters?.typeParameters?.length ?? 0); 59 node.typeParameters?.typeParameters?.length ?? 0);
60 } 60 }
61 61
62 @override 62 @override
63 visitClassTypeAlias(ClassTypeAlias node) { 63 visitClassTypeAlias(ClassTypeAlias node) {
64 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, 64 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum,
65 node.typeParameters?.typeParameters?.length ?? 0); 65 node.typeParameters?.typeParameters?.length ?? 0);
66 } 66 }
67 67
68 @override 68 @override
69 visitEnumDeclaration(EnumDeclaration node) { 69 visitEnumDeclaration(EnumDeclaration node) {
70 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, 0); 70 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, 0);
71 } 71 }
72 72
73 @override 73 @override
74 visitExportDirective(ExportDirective node) { 74 visitExportDirective(ExportDirective node) {
75 exports.add(encodeUnlinkedExportPublic( 75 exports.add(new UnlinkedExportPublicBuilder(
76 uri: node.uri.stringValue, 76 uri: node.uri.stringValue,
77 combinators: node.combinators 77 combinators: node.combinators
78 .map((Combinator c) => c.accept(new _CombinatorEncoder())) 78 .map((Combinator c) => c.accept(new _CombinatorEncoder()))
79 .toList())); 79 .toList()));
80 } 80 }
81 81
82 @override 82 @override
83 visitFunctionDeclaration(FunctionDeclaration node) { 83 visitFunctionDeclaration(FunctionDeclaration node) {
84 String name = node.name.name; 84 String name = node.name.name;
85 if (node.isSetter) { 85 if (node.isSetter) {
(...skipping 21 matching lines...) Expand all
107 @override 107 @override
108 visitVariableDeclaration(VariableDeclaration node) { 108 visitVariableDeclaration(VariableDeclaration node) {
109 String name = node.name.name; 109 String name = node.name.name;
110 addNameIfPublic(name, PrelinkedReferenceKind.topLevelPropertyAccessor, 0); 110 addNameIfPublic(name, PrelinkedReferenceKind.topLevelPropertyAccessor, 0);
111 if (!node.isFinal && !node.isConst) { 111 if (!node.isFinal && !node.isConst) {
112 addNameIfPublic( 112 addNameIfPublic(
113 '$name=', PrelinkedReferenceKind.topLevelPropertyAccessor, 0); 113 '$name=', PrelinkedReferenceKind.topLevelPropertyAccessor, 0);
114 } 114 }
115 } 115 }
116 } 116 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/prelink.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698