Skip to content

Commit

Permalink
Clean up new o.e.core.resources.undo.snapshot API to make it more usable
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker authored and mickaelistria committed Oct 5, 2023
1 parent 5f450df commit 229beea
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected AbstractResourceSnapshot(T resource) {
@Override
public T createResource(IProgressMonitor monitor) throws CoreException {
T resource = createResourceHandle();
createExistentResourceFromHandle(resource, monitor);
createExistentResourceFromHandle(monitor);
restoreResourceAttributes(resource);
return resource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceFilterDescription;
Expand Down Expand Up @@ -183,20 +181,16 @@ protected final void createChildResources(IContainer parentHandle,
}

@Override
public void recordStateFromHistory(T resource, IProgressMonitor mon) throws CoreException {
public void recordStateFromHistory(IProgressMonitor mon) throws CoreException {
if (members != null) {
SubMonitor subMonitor = SubMonitor.convert(mon, ResourceSnapshotMessages.FolderDescription_SavingUndoInfoProgress,
members.size());
for (IResourceSnapshot<? extends IResource> member : members) {
SubMonitor iterationMonitor = subMonitor.split(1);
if (member instanceof FileSnapshot fileSnapshot) {
IPath path = resource.getFullPath().append(fileSnapshot.name);
IFile fileHandle = resource.getWorkspace().getRoot().getFile(path);
fileSnapshot.recordStateFromHistory(fileHandle, iterationMonitor);
fileSnapshot.recordStateFromHistory(iterationMonitor);
} else if (member instanceof FolderSnapshot folderSnapshot) {
IPath path = resource.getFullPath().append(folderSnapshot.name);
IFolder folderHandle = resource.getWorkspace().getRoot().getFolder(path);
folderSnapshot.recordStateFromHistory(folderHandle, iterationMonitor);
folderSnapshot.recordStateFromHistory(iterationMonitor);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public FileSnapshot(IFile file, URI linkLocation,
}

@Override
public void recordStateFromHistory(IFile resource,
IProgressMonitor monitor) throws CoreException {
public void recordStateFromHistory(IProgressMonitor monitor) throws CoreException {
IFile resource = createResourceHandle();
Assert.isLegal(resource.getType() == IResource.FILE);
if (location != null) {
// file is linked, no need to record any history
Expand Down Expand Up @@ -131,7 +131,8 @@ public IFile createResourceHandle() {
}

@Override
public void createExistentResourceFromHandle(IFile fileHandle, IProgressMonitor mon) throws CoreException {
public void createExistentResourceFromHandle(IProgressMonitor mon) throws CoreException {
IFile fileHandle = createResourceHandle();
if (fileHandle.exists()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.eclipse.core.internal.resources.undo.snapshot;

import java.net.URI;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceFilterDescription;
Expand Down Expand Up @@ -74,7 +73,8 @@ public IFolder createResourceHandle() {
}

@Override
public void createExistentResourceFromHandle(final IFolder folderHandle, IProgressMonitor mon) throws CoreException {
public void createExistentResourceFromHandle(IProgressMonitor mon) throws CoreException {
IFolder folderHandle = createResourceHandle();
if (folderHandle.exists()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public IProject createResourceHandle() {
}

@Override
public void createExistentResourceFromHandle(IProject projectHandle, IProgressMonitor monitor) throws CoreException {
public void createExistentResourceFromHandle(IProgressMonitor monitor) throws CoreException {
IProject projectHandle = createResourceHandle();
SubMonitor subMonitor = SubMonitor.convert(monitor, 200);
if (projectHandle.exists()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ public interface IResourceSnapshot<T extends IResource> {
* Given a resource handle, create an actual resource with the attributes of
* the receiver resource description.
*
* @param resource
* the resource handle
* @param monitor
* the progress monitor to be used when creating the resource
* @throws CoreException if creation failed
*/
public void createExistentResourceFromHandle(T resource, IProgressMonitor monitor) throws CoreException;
public void createExistentResourceFromHandle(IProgressMonitor monitor) throws CoreException;

/**
* Return a boolean indicating whether this resource description has enough
Expand All @@ -82,13 +80,11 @@ public interface IResourceSnapshot<T extends IResource> {
* Record the appropriate state of this resource description using
* any available resource history.
*
* @param resource
* the resource whose state is to be recorded.
* @param monitor
* the progress monitor to be used
* @throws CoreException in case of error
*/
public void recordStateFromHistory(T resource, IProgressMonitor monitor) throws CoreException;
public void recordStateFromHistory(IProgressMonitor monitor) throws CoreException;

/**
* Return a boolean indicating whether this description represents an
Expand Down

0 comments on commit 229beea

Please sign in to comment.