Skip to content

Package: ResourceUtil

ResourceUtil

nameinstructionbranchcomplexitylinemethod
getResourceFromURI(URI)
M: 14 C: 15
52%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 4
57%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * mborkowski - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.editor.helpers;
15:
16: import org.eclipse.core.resources.IResource;
17: import org.eclipse.core.resources.ResourcesPlugin;
18: import org.eclipse.core.runtime.IPath;
19: import org.eclipse.core.runtime.Path;
20: import org.eclipse.emf.common.util.URI;
21:
22: /**
23: * This is a utility class helping with working with {@link IResource} objects in the context of EMF.
24: */
25: public final class ResourceUtil {
26:         private ResourceUtil() {
27:         }
28:
29:         /**
30:          * Resolved the given {@link URI} to an {@link IResource}.
31:          *
32:          * @param uri the {@link URI} to resolve
33:          * @return the resulting {@link IResource}
34:          */
35:         public static IResource getResourceFromURI(final URI uri) {
36:                 final IResource targetFile;
37:•                if (uri.isPlatform()) {
38:                         final IPath platformString = new Path(uri.trimFragment().toPlatformString(true));
39:                         targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(platformString);
40:                 } else {
41:                         targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(
42:                                 new Path(uri.trimFragment().toString()));
43:                 }
44:                 return targetFile;
45:         }
46: }