Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /// A bit flag used by [LibraryInfo] indicating that a library is used by | |
|
Siggi Cherem (dart-lang)
2016/12/14 20:48:43
+dartdoc for the library.
I wonder if we can avoi
Paul Berry
2016/12/14 23:17:25
Hmm, let me think about that. Assuming we keep li
| |
| 2 /// dart2js. | |
| 3 /// | |
| 4 /// This declaration duplicates the declaration in the SDK's "libraries.dart". | |
| 5 const int DART2JS_PLATFORM = 1; | |
| 6 | |
| 7 /// A bit flag used by [LibraryInfo] indicating that a library is used by the | |
| 8 /// VM. | |
| 9 /// | |
| 10 /// This declaration duplicates the declaration in the SDK's "libraries.dart". | |
| 11 const int VM_PLATFORM = 2; | |
| 12 | |
| 13 /// Parse a category string in the SDK's "libraries.dart". | |
| 14 /// | |
| 15 /// This declaration duplicates the declaration in the SDK's "libraries.dart". | |
| 16 Category parseCategory(String name) { | |
| 17 switch (name) { | |
| 18 case 'Client': | |
| 19 return Category.client; | |
| 20 case 'Server': | |
| 21 return Category.server; | |
| 22 case 'Embedded': | |
| 23 return Category.embedded; | |
| 24 } | |
| 25 return null; | |
| 26 } | |
| 27 | |
| 28 /// The contexts that a library can be used from. | |
| 29 /// | |
| 30 /// This declaration duplicates the declaration in the SDK's "libraries.dart". | |
| 31 enum Category { | |
| 32 /// Indicates that a library can be used in a browser context. | |
| 33 client, | |
| 34 | |
| 35 /// Indicates that a lbirary can be used in a command line context. | |
| 36 server, | |
| 37 | |
| 38 /// Indicates that a library can be used from embedded devices. | |
| 39 embedded | |
| 40 } | |
| 41 | |
| 42 /// Information about a "dart:" library gleaned from the SDK's "libraries.dart" | |
| 43 /// file. | |
| 44 /// | |
| 45 /// This declaration duplicates the declaration in "libraries.dart". | |
| 46 class LibraryInfo { | |
| 47 /// Path to the library's *.dart file relative to the SDK's "lib" directory. | |
| 48 final String path; | |
| 49 | |
| 50 /// The categories in which the library can be used, encoded as a | |
| 51 /// comma-separated String. | |
| 52 final String _categories; | |
| 53 | |
| 54 /// Path to the dart2js library's *.dart file relative to the SDK's "lib" | |
| 55 /// directory, or null if dart2js uses the common library path defined above. | |
| 56 final String dart2jsPath; | |
| 57 | |
| 58 /// Path to the dart2js library's patch file relative to the SDK's "lib" | |
| 59 /// directory, or null if no dart2js patch file associated with this library. | |
| 60 final String dart2jsPatchPath; | |
| 61 | |
| 62 /// True if this library is documented and should be shown to the user. | |
| 63 final bool documented; | |
| 64 | |
| 65 /// Bit flags indicating which platforms consume this library. See | |
| 66 /// [DART2JS_LIBRARY] and [VM_LIBRARY]. | |
| 67 final int platforms; | |
| 68 | |
| 69 /// True if the library contains implementation details for another library. | |
| 70 /// The implication is that these libraries are less commonly used and that | |
| 71 /// tools like the analysis server should not show these libraries in a list | |
| 72 /// of all libraries unless the user specifically asks the tool to do so. | |
| 73 final bool implementation; | |
| 74 | |
| 75 /// States the current maturity of this library. | |
| 76 final Maturity maturity; | |
| 77 | |
| 78 const LibraryInfo(this.path, | |
| 79 {String categories: "", | |
| 80 this.dart2jsPath, | |
| 81 this.dart2jsPatchPath, | |
| 82 this.implementation: false, | |
| 83 this.documented: true, | |
| 84 this.maturity: Maturity.UNSPECIFIED, | |
| 85 this.platforms: DART2JS_PLATFORM | VM_PLATFORM}) | |
| 86 : _categories = categories; | |
| 87 | |
| 88 /// The categories in which the library can be used. | |
| 89 /// | |
| 90 /// If no categories are specified, the library is internal and cannot be | |
| 91 /// loaded by user code. | |
| 92 List<Category> get categories { | |
| 93 // `''.split(',')` returns [''], not [], so we handle that case separately. | |
| 94 if (_categories.isEmpty) return const <Category>[]; | |
| 95 return _categories.split(',').map(parseCategory).toList(); | |
| 96 } | |
| 97 | |
| 98 /// The original "categories" String that was passed to the constructor. | |
| 99 /// | |
| 100 /// Can be used to construct a slightly modified copy of this LibraryInfo. | |
| 101 String get categoriesString { | |
| 102 return _categories; | |
| 103 } | |
| 104 | |
| 105 bool get isDart2jsLibrary => (platforms & DART2JS_PLATFORM) != 0; | |
| 106 | |
| 107 bool get isInternal => categories.isEmpty; | |
| 108 | |
| 109 bool get isVmLibrary => (platforms & VM_PLATFORM) != 0; | |
| 110 } | |
| 111 | |
| 112 /// Abstraction to capture the maturity of a library. | |
| 113 class Maturity { | |
| 114 static const Maturity DEPRECATED = const Maturity(0, "Deprecated", | |
| 115 "This library will be remove before next major release."); | |
| 116 static const Maturity EXPERIMENTAL = const Maturity( | |
| 117 1, | |
| 118 "Experimental", | |
| 119 "This library is experimental and will likely change or be removed\n" | |
| 120 "in future versions."); | |
| 121 static const Maturity UNSTABLE = const Maturity( | |
| 122 2, | |
| 123 "Unstable", | |
| 124 "This library is in still changing and have not yet endured\n" | |
| 125 "sufficient real-world testing.\n" | |
| 126 "Backwards-compatibility is NOT guaranteed."); | |
| 127 | |
| 128 static const Maturity WEB_STABLE = const Maturity( | |
| 129 3, | |
| 130 "Web Stable", | |
| 131 "This library is tracking the DOM evolution as defined by WC3.\n" | |
| 132 "Backwards-compatibility is NOT guaranteed."); | |
| 133 | |
| 134 static const Maturity STABLE = const Maturity( | |
| 135 4, | |
| 136 "Stable", | |
| 137 "The library is stable. API backwards-compatibility is guaranteed.\n" | |
| 138 "However implementation details might change."); | |
| 139 | |
| 140 static const Maturity LOCKED = const Maturity(5, "Locked", | |
| 141 "This library will not change except when serious bugs are encountered."); | |
| 142 | |
| 143 static const Maturity UNSPECIFIED = const Maturity(-1, "Unspecified", | |
| 144 "The maturity for this library has not been specified."); | |
| 145 | |
| 146 final int level; | |
| 147 | |
| 148 final String name; | |
| 149 | |
| 150 final String description; | |
| 151 | |
| 152 const Maturity(this.level, this.name, this.description); | |
| 153 | |
| 154 String toString() => "$name: $level\n$description\n"; | |
| 155 } | |
| OLD | NEW |