Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2016-09-09 09:32:31 +0000
committerSergey Prigogin2016-09-20 16:01:29 +0000
commita20d8ab3c79e1936315b2f15b9b9f5d4ee6a70d5 (patch)
tree50d2d8aef7f843ed8542e91de407b3032b1f9fc7 /org.eclipse.core.filebuffers
parent553d5cdf11633ddb611e861062fc7561a0f361d2 (diff)
downloadeclipse.platform.text-a20d8ab3c79e1936315b2f15b9b9f5d4ee6a70d5.tar.gz
eclipse.platform.text-a20d8ab3c79e1936315b2f15b9b9f5d4ee6a70d5.tar.xz
eclipse.platform.text-a20d8ab3c79e1936315b2f15b9b9f5d4ee6a70d5.zip
Bug 501121 - Remove org.eclipse.core.internal.filebuffers.Progress and
convert to SubMonitor Migrates the following classes to get started with the change - ResourceFileBuffer - RemoveTrailingWhitespaceOperation - TextFileBufferOperation - ResourceTextFileBuffer - ConvertLineDelimitersOperation Change-Id: Id607fdb868d264f102c09acbeb32b8ccdaf8ed47 Signed-off-by: Lars Vogel <Lars.Vogel@vogella
Diffstat (limited to 'org.eclipse.core.filebuffers')
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/ConvertLineDelimitersOperation.java14
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/RemoveTrailingWhitespaceOperation.java16
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/TextFileBufferOperation.java28
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java42
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java23
5 files changed, 41 insertions, 82 deletions
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/ConvertLineDelimitersOperation.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/ConvertLineDelimitersOperation.java
index f0bb8b6bc..b491edd92 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/ConvertLineDelimitersOperation.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/ConvertLineDelimitersOperation.java
@@ -11,13 +11,11 @@
package org.eclipse.core.filebuffers.manipulation;
import org.eclipse.core.internal.filebuffers.FileBuffersPlugin;
-import org.eclipse.core.internal.filebuffers.Progress;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.filebuffers.IFileBufferStatusCodes;
import org.eclipse.core.filebuffers.ITextFileBuffer;
@@ -55,30 +53,24 @@ public class ConvertLineDelimitersOperation extends TextFileBufferOperation {
IDocument document= fileBuffer.getDocument();
int lineCount= document.getNumberOfLines();
- progressMonitor= Progress.getMonitor(progressMonitor);
- progressMonitor.beginTask(FileBuffersMessages.ConvertLineDelimitersOperation_task_generatingChanges, lineCount);
+ SubMonitor subMonitor= SubMonitor.convert(progressMonitor, FileBuffersMessages.ConvertLineDelimitersOperation_task_generatingChanges, lineCount);
try {
MultiTextEditWithProgress multiEdit= new MultiTextEditWithProgress(FileBuffersMessages.ConvertLineDelimitersOperation_task_applyingChanges);
for (int i= 0; i < lineCount; i++) {
- if (progressMonitor.isCanceled())
- throw new OperationCanceledException();
-
final String delimiter= document.getLineDelimiter(i);
if (delimiter != null && delimiter.length() > 0 && !delimiter.equals(fLineDelimiter)) {
IRegion region= document.getLineInformation(i);
multiEdit.addChild(new ReplaceEdit(region.getOffset() + region.getLength(), delimiter.length(), fLineDelimiter));
}
- progressMonitor.worked(1);
+ subMonitor.step(1);
}
return multiEdit.getChildrenSize() <= 0 ? null : multiEdit;
} catch (BadLocationException x) {
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CONTENT_CHANGE_FAILED, "", x)); //$NON-NLS-1$
- } finally {
- progressMonitor.done();
}
}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/RemoveTrailingWhitespaceOperation.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/RemoveTrailingWhitespaceOperation.java
index 55b69af8b..026b51790 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/RemoveTrailingWhitespaceOperation.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/RemoveTrailingWhitespaceOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,13 +11,11 @@
package org.eclipse.core.filebuffers.manipulation;
import org.eclipse.core.internal.filebuffers.FileBuffersPlugin;
-import org.eclipse.core.internal.filebuffers.Progress;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.filebuffers.IFileBufferStatusCodes;
import org.eclipse.core.filebuffers.ITextFileBuffer;
@@ -48,16 +46,12 @@ public class RemoveTrailingWhitespaceOperation extends TextFileBufferOperation {
IDocument document= fileBuffer.getDocument();
int lineCount= document.getNumberOfLines();
- progressMonitor= Progress.getMonitor(progressMonitor);
- progressMonitor.beginTask(FileBuffersMessages.RemoveTrailingWhitespaceOperation_task_generatingChanges, lineCount);
+ SubMonitor subMonitor= SubMonitor.convert(progressMonitor, FileBuffersMessages.RemoveTrailingWhitespaceOperation_task_generatingChanges, lineCount);
try {
MultiTextEditWithProgress multiEdit= new MultiTextEditWithProgress(FileBuffersMessages.RemoveTrailingWhitespaceOperation_task_applyingChanges);
for (int i= 0; i < lineCount; i++) {
- if (progressMonitor.isCanceled())
- throw new OperationCanceledException();
-
IRegion region= document.getLineInformation(i);
if (region.getLength() == 0)
continue;
@@ -69,15 +63,13 @@ public class RemoveTrailingWhitespaceOperation extends TextFileBufferOperation {
++j;
if (j < lineExclusiveEnd)
multiEdit.addChild(new DeleteEdit(j, lineExclusiveEnd - j));
- progressMonitor.worked(1);
+ subMonitor.step(1);
}
return multiEdit.getChildrenSize() <= 0 ? null : multiEdit;
} catch (BadLocationException x) {
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CONTENT_CHANGE_FAILED, "", x)); //$NON-NLS-1$
- } finally {
- progressMonitor.done();
}
}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/TextFileBufferOperation.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/TextFileBufferOperation.java
index 37e96d2ad..a95e395b2 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/TextFileBufferOperation.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/filebuffers/manipulation/TextFileBufferOperation.java
@@ -13,14 +13,13 @@ package org.eclipse.core.filebuffers.manipulation;
import java.util.Map;
import org.eclipse.core.internal.filebuffers.FileBuffersPlugin;
-import org.eclipse.core.internal.filebuffers.Progress;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.filebuffers.IFileBuffer;
import org.eclipse.core.filebuffers.IFileBufferStatusCodes;
@@ -90,24 +89,15 @@ public abstract class TextFileBufferOperation implements IFileBufferOperation {
ITextFileBuffer textFileBuffer= (ITextFileBuffer) fileBuffer;
IPath path= textFileBuffer.getLocation();
String taskName= path == null ? getOperationName() : path.lastSegment();
- progressMonitor= Progress.getMonitor(progressMonitor);
- progressMonitor.beginTask(taskName, 100);
- try {
- IProgressMonitor subMonitor= Progress.getSubMonitor(progressMonitor, 10);
- MultiTextEditWithProgress edit= computeTextEdit(textFileBuffer, subMonitor);
- subMonitor.done();
- if (edit != null) {
- Map<String, IDocumentPartitioner> stateData= startRewriteSession(textFileBuffer);
- try {
- subMonitor= Progress.getSubMonitor(progressMonitor, 90);
- applyTextEdit(textFileBuffer, edit, subMonitor);
- subMonitor.done();
- } finally {
- stopRewriteSession(textFileBuffer, stateData);
- }
+ SubMonitor subMonitor= SubMonitor.convert(progressMonitor, taskName, 100);
+ MultiTextEditWithProgress edit= computeTextEdit(textFileBuffer, subMonitor.split(10));
+ if (edit != null) {
+ Map<String, IDocumentPartitioner> stateData= startRewriteSession(textFileBuffer);
+ try {
+ applyTextEdit(textFileBuffer, edit, subMonitor.split(90));
+ } finally {
+ stopRewriteSession(textFileBuffer, stateData);
}
- } finally {
- progressMonitor.done();
}
}
}
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 514911246..6c1c78125 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
@@ -23,7 +23,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.resources.IFile;
@@ -227,34 +227,28 @@ public abstract class ResourceFileBuffer extends AbstractFileBuffer {
@Override
public void create(IPath location, IProgressMonitor monitor) throws CoreException {
- monitor= Progress.getMonitor(monitor);
- monitor.beginTask(FileBuffersMessages.ResourceFileBuffer_task_creatingFileBuffer, 2);
-
- try {
- IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
- IFile file= workspaceRoot.getFile(location);
- URI uri= file.getLocationURI();
- if (uri == null) {
- String message= NLSUtility.format(FileBuffersMessages.ResourceFileBuffer_error_cannot_determine_URI, location);
- throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null));
- }
+ SubMonitor subMonitor= SubMonitor.convert(monitor, FileBuffersMessages.ResourceFileBuffer_task_creatingFileBuffer, 2);
+
+ IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
+ IFile file= workspaceRoot.getFile(location);
+ URI uri= file.getLocationURI();
+ if (uri == null) {
+ String message= NLSUtility.format(FileBuffersMessages.ResourceFileBuffer_error_cannot_determine_URI, location);
+ throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null));
+ }
- fLocation= location;
- fFile= file;
- fFileStore= EFS.getStore(uri);
- fFileSynchronizer= new FileSynchronizer();
+ fLocation= location;
+ fFile= file;
+ fFileStore= EFS.getStore(uri);
+ fFileSynchronizer= new FileSynchronizer();
- SubProgressMonitor subMonitor= new SubProgressMonitor(monitor, 1);
- initializeFileBufferContent(subMonitor);
- subMonitor.done();
+ initializeFileBufferContent(subMonitor.split(1));
- fSynchronizationStamp= fFile.getModificationStamp();
+ fSynchronizationStamp= fFile.getModificationStamp();
- addFileBufferContentListeners();
+ addFileBufferContentListeners();
+ subMonitor.step(1);
- } finally {
- monitor.done();
- }
}
@Override
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
index 465995a4b..27926a476 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
@@ -34,7 +34,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.content.IContentType;
@@ -384,26 +384,17 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
}
} else {
+ SubMonitor subMonitor= SubMonitor.convert(monitor, FileBuffersMessages.ResourceTextFileBuffer_task_saving, 2);
+ ContainerCreator creator= new ContainerCreator(fFile.getWorkspace(), fFile.getParent().getFullPath());
+ creator.createContainer(subMonitor.split(1));
+
+ fFile.create(stream, false, subMonitor.split(1));
- monitor= Progress.getMonitor(monitor);
- try {
- monitor.beginTask(FileBuffersMessages.ResourceTextFileBuffer_task_saving, 2);
- ContainerCreator creator = new ContainerCreator(fFile.getWorkspace(), fFile.getParent().getFullPath());
- IProgressMonitor subMonitor= new SubProgressMonitor(monitor, 1);
- creator.createContainer(subMonitor);
- subMonitor.done();
-
- subMonitor= new SubProgressMonitor(monitor, 1);
- fFile.create(stream, false, subMonitor);
- subMonitor.done();
-
- } finally {
- monitor.done();
- }
// set synchronization stamp to know whether the file synchronizer must become active
fSynchronizationStamp= fFile.getModificationStamp();
+ subMonitor.step(1);
// TODO commit persistable annotation model
}

Back to the top