Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: pkg/analyzer/lib/source/package_map_resolver.dart

Issue 907483004: Handle exception and clean-up code (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 source.package_map_resolver; 5 library source.package_map_resolver;
6 6
7 import 'package:analyzer/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/util/asserts.dart' as asserts; 9 import 'package:analyzer/src/util/asserts.dart' as asserts;
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 @override 44 @override
45 Source resolveAbsolute(Uri uri) { 45 Source resolveAbsolute(Uri uri) {
46 if (!isPackageUri(uri)) { 46 if (!isPackageUri(uri)) {
47 return null; 47 return null;
48 } 48 }
49 // Prepare path. 49 // Prepare path.
50 String path = uri.path; 50 String path = uri.path;
51 // Prepare path components. 51 // Prepare path components.
52 String pkgName;
53 String relPath;
54 int index = path.indexOf('/'); 52 int index = path.indexOf('/');
55 if (index == -1 || index == 0) { 53 if (index == -1 || index == 0) {
56 return null; 54 return null;
57 } else {
58 // <pkgName>/<relPath>
59 pkgName = path.substring(0, index);
60 relPath = path.substring(index + 1);
61 } 55 }
56 // <pkgName>/<relPath>
57 String pkgName = path.substring(0, index);
58 String relPath = path.substring(index + 1);
62 // Try to find an existing file. 59 // Try to find an existing file.
63 List<Folder> packageDirs = packageMap[pkgName]; 60 List<Folder> packageDirs = packageMap[pkgName];
64 if (packageDirs != null) { 61 if (packageDirs != null) {
65 for (Folder packageDir in packageDirs) { 62 for (Folder packageDir in packageDirs) {
66 if (packageDir.exists) { 63 if (packageDir.exists) {
67 Resource result = packageDir.getChild(relPath); 64 Resource result = packageDir.getChild(relPath);
68 if (result is File && result.exists) { 65 if (result is File && result.exists) {
69 return result.createSource(uri); 66 return result.createSource(uri);
70 } 67 }
71 } 68 }
(...skipping 21 matching lines...) Expand all
93 return null; 90 return null;
94 } 91 }
95 92
96 /** 93 /**
97 * Returns `true` if [uri] is a `package` URI. 94 * Returns `true` if [uri] is a `package` URI.
98 */ 95 */
99 static bool isPackageUri(Uri uri) { 96 static bool isPackageUri(Uri uri) {
100 return uri.scheme == PACKAGE_SCHEME; 97 return uri.scheme == PACKAGE_SCHEME;
101 } 98 }
102 } 99 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/index/store/codec.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698