| 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 analyzer.src.generated.source_io; | 5 library analyzer.src.generated.source_io; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 10 import 'package:analyzer/src/generated/java_core.dart'; |
| 11 import 'package:analyzer/src/generated/java_engine.dart'; | 11 import 'package:analyzer/src/generated/java_engine.dart'; |
| 12 import 'package:analyzer/src/generated/java_io.dart'; | 12 import 'package:analyzer/src/generated/java_io.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 14 | 15 |
| 15 export 'package:analyzer/src/generated/source.dart'; | 16 export 'package:analyzer/src/generated/source.dart'; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that | 19 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that |
| 19 * contains all sources within a given directory. | 20 * contains all sources within a given directory. |
| 20 */ | 21 */ |
| 21 class DirectoryBasedSourceContainer implements SourceContainer { | 22 class DirectoryBasedSourceContainer implements SourceContainer { |
| 22 /** | 23 /** |
| 23 * The container's path (not `null`). | 24 * The container's path (not `null`). |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 241 } |
| 241 | 242 |
| 242 @override | 243 @override |
| 243 bool operator ==(Object object) => | 244 bool operator ==(Object object) => |
| 244 object is FileBasedSource && id == object.id; | 245 object is FileBasedSource && id == object.id; |
| 245 | 246 |
| 246 @override | 247 @override |
| 247 bool exists() => file.isFile(); | 248 bool exists() => file.isFile(); |
| 248 | 249 |
| 249 @override | 250 @override |
| 250 Uri resolveRelativeUri(Uri containedUri) { | |
| 251 try { | |
| 252 Uri baseUri = uri; | |
| 253 bool isOpaque = uri.isAbsolute && !uri.path.startsWith('/'); | |
| 254 if (isOpaque) { | |
| 255 String scheme = uri.scheme; | |
| 256 String part = uri.path; | |
| 257 if (scheme == DartUriResolver.DART_SCHEME && part.indexOf('/') < 0) { | |
| 258 part = "$part/$part.dart"; | |
| 259 } | |
| 260 baseUri = parseUriWithException("$scheme:/$part"); | |
| 261 } | |
| 262 Uri result = baseUri.resolveUri(containedUri); | |
| 263 if (isOpaque) { | |
| 264 result = parseUriWithException( | |
| 265 "${result.scheme}:${result.path.substring(1)}"); | |
| 266 } | |
| 267 return result; | |
| 268 } catch (exception, stackTrace) { | |
| 269 throw new AnalysisException( | |
| 270 "Could not resolve URI ($containedUri) relative to source ($uri)", | |
| 271 new CaughtException(exception, stackTrace)); | |
| 272 } | |
| 273 } | |
| 274 | |
| 275 @override | |
| 276 String toString() { | 251 String toString() { |
| 277 if (file == null) { | 252 if (file == null) { |
| 278 return "<unknown source>"; | 253 return "<unknown source>"; |
| 279 } | 254 } |
| 280 return file.getAbsolutePath(); | 255 return file.getAbsolutePath(); |
| 281 } | 256 } |
| 282 } | 257 } |
| 283 | 258 |
| 284 /** | 259 /** |
| 285 * Instances of the class `FileUriResolver` resolve `file` URI's. | 260 * Instances of the class `FileUriResolver` resolve `file` URI's. |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 } | 554 } |
| 580 | 555 |
| 581 /** | 556 /** |
| 582 * Return `true` if the given URI is a `file` URI. | 557 * Return `true` if the given URI is a `file` URI. |
| 583 * | 558 * |
| 584 * @param uri the URI being tested | 559 * @param uri the URI being tested |
| 585 * @return `true` if the given URI is a `file` URI | 560 * @return `true` if the given URI is a `file` URI |
| 586 */ | 561 */ |
| 587 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; | 562 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; |
| 588 } | 563 } |
| OLD | NEW |