Class EclipseResource

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected EclipseResource​(org.eclipse.core.resources.IResource resource)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void copy​(java.nio.file.Path destination, org.eclipse.core.runtime.IProgressMonitor monitor)
      Copies this resource to the given destination.
      AMarker createMarker​(java.lang.String markerType)
      Creates a new marker of the given type for this resource.
      void delete​(org.eclipse.core.runtime.IProgressMonitor monitor)
      Deletes the resource from the file system.
      void deleteMarkers​(java.lang.String type, boolean includeSubtypes, AResource.AResourceTreeTraversalDepth depth)
      Deletes all markers of the given type from this resource.
      boolean exists()
      A resource exists if its file-system equivalent exists (the path corresponds to an actual file/folder).
      java.util.Set<AMarker> findMarkers​(java.lang.String type, boolean includeSubtypes, AResource.AResourceTreeTraversalDepth depth)
      Returns all markers of the given type on this resource.
      <T> T getAdapter​(java.lang.Class<T> adapter)  
      long getLocalTimeStamp()
      Returns the corresponding file's last modification as milliseconds since the epoch (1970-1-1).
      java.nio.file.Path getLocation()
      Returns the absolute location of this resource in the file system.
      long getModificationStamp()
      Returns the corresponding file's modification stamp.
      java.lang.String getName()
      The local name of this resource inside its parent.
      AContainer getParent()
      A resource's parent ist the resource representing the containing folder.
      AProject getProject()
      Returns the project containing this resource.
      java.nio.file.Path getProjectRelativePath()
      Returns the relative location of this resource in the containing project.
      AResource.AResourceType getType()
      A resource type can be used instead of checking for instanceof with concrete implementations.
      AWorkspace getWorkspace()
      Returns the workspace containing this resource.
      java.nio.file.Path getWorkspaceRelativePath()
      Returns the relative location of this resource in the containing workspace.
      boolean isAccessible()
      An accessible resource AResource.exists() and can be used.
      boolean isDerived()
      Returns whether this resource is derived (can be recreated from source files).
      boolean isSynchronized​(AResource.AResourceTreeTraversalDepth depth)
      Checks whether this resource is in sync with its corresponding file-system resource.
      void move​(java.nio.file.Path destination, org.eclipse.core.runtime.IProgressMonitor monitor)
      Moves this resource to the given destination.
      void refreshLocal​(AResource.AResourceTreeTraversalDepth depth, org.eclipse.core.runtime.IProgressMonitor monitor)
      Synchronizes this resource with its corresponding file-system objects.
      void setDerived​(boolean isDerived, org.eclipse.core.runtime.IProgressMonitor monitor)
      Sets this resource (and, in case this is a container, its children) as derived.
      void touch​(org.eclipse.core.runtime.IProgressMonitor monitor)
      Marks this resource as modified, updating the local time stamp and modification stamp.
      org.eclipse.core.resources.IResource unwrap()
      Returns the platform-specific object corresponding to this abstraction.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • EclipseResource

        protected EclipseResource​(org.eclipse.core.resources.IResource resource)
    • Method Detail

      • unwrap

        public org.eclipse.core.resources.IResource unwrap()
        Description copied from interface: AAbstraction
        Returns the platform-specific object corresponding to this abstraction. The generic type parameter is used to avoid casts when assigning to platform-specific objects. It is the obligation of the caller to make sure the right type is used, otherwise a ClassCastException will be thrown.

        Sample usage:

         
         interface ACalendar extends AAbstraction[...]
         class LocalDateAsCalendarWrapper extends AWrapper<LocalDate>[...]
         [...]
         ACalendar calendar = Wrappers.of(LocalDate.now()).as(ACalendar.class);
         [...]
         LocalDate date = calendar.unwrap();
         
         
        Specified by:
        unwrap in interface AAbstraction
        Overrides:
        unwrap in class AWrapper<org.eclipse.core.resources.IResource>
        See Also:
        Wrappers#unwrap(AAbstraction) for a way to unwrap potentially null abstractions.
      • getAdapter

        public <T> T getAdapter​(java.lang.Class<T> adapter)
        Specified by:
        getAdapter in interface org.eclipse.core.runtime.IAdaptable
      • isAccessible

        public boolean isAccessible()
        Description copied from interface: AResource
        An accessible resource AResource.exists() and can be used. For example a project in Eclipse needs to be open to be accessible.
        Specified by:
        isAccessible in interface AResource
        Returns:
        whether this resource is accessible
      • exists

        public boolean exists()
        Description copied from interface: AResource
        A resource exists if its file-system equivalent exists (the path corresponds to an actual file/folder).
        Specified by:
        exists in interface AResource
        Returns:
        whether this resource exists
      • getParent

        public AContainer getParent()
        Description copied from interface: AResource
        A resource's parent ist the resource representing the containing folder. Not all resources have a parent, for example a workspace only contains other resources but has not parent.
        Specified by:
        getParent in interface AResource
        Returns:
        this resource's parent, or null if it has no parent
      • getName

        public java.lang.String getName()
        Description copied from interface: AResource
        The local name of this resource inside its parent.
        Specified by:
        getName in interface AResource
        Returns:
        this resource's name
      • getLocation

        public java.nio.file.Path getLocation()
        Description copied from interface: AResource
        Returns the absolute location of this resource in the file system.
        Specified by:
        getLocation in interface AResource
        Returns:
        this resource's location
      • getProjectRelativePath

        public java.nio.file.Path getProjectRelativePath()
        Description copied from interface: AResource
        Returns the relative location of this resource in the containing project.
        Specified by:
        getProjectRelativePath in interface AResource
        Returns:
        this resource's location relative to its project or an empty path if the resource is not contained in a project
      • getWorkspaceRelativePath

        public java.nio.file.Path getWorkspaceRelativePath()
        Description copied from interface: AResource
        Returns the relative location of this resource in the containing workspace.
        Specified by:
        getWorkspaceRelativePath in interface AResource
        Returns:
        this resource's location relative to its project or an empty path if the resource is not contained in a workspace
      • delete

        public void delete​(org.eclipse.core.runtime.IProgressMonitor monitor)
        Description copied from interface: AResource
        Deletes the resource from the file system.
        Specified by:
        delete in interface AResource
        Parameters:
        monitor - a progress monitor that is notified about the deletion process. When deleting a directory, individual file deletions are reported to the monitor to allow fine-grained progress reporting. The monitor may be null when progress does not need to be reported.
      • getModificationStamp

        public long getModificationStamp()
        Description copied from interface: AResource
        Returns the corresponding file's modification stamp. This may correspond to the AResource.getLocalTimeStamp() from the file system or be more fine-grained.
        Specified by:
        getModificationStamp in interface AResource
        Returns:
        the file's modification time stamp, or -1 if the file does not exist
      • getLocalTimeStamp

        public long getLocalTimeStamp()
        Description copied from interface: AResource
        Returns the corresponding file's last modification as milliseconds since the epoch (1970-1-1).
        Specified by:
        getLocalTimeStamp in interface AResource
        Returns:
        the file's time stamp, or -1 if the file does not exist
      • getType

        public AResource.AResourceType getType()
        Description copied from interface: AResource
        A resource type can be used instead of checking for instanceof with concrete implementations.
        Specified by:
        getType in interface AResource
        Returns:
        the resource's type
      • findMarkers

        public java.util.Set<AMarker> findMarkers​(java.lang.String type,
                                                  boolean includeSubtypes,
                                                  AResource.AResourceTreeTraversalDepth depth)
        Description copied from interface: AResource
        Returns all markers of the given type on this resource. If includeSubtypes is true, then markers of types that are subtypes of the given type are also returned. The depth determines whether only markers from this resource are returned or also from its children (if this resource is a container).
        Specified by:
        findMarkers in interface AResource
        Parameters:
        type - a marker type
        includeSubtypes - whether to include subtypes of the given marker type
        depth - whether to scan only this resource, or also its children (and their children...)
        Returns:
        all markers matching the given type and search depth
      • createMarker

        public AMarker createMarker​(java.lang.String markerType)
        Description copied from interface: AResource
        Creates a new marker of the given type for this resource.
        Specified by:
        createMarker in interface AResource
        Parameters:
        markerType - the marker type
        Returns:
        the created marker
      • deleteMarkers

        public void deleteMarkers​(java.lang.String type,
                                  boolean includeSubtypes,
                                  AResource.AResourceTreeTraversalDepth depth)
        Description copied from interface: AResource
        Deletes all markers of the given type from this resource. If includeSubtypes is true, then markers of types that are subtypes of the given type are also deleted. The depth determines whether only markers from this resource are deleted or also from its children.
        Specified by:
        deleteMarkers in interface AResource
        Parameters:
        type - a marker type
        includeSubtypes - whether to include subtypes of the given marker type
        depth - whether to clean only this resource, or also its children (and their children...)
      • isDerived

        public boolean isDerived()
        Description copied from interface: AResource
        Returns whether this resource is derived (can be recreated from source files).
        Specified by:
        isDerived in interface AResource
      • setDerived

        public void setDerived​(boolean isDerived,
                               org.eclipse.core.runtime.IProgressMonitor monitor)
        Description copied from interface: AResource
        Sets this resource (and, in case this is a container, its children) as derived.
        Specified by:
        setDerived in interface AResource
        Parameters:
        isDerived - whether to mark this resource as derived
        monitor - a progress monitor that is notified about this process. When marking a directory as (not) derived, individual file processing is reported to the monitor to allow fine-grained progress reporting. The monitor may be null when progress does not need to be reported.
      • getProject

        public AProject getProject()
        Description copied from interface: AResource
        Returns the project containing this resource.
        Specified by:
        getProject in interface AResource
        Returns:
        the project containing this resource; the project itself if this resource is a project and null if this resource is the workspace.
      • refreshLocal

        public void refreshLocal​(AResource.AResourceTreeTraversalDepth depth,
                                 org.eclipse.core.runtime.IProgressMonitor monitor)
        Description copied from interface: AResource
        Synchronizes this resource with its corresponding file-system objects.
        Specified by:
        refreshLocal in interface AResource
        Parameters:
        depth - whether to synchronize only this resource, or also its children (and their children...)
        monitor - a progress monitor that is notified about this process. When synchronizing a directory, individual file synchronization is reported to the monitor to allow fine-grained progress reporting. The monitor may be null when progress does not need to be reported.
      • getWorkspace

        public AWorkspace getWorkspace()
        Description copied from interface: AResource
        Returns the workspace containing this resource.
        Specified by:
        getWorkspace in interface AResource
        Returns:
        the workspace containing this resource; the workspace itself if this resource is a workspace.
      • copy

        public void copy​(java.nio.file.Path destination,
                         org.eclipse.core.runtime.IProgressMonitor monitor)
        Description copied from interface: AResource
        Copies this resource to the given destination.
        Specified by:
        copy in interface AResource
        Parameters:
        destination - an existing resource of the same type as this resource
        monitor - a progress monitor that is notified about the copy process. When copying a directory, individual file copies are reported to the monitor to allow fine-grained progress reporting. The monitor may be null when progress does not need to be reported.
      • move

        public void move​(java.nio.file.Path destination,
                         org.eclipse.core.runtime.IProgressMonitor monitor)
        Description copied from interface: AResource
        Moves this resource to the given destination.
        Specified by:
        move in interface AResource
        Parameters:
        destination - an existing resource of the same type as this resource
        monitor - a progress monitor that is notified about the move process. When moving a directory, individual file copies are reported to the monitor to allow fine-grained progress reporting. The monitor may be null when progress does not need to be reported.
      • touch

        public void touch​(org.eclipse.core.runtime.IProgressMonitor monitor)
        Description copied from interface: AResource
        Marks this resource as modified, updating the local time stamp and modification stamp.
        Specified by:
        touch in interface AResource
        Parameters:
        monitor - a progress monitor that is notified about this process. The monitor may be null when progress does not need to be reported.
      • isSynchronized

        public boolean isSynchronized​(AResource.AResourceTreeTraversalDepth depth)
        Description copied from interface: AResource
        Checks whether this resource is in sync with its corresponding file-system resource. Both need to
        Specified by:
        isSynchronized in interface AResource
        Parameters:
        depth - whether to check only this resource, or also its children (and their children...)
        Returns:
        whether this resource (and its children) is/are in sync with its/their corresponding file-system resource(s)