| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 docgen.model_helpers; | 5 library docgen.model_helpers; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors; | 9 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors; |
| 10 import '../exports/mirrors_util.dart' as dart2js_util; | 10 import '../exports/mirrors_util.dart' as dart2js_util; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 // TODO(kevmoo) Handle consts of non-core types | 73 // TODO(kevmoo) Handle consts of non-core types |
| 74 | 74 |
| 75 return '${valueMirror}'; | 75 return '${valueMirror}'; |
| 76 } | 76 } |
| 77 | 77 |
| 78 /// Returns a list of meta annotations assocated with a mirror. | 78 /// Returns a list of meta annotations assocated with a mirror. |
| 79 List<Annotation> createAnnotations(DeclarationMirror mirror, | 79 List<Annotation> createAnnotations(DeclarationMirror mirror, |
| 80 Library owningLibrary) { | 80 Library owningLibrary) { |
| 81 var annotationMirrors = mirror.metadata | |
| 82 .where((e) => e is dart2js_mirrors.Dart2JsConstructedConstantMirror); | |
| 83 var annotations = []; | 81 var annotations = []; |
| 84 annotationMirrors.forEach((annotation) { | 82 for (dart2js_mirrors.ResolvedNode node in |
| 85 var docgenAnnotation = new Annotation(annotation, owningLibrary); | 83 dart2js_mirrors.BackDoor.metadataSyntaxOf(mirror)) { |
| 84 var docgenAnnotation = new Annotation(node, owningLibrary); |
| 86 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf( | 85 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf( |
| 87 docgenAnnotation.mirror))) { | 86 docgenAnnotation.mirror))) { |
| 88 annotations.add(docgenAnnotation); | 87 annotations.add(docgenAnnotation); |
| 89 } | 88 } |
| 90 }); | 89 } |
| 91 return annotations; | 90 return annotations; |
| 92 } | 91 } |
| 93 | 92 |
| 94 /// A declaration is private if itself is private, or the owner is private. | 93 /// A declaration is private if itself is private, or the owner is private. |
| 95 bool isHidden(DeclarationSourceMirror mirror) { | 94 bool isHidden(DeclarationSourceMirror mirror) { |
| 96 if (mirror is LibraryMirror) { | 95 if (mirror is LibraryMirror) { |
| 97 return _isLibraryPrivate(mirror); | 96 return _isLibraryPrivate(mirror); |
| 98 } else if (mirror.owner is LibraryMirror) { | 97 } else if (mirror.owner is LibraryMirror) { |
| 99 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) || | 98 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) || |
| 100 mirror.isNameSynthetic); | 99 mirror.isNameSynthetic); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 Map<String, Map<String, DeclarationMirror>> calcExportedItems( | 149 Map<String, Map<String, DeclarationMirror>> calcExportedItems( |
| 151 LibrarySourceMirror library) { | 150 LibrarySourceMirror library) { |
| 152 var exports = {}; | 151 var exports = {}; |
| 153 exports['classes'] = {}; | 152 exports['classes'] = {}; |
| 154 exports['methods'] = {}; | 153 exports['methods'] = {}; |
| 155 exports['variables'] = {}; | 154 exports['variables'] = {}; |
| 156 | 155 |
| 157 // Determine the classes, variables and methods that are exported for a | 156 // Determine the classes, variables and methods that are exported for a |
| 158 // specific dependency. | 157 // specific dependency. |
| 159 void _populateExports(LibraryDependencyMirror export, bool showExport) { | 158 void _populateExports(LibraryDependencyMirror export, bool showExport) { |
| 159 var transitiveExports = calcExportedItems(export.targetLibrary); |
| 160 exports['classes'].addAll(transitiveExports['classes']); |
| 161 exports['methods'].addAll(transitiveExports['methods']); |
| 162 exports['variables'].addAll(transitiveExports['variables']); |
| 163 // If there is a show in the export, add only the show items to the |
| 164 // library. Ex: "export foo show bar" |
| 165 // Otherwise, add all items, and then remove the hidden ones. |
| 166 // Ex: "export foo hide bar" |
| 167 |
| 160 if (!showExport) { | 168 if (!showExport) { |
| 161 // Add all items, and then remove the hidden ones. | 169 // Add all items, and then remove the hidden ones. |
| 162 // Ex: "export foo hide bar" | 170 // Ex: "export foo hide bar" |
| 163 addAll(exports['classes'], | 171 addAll(exports['classes'], |
| 164 dart2js_util.typesOf(export.targetLibrary.declarations)); | 172 dart2js_util.typesOf(export.targetLibrary.declarations)); |
| 165 addAll(exports['methods'], | 173 addAll(exports['methods'], |
| 166 export.targetLibrary.declarations.values.where( | 174 export.targetLibrary.declarations.values.where( |
| 167 (mirror) => mirror is MethodMirror)); | 175 (mirror) => mirror is MethodMirror)); |
| 168 addAll(exports['variables'], | 176 addAll(exports['variables'], |
| 169 dart2js_util.variablesOf(export.targetLibrary.declarations)); | 177 dart2js_util.variablesOf(export.targetLibrary.declarations)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 192 subMap.remove(identifier); | 200 subMap.remove(identifier); |
| 193 } | 201 } |
| 194 } | 202 } |
| 195 } | 203 } |
| 196 } | 204 } |
| 197 } | 205 } |
| 198 | 206 |
| 199 Iterable<LibraryDependencyMirror> exportList = | 207 Iterable<LibraryDependencyMirror> exportList = |
| 200 library.libraryDependencies.where((lib) => lib.isExport); | 208 library.libraryDependencies.where((lib) => lib.isExport); |
| 201 for (LibraryDependencyMirror export in exportList) { | 209 for (LibraryDependencyMirror export in exportList) { |
| 202 // If there is a show in the export, add only the show items to the | |
| 203 // library. Ex: "export foo show bar" | |
| 204 // Otherwise, add all items, and then remove the hidden ones. | |
| 205 // Ex: "export foo hide bar" | |
| 206 _populateExports(export, | 210 _populateExports(export, |
| 207 export.combinators.any((combinator) => combinator.isShow)); | 211 export.combinators.any((combinator) => combinator.isShow)); |
| 208 } | 212 } |
| 209 return exports; | 213 return exports; |
| 210 } | 214 } |
| 211 | 215 |
| 212 | 216 |
| 213 /// Returns a map of [Variable] objects constructed from [mirrorMap]. | 217 /// Returns a map of [Variable] objects constructed from [mirrorMap]. |
| 214 /// The optional parameter [containingLibrary] is contains data for variables | 218 /// The optional parameter [containingLibrary] is contains data for variables |
| 215 /// defined at the top level of a library (potentially for exporting | 219 /// defined at the top level of a library (potentially for exporting |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // the time. | 281 // the time. |
| 278 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)]; | 282 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)]; |
| 279 if (sdkLibrary != null) { | 283 if (sdkLibrary != null) { |
| 280 return !sdkLibrary.documented; | 284 return !sdkLibrary.documented; |
| 281 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf( | 285 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf( |
| 282 mirror).contains('._')) { | 286 mirror).contains('._')) { |
| 283 return true; | 287 return true; |
| 284 } | 288 } |
| 285 return false; | 289 return false; |
| 286 } | 290 } |
| OLD | NEW |