public final class ResourceUtil extends Object
Modifier and Type | Method and Description |
---|---|
static com.google.common.base.Function<org.eclipse.core.resources.IStorage,URI> |
asURI()
|
static boolean |
binaryIdentical(org.eclipse.core.resources.IStorage left,
org.eclipse.core.resources.IStorage right)
Checks whether the two given storages point to binary identical data.
|
static boolean |
binaryIdentical(org.eclipse.core.resources.IStorage left,
org.eclipse.core.resources.IStorage right,
org.eclipse.core.resources.IStorage origin)
Checks whether the three given storages point to binary identical data.
|
static URI |
createURIFor(org.eclipse.core.resources.IFile file)
Create the URI with which we'll load the given IFile as an EMF resource.
|
static URI |
createURIFor(org.eclipse.core.resources.IStorage storage)
Create the URI with which we'll load the given IStorage as an EMF resource.
|
static org.eclipse.core.runtime.IPath |
getAbsolutePath(org.eclipse.core.resources.IStorage storage)
Returns an absolute path for this storage if one exists.
|
static org.eclipse.core.runtime.content.IContentType[] |
getContentTypes(org.eclipse.core.resources.IFile file)
Returns the whole list of content types of the given IFile, or an empty array if none.
|
static org.eclipse.core.runtime.IPath |
getFixedPath(org.eclipse.core.resources.IStorage storage)
Returns a path for this storage after fixing from an
IStoragePathProvider if one exists. |
static org.eclipse.core.resources.IResource |
getResourceFromURI(URI uri)
Tries and retrieve the
IResource associated with the given URI . |
static boolean |
hasContentType(String contentTypeId,
List<org.eclipse.core.runtime.content.IContentType> contentTypes)
This will return
true if the given contentTypeId represents a content-type
contained in the given array. |
static boolean |
hasModelType(org.eclipse.core.resources.IFile file)
Checks whether the given file has one of the content types described in
MODEL_CONTENT_TYPES . |
static Resource |
loadResource(org.eclipse.core.resources.IStorage storage,
ResourceSet resourceSet,
Map<?,?> options)
This will try and load the given file as an EMF model, and return the corresponding
Resource if
at all possible. |
static void |
saveAllResources(ResourceSet resourceSet,
Map<?,?> options)
This can be called to save all resources contained by the resource set.
|
static void |
saveAllResources(ResourceSet resourceSet,
Map<?,?> options,
StorageTraversal leftTraversal,
StorageTraversal rightTraversal,
StorageTraversal originTraversal)
This can be called to save all resources contained by the resource set.
|
static void |
saveResource(Resource resource,
Map<?,?> options)
This can be called to save the given resource.
|
public static com.google.common.base.Function<org.eclipse.core.resources.IStorage,URI> asURI()
Function
that converts an IStorage
into a URI
. This function
transforms a null
storage into a null
URI.public static Resource loadResource(org.eclipse.core.resources.IStorage storage, ResourceSet resourceSet, Map<?,?> options)
Resource
if
at all possible.storage
- The file we need to try and load as a model.resourceSet
- The resource set in which to load this Resource.options
- The options to pass to Resource.load(java.util.Map)
.file
was a model, null
otherwise.public static boolean binaryIdentical(org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right)
left
- First of the two storages which content we are testing.right
- Second of the two storages which content we are testing.true
if left
and right
are binary identical.public static boolean binaryIdentical(org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right, org.eclipse.core.resources.IStorage origin)
binaryIdentical(IStorage, IStorage)
twice, though this implementation allows us to shortcut
whenever one byte differs... and will read one less file from its input stream.left
- First of the three storages which content we are testing.right
- Second of the three storages which content we are testing.origin
- Third of the three storages which content we are testing.true
if left
, right
and origin
are binary identical.public static URI createURIFor(org.eclipse.core.resources.IFile file)
file
- The file for which we need an EMF URI.public static URI createURIFor(org.eclipse.core.resources.IStorage storage)
storage
- The storage for which we need an EMF URI.public static org.eclipse.core.resources.IResource getResourceFromURI(URI uri)
IResource
associated with the given URI
. This returns a file
handle, which might point to a non-existing IResource.uri
- the URI for which we want the IResource
.IResource
if found, null otherwise.public static org.eclipse.core.runtime.IPath getFixedPath(org.eclipse.core.resources.IStorage storage)
IStoragePathProvider
if one exists.storage
- The storage for which we need a fixed full path.public static org.eclipse.core.runtime.IPath getAbsolutePath(org.eclipse.core.resources.IStorage storage)
IStoragePathProvider2
, it will call computeAbsolutePath from this interface. If the storage is
a File, a Path
will be created and then getAbsolutePath will be called. In other cases, the
method will return the full path of the storage.storage
- The storage for which we need an absolute path.public static void saveAllResources(ResourceSet resourceSet, Map<?,?> options)
resourceSet
- The resource set to save.options
- The options we are to pass on to Resource.save(Map)
.public static void saveAllResources(ResourceSet resourceSet, Map<?,?> options, StorageTraversal leftTraversal, StorageTraversal rightTraversal, StorageTraversal originTraversal)
resourceSet
- The resource set to save.options
- The options we are to pass on to Resource.save(Map)
.leftTraversal
- The traversal corresponding to the left side.rightTraversal
- The traversal corresponding to the right side.originTraversal
- The traversal corresponding to the common ancestor of both other side. Can be
null
.public static void saveResource(Resource resource, Map<?,?> options)
resource
- The resource to save.options
- The options we are to pass on to Resource.save(Map)
.public static boolean hasContentType(String contentTypeId, List<org.eclipse.core.runtime.content.IContentType> contentTypes)
true
if the given contentTypeId represents a content-type
contained in the given array.contentTypeId
- Fully qualified identifier of the content type we seek.contentTypes
- The array of content-types to compare against.true
if the given array contains a content-type with this id.public static boolean hasModelType(org.eclipse.core.resources.IFile file)
MODEL_CONTENT_TYPES
.file
- The file which contents are to be checked.true
if this file has one of the "model" content types.public static org.eclipse.core.runtime.content.IContentType[] getContentTypes(org.eclipse.core.resources.IFile file)
file
- The file we need the content types of.
Copyright (c) 2006, 2015 Obeo and others. All rights reserved.