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

Side by Side Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/util/ResourceUtil.java

Issue 8371019: Fix a URI related problem on windows. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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 /* 1 /*
2 * Copyright (c) 2011, the Dart project authors. 2 * Copyright (c) 2011, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
11 * or implied. See the License for the specific language governing permissions a nd limitations under 11 * or implied. See the License for the specific language governing permissions a nd limitations under
12 * the License. 12 * the License.
13 */ 13 */
14 package com.google.dart.tools.core.internal.util; 14 package com.google.dart.tools.core.internal.util;
15 15
16 import com.google.dart.compiler.Source; 16 import com.google.dart.compiler.Source;
17 import com.google.dart.compiler.SystemLibraryManager; 17 import com.google.dart.compiler.SystemLibraryManager;
18 import com.google.dart.tools.core.DartCore;
18 import com.google.dart.tools.core.utilities.net.URIUtilities; 19 import com.google.dart.tools.core.utilities.net.URIUtilities;
19 20
20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.resources.IWorkspaceRoot; 22 import org.eclipse.core.resources.IWorkspaceRoot;
22 import org.eclipse.core.resources.ResourcesPlugin; 23 import org.eclipse.core.resources.ResourcesPlugin;
23 24
24 import java.io.File; 25 import java.io.File;
25 import java.net.URI; 26 import java.net.URI;
26 27
27 /** 28 /**
28 * Utilities for mapping {@link Source} to {@link File} to {@link IFile} 29 * Utilities for mapping {@link Source} to {@link File} to {@link IFile}
29 */ 30 */
30 public class ResourceUtil { 31 public class ResourceUtil {
31 public static IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 32 public static IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
32 33
33 /** 34 /**
34 * Answer the file for the specified Dart source or <code>null</code> if none 35 * Answer the file for the specified Dart source or <code>null</code> if none
35 */ 36 */
36 public static File getFile(Source source) { 37 public static File getFile(Source source) {
37 if (source == null) { 38 if (source == null) {
38 return null; 39 return null;
39 } 40 }
41
42 URI uri = URIUtilities.safelyResolveDartUri(source.getUri());
43
40 try { 44 try {
41 URI uri = URIUtilities.safelyResolveDartUri(source.getUri());
42 if (uri.isAbsolute() && "file".equals(uri.getScheme())) { 45 if (uri.isAbsolute() && "file".equals(uri.getScheme())) {
43 return new File(uri); 46 return new File(uri);
44 } 47 }
45 String relativePath = uri.getPath(); 48 String relativePath = uri.getPath();
46 return new File(new File(".").getAbsoluteFile(), relativePath); 49 return new File(new File(".").getAbsoluteFile(), relativePath);
47 } catch (IllegalArgumentException ex) { 50 } catch (IllegalArgumentException ex) {
48 // Thrown if the url was not a legal file url. 51 DartCore.logError("Illegal file URI: " + uri, ex);
52
49 return null; 53 return null;
50 } 54 }
51 } 55 }
52 56
53 /** 57 /**
54 * Answer the Eclipse resource associated with the specified file or <code>nul l</code> if none 58 * Answer the Eclipse resource associated with the specified file or <code>nul l</code> if none
55 */ 59 */
56 public static IFile getResource(File file) { 60 public static IFile getResource(File file) {
57 IFile[] resources = ResourceUtil.getResources(file); 61 IFile[] resources = ResourceUtil.getResources(file);
58 if (resources != null) { 62 if (resources != null) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 if (SystemLibraryManager.isDartUri(uri)) { 120 if (SystemLibraryManager.isDartUri(uri)) {
117 return null; 121 return null;
118 } 122 }
119 return root.findFilesForLocationURI(uri); 123 return root.findFilesForLocationURI(uri);
120 } 124 }
121 125
122 // No instances 126 // No instances
123 private ResourceUtil() { 127 private ResourceUtil() {
124 } 128 }
125 } 129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698