Skip to content

Commit

Permalink
Rename API to use snapshot instead of description for clarity
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Sep 14, 2023
1 parent 7286d1c commit f6cf377
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Export-Package: org.eclipse.core.internal.dtree;x-internal:=true,
org.eclipse.core.resources.mapping,
org.eclipse.core.resources.refresh,
org.eclipse.core.resources.team,
org.eclipse.core.resources.undo.snapshot,
org.eclipse.core.resources.variableresolvers
Require-Bundle: org.eclipse.ant.core;bundle-version="[3.1.0,4.0.0)";resolution:=optional,
org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.core.resources.descriptions;
package org.eclipse.core.resources.undo.snapshot;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IMarker;
Expand All @@ -24,15 +24,15 @@
import org.eclipse.core.runtime.IProgressMonitor;

/**
* Base implementation of ResourceDescription that describes the common
* attributes of a resource to be created.
* Base implementation of ResourceSnapshot that describes the common attributes
* of a resource to be created.
*
* This class is not intended to be instantiated or used by clients.
*
* @since 3.20
*
*/
abstract class AbstractResourceDescription extends ResourceDescription {
abstract class AbstractResourceSnapshot extends ResourceSnapshot {
IContainer parent;

long modificationStamp = IResource.NULL_STAMP;
Expand All @@ -41,12 +41,12 @@ abstract class AbstractResourceDescription extends ResourceDescription {

ResourceAttributes resourceAttributes;

MarkerDescription[] markerDescriptions;
MarkerSnapshot[] markerDescriptions;

/**
* Create a resource description with no initial attributes
*/
protected AbstractResourceDescription() {
protected AbstractResourceSnapshot() {
super();
}

Expand All @@ -56,7 +56,7 @@ protected AbstractResourceDescription() {
* @param resource
* the resource to be described
*/
protected AbstractResourceDescription(IResource resource) {
protected AbstractResourceSnapshot(IResource resource) {
super();
parent = resource.getParent();
if (resource.isAccessible()) {
Expand All @@ -66,9 +66,9 @@ protected AbstractResourceDescription(IResource resource) {
try {
IMarker[] markers = resource.findMarkers(null, true,
IResource.DEPTH_INFINITE);
markerDescriptions = new MarkerDescription[markers.length];
markerDescriptions = new MarkerSnapshot[markers.length];
for (int i = 0; i < markers.length; i++) {
markerDescriptions[i] = new MarkerDescription(markers[i]);
markerDescriptions[i] = new MarkerSnapshot(markers[i]);
}
} catch (CoreException e) {
// Eat this exception because it only occurs when the resource
Expand Down Expand Up @@ -114,7 +114,7 @@ protected void restoreResourceAttributes(IResource resource)
resource.setResourceAttributes(resourceAttributes);
}
if (markerDescriptions != null) {
for (MarkerDescription markerDescription : markerDescriptions) {
for (MarkerSnapshot markerDescription : markerDescriptions) {
if (markerDescription.resource.exists())
markerDescription.createMarker();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.core.resources.descriptions;
package org.eclipse.core.resources.undo.snapshot;

import java.net.URI;
import org.eclipse.core.resources.IContainer;
Expand All @@ -37,7 +37,7 @@
* @since 3.20
*
*/
public abstract class ContainerDescription extends AbstractResourceDescription {
public abstract class ContainerSnapshot extends AbstractResourceSnapshot {

String name;

Expand All @@ -47,7 +47,7 @@ public abstract class ContainerDescription extends AbstractResourceDescription {

String defaultCharSet;

AbstractResourceDescription[] members;
AbstractResourceSnapshot[] members;

/**
* Create a container description from the specified container handle that
Expand All @@ -61,7 +61,7 @@ public abstract class ContainerDescription extends AbstractResourceDescription {
* non-existing parents.
*/

public static ContainerDescription fromContainer(IContainer container) {
public static ContainerSnapshot fromContainer(IContainer container) {
return fromContainer(container, false);
}

Expand All @@ -77,21 +77,21 @@ public static ContainerDescription fromContainer(IContainer container) {
* non-existing parents.
*/

public static ContainerDescription fromVirtualFolderContainer(IContainer container) {
public static ContainerSnapshot fromVirtualFolderContainer(IContainer container) {
return fromContainer(container, true);
}

protected static ContainerDescription fromContainer(IContainer container, boolean usingVirtualFolder) {
protected static ContainerSnapshot fromContainer(IContainer container, boolean usingVirtualFolder) {
IPath fullPath = container.getFullPath();
ContainerDescription firstCreatedParent = null;
ContainerDescription currentContainerDescription = null;
ContainerSnapshot firstCreatedParent = null;
ContainerSnapshot currentContainerDescription = null;

// Does the container exist already? If so, then the parent exists and
// we use the normal creation constructor.
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IContainer currentContainer = (IContainer) root.findMember(fullPath);
if (currentContainer != null) {
return (ContainerDescription) ResourceDescription
return (ContainerSnapshot) ResourceSnapshot
.fromResource(container);
}

Expand All @@ -106,13 +106,13 @@ protected static ContainerDescription fromContainer(IContainer container, boolea
currentContainer = (IContainer) resource;
} else if (i == 0) {
// parent does not exist and it is a project
firstCreatedParent = new ProjectDescription(root
firstCreatedParent = new ProjectSnapshot(root
.getProject(currentSegment));
currentContainerDescription = firstCreatedParent;
} else {
IFolder folderHandle = currentContainer.getFolder(IPath.fromOSString(currentSegment));
ContainerDescription currentFolder;
currentFolder = new FolderDescription(folderHandle, usingVirtualFolder);
ContainerSnapshot currentFolder;
currentFolder = new FolderSnapshot(folderHandle, usingVirtualFolder);
currentContainer = folderHandle;
if (currentContainerDescription != null) {
currentContainerDescription.addMember(currentFolder);
Expand All @@ -129,7 +129,7 @@ protected static ContainerDescription fromContainer(IContainer container, boolea
/**
* Create a ContainerDescription with no state.
*/
public ContainerDescription() {
public ContainerSnapshot() {

}

Expand All @@ -142,7 +142,7 @@ public ContainerDescription() {
* @param container
* the container to be described
*/
public ContainerDescription(IContainer container) {
public ContainerSnapshot(IContainer container) {
super(container);
this.name = container.getName();
if (container.isLinked()) {
Expand All @@ -152,9 +152,9 @@ public ContainerDescription(IContainer container) {
if (container.isAccessible()) {
defaultCharSet = container.getDefaultCharset(false);
IResource[] resourceMembers = container.members();
members = new AbstractResourceDescription[resourceMembers.length];
members = new AbstractResourceSnapshot[resourceMembers.length];
for (int i = 0; i < resourceMembers.length; i++) {
members[i] = (AbstractResourceDescription) ResourceDescription
members[i] = (AbstractResourceSnapshot) ResourceSnapshot
.fromResource(resourceMembers[i]);
}
}
Expand All @@ -180,7 +180,7 @@ protected final void createChildResources(IContainer parentHandle,
// restore any children
if (members != null && members.length > 0) {
SubMonitor subMonitor = SubMonitor.convert(monitor, members.length);
for (AbstractResourceDescription member : members) {
for (AbstractResourceSnapshot member : members) {
member.parent = parentHandle;
member.createResource(subMonitor.split(1));
}
Expand All @@ -190,16 +190,16 @@ protected final void createChildResources(IContainer parentHandle,
@Override
public void recordStateFromHistory(IResource resource, IProgressMonitor mon) throws CoreException {
if (members != null) {
SubMonitor subMonitor = SubMonitor.convert(mon, ResourceDescriptionMessages.FolderDescription_SavingUndoInfoProgress,
SubMonitor subMonitor = SubMonitor.convert(mon, ResourceSnapshotMessages.FolderDescription_SavingUndoInfoProgress,
members.length);
for (AbstractResourceDescription member : members) {
for (AbstractResourceSnapshot member : members) {
SubMonitor iterationMonitor = subMonitor.split(1);
if (member instanceof FileDescription) {
IPath path = resource.getFullPath().append(((FileDescription) member).name);
if (member instanceof FileSnapshot) {
IPath path = resource.getFullPath().append(((FileSnapshot) member).name);
IFile fileHandle = resource.getWorkspace().getRoot().getFile(path);
member.recordStateFromHistory(fileHandle, iterationMonitor);
} else if (member instanceof FolderDescription) {
IPath path = resource.getFullPath().append(((FolderDescription) member).name);
} else if (member instanceof FolderSnapshot) {
IPath path = resource.getFullPath().append(((FolderSnapshot) member).name);
IFolder folderHandle = resource.getWorkspace().getRoot().getFolder(path);
member.recordStateFromHistory(folderHandle, iterationMonitor);
}
Expand All @@ -223,15 +223,15 @@ public String getName() {
* @return the container description for the first child in the receiver
* that is a leaf, or this container if there are no children.
*/
public ContainerDescription getFirstLeafFolder() {
public ContainerSnapshot getFirstLeafFolder() {
// If there are no members, this is a leaf
if (members == null || members.length == 0) {
return this;
}
// Traverse the members and find the first potential leaf
for (AbstractResourceDescription member : members) {
if (member instanceof ContainerDescription) {
return ((ContainerDescription) member).getFirstLeafFolder();
for (AbstractResourceSnapshot member : members) {
if (member instanceof ContainerSnapshot) {
return ((ContainerSnapshot) member).getFirstLeafFolder();
}
}
// No child folders were found, this is a leaf
Expand All @@ -246,11 +246,11 @@ public ContainerDescription getFirstLeafFolder() {
* the resource description considered a member of this
* container.
*/
public void addMember(AbstractResourceDescription member) {
public void addMember(AbstractResourceSnapshot member) {
if (members == null) {
members = new AbstractResourceDescription[] { member };
members = new AbstractResourceSnapshot[] { member };
} else {
AbstractResourceDescription[] expandedMembers = new AbstractResourceDescription[members.length + 1];
AbstractResourceSnapshot[] expandedMembers = new AbstractResourceSnapshot[members.length + 1];
System.arraycopy(members, 0, expandedMembers, 0, members.length);
expandedMembers[members.length] = member;
members = expandedMembers;
Expand Down Expand Up @@ -295,7 +295,7 @@ public boolean verifyExistence(boolean checkMembers) {
if (checkMembers) {
// restore any children
if (members != null && members.length > 0) {
for (AbstractResourceDescription member : members) {
for (AbstractResourceSnapshot member : members) {
if (!member.verifyExistence(checkMembers)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.core.resources.descriptions;
package org.eclipse.core.resources.undo.snapshot;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -38,25 +38,24 @@
* @since 3.20
*
*/
public class FileDescription extends AbstractResourceDescription {
public class FileSnapshot extends AbstractResourceSnapshot {

String name;

URI location;

String charset;

private IFileContentDescription fileContentDescription;
private IFileContentSnapshot fileContentDescription;

/**
* Create a FileDescription that can be used to later restore the given
* file. The file typically already exists, but this constructor will not
* fail if the file does not exist.
* Create a FileSnapshot that can be used to later restore the given file. The
* file typically already exists, but this constructor will not fail if the file
* does not exist.
*
* @param file
* the file to be restored.
* @param file the file to be restored.
*/
public FileDescription(IFile file) {
public FileSnapshot(IFile file) {
super(file);
this.name = file.getName();
try {
Expand All @@ -71,23 +70,21 @@ public FileDescription(IFile file) {
}

/**
* Create a file description from the specified file handle. The handle does
* not exist, so no information should be derived from it. If a location
* path is specified, this file should represent a link to another location.
* The content description describes any state that should be used when the
* file resource is created.
* Create a file snapshot from the specified file handle. The handle does not
* exist, so no information should be derived from it. If a location path is
* specified, this file should represent a link to another location. The content
* description describes any state that should be used when the file resource is
* created.
*
* @param file
* the file to be described
* @param linkLocation
* the location of the file's link, or <code>null</code> if the
* file is not linked
* @param fileContentDescription
* the file content description that can be used to get
* information about the file, such as its initial content
* @param file the file to be described
* @param linkLocation the location of the file's link, or
* <code>null</code> if the file is not linked
* @param fileContentDescription the file content description that can be used
* to get information about the file, such as its
* initial content
*/
public FileDescription(IFile file, URI linkLocation,
IFileContentDescription fileContentDescription) {
public FileSnapshot(IFile file, URI linkLocation,
IFileContentSnapshot fileContentDescription) {
super(file);
this.name = file.getName();
this.location = linkLocation;
Expand All @@ -107,7 +104,7 @@ public void recordStateFromHistory(IResource resource,
IFileState[] states = ((IFile) resource).getHistory(monitor);
if (states.length > 0) {
final IFileState state = getMatchingFileState(states);
this.fileContentDescription = new IFileContentDescription() {
this.fileContentDescription = new IFileContentSnapshot() {
@Override
public boolean exists() {
return state.exists();
Expand Down Expand Up @@ -142,13 +139,13 @@ public void createExistentResourceFromHandle(IResource resource, IProgressMonito
}
IFile fileHandle = (IFile) resource;
SubMonitor subMonitor = SubMonitor.convert(mon, 200);
subMonitor.setTaskName(ResourceDescriptionMessages.FileDescription_NewFileProgress);
subMonitor.setTaskName(ResourceSnapshotMessages.FileDescription_NewFileProgress);
try {
if (location != null) {
fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, subMonitor.split(200));
} else {
InputStream contents = new ByteArrayInputStream(
ResourceDescriptionMessages.FileDescription_ContentsCouldNotBeRestored
ResourceSnapshotMessages.FileDescription_ContentsCouldNotBeRestored
.getBytes());
// Retrieve the contents from the file content
// description. Other file state attributes, such as timestamps,
Expand Down
Loading

0 comments on commit f6cf377

Please sign in to comment.