Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-07-26 06:39:27 +0000
committerEike Stepper2012-07-26 06:39:27 +0000
commit484f99da1a8e32fecb8f0e8dc2995feae6975ae7 (patch)
tree43244c9bfb8dfc06135dcbc9c83d9ebf14f4f83c /plugins
parent1734aeaae08c9204fbbae064afc075aec07a8a6c (diff)
downloadcdo-484f99da1a8e32fecb8f0e8dc2995feae6975ae7.tar.gz
cdo-484f99da1a8e32fecb8f0e8dc2995feae6975ae7.tar.xz
cdo-484f99da1a8e32fecb8f0e8dc2995feae6975ae7.zip
Use ITextFileBuffer for quick fixes
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.ui/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java66
2 files changed, 46 insertions, 24 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.releng.version.ui/META-INF/MANIFEST.MF
index e1f46ebc58..bd2d21560c 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.releng.version.ui/META-INF/MANIFEST.MF
@@ -11,6 +11,8 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Require-Bundle: org.eclipse.emf.cdo.releng.version;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
org.eclipse.ui;bundle-version="[3.4.0,4.0.0)";visibility:=reexport,
- org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)";visibility:=reexport
+ org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)";visibility:=reexport,
+ org.eclipse.core.filebuffers;bundle-version="[3.5.0,4.0.0)",
+ org.eclipse.jface.text;bundle-version="[3.8.0,4.0.0)"
Export-Package: org.eclipse.emf.cdo.releng.version.ui;version="1.0.0"
Eclipse-BuddyPolicy: dependent
diff --git a/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java b/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java
index 184f2ae839..07cb2072b4 100644
--- a/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java
+++ b/plugins/org.eclipse.emf.cdo.releng.version.ui/src/org/eclipse/emf/cdo/releng/version/ui/QuickFixer.java
@@ -12,18 +12,19 @@ package org.eclipse.emf.cdo.releng.version.ui;
import org.eclipse.emf.cdo.releng.version.Markers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.CharArrayWriter;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@@ -92,37 +93,56 @@ public class QuickFixer implements IMarkerResolutionGenerator2
if (regEx != null)
{
IFile file = (IFile)marker.getResource();
- InputStream contents = file.getContents();
- BufferedReader reader = new BufferedReader(new InputStreamReader(contents, file.getCharset()));
- CharArrayWriter caw = new CharArrayWriter();
- int c;
- while ((c = reader.read()) != -1)
- {
- caw.write(c);
- }
+ IPath fullPath = file.getFullPath();
+ ITextFileBufferManager.DEFAULT.connect(fullPath, LocationKind.IFILE, new NullProgressMonitor());
+ ITextFileBuffer buffer = ITextFileBufferManager.DEFAULT.getTextFileBuffer(fullPath, LocationKind.IFILE);
+ boolean wasDirty = buffer.isDirty();
+
+ IDocument document = buffer.getDocument();
+ String content = document.get();
+
+ // InputStream contents = file.getContents();
+ // BufferedReader reader = new BufferedReader(new InputStreamReader(contents, file.getCharset()));
+ // CharArrayWriter caw = new CharArrayWriter();
+ //
+ // int c;
+ // while ((c = reader.read()) != -1)
+ // {
+ // caw.write(c);
+ // }
+ //
+ // String content = caw.toString();
- String string = caw.toString();
Pattern pattern = Pattern.compile(regEx, Pattern.MULTILINE | Pattern.DOTALL);
- Matcher matcher = pattern.matcher(string);
+ Matcher matcher = pattern.matcher(content);
if (matcher.find())
{
- String before;
- String after;
+ int start;
+ int end;
if (replacement != null)
{
- before = string.substring(0, matcher.start(1));
- after = string.substring(matcher.end(1));
+ start = matcher.start(1);
+ end = matcher.end(1);
}
else
{
- before = string.substring(0, matcher.start());
- after = string.substring(matcher.end());
+ start = matcher.start();
+ end = matcher.end();
replacement = "";
}
- file.setContents(new ByteArrayInputStream((before + replacement + after).getBytes(file.getCharset())), true, true,
- null);
+ document.replace(start, end - start, replacement);
+
+ // file.setContents(new ByteArrayInputStream((before + replacement + after).getBytes(file.getCharset())),
+ // true, true, null);
+
+ if (!wasDirty && !buffer.isShared())
+ {
+ buffer.commit(new NullProgressMonitor(), true);
+ }
+
+ ITextFileBufferManager.DEFAULT.disconnect(fullPath, LocationKind.IFILE, new NullProgressMonitor());
}
}
}

Back to the top