diff options
author | Kai Maetzel | 2003-10-16 20:32:00 +0000 |
---|---|---|
committer | Kai Maetzel | 2003-10-16 20:32:00 +0000 |
commit | eaf219352f0f928c33d6493a9a3afb965a1e882d (patch) | |
tree | eed182644e00c2d431c6dc99e24658d67710abc8 /org.eclipse.core.filebuffers | |
parent | ba48a53e9934936552c423bf2f5c457ca3c34bd2 (diff) | |
download | eclipse.platform.text-eaf219352f0f928c33d6493a9a3afb965a1e882d.tar.gz eclipse.platform.text-eaf219352f0f928c33d6493a9a3afb965a1e882d.tar.xz eclipse.platform.text-eaf219352f0f928c33d6493a9a3afb965a1e882d.zip |
*** empty log message ***
Diffstat (limited to 'org.eclipse.core.filebuffers')
6 files changed, 86 insertions, 87 deletions
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java index 83df569e7..6f73ded95 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/FileBuffers.java @@ -11,6 +11,10 @@ Contributors: package org.eclipse.core.filebuffers; import org.eclipse.core.internal.filebuffers.FileBuffersPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; /** * Facade for the file buffers plug-in. Provides access to the @@ -34,4 +38,38 @@ public final class FileBuffers { public static ITextFileBufferManager getTextFileBufferManager() { return FileBuffersPlugin.getDefault().getFileBufferManager(); } + + /** + * Returns the workspace file at the given location or <code>null</code> if + * the location is not a valid location in the workspace. + * + * @param location the location + * @return the workspace file at the location or <code>null</code> + */ + public static IFile getWorkspaceFileAtLocation(IPath location) { + IPath normalized= normalizeLocation(location); + IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); + IFile file= workspaceRoot.getFile(normalized); + if (file != null && file.exists()) + return file; + return null; + } + + /** + * Returns a copy of the given location in a normalized form. + * + * @param location the location to be normalized + * @return normalized copy of location + */ + public static IPath normalizeLocation(IPath location) { + IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); + IPath workspacePath= workspaceRoot.getLocation(); + if (!workspacePath.isPrefixOf(location)) + return location.makeAbsolute(); + + IPath fileLocation= location.removeFirstSegments(workspacePath.segmentCount()); + fileLocation= fileLocation.setDevice(null); + return fileLocation.makeAbsolute(); + + } } diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java index d40f625bb..8ae2afeea 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBuffer.java @@ -31,15 +31,9 @@ public interface IFileBuffer { /** * Returns the location of this file buffer. * <p> - * The returned location fulfills the following requirements: + * The location is either a full path of a workspace resource or an + * absolute path in the local file system. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the file buffer as been provided for a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @return the location of this file buffer */ diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java index 8f3ba88fe..f0e7cae7f 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/IFileBufferManager.java @@ -34,15 +34,11 @@ public interface IFileBufferManager { * successfully completed it is guaranteed that each call to <code>getFileBuffer</code> * returns the same file buffer until <code>disconnect</code> is called. * <p> - * The provided location must fulfill the following requirements: + * The provided location is either a full path of a workspace resource or + * an absolute path in the local file system. The file buffer manager does + * not resolve the location of workspace resources in the case of linked + * resources. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the location is the location of a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @param location the location of the file to be connected * @param monitor the progress monitor @@ -55,15 +51,11 @@ public interface IFileBufferManager { * call successfully completed there is no guarantee that <code>getFileBuffer</code> * will return a valid file buffer. * <p> - * The provided location must fulfill the following requirements: + * The provided location is either a full path of a workspace resource or + * an absolute path in the local file system. The file buffer manager does + * not resolve the location of workspace resources in the case of linked + * resources. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the location is the location of a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @param location the location of the file to be disconnected * @param monitor the progress monitor @@ -75,15 +67,11 @@ public interface IFileBufferManager { * Returns the file buffer managed for the given location or <code>null</code> * if there is no such file buffer. * <p> - * The provided location must fulfill the following requirements: + * The provided location is either a full path of a workspace resource or + * an absolute path in the local file system. The file buffer manager does + * not resolve the location of workspace resources in the case of linked + * resources. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the location is the location of a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @param location the location * @return the file buffer managed for that location or <code>null</code> @@ -104,15 +92,11 @@ public interface IFileBufferManager { * given location with its file buffer. This call as no effect if there is * no file buffer managed for the given location. * <p> - * The provided location must fulfill the following requirements: + * The provided location is either a full path of a workspace resource or + * an absolute path in the local file system. The file buffer manager does + * not resolve the location of workspace resources in the case of linked + * resources. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the location is the location of a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @param location the location */ @@ -123,15 +107,11 @@ public interface IFileBufferManager { * the given location. This method has no effect if there is no file buffer * managed for this location. * <p> - * The provided location must fulfill the following requirements: + * The provided location is either a full path of a workspace resource or + * an absolute path in the local file system. The file buffer manager does + * not resolve the location of workspace resources in the case of linked + * resources. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the location is the location of a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @param location the location */ diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java index d1e6e658a..6897cdf56 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/ITextFileBufferManager.java @@ -28,15 +28,11 @@ public interface ITextFileBufferManager extends IFileBufferManager { * Returns the text file buffer managed for the file at the given location * or <code>null</code> if either there is no such text file buffer. * <p> - * The provided location must fulfill the following requirements: + * The provided location is either a full path of a workspace resource or + * an absolute path in the local file system. The file buffer manager does + * not resolve the location of workspace resources in the case of linked + * resources. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the location is the location of a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @param location the location * @return the text file buffer managed for that location or <code>null</code> @@ -55,15 +51,11 @@ public interface ITextFileBufferManager extends IFileBufferManager { * Creates a new empty document . The document is set up in the same way as * it would be used in a text file buffer for a file at the given location. * <p> - * The provided location must fulfill the following requirements: + * The provided location is either a full path of a workspace resource or + * an absolute path in the local file system. The file buffer manager does + * not resolve the location of workspace resources in the case of linked + * resources. * </p> - * <ul> - * <li>It is given as an absolute path in the local file system.</li> - * <li>If the location is the location of a workspace resource, the - * location describes the location inside the workspace. I.e. for linked - * resources the location is the unresolved location and the not the - * resolved location to the lnked resource's local content.</li> - * </ul> * * @param location the location used to set up the newly created document * @return a new empty document diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java index 34d35d32e..2964a13a0 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java @@ -28,6 +28,8 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.core.filebuffers.FileBuffers; + public abstract class ResourceFileBuffer extends AbstractFileBuffer { @@ -215,7 +217,7 @@ public abstract class ResourceFileBuffer extends AbstractFileBuffer { abstract protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException; public void create(IPath location, IProgressMonitor monitor) throws CoreException { - IFile file= fManager.getWorkspaceFileAtLocation(location); + IFile file= FileBuffers.getWorkspaceFileAtLocation(location); if (file == null || !file.exists()) throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, "File does not exist", null)); diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java index 34382dcbb..e26855620 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java @@ -16,8 +16,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -25,6 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.filebuffers.FileBuffers; import org.eclipse.core.filebuffers.IDocumentFactory; import org.eclipse.core.filebuffers.IDocumentSetupParticipant; import org.eclipse.core.filebuffers.IFileBuffer; @@ -57,6 +56,8 @@ public class TextFileBufferManager implements ITextFileBufferManager { */ public void connect(IPath location, IProgressMonitor monitor) throws CoreException { Assert.isNotNull(location); + location= FileBuffers.normalizeLocation(location); + AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location); if (fileBuffer == null) { @@ -79,6 +80,8 @@ public class TextFileBufferManager implements ITextFileBufferManager { */ public void disconnect(IPath location, IProgressMonitor monitor) throws CoreException { Assert.isNotNull(location); + location= FileBuffers.normalizeLocation(location); + AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location); if (fileBuffer != null) { fileBuffer.disconnect(); @@ -99,27 +102,8 @@ public class TextFileBufferManager implements ITextFileBufferManager { return new JavaTextFileBuffer(this); } - /** - * Returns the workspace file at the given location or <code>null</code> if - * the location is not a valid location in the workspace. - * - * @param location the location - * @return the workspace file at the location or <code>null</code> - */ - public IFile getWorkspaceFileAtLocation(IPath location) { - IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); - IPath workspacePath= workspaceRoot.getLocation(); - if (workspacePath.isPrefixOf(location)) { - IPath fileLocation= location.removeFirstSegments(workspacePath.segmentCount()); - IFile file= workspaceRoot.getFile(fileLocation); - if (file != null && file.exists()) - return file; - } - return null; - } - private boolean isWorkspaceResource(IPath location) { - return getWorkspaceFileAtLocation(location) != null; + return FileBuffers.getWorkspaceFileAtLocation(location) != null; } private boolean isTextFile(IPath location) { @@ -130,6 +114,7 @@ public class TextFileBufferManager implements ITextFileBufferManager { * @see org.eclipse.core.filebuffers.IFileBufferManager#getFileBuffer(org.eclipse.core.runtime.IPath) */ public IFileBuffer getFileBuffer(IPath location) { + location= FileBuffers.normalizeLocation(location); return (IFileBuffer) fFilesBuffers.get(location); } @@ -137,6 +122,7 @@ public class TextFileBufferManager implements ITextFileBufferManager { * @see org.eclipse.core.filebuffers.ITextFileBufferManager#getTextFileBuffer(org.eclipse.core.runtime.IPath) */ public ITextFileBuffer getTextFileBuffer(IPath location) { + location= FileBuffers.normalizeLocation(location); return (ITextFileBuffer) fFilesBuffers.get(location); } @@ -151,6 +137,9 @@ public class TextFileBufferManager implements ITextFileBufferManager { * @see org.eclipse.core.filebuffers.ITextFileBufferManager#createEmptyDocument(org.eclipse.core.runtime.IPath) */ public IDocument createEmptyDocument(IPath location) { + Assert.isNotNull(location); + location= FileBuffers.normalizeLocation(location); + IDocumentFactory factory= fRegistry.getDocumentFactory(location); IDocument document= null; @@ -197,6 +186,8 @@ public class TextFileBufferManager implements ITextFileBufferManager { */ public void requestSynchronizationContext(IPath location) { Assert.isNotNull(location); + location= FileBuffers.normalizeLocation(location); + AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location); if (fileBuffer != null) fileBuffer.requestSynchronizationContext(); @@ -207,6 +198,8 @@ public class TextFileBufferManager implements ITextFileBufferManager { */ public void releaseSynchronizationContext(IPath location) { Assert.isNotNull(location); + location= FileBuffers.normalizeLocation(location); + AbstractFileBuffer fileBuffer= (AbstractFileBuffer) fFilesBuffers.get(location); if (fileBuffer != null) fileBuffer.releaseSynchronizationContext(); |