1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-10-30 20:11:51 -07:00
parent 5e8ca6778d
commit 8da748eb55
3 changed files with 19 additions and 46 deletions

View file

@ -22,33 +22,29 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*
*/ */
public class FileContentHelper { public class FileContentHelper {
private static final int BUFFER_SIZE = 2048;
private static final int bufferSize = 512;
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); InputStreamReader reader = getReaderForFile(file);
skip(start, reader); skip(start, reader);
final String rest = readRest(reader); final String rest = readRest(reader);
reader.close(); reader.close();
return rest; return rest;
} }
public static String getContent(IFile file, int start, int length) { public static String getContent(IFile file, int start, int length) {
try { try {
InputStreamReader r = getReaderForFile(file); InputStreamReader r = getReaderForFile(file);
char[] bytes = new char[length]; char[] chars = new char[length];
skip(start, r); skip(start, r);
read(length, r, bytes); read(length, r, chars);
r.close(); r.close();
return new String(bytes); return new String(chars);
} catch (IOException e) { } catch (IOException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} catch (CoreException e) { } catch (CoreException e) {
@ -60,24 +56,21 @@ public class FileContentHelper {
private static InputStreamReader getReaderForFile(IFile file) private static InputStreamReader getReaderForFile(IFile file)
throws CoreException, UnsupportedEncodingException { throws CoreException, UnsupportedEncodingException {
InputStream contents = file.getContents(); InputStream contents = file.getContents();
InputStreamReader r = new InputStreamReader(contents, file.getCharset()); return new InputStreamReader(contents, file.getCharset());
return r;
} }
private static String readRest(InputStreamReader reader) throws IOException { private static String readRest(InputStreamReader reader) throws IOException {
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
char[] buffer = new char[bufferSize]; char[] buffer = new char[BUFFER_SIZE];
int bytesRead = 0; int bytesRead = 0;
while ((bytesRead = reader.read(buffer)) >= 0) { while ((bytesRead = reader.read(buffer)) >= 0) {
content.append(buffer, 0, bytesRead); content.append(buffer, 0, bytesRead);
} }
return content.toString(); return content.toString();
} }
private static void read(int length, InputStreamReader r, char[] bytes) private static void read(int length, InputStreamReader r, char[] bytes) throws IOException {
throws IOException {
int bufferOffset = 0; int bufferOffset = 0;
int charactersRead = 0; int charactersRead = 0;
while (charactersRead >= 0 && length > 0) { while (charactersRead >= 0 && length > 0) {
@ -98,5 +91,4 @@ public class FileContentHelper {
} }
} }
} }
} }

View file

@ -34,9 +34,6 @@ public class SimpleScanner {
private boolean fSplitPreprocessor; private boolean fSplitPreprocessor;
private final StringBuilder fUniversalCharBuffer= new StringBuilder(); private final StringBuilder fUniversalCharBuffer= new StringBuilder();
/**
*
*/
public SimpleScanner() { public SimpleScanner() {
super(); super();
} }
@ -736,8 +733,7 @@ public class SimpleScanner {
matchStringLiteral(); matchStringLiteral();
c= getChar(); c= getChar();
break; break;
} } else {
else {
ungetChar(c); ungetChar(c);
return newPreprocessorToken(); return newPreprocessorToken();
} }
@ -752,8 +748,7 @@ public class SimpleScanner {
ungetChar(next); ungetChar(next);
ungetChar(c); ungetChar(c);
result= newPreprocessorToken(); result= newPreprocessorToken();
} } else {
else {
matchSinglelineComment(); matchSinglelineComment();
result= newToken(Token.tLINECOMMENT); result= newToken(Token.tLINECOMMENT);
} }

View file

@ -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.DocumentAdapter;
import org.eclipse.cdt.internal.ui.refactoring.UndoCTextFileChange; import org.eclipse.cdt.internal.ui.refactoring.UndoCTextFileChange;
/** /**
* A TextFileChange that uses a working copy in order to generate CModel events. * 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); setTextType(TEXT_TYPE);
} }
/*
* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.TextFileChange#acquireDocument(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override @Override
protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException { protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException {
IDocument doc= super.acquireDocument(pm); 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 { protected void commit(final IDocument document, final IProgressMonitor pm) throws CoreException {
if (fWorkingCopy == null) { if (fWorkingCopy == null) {
super.commit(document, pm); super.commit(document, pm);
} } else if (needsSaving()) {
else if (needsSaving()) {
fWorkingCopy.commit(false, pm); 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 @Override
protected void releaseDocument(IDocument document, IProgressMonitor pm) throws CoreException { protected void releaseDocument(IDocument document, IProgressMonitor pm) throws CoreException {
super.releaseDocument(document, pm); super.releaseDocument(document, pm);
@ -106,10 +96,6 @@ 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 @Override
protected Change createUndoChange(UndoEdit edit, ContentStamp stampToRestore) { protected Change createUndoChange(UndoEdit edit, ContentStamp stampToRestore) {
return new UndoCTextFileChange(getName(), getFile(), edit, stampToRestore, getSaveMode()); return new UndoCTextFileChange(getName(), getFile(), edit, stampToRestore, getSaveMode());