| OLD | NEW |
| 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/base.dart'; | |
| 9 import 'package:analyzer/src/summary/format.dart'; | 8 import 'package:analyzer/src/summary/format.dart'; |
| 10 | 9 |
| 11 /** | 10 /** |
| 12 * 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], |
| 13 * which is presumed to be an unresolved AST. | 12 * which is presumed to be an unresolved AST. |
| 14 */ | 13 */ |
| 15 UnlinkedPublicNamespaceBuilder computePublicNamespace( | 14 UnlinkedPublicNamespaceBuilder computePublicNamespace(CompilationUnit unit) { |
| 16 BuilderContext ctx, CompilationUnit unit) { | 15 _PublicNamespaceVisitor visitor = new _PublicNamespaceVisitor(); |
| 17 _PublicNamespaceVisitor visitor = new _PublicNamespaceVisitor(ctx); | |
| 18 unit.accept(visitor); | 16 unit.accept(visitor); |
| 19 return encodeUnlinkedPublicNamespace(ctx, | 17 return encodeUnlinkedPublicNamespace( |
| 20 names: visitor.names, exports: visitor.exports, parts: visitor.parts); | 18 names: visitor.names, exports: visitor.exports, parts: visitor.parts); |
| 21 } | 19 } |
| 22 | 20 |
| 23 class _CombinatorEncoder extends SimpleAstVisitor<UnlinkedCombinatorBuilder> { | 21 class _CombinatorEncoder extends SimpleAstVisitor<UnlinkedCombinatorBuilder> { |
| 24 final BuilderContext ctx; | 22 _CombinatorEncoder(); |
| 25 | |
| 26 _CombinatorEncoder(this.ctx); | |
| 27 | 23 |
| 28 List<String> encodeNames(NodeList<SimpleIdentifier> names) => | 24 List<String> encodeNames(NodeList<SimpleIdentifier> names) => |
| 29 names.map((SimpleIdentifier id) => id.name).toList(); | 25 names.map((SimpleIdentifier id) => id.name).toList(); |
| 30 | 26 |
| 31 @override | 27 @override |
| 32 UnlinkedCombinatorBuilder visitHideCombinator(HideCombinator node) { | 28 UnlinkedCombinatorBuilder visitHideCombinator(HideCombinator node) { |
| 33 return encodeUnlinkedCombinator(ctx, hides: encodeNames(node.hiddenNames)); | 29 return encodeUnlinkedCombinator(hides: encodeNames(node.hiddenNames)); |
| 34 } | 30 } |
| 35 | 31 |
| 36 @override | 32 @override |
| 37 UnlinkedCombinatorBuilder visitShowCombinator(ShowCombinator node) { | 33 UnlinkedCombinatorBuilder visitShowCombinator(ShowCombinator node) { |
| 38 return encodeUnlinkedCombinator(ctx, shows: encodeNames(node.shownNames)); | 34 return encodeUnlinkedCombinator(shows: encodeNames(node.shownNames)); |
| 39 } | 35 } |
| 40 } | 36 } |
| 41 | 37 |
| 42 class _PublicNamespaceVisitor extends RecursiveAstVisitor { | 38 class _PublicNamespaceVisitor extends RecursiveAstVisitor { |
| 43 final BuilderContext ctx; | |
| 44 final List<UnlinkedPublicNameBuilder> names = <UnlinkedPublicNameBuilder>[]; | 39 final List<UnlinkedPublicNameBuilder> names = <UnlinkedPublicNameBuilder>[]; |
| 45 final List<UnlinkedExportPublicBuilder> exports = | 40 final List<UnlinkedExportPublicBuilder> exports = |
| 46 <UnlinkedExportPublicBuilder>[]; | 41 <UnlinkedExportPublicBuilder>[]; |
| 47 final List<String> parts = <String>[]; | 42 final List<String> parts = <String>[]; |
| 48 | 43 |
| 49 _PublicNamespaceVisitor(this.ctx); | 44 _PublicNamespaceVisitor(); |
| 50 | 45 |
| 51 void addNameIfPublic( | 46 void addNameIfPublic( |
| 52 String name, PrelinkedReferenceKind kind, int numTypeParameters) { | 47 String name, PrelinkedReferenceKind kind, int numTypeParameters) { |
| 53 if (isPublic(name)) { | 48 if (isPublic(name)) { |
| 54 names.add(encodeUnlinkedPublicName(ctx, | 49 names.add(encodeUnlinkedPublicName( |
| 55 name: name, kind: kind, numTypeParameters: numTypeParameters)); | 50 name: name, kind: kind, numTypeParameters: numTypeParameters)); |
| 56 } | 51 } |
| 57 } | 52 } |
| 58 | 53 |
| 59 bool isPublic(String name) => !name.startsWith('_'); | 54 bool isPublic(String name) => !name.startsWith('_'); |
| 60 | 55 |
| 61 @override | 56 @override |
| 62 visitClassDeclaration(ClassDeclaration node) { | 57 visitClassDeclaration(ClassDeclaration node) { |
| 63 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, | 58 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, |
| 64 node.typeParameters?.typeParameters?.length ?? 0); | 59 node.typeParameters?.typeParameters?.length ?? 0); |
| 65 } | 60 } |
| 66 | 61 |
| 67 @override | 62 @override |
| 68 visitClassTypeAlias(ClassTypeAlias node) { | 63 visitClassTypeAlias(ClassTypeAlias node) { |
| 69 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, | 64 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, |
| 70 node.typeParameters?.typeParameters?.length ?? 0); | 65 node.typeParameters?.typeParameters?.length ?? 0); |
| 71 } | 66 } |
| 72 | 67 |
| 73 @override | 68 @override |
| 74 visitEnumDeclaration(EnumDeclaration node) { | 69 visitEnumDeclaration(EnumDeclaration node) { |
| 75 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, 0); | 70 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum, 0); |
| 76 } | 71 } |
| 77 | 72 |
| 78 @override | 73 @override |
| 79 visitExportDirective(ExportDirective node) { | 74 visitExportDirective(ExportDirective node) { |
| 80 exports.add(encodeUnlinkedExportPublic(ctx, | 75 exports.add(encodeUnlinkedExportPublic( |
| 81 uri: node.uri.stringValue, | 76 uri: node.uri.stringValue, |
| 82 combinators: node.combinators | 77 combinators: node.combinators |
| 83 .map((Combinator c) => c.accept(new _CombinatorEncoder(ctx))) | 78 .map((Combinator c) => c.accept(new _CombinatorEncoder())) |
| 84 .toList())); | 79 .toList())); |
| 85 } | 80 } |
| 86 | 81 |
| 87 @override | 82 @override |
| 88 visitFunctionDeclaration(FunctionDeclaration node) { | 83 visitFunctionDeclaration(FunctionDeclaration node) { |
| 89 String name = node.name.name; | 84 String name = node.name.name; |
| 90 if (node.isSetter) { | 85 if (node.isSetter) { |
| 91 name += '='; | 86 name += '='; |
| 92 } | 87 } |
| 93 addNameIfPublic(name, PrelinkedReferenceKind.other, | 88 addNameIfPublic(name, PrelinkedReferenceKind.other, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 107 | 102 |
| 108 @override | 103 @override |
| 109 visitVariableDeclaration(VariableDeclaration node) { | 104 visitVariableDeclaration(VariableDeclaration node) { |
| 110 String name = node.name.name; | 105 String name = node.name.name; |
| 111 addNameIfPublic(name, PrelinkedReferenceKind.other, 0); | 106 addNameIfPublic(name, PrelinkedReferenceKind.other, 0); |
| 112 if (!node.isFinal && !node.isConst) { | 107 if (!node.isFinal && !node.isConst) { |
| 113 addNameIfPublic('$name=', PrelinkedReferenceKind.other, 0); | 108 addNameIfPublic('$name=', PrelinkedReferenceKind.other, 0); |
| 114 } | 109 } |
| 115 } | 110 } |
| 116 } | 111 } |
| OLD | NEW |