Class ResourceUtil

java.lang.Object
org.eclipse.emf.compare.ide.utils.ResourceUtil

public final class ResourceUtil extends Object
This class will be used to provide various utilities aimed at IResource manipulation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.common.base.Function<org.eclipse.core.resources.IStorage,URI>
    Provides a Function that converts an IStorage into a URI.
    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.
    protected static void
    Delete the given 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.resources.IStorage
    Returns the storage associated with the resource.
    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
    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.
    protected static boolean
    mustDelete(Resource resource)
    Check if the given resource must be deleted.
    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.
    static void
    setAssociatedStorage(Resource resource, org.eclipse.core.resources.IStorage storage)
    Associates the storage with the resource such that getAssociatedStorage(Resource) will return this storage for the resource.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • asURI

      public static com.google.common.base.Function<org.eclipse.core.resources.IStorage,URI> asURI()
      Provides a Function that converts an IStorage into a URI.
      Returns:
      A Function that converts an IStorage into a URI. This function transforms a null storage into a null URI.
      Since:
      3.2
    • loadResource

      public 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.
      Parameters:
      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).
      Returns:
      The loaded EMF Resource if file was a model, null otherwise.
    • getAssociatedStorage

      public static org.eclipse.core.resources.IStorage getAssociatedStorage(Resource resource)
      Returns the storage associated with the resource.
      Parameters:
      resource - the resource.
      Returns:
      the associated storage or null if there isn't one.
      See Also:
    • setAssociatedStorage

      public static void setAssociatedStorage(Resource resource, org.eclipse.core.resources.IStorage storage)
      Associates the storage with the resource such that getAssociatedStorage(Resource) will return this storage for the resource.
      Parameters:
      resource - the resource.
      storage - the associated storage.
    • binaryIdentical

      public 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.
      Parameters:
      left - First of the two storages which content we are testing.
      right - Second of the two storages which content we are testing.
      Returns:
      true if left and right are binary identical.
    • binaryIdentical

      public 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. This could be done by calling 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.
      Parameters:
      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.
      Returns:
      true if left, right and origin are binary identical.
    • createURIFor

      public static URI createURIFor(org.eclipse.core.resources.IFile file)
      Create the URI with which we'll load the given IFile as an EMF resource.
      Parameters:
      file - The file for which we need an EMF URI.
      Returns:
      The created URI.
      Since:
      3.1
    • createURIFor

      public static URI createURIFor(org.eclipse.core.resources.IStorage storage)
      Create the URI with which we'll load the given IStorage as an EMF resource.
      Parameters:
      storage - The storage for which we need an EMF URI.
      Returns:
      The created URI.
    • getResourceFromURI

      public static org.eclipse.core.resources.IResource getResourceFromURI(URI uri)
      Tries and retrieve the IResource associated with the given URI. This returns a file handle, which might point to a non-existing IResource.
      Parameters:
      uri - the URI for which we want the IResource.
      Returns:
      the IResource if found, null otherwise.
      Since:
      3.2
    • getFixedPath

      public 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.
      Parameters:
      storage - The storage for which we need a fixed full path.
      Returns:
      The full path to this storage, fixed if need be.
      Since:
      3.2
    • getAbsolutePath

      public static org.eclipse.core.runtime.IPath getAbsolutePath(org.eclipse.core.resources.IStorage storage)
      Returns an absolute path for this storage if one exists. If the storage can be adapted to 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.
      Parameters:
      storage - The storage for which we need an absolute path.
      Returns:
      The absolute path to this storage.
      Since:
      3.3
    • saveAllResources

      public static void saveAllResources(ResourceSet resourceSet, Map<?,?> options)
      This can be called to save all resources contained by the resource set. This will not try and save resources that do not support output.
      Parameters:
      resourceSet - The resource set to save.
      options - The options we are to pass on to Resource.save(Map).
    • saveAllResources

      public 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. This will not try and save resources that do not support output.
      Parameters:
      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.
      Since:
      3.3
    • saveResource

      public static void saveResource(Resource resource, Map<?,?> options)
      This can be called to save the given resource. This will not try and save a resource that does not support output.
      Parameters:
      resource - The resource to save.
      options - The options we are to pass on to Resource.save(Map).
      Since:
      3.1
    • mustDelete

      protected static boolean mustDelete(Resource resource)
      Check if the given resource must be deleted.
      Parameters:
      resource - The resource to delete, must not be null.
      Returns:
      true if the given resource must be deleted, false otherwise.
      Since:
      3.4
    • deleteResource

      protected static void deleteResource(Resource resource)
      Delete the given resource.
      Parameters:
      resource - The resource to delete, must not be null.
      Since:
      3.4
    • hasContentType

      public 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.
      Parameters:
      contentTypeId - Fully qualified identifier of the content type we seek.
      contentTypes - The array of content-types to compare against.
      Returns:
      true if the given array contains a content-type with this id.
      Since:
      3.1
    • hasModelType

      public 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.
      Parameters:
      file - The file which contents are to be checked.
      Returns:
      true if this file has one of the "model" content types.
      Since:
      3.1
    • getContentTypes

      public 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.
      Parameters:
      file - The file we need the content types of.
      Returns:
      All content types associated with the given file, an empty array if none.
      Since:
      3.1