| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.context.source; | 5 library analyzer.src.context.source; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; |
| 8 | 9 |
| 9 import 'package:analyzer/exception/exception.dart'; | 10 import 'package:analyzer/exception/exception.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/file_system/physical_file_system.dart'; | 12 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 12 import 'package:analyzer/source/package_map_resolver.dart'; | 13 import 'package:analyzer/source/package_map_resolver.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analyzer/src/generated/sdk.dart'; | 15 import 'package:analyzer/src/generated/sdk.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/generated/utilities_dart.dart' as utils; | 17 import 'package:analyzer/src/generated/utilities_dart.dart' as utils; |
| 17 import 'package:analyzer/src/util/fast_uri.dart'; | 18 import 'package:analyzer/src/util/fast_uri.dart'; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 197 } |
| 197 if (sourceUri.scheme != 'file') { | 198 if (sourceUri.scheme != 'file') { |
| 198 //TODO(pquitslund): verify this works for non-file URIs. | 199 //TODO(pquitslund): verify this works for non-file URIs. |
| 199 return null; | 200 return null; |
| 200 } | 201 } |
| 201 | 202 |
| 202 Uri packageUri; | 203 Uri packageUri; |
| 203 _packages.asMap().forEach((String name, Uri uri) { | 204 _packages.asMap().forEach((String name, Uri uri) { |
| 204 if (packageUri == null) { | 205 if (packageUri == null) { |
| 205 if (utils.startsWith(sourceUri, uri)) { | 206 if (utils.startsWith(sourceUri, uri)) { |
| 206 packageUri = Uri.parse( | 207 String relativePath = sourceUri.path |
| 207 'package:$name/${sourceUri.path.substring(uri.path.length)}'); | 208 .substring(min(uri.path.length, sourceUri.path.length)); |
| 209 packageUri = Uri.parse('package:$name/$relativePath'); |
| 208 } | 210 } |
| 209 } | 211 } |
| 210 }); | 212 }); |
| 211 return packageUri; | 213 return packageUri; |
| 212 } | 214 } |
| 213 | 215 |
| 214 /** | 216 /** |
| 215 * Return a source object representing the URI that results from resolving | 217 * Return a source object representing the URI that results from resolving |
| 216 * the given (possibly relative) contained URI against the URI associated | 218 * the given (possibly relative) contained URI against the URI associated |
| 217 * with an existing source object, or `null` if the URI could not be resolved. | 219 * with an existing source object, or `null` if the URI could not be resolved. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 for (UriResolver resolver in resolvers) { | 261 for (UriResolver resolver in resolvers) { |
| 260 Source result = resolver.resolveAbsolute(containedUri, actualUri); | 262 Source result = resolver.resolveAbsolute(containedUri, actualUri); |
| 261 if (result != null) { | 263 if (result != null) { |
| 262 return result; | 264 return result; |
| 263 } | 265 } |
| 264 } | 266 } |
| 265 return null; | 267 return null; |
| 266 }); | 268 }); |
| 267 } | 269 } |
| 268 } | 270 } |
| OLD | NEW |