| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.src.summary.public_namespace_visitor; |
| 6 |
| 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/src/summary/base.dart'; |
| 9 import 'package:analyzer/src/summary/format.dart'; |
| 10 |
| 11 /** |
| 12 * Compute the public namespace portion of the summary for the given [unit], |
| 13 * which is presumed to be an unresolved AST. |
| 14 */ |
| 15 UnlinkedPublicNamespaceBuilder computePublicNamespace( |
| 16 BuilderContext ctx, CompilationUnit unit) { |
| 17 _PublicNamespaceVisitor visitor = new _PublicNamespaceVisitor(ctx); |
| 18 unit.accept(visitor); |
| 19 return encodeUnlinkedPublicNamespace(ctx, |
| 20 names: visitor.names, exports: visitor.exports, parts: visitor.parts); |
| 21 } |
| 22 |
| 23 class _CombinatorEncoder extends SimpleAstVisitor<UnlinkedCombinatorBuilder> { |
| 24 final BuilderContext ctx; |
| 25 |
| 26 _CombinatorEncoder(this.ctx); |
| 27 |
| 28 List<UnlinkedCombinatorNameBuilder> encodeNames( |
| 29 NodeList<SimpleIdentifier> names) => |
| 30 names |
| 31 .map((SimpleIdentifier id) => |
| 32 encodeUnlinkedCombinatorName(ctx, name: id.name)) |
| 33 .toList(); |
| 34 |
| 35 @override |
| 36 UnlinkedCombinatorBuilder visitHideCombinator(HideCombinator node) { |
| 37 return encodeUnlinkedCombinator(ctx, hides: encodeNames(node.hiddenNames)); |
| 38 } |
| 39 |
| 40 @override |
| 41 UnlinkedCombinatorBuilder visitShowCombinator(ShowCombinator node) { |
| 42 return encodeUnlinkedCombinator(ctx, shows: encodeNames(node.shownNames)); |
| 43 } |
| 44 } |
| 45 |
| 46 class _PublicNamespaceVisitor extends RecursiveAstVisitor { |
| 47 final BuilderContext ctx; |
| 48 final List<UnlinkedPublicNameBuilder> names = <UnlinkedPublicNameBuilder>[]; |
| 49 final List<UnlinkedExportBuilder> exports = <UnlinkedExportBuilder>[]; |
| 50 final List<UnlinkedPartBuilder> parts = <UnlinkedPartBuilder>[]; |
| 51 |
| 52 _PublicNamespaceVisitor(this.ctx); |
| 53 |
| 54 void addNameIfPublic(String name, PrelinkedReferenceKind kind) { |
| 55 if (isPublic(name)) { |
| 56 names.add(encodeUnlinkedPublicName(ctx, name: name, kind: kind)); |
| 57 } |
| 58 } |
| 59 |
| 60 bool isPublic(String name) => !name.startsWith('_'); |
| 61 |
| 62 @override |
| 63 visitClassDeclaration(ClassDeclaration node) { |
| 64 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum); |
| 65 } |
| 66 |
| 67 @override |
| 68 visitClassTypeAlias(ClassTypeAlias node) { |
| 69 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum); |
| 70 } |
| 71 |
| 72 @override |
| 73 visitEnumDeclaration(EnumDeclaration node) { |
| 74 addNameIfPublic(node.name.name, PrelinkedReferenceKind.classOrEnum); |
| 75 } |
| 76 |
| 77 @override |
| 78 visitExportDirective(ExportDirective node) { |
| 79 exports.add(encodeUnlinkedExport(ctx, |
| 80 uri: node.uri.stringValue, |
| 81 combinators: node.combinators |
| 82 .map((Combinator c) => c.accept(new _CombinatorEncoder(ctx))) |
| 83 .toList())); |
| 84 } |
| 85 |
| 86 @override |
| 87 visitFunctionDeclaration(FunctionDeclaration node) { |
| 88 String name = node.name.name; |
| 89 if (node.isSetter) { |
| 90 name += '='; |
| 91 } |
| 92 addNameIfPublic(name, PrelinkedReferenceKind.other); |
| 93 } |
| 94 |
| 95 @override |
| 96 visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 97 addNameIfPublic(node.name.name, PrelinkedReferenceKind.typedef); |
| 98 } |
| 99 |
| 100 @override |
| 101 visitPartDirective(PartDirective node) { |
| 102 parts.add(encodeUnlinkedPart(ctx, uri: node.uri.stringValue)); |
| 103 } |
| 104 |
| 105 @override |
| 106 visitVariableDeclaration(VariableDeclaration node) { |
| 107 String name = node.name.name; |
| 108 addNameIfPublic(name, PrelinkedReferenceKind.other); |
| 109 if (!node.isFinal && !node.isConst) { |
| 110 addNameIfPublic('$name=', PrelinkedReferenceKind.other); |
| 111 } |
| 112 } |
| 113 } |
| OLD | NEW |