| OLD | NEW |
| (Empty) | |
| 1 library docgen.utils; |
| 2 |
| 3 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir
rors.dart'; |
| 4 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut
il.dart' |
| 5 as dart2js_util; |
| 6 import '../../../../sdk/lib/_internal/libraries.dart'; |
| 7 |
| 8 // HTML escaped version of '<' character. |
| 9 const LESS_THAN = '<'; |
| 10 |
| 11 /// A declaration is private if itself is private, or the owner is private. |
| 12 // Issue(12202) - A declaration is public even if it's owner is private. |
| 13 bool isHidden(DeclarationMirror mirror) { |
| 14 if (mirror is LibraryMirror) { |
| 15 return _isLibraryPrivate(mirror); |
| 16 } else if (mirror.owner is LibraryMirror) { |
| 17 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) || |
| 18 mirror.isNameSynthetic); |
| 19 } else { |
| 20 return (mirror.isPrivate || isHidden(mirror.owner) || |
| 21 mirror.isNameSynthetic); |
| 22 } |
| 23 } |
| 24 |
| 25 /// Returns true if a library name starts with an underscore, and false |
| 26 /// otherwise. |
| 27 /// |
| 28 /// An example that starts with _ is _js_helper. |
| 29 /// An example that contains ._ is dart._collection.dev |
| 30 bool _isLibraryPrivate(LibraryMirror mirror) { |
| 31 // This method is needed because LibraryMirror.isPrivate returns `false` all |
| 32 // the time. |
| 33 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)]; |
| 34 if (sdkLibrary != null) { |
| 35 return !sdkLibrary.documented; |
| 36 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf( |
| 37 mirror).contains('._')) { |
| 38 return true; |
| 39 } |
| 40 return false; |
| 41 } |
| 42 |
| 43 /// Transforms the map by calling toMap on each value in it. |
| 44 Map recurseMap(Map inputMap) { |
| 45 var outputMap = {}; |
| 46 inputMap.forEach((key, value) { |
| 47 if (value is Map) { |
| 48 outputMap[key] = recurseMap(value); |
| 49 } else { |
| 50 outputMap[key] = value.toMap(); |
| 51 } |
| 52 }); |
| 53 return outputMap; |
| 54 } |
| 55 |
| 56 Map filterMap(Map map, Function test) { |
| 57 var exported = new Map(); |
| 58 map.forEach((key, value) { |
| 59 if (test(key, value)) exported[key] = value; |
| 60 }); |
| 61 return exported; |
| 62 } |
| 63 |
| 64 /// Chunk the provided name into individual parts to be resolved. We take a |
| 65 /// simplistic approach to chunking, though, we break at " ", ",", "<" |
| 66 /// and ">". All other characters are grouped into the name to be resolved. |
| 67 /// As a result, these characters will all be treated as part of the item to |
| 68 /// be resolved (aka the * is interpreted literally as a *, not as an |
| 69 /// indicator for bold <em>. |
| 70 List<String> tokenizeComplexReference(String name) { |
| 71 var tokens = []; |
| 72 var append = false; |
| 73 var index = 0; |
| 74 while (index < name.length) { |
| 75 if (name.indexOf(LESS_THAN, index) == index) { |
| 76 tokens.add(LESS_THAN); |
| 77 append = false; |
| 78 index += LESS_THAN.length; |
| 79 } else if (name[index] == ' ' || name[index] == ',' || name[index] == '>') { |
| 80 tokens.add(name[index]); |
| 81 append = false; |
| 82 index++; |
| 83 } else { |
| 84 if (append) { |
| 85 tokens[tokens.length - 1] = tokens.last + name[index]; |
| 86 } else { |
| 87 tokens.add(name[index]); |
| 88 append = true; |
| 89 } |
| 90 index++; |
| 91 } |
| 92 } |
| 93 return tokens; |
| 94 } |
| 95 |
| 96 typedef DeclarationMirror LookupFunction(DeclarationSourceMirror declaration, |
| 97 String name); |
| 98 |
| 99 /// For a given name, determine if we need to resolve it as a qualified name |
| 100 /// or a simple name in the source mirors. |
| 101 LookupFunction determineLookupFunc(String name) => name.contains('.') ? |
| 102 dart2js_util.lookupQualifiedInScope : |
| 103 (mirror, name) => mirror.lookupInScope(name); |
| OLD | NEW |