| OLD | NEW |
| (Empty) | |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. |
| 3 |
| 4 library engine.source.io; |
| 5 |
| 6 import 'source.dart'; |
| 7 import 'dart:io'; |
| 8 import 'dart:uri'; |
| 9 import 'java_core.dart'; |
| 10 import 'java_io.dart'; |
| 11 import 'package:analyzer-experimental/src/generated/sdk.dart' show DartSdk; |
| 12 export 'source.dart'; |
| 13 |
| 14 /** |
| 15 * Instances of the class {@code FileBasedSource} implement a source that repres
ents a file. |
| 16 */ |
| 17 class FileBasedSource implements Source { |
| 18 /** |
| 19 * The source factory that created this source and that should be used to reso
lve URI's against |
| 20 * this source. |
| 21 */ |
| 22 SourceFactory _factory; |
| 23 /** |
| 24 * The file represented by this source. |
| 25 */ |
| 26 File _file; |
| 27 /** |
| 28 * A flag indicating whether this source is in one of the system libraries. |
| 29 */ |
| 30 bool _inSystemLibrary = false; |
| 31 /** |
| 32 * Initialize a newly created source object. The source object is assumed to n
ot be in a system |
| 33 * library. |
| 34 * @param factory the source factory that created this source |
| 35 * @param file the file represented by this source |
| 36 */ |
| 37 FileBasedSource.con1(SourceFactory factory, File file) { |
| 38 _jtd_constructor_278_impl(factory, file); |
| 39 } |
| 40 _jtd_constructor_278_impl(SourceFactory factory, File file) { |
| 41 _jtd_constructor_279_impl(factory, file, false); |
| 42 } |
| 43 /** |
| 44 * Initialize a newly created source object. |
| 45 * @param factory the source factory that created this source |
| 46 * @param file the file represented by this source |
| 47 * @param inSystemLibrary {@code true} if this source is in one of the system
libraries |
| 48 */ |
| 49 FileBasedSource.con2(SourceFactory factory2, File file3, bool inSystemLibrary2
) { |
| 50 _jtd_constructor_279_impl(factory2, file3, inSystemLibrary2); |
| 51 } |
| 52 _jtd_constructor_279_impl(SourceFactory factory2, File file3, bool inSystemLib
rary2) { |
| 53 this._factory = factory2; |
| 54 this._file = file3; |
| 55 this._inSystemLibrary = inSystemLibrary2; |
| 56 } |
| 57 bool operator ==(Object object) => object != null && identical(this.runtimeTyp
e, object.runtimeType) && _file == ((object as FileBasedSource))._file; |
| 58 bool exists() => _file.existsSync(); |
| 59 void getContents(Source_ContentReceiver receiver) { |
| 60 receiver.accept2(_file.readAsStringSync()); |
| 61 } |
| 62 String get encoding => newUriFromFile(_file).toString(); |
| 63 String get fullName => _file.fullPathSync(); |
| 64 String get shortName => _file.path; |
| 65 int get hashCode => _file.hashCode; |
| 66 bool isInSystemLibrary() => _inSystemLibrary; |
| 67 Source resolve(String uri) => _factory.resolveUri(this, uri); |
| 68 Source resolveRelative(Uri containedUri) { |
| 69 try { |
| 70 Uri resolvedUri = newUriFromFile(file).resolveUri(containedUri); |
| 71 return new FileBasedSource.con1(_factory, newFileFromUri(resolvedUri)); |
| 72 } on JavaException catch (exception) { |
| 73 } |
| 74 return null; |
| 75 } |
| 76 String toString() { |
| 77 if (_file == null) { |
| 78 return "<unknown source>"; |
| 79 } |
| 80 return _file.fullPathSync(); |
| 81 } |
| 82 /** |
| 83 * Return the file represented by this source. This is an internal method that
is only intended to |
| 84 * be used by {@link UriResolver}. |
| 85 * @return the file represented by this source |
| 86 */ |
| 87 File get file => _file; |
| 88 } |
| 89 /** |
| 90 * Instances of the class {@code DartUriResolver} resolve {@code dart} URI's. |
| 91 */ |
| 92 class DartUriResolver extends UriResolver { |
| 93 /** |
| 94 * The Dart SDK against which URI's are to be resolved. |
| 95 */ |
| 96 DartSdk _sdk; |
| 97 /** |
| 98 * The name of the {@code dart} scheme. |
| 99 */ |
| 100 static String _DART_SCHEME = "dart"; |
| 101 /** |
| 102 * Return {@code true} if the given URI is a {@code dart:} URI. |
| 103 * @param uri the URI being tested |
| 104 * @return {@code true} if the given URI is a {@code dart:} URI |
| 105 */ |
| 106 static bool isDartUri(Uri uri) => uri.scheme == _DART_SCHEME; |
| 107 /** |
| 108 * Initialize a newly created resolver to resolve Dart URI's against the given
platform within the |
| 109 * given Dart SDK. |
| 110 * @param sdk the Dart SDK against which URI's are to be resolved |
| 111 */ |
| 112 DartUriResolver(DartSdk sdk) { |
| 113 this._sdk = sdk; |
| 114 } |
| 115 Source resolveAbsolute(SourceFactory factory, Uri uri) { |
| 116 if (!isDartUri(uri)) { |
| 117 return null; |
| 118 } |
| 119 File resolvedFile = _sdk.mapDartUri(uri.toString()); |
| 120 return new FileBasedSource.con2(factory, resolvedFile, true); |
| 121 } |
| 122 } |
| 123 /** |
| 124 * Instances of the class {@code PackageUriResolver} resolve {@code package} URI
's in the context of |
| 125 * an application. |
| 126 */ |
| 127 class PackageUriResolver extends UriResolver { |
| 128 /** |
| 129 * The package directories that {@code package} URI's are assumed to be relati
ve to. |
| 130 */ |
| 131 List<File> _packagesDirectories; |
| 132 /** |
| 133 * The name of the {@code package} scheme. |
| 134 */ |
| 135 static String _PACKAGE_SCHEME = "package"; |
| 136 /** |
| 137 * Return {@code true} if the given URI is a {@code package} URI. |
| 138 * @param uri the URI being tested |
| 139 * @return {@code true} if the given URI is a {@code package} URI |
| 140 */ |
| 141 static bool isPackageUri(Uri uri) => uri.scheme == _PACKAGE_SCHEME; |
| 142 /** |
| 143 * Initialize a newly created resolver to resolve {@code package} URI's relati
ve to the given |
| 144 * package directories. |
| 145 * @param packagesDirectories the package directories that {@code package} URI
's are assumed to be |
| 146 * relative to |
| 147 */ |
| 148 PackageUriResolver(List<File> packagesDirectories) { |
| 149 if (packagesDirectories.length < 1) { |
| 150 throw new IllegalArgumentException("At least one package directory must be
provided"); |
| 151 } |
| 152 this._packagesDirectories = packagesDirectories; |
| 153 } |
| 154 Source resolveAbsolute(SourceFactory factory, Uri uri) { |
| 155 if (!isPackageUri(uri)) { |
| 156 return null; |
| 157 } |
| 158 String path4 = uri.path; |
| 159 if (path4 == null) { |
| 160 path4 = uri.path; |
| 161 if (path4 == null) { |
| 162 return null; |
| 163 } |
| 164 } |
| 165 for (File packagesDirectory in _packagesDirectories) { |
| 166 File resolvedFile = newRelativeFile(packagesDirectory, path4); |
| 167 if (resolvedFile.existsSync()) { |
| 168 return new FileBasedSource.con1(factory, resolvedFile); |
| 169 } |
| 170 } |
| 171 return new FileBasedSource.con1(factory, newRelativeFile(_packagesDirectorie
s[0], path4)); |
| 172 } |
| 173 } |
| 174 /** |
| 175 * Instances of the class {@link DirectoryBasedSourceContainer} represent a sour
ce container that |
| 176 * contains all sources within a given directory. |
| 177 */ |
| 178 class DirectoryBasedSourceContainer implements SourceContainer { |
| 179 /** |
| 180 * Append the system file separator to the given path unless the path already
ends with a |
| 181 * separator. |
| 182 * @param path the path to which the file separator is to be added |
| 183 * @return a path that ends with the system file separator |
| 184 */ |
| 185 static String appendFileSeparator(String path) { |
| 186 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) ==
JavaSystemIO.pathSeparatorChar) { |
| 187 return path; |
| 188 } |
| 189 return "${path}${JavaSystemIO.pathSeparator}"; |
| 190 } |
| 191 /** |
| 192 * The container's path (not {@code null}). |
| 193 */ |
| 194 String _path; |
| 195 /** |
| 196 * Construct a container representing the specified directory and containing a
ny sources whose{@link Source#getFullName()} starts with the directory's path. T
his is a convenience method, |
| 197 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour
ceContainer(String)}. |
| 198 * @param directory the directory (not {@code null}) |
| 199 */ |
| 200 DirectoryBasedSourceContainer.con1(File directory) { |
| 201 _jtd_constructor_276_impl(directory); |
| 202 } |
| 203 _jtd_constructor_276_impl(File directory) { |
| 204 _jtd_constructor_277_impl(directory.fullPathSync()); |
| 205 } |
| 206 /** |
| 207 * Construct a container representing the specified path and containing any so
urces whose{@link Source#getFullName()} starts with the specified path. |
| 208 * @param path the path (not {@code null} and not empty) |
| 209 */ |
| 210 DirectoryBasedSourceContainer.con2(String path3) { |
| 211 _jtd_constructor_277_impl(path3); |
| 212 } |
| 213 _jtd_constructor_277_impl(String path3) { |
| 214 this._path = appendFileSeparator(path3); |
| 215 } |
| 216 bool contains(Source source) => source.fullName.startsWith(_path); |
| 217 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; |
| 218 /** |
| 219 * Answer the receiver's path, used to determine if a source is contained in t
he receiver. |
| 220 * @return the path (not {@code null}, not empty) |
| 221 */ |
| 222 String get path => _path; |
| 223 int get hashCode => _path.hashCode; |
| 224 } |
| 225 /** |
| 226 * Instances of the class {@code FileUriResolver} resolve {@code file} URI's. |
| 227 */ |
| 228 class FileUriResolver extends UriResolver { |
| 229 /** |
| 230 * The name of the {@code file} scheme. |
| 231 */ |
| 232 static String _FILE_SCHEME = "file"; |
| 233 /** |
| 234 * Return {@code true} if the given URI is a {@code file} URI. |
| 235 * @param uri the URI being tested |
| 236 * @return {@code true} if the given URI is a {@code file} URI |
| 237 */ |
| 238 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; |
| 239 /** |
| 240 * Initialize a newly created resolver to resolve {@code file} URI's relative
to the given root |
| 241 * directory. |
| 242 */ |
| 243 FileUriResolver() : super() { |
| 244 } |
| 245 Source resolveAbsolute(SourceFactory factory, Uri uri) { |
| 246 if (!isFileUri(uri)) { |
| 247 return null; |
| 248 } |
| 249 return new FileBasedSource.con1(factory, newFileFromUri(uri)); |
| 250 } |
| 251 } |
| OLD | NEW |