Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java38
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/CTextFileChange.java18
3 files changed, 19 insertions, 46 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
index 6c8aaa8c51f..8fc40a49d76 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.util;
@@ -22,33 +22,29 @@ import org.eclipse.core.runtime.CoreException;
/**
* @author Emanuel Graf IFS
- *
*/
public class FileContentHelper {
-
- private static final int bufferSize = 512;
+ private static final int BUFFER_SIZE = 2048;
- public static String getContent(IFile file, int start) throws CoreException, IOException{
-
+ public static String getContent(IFile file, int start) throws CoreException, IOException {
InputStreamReader reader = getReaderForFile(file);
skip(start, reader);
final String rest = readRest(reader);
reader.close();
return rest;
-
}
public static String getContent(IFile file, int start, int length) {
try {
InputStreamReader r = getReaderForFile(file);
- char[] bytes = new char[length];
+ char[] chars = new char[length];
skip(start, r);
- read(length, r, bytes);
+ read(length, r, chars);
r.close();
- return new String(bytes);
+ return new String(chars);
} catch (IOException e) {
CCorePlugin.log(e);
} catch (CoreException e) {
@@ -60,29 +56,26 @@ public class FileContentHelper {
private static InputStreamReader getReaderForFile(IFile file)
throws CoreException, UnsupportedEncodingException {
InputStream contents = file.getContents();
- InputStreamReader r = new InputStreamReader(contents, file.getCharset());
- return r;
+ return new InputStreamReader(contents, file.getCharset());
}
- private static String readRest(InputStreamReader reader) throws IOException{
+ private static String readRest(InputStreamReader reader) throws IOException {
StringBuilder content = new StringBuilder();
- char[] buffer = new char[bufferSize];
+ char[] buffer = new char[BUFFER_SIZE];
int bytesRead = 0;
- while((bytesRead = reader.read(buffer)) >= 0){
+ while ((bytesRead = reader.read(buffer)) >= 0) {
content.append(buffer, 0, bytesRead);
}
-
return content.toString();
}
- private static void read(int length, InputStreamReader r, char[] bytes)
- throws IOException {
+ private static void read(int length, InputStreamReader r, char[] bytes) throws IOException {
int bufferOffset = 0;
int charactersRead = 0;
- while(charactersRead >= 0 && length > 0){
+ while (charactersRead >= 0 && length > 0) {
charactersRead = r.read(bytes, bufferOffset, length);
- if(charactersRead > 0){
+ if (charactersRead > 0) {
bufferOffset += charactersRead;
length -= charactersRead;
}
@@ -91,12 +84,11 @@ public class FileContentHelper {
private static void skip(int start, InputStreamReader r) throws IOException {
long skipped = 0;
- while(skipped >= 0 && start > 0 && r.ready()){
+ while (skipped >= 0 && start > 0 && r.ready()) {
skipped = r.skip(start);
- if(skipped > 0){
+ if (skipped > 0) {
start -= skipped;
}
}
}
-
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java
index e536b53d38f..e4517d1523a 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java
@@ -34,9 +34,6 @@ public class SimpleScanner {
private boolean fSplitPreprocessor;
private final StringBuilder fUniversalCharBuffer= new StringBuilder();
- /**
- *
- */
public SimpleScanner() {
super();
}
@@ -736,8 +733,7 @@ public class SimpleScanner {
matchStringLiteral();
c= getChar();
break;
- }
- else {
+ } else {
ungetChar(c);
return newPreprocessorToken();
}
@@ -752,8 +748,7 @@ public class SimpleScanner {
ungetChar(next);
ungetChar(c);
result= newPreprocessorToken();
- }
- else {
+ } else {
matchSinglelineComment();
result= newToken(Token.tLINECOMMENT);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/CTextFileChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/CTextFileChange.java
index 8c339a7237a..e4042acb048 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/CTextFileChange.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/CTextFileChange.java
@@ -31,7 +31,6 @@ import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.ui.refactoring.DocumentAdapter;
import org.eclipse.cdt.internal.ui.refactoring.UndoCTextFileChange;
-
/**
* A TextFileChange that uses a working copy in order to generate CModel events.
*
@@ -63,10 +62,6 @@ public class CTextFileChange extends TextFileChange {
setTextType(TEXT_TYPE);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.TextFileChange#acquireDocument(org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException {
IDocument doc= super.acquireDocument(pm);
@@ -85,16 +80,11 @@ public class CTextFileChange extends TextFileChange {
protected void commit(final IDocument document, final IProgressMonitor pm) throws CoreException {
if (fWorkingCopy == null) {
super.commit(document, pm);
- }
- else if (needsSaving()) {
+ } else if (needsSaving()) {
fWorkingCopy.commit(false, pm);
}
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.TextFileChange#releaseDocument(org.eclipse.jface.text.IDocument, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
protected void releaseDocument(IDocument document, IProgressMonitor pm) throws CoreException {
super.releaseDocument(document, pm);
@@ -105,11 +95,7 @@ public class CTextFileChange extends TextFileChange {
}
}
}
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.TextFileChange#createUndoChange(org.eclipse.text.edits.UndoEdit, org.eclipse.ltk.core.refactoring.ContentStamp)
- */
+
@Override
protected Change createUndoChange(UndoEdit edit, ContentStamp stampToRestore) {
return new UndoCTextFileChange(getName(), getFile(), edit, stampToRestore, getSaveMode());

Back to the top