OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, 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 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 /** | 112 /** |
113 * Answer the Eclipse resource associated with the specified file or <code>nul
l</code> if none | 113 * Answer the Eclipse resource associated with the specified file or <code>nul
l</code> if none |
114 */ | 114 */ |
115 public static IResource getResource(File file) { | 115 public static IResource getResource(File file) { |
116 if (file == null) { | 116 if (file == null) { |
117 return null; | 117 return null; |
118 } | 118 } |
119 return getResource(getCanonicalUri(file)); | 119 if (file.isDirectory()) { |
| 120 return getResource(getCanonicalUri(file)); |
| 121 } else { |
| 122 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
| 123 IFile[] files = workspaceRoot.findFilesForLocationURI(file.toURI()); |
| 124 if (files.length == 0) { |
| 125 return null; |
| 126 } |
| 127 return files[0]; |
| 128 } |
120 } | 129 } |
121 | 130 |
122 /** | 131 /** |
123 * Return the resource associated with the given URI, or <code>null</code> if
the URI does not | 132 * Return the resource associated with the given URI, or <code>null</code> if
the URI does not |
124 * correspond to an existing resource. | 133 * correspond to an existing resource. |
125 * | 134 * |
126 * @param uri the URI representing the resource to be returned | 135 * @param uri the URI representing the resource to be returned |
127 * @return the resource associated with the given URI | 136 * @return the resource associated with the given URI |
128 */ | 137 */ |
129 public static IResource getResource(URI uri) { | 138 public static IResource getResource(URI uri) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 249 } |
241 } | 250 } |
242 return resourceMap; | 251 return resourceMap; |
243 } | 252 } |
244 } | 253 } |
245 | 254 |
246 // No instances | 255 // No instances |
247 private ResourceUtil() { | 256 private ResourceUtil() { |
248 } | 257 } |
249 } | 258 } |
OLD | NEW |