1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Use StringBuilder

This commit is contained in:
Anton Leherbauer 2008-05-15 08:53:15 +00:00
parent fec33bb137
commit 5f53601812
5 changed files with 109 additions and 109 deletions

View file

@ -224,9 +224,9 @@ public class IndentAction extends TextEditorAction {
wsStart= offset + slashes; wsStart= offset + slashes;
StringBuffer computed= indenter.computeIndentation(offset); StringBuilder computed= indenter.computeIndentation(offset);
if (computed == null) if (computed == null)
computed= new StringBuffer(0); computed= new StringBuilder(0);
int tabSize= getTabSize(); int tabSize= getTabSize();
while (slashes > 0 && computed.length() > 0) { while (slashes > 0 && computed.length() > 0) {
char c= computed.charAt(0); char c= computed.charAt(0);
@ -251,7 +251,7 @@ public class IndentAction extends TextEditorAction {
// standard C code indentation // standard C code indentation
if (indent == null) { if (indent == null) {
StringBuffer computed= indenter.computeIndentation(offset); StringBuilder computed= indenter.computeIndentation(offset);
if (computed != null) if (computed != null)
indent= computed.toString(); indent= computed.toString();
else else

View file

@ -181,10 +181,10 @@ public final class IndentUtil {
boolean indentInsideLineComments= indentInsideLineComments(project); boolean indentInsideLineComments= indentInsideLineComments(project);
String current= getCurrentIndent(document, lines.getStartLine(), indentInsideLineComments); String current= getCurrentIndent(document, lines.getStartLine(), indentInsideLineComments);
StringBuffer correct= new StringBuffer(computeIndent(document, lines.getStartLine(), indenter, scanner)); StringBuilder correct= new StringBuilder(computeIndent(document, lines.getStartLine(), indenter, scanner));
int tabSize= CodeFormatterUtil.getTabWidth(project); int tabSize= CodeFormatterUtil.getTabWidth(project);
StringBuffer addition= new StringBuffer(); StringBuilder addition= new StringBuilder();
int difference= subtractIndent(correct, current, addition, tabSize); int difference= subtractIndent(correct, current, addition, tabSize);
if (difference == 0) if (difference == 0)
@ -308,7 +308,7 @@ public final class IndentUtil {
* @param difference a string buffer - if the return value is positive, it will be cleared and set to the substring of <code>current</code> of that length * @param difference a string buffer - if the return value is positive, it will be cleared and set to the substring of <code>current</code> of that length
* @return the difference in lenght of <code>correct</code> and <code>current</code> * @return the difference in lenght of <code>correct</code> and <code>current</code>
*/ */
private static int subtractIndent(CharSequence correct, CharSequence current, StringBuffer difference, int tabSize) { private static int subtractIndent(CharSequence correct, CharSequence current, StringBuilder difference, int tabSize) {
int c1= computeVisualLength(correct, tabSize); int c1= computeVisualLength(correct, tabSize);
int c2= computeVisualLength(current, tabSize); int c2= computeVisualLength(current, tabSize);
int diff= c1 - c2; int diff= c1 - c2;
@ -454,7 +454,7 @@ public final class IndentUtil {
// standard C code indentation // standard C code indentation
if (indent == null) { if (indent == null) {
StringBuffer computed= indenter.computeIndentation(offset); StringBuilder computed= indenter.computeIndentation(offset);
if (computed != null) if (computed != null)
indent= computed.toString(); indent= computed.toString();
else else
@ -517,7 +517,7 @@ public final class IndentUtil {
// standard C code indentation // standard C code indentation
if (indent == null) { if (indent == null) {
StringBuffer computed= indenter.computeIndentation(offset); StringBuilder computed= indenter.computeIndentation(offset);
if (computed != null) if (computed != null)
indent= computed.toString(); indent= computed.toString();
else else
@ -559,7 +559,7 @@ public final class IndentUtil {
int previousLineLength= previousLine.getLength(); int previousLineLength= previousLine.getLength();
int previousLineEnd= previousLineStart + previousLineLength; int previousLineEnd= previousLineStart + previousLineLength;
StringBuffer buf= new StringBuffer(); StringBuilder buf= new StringBuilder();
int previousLineNonWS= scanner.findNonWhitespaceForwardInAnyPartition(previousLineStart, previousLineEnd); int previousLineNonWS= scanner.findNonWhitespaceForwardInAnyPartition(previousLineStart, previousLineEnd);
if (previousLineNonWS == CHeuristicScanner.NOT_FOUND || document.getChar(previousLineNonWS) != '*') { if (previousLineNonWS == CHeuristicScanner.NOT_FOUND || document.getChar(previousLineNonWS) != '*') {
// align with the comment start if the previous line is not an asterix line // align with the comment start if the previous line is not an asterix line
@ -598,9 +598,9 @@ public final class IndentUtil {
CHeuristicScanner ppScanner= new CHeuristicScanner(document, ICPartitions.C_PARTITIONING, partition.getType()); CHeuristicScanner ppScanner= new CHeuristicScanner(document, ICPartitions.C_PARTITIONING, partition.getType());
CIndenter ppIndenter= new CIndenter(document, ppScanner); CIndenter ppIndenter= new CIndenter(document, ppScanner);
if (line == ppFirstLine + 1) { if (line == ppFirstLine + 1) {
return ppIndenter.createReusingIndent(new StringBuffer(), 1).toString(); return ppIndenter.createReusingIndent(new StringBuilder(), 1).toString();
} }
StringBuffer computed= ppIndenter.computeIndentation(document.getLineOffset(line), false); StringBuilder computed= ppIndenter.computeIndentation(document.getLineOffset(line), false);
if (computed != null) { if (computed != null) {
return computed.toString(); return computed.toString();
} }
@ -612,7 +612,7 @@ public final class IndentUtil {
int previousLineNonWS= ppScanner.findNonWhitespaceForwardInAnyPartition(previousLineStart, previousLineEnd); int previousLineNonWS= ppScanner.findNonWhitespaceForwardInAnyPartition(previousLineStart, previousLineEnd);
String previousIndent= document.get(previousLineStart, previousLineNonWS - previousLineStart); String previousIndent= document.get(previousLineStart, previousLineNonWS - previousLineStart);
computed= new StringBuffer(previousIndent); computed= new StringBuilder(previousIndent);
return computed.toString(); return computed.toString();
} }
@ -628,7 +628,7 @@ public final class IndentUtil {
if (column > displayedWidth) { if (column > displayedWidth) {
return prefix; return prefix;
} }
final StringBuffer buffer = new StringBuffer(prefix); final StringBuilder buffer = new StringBuilder(prefix);
appendIndent(buffer, displayedWidth, tabWidth, useSpaces, column); appendIndent(buffer, displayedWidth, tabWidth, useSpaces, column);
return buffer.toString(); return buffer.toString();
} }
@ -640,9 +640,9 @@ public final class IndentUtil {
* @param tabWidth the configured tab width * @param tabWidth the configured tab width
* @param useSpaces whether tabs should be substituted by spaces * @param useSpaces whether tabs should be substituted by spaces
* @param startColumn the column where to start measurement * @param startColumn the column where to start measurement
* @return StringBuffer * @return StringBuilder
*/ */
private static StringBuffer appendIndent(StringBuffer buffer, int width, int tabWidth, boolean useSpaces, int startColumn) { private static StringBuilder appendIndent(StringBuilder buffer, int width, int tabWidth, boolean useSpaces, int startColumn) {
assert tabWidth > 0; assert tabWidth > 0;
int tabStop = startColumn - startColumn % tabWidth; int tabStop = startColumn - startColumn % tabWidth;
int tabs = useSpaces ? 0 : (width-tabStop) / tabWidth; int tabs = useSpaces ? 0 : (width-tabStop) / tabWidth;

View file

@ -49,15 +49,15 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
private static final String LINE_COMMENT= "//"; //$NON-NLS-1$ private static final String LINE_COMMENT= "//"; //$NON-NLS-1$
// private static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration(); // private static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
private static class CompilationUnitInfo { // private static class CompilationUnitInfo {
char[] buffer; // char[] buffer;
int delta; // int delta;
//
CompilationUnitInfo(char[] buffer, int delta) { // CompilationUnitInfo(char[] buffer, int delta) {
this.buffer = buffer; // this.buffer = buffer;
this.delta = delta; // this.delta = delta;
} // }
} // }
private boolean fCloseBrace; private boolean fCloseBrace;
private boolean fIsSmartMode; private boolean fIsSmartMode;
@ -186,7 +186,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
int indLine = d.getLineOfOffset(reference); int indLine = d.getLineOfOffset(reference);
if (indLine != -1 && indLine != line) { if (indLine != -1 && indLine != line) {
// take the indent of the found line // take the indent of the found line
StringBuffer replaceText = new StringBuffer(getIndentOfLine(d, indLine)); StringBuilder replaceText = new StringBuilder(getIndentOfLine(d, indLine));
// add the rest of the current line including the just added close bracket // add the rest of the current line including the just added close bracket
replaceText.append(d.get(whiteend, c.offset - whiteend)); replaceText.append(d.get(whiteend, c.offset - whiteend));
replaceText.append(c.text); replaceText.append(c.text);
@ -230,7 +230,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
// Only shift if the last C line is further up and is a braceless block candidate // Only shift if the last C line is further up and is a braceless block candidate
if (lastLine < line) { if (lastLine < line) {
CIndenter indenter = new CIndenter(d, scanner, fProject); CIndenter indenter = new CIndenter(d, scanner, fProject);
StringBuffer indent = indenter.computeIndentation(p, true); StringBuilder indent = indenter.computeIndentation(p, true);
String toDelete = d.get(lineOffset, c.offset - lineOffset); String toDelete = d.get(lineOffset, c.offset - lineOffset);
if (indent != null && !indent.toString().equals(toDelete)) { if (indent != null && !indent.toString().equals(toDelete)) {
c.text = indent.append(c.text).toString(); c.text = indent.append(c.text).toString();
@ -253,7 +253,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
CHeuristicScanner scanner= new CHeuristicScanner(d); CHeuristicScanner scanner= new CHeuristicScanner(d);
try { try {
ITypedRegion partition= TextUtilities.getPartition(d, fPartitioning, c.offset, false); ITypedRegion partition= TextUtilities.getPartition(d, fPartitioning, c.offset, false);
if (ICPartitions.C_PREPROCESSOR.equals(partition.getType()) && d.get(c.offset-1, 1).charAt(0) == '\\') { if (ICPartitions.C_PREPROCESSOR.equals(partition.getType()) && c.offset > 0 && d.getChar(c.offset-1) == '\\') {
scanner = new CHeuristicScanner(d, fPartitioning, ICPartitions.C_PREPROCESSOR); scanner = new CHeuristicScanner(d, fPartitioning, ICPartitions.C_PREPROCESSOR);
addIndent= 1; addIndent= 1;
} }
@ -263,7 +263,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
int start = reg.getOffset(); int start = reg.getOffset();
int lineEnd = start + reg.getLength(); int lineEnd = start + reg.getLength();
StringBuffer indent= null; StringBuilder indent= null;
CIndenter indenter= new CIndenter(d, scanner, fProject); CIndenter indenter= new CIndenter(d, scanner, fProject);
if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_AUTO_INDENT)) { if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_AUTO_INDENT)) {
indent= indenter.computeIndentation(c.offset); indent= indenter.computeIndentation(c.offset);
@ -271,18 +271,18 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
// reuse existing indent // reuse existing indent
int wsEnd= findEndOfWhiteSpace(d, start, c.offset); int wsEnd= findEndOfWhiteSpace(d, start, c.offset);
if (wsEnd > start) { if (wsEnd > start) {
indent= new StringBuffer(d.get(start, wsEnd - start)); indent= new StringBuilder(d.get(start, wsEnd - start));
addIndent= 0; addIndent= 0;
} }
} }
if (indent == null) { if (indent == null) {
indent= new StringBuffer(); indent= new StringBuilder();
} }
if (addIndent > 0 && indent.length() == 0) { if (addIndent > 0 && indent.length() == 0) {
indent= indenter.createReusingIndent(indent, addIndent); indent= indenter.createReusingIndent(indent, addIndent);
} }
StringBuffer buf = new StringBuffer(c.text + indent); StringBuilder buf = new StringBuilder(c.text + indent);
int contentStart = findEndOfWhiteSpace(d, c.offset, lineEnd); int contentStart = findEndOfWhiteSpace(d, c.offset, lineEnd);
c.length = Math.max(contentStart - c.offset, 0); c.length = Math.max(contentStart - c.offset, 0);
@ -301,10 +301,10 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
} }
buf.append(TextUtilities.getDefaultLineDelimiter(d)); buf.append(TextUtilities.getDefaultLineDelimiter(d));
StringBuffer reference = null; StringBuilder reference = null;
int nonWS = findEndOfWhiteSpace(d, start, lineEnd); int nonWS = findEndOfWhiteSpace(d, start, lineEnd);
if (nonWS < c.offset && d.getChar(nonWS) == '{') if (nonWS < c.offset && d.getChar(nonWS) == '{')
reference = new StringBuffer(d.get(start, nonWS - start)); reference = new StringBuilder(d.get(start, nonWS - start));
else else
reference = indenter.getReferenceIndentation(c.offset); reference = indenter.getReferenceIndentation(c.offset);
if (reference != null) if (reference != null)
@ -326,10 +326,10 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
c.caretOffset = c.offset + buf.length(); c.caretOffset = c.offset + buf.length();
c.shiftsCaret = false; c.shiftsCaret = false;
StringBuffer reference = null; StringBuilder reference = null;
int nonWS = findEndOfWhiteSpace(d, start, lineEnd); int nonWS = findEndOfWhiteSpace(d, start, lineEnd);
if (nonWS < c.offset && d.getChar(nonWS) == '{') if (nonWS < c.offset && d.getChar(nonWS) == '{')
reference = new StringBuffer(d.get(start, nonWS - start)); reference = new StringBuilder(d.get(start, nonWS - start));
else else
reference = indenter.getReferenceIndentation(c.offset); reference = indenter.getReferenceIndentation(c.offset);
@ -408,12 +408,12 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
} }
private boolean isClosedBrace(IDocument document, int offset, int length) { private boolean isClosedBrace(IDocument document, int offset, int length) {
CompilationUnitInfo info = getCompilationUnitForMethod(document, offset, fPartitioning);
if (info == null)
return false;
return getBlockBalance(document, offset, fPartitioning) <= 0; return getBlockBalance(document, offset, fPartitioning) <= 0;
//TODO: Use smarter algorithm based on //TODO: Use smarter algorithm based on
// CompilationUnitInfo info = getCompilationUnitForMethod(document, offset, fPartitioning);
// if (info == null)
// return false;
//
// CodeReader reader = new CodeReader(info.buffer); // CodeReader reader = new CodeReader(info.buffer);
// ICodeReaderFactory fileCreator = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE); // ICodeReaderFactory fileCreator = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE);
// //
@ -582,7 +582,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
// (as the first might be partially selected) and use the value to // (as the first might be partially selected) and use the value to
// indent all other lines. // indent all other lines.
boolean isIndentDetected= false; boolean isIndentDetected= false;
StringBuffer addition= new StringBuffer(); StringBuilder addition= new StringBuilder();
int insertLength= 0; int insertLength= 0;
int first= document.computeNumberOfLines(prefix) + firstLine; // don't format first line int first= document.computeNumberOfLines(prefix) + firstLine; // don't format first line
int lines= temp.getNumberOfLines(); int lines= temp.getNumberOfLines();
@ -600,7 +600,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
if (!isIndentDetected) { if (!isIndentDetected) {
// indent the first pasted line // indent the first pasted line
String current= IndentUtil.getCurrentIndent(temp, l, indentInsideLineComments); String current= IndentUtil.getCurrentIndent(temp, l, indentInsideLineComments);
StringBuffer correct= new StringBuffer(IndentUtil.computeIndent(temp, l, indenter, scanner)); StringBuilder correct= new StringBuilder(IndentUtil.computeIndent(temp, l, indenter, scanner));
insertLength= subtractIndent(correct, current, addition); insertLength= subtractIndent(correct, current, addition);
// workaround for bug 181139 // workaround for bug 181139
@ -651,7 +651,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
* @param difference a string buffer - if the return value is positive, it will be cleared and set to the substring of <code>current</code> of that length * @param difference a string buffer - if the return value is positive, it will be cleared and set to the substring of <code>current</code> of that length
* @return the difference in lenght of <code>correct</code> and <code>current</code> * @return the difference in lenght of <code>correct</code> and <code>current</code>
*/ */
private int subtractIndent(CharSequence correct, CharSequence current, StringBuffer difference) { private int subtractIndent(CharSequence correct, CharSequence current, StringBuilder difference) {
int c1= computeVisualLength(correct); int c1= computeVisualLength(correct);
int c2= computeVisualLength(current); int c2= computeVisualLength(current);
int diff= c1 - c2; int diff= c1 - c2;
@ -1164,29 +1164,29 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
return false; return false;
} }
private static CompilationUnitInfo getCompilationUnitForMethod(IDocument document, int offset, String partitioning) { // private static CompilationUnitInfo getCompilationUnitForMethod(IDocument document, int offset, String partitioning) {
try { // try {
CHeuristicScanner scanner = new CHeuristicScanner(document); // CHeuristicScanner scanner = new CHeuristicScanner(document);
//
IRegion sourceRange = scanner.findSurroundingBlock(offset); // IRegion sourceRange = scanner.findSurroundingBlock(offset);
if (sourceRange == null) // if (sourceRange == null)
return null; // return null;
String source = document.get(sourceRange.getOffset(), sourceRange.getLength()); // String source = document.get(sourceRange.getOffset(), sourceRange.getLength());
//
StringBuffer contents = new StringBuffer(); // StringBuilder contents = new StringBuilder();
contents.append("class ____C{void ____m()"); //$NON-NLS-1$ // contents.append("class ____C{void ____m()"); //$NON-NLS-1$
final int methodOffset = contents.length(); // final int methodOffset = contents.length();
contents.append(source); // contents.append(source);
contents.append("};"); //$NON-NLS-1$ // contents.append("};"); //$NON-NLS-1$
//
char[] buffer = contents.toString().toCharArray(); // char[] buffer = contents.toString().toCharArray();
return new CompilationUnitInfo(buffer, sourceRange.getOffset() - methodOffset); // return new CompilationUnitInfo(buffer, sourceRange.getOffset() - methodOffset);
} catch (BadLocationException e) { // } catch (BadLocationException e) {
CUIPlugin.log(e); // CUIPlugin.log(e);
} // }
//
return null; // return null;
} // }
/** /**
* Returns the block balance, i.e. zero if the blocks are balanced at * Returns the block balance, i.e. zero if the blocks are balanced at

View file

@ -409,7 +409,7 @@ public final class CIndenter {
* reference position to <code>offset</code> resides, or <code>null</code> * reference position to <code>offset</code> resides, or <code>null</code>
* if it cannot be determined * if it cannot be determined
*/ */
public StringBuffer getReferenceIndentation(int offset) { public StringBuilder getReferenceIndentation(int offset) {
return getReferenceIndentation(offset, false); return getReferenceIndentation(offset, false);
} }
@ -422,7 +422,7 @@ public final class CIndenter {
* reference position to <code>offset</code> resides, or <code>null</code> * reference position to <code>offset</code> resides, or <code>null</code>
* if it cannot be determined * if it cannot be determined
*/ */
private StringBuffer getReferenceIndentation(int offset, boolean assumeOpeningBrace) { private StringBuilder getReferenceIndentation(int offset, boolean assumeOpeningBrace) {
int unit; int unit;
if (assumeOpeningBrace) if (assumeOpeningBrace)
unit= findReferencePosition(offset, Symbols.TokenLBRACE); unit= findReferencePosition(offset, Symbols.TokenLBRACE);
@ -444,7 +444,7 @@ public final class CIndenter {
* which offset resides, or <code>null</code> if it cannot be * which offset resides, or <code>null</code> if it cannot be
* determined * determined
*/ */
public StringBuffer computeIndentation(int offset) { public StringBuilder computeIndentation(int offset) {
return computeIndentation(offset, false); return computeIndentation(offset, false);
} }
@ -457,8 +457,8 @@ public final class CIndenter {
* which offset resides, or <code>null</code> if it cannot be * which offset resides, or <code>null</code> if it cannot be
* determined * determined
*/ */
public StringBuffer computeIndentation(int offset, boolean assumeOpeningBrace) { public StringBuilder computeIndentation(int offset, boolean assumeOpeningBrace) {
StringBuffer reference= getReferenceIndentation(offset, assumeOpeningBrace); StringBuilder reference= getReferenceIndentation(offset, assumeOpeningBrace);
// handle special alignment // handle special alignment
if (fAlign != CHeuristicScanner.NOT_FOUND) { if (fAlign != CHeuristicScanner.NOT_FOUND) {
@ -483,13 +483,13 @@ public final class CIndenter {
* Computes the indentation for a continuation line at <code>offset</code>. * Computes the indentation for a continuation line at <code>offset</code>.
* *
* @param offset the offset in the document * @param offset the offset in the document
* @return a StringBuffer which reflects the correct indentation for * @return a StringBuilder which reflects the correct indentation for
* the line in which offset resides, or <code>null</code> if it cannot be * the line in which offset resides, or <code>null</code> if it cannot be
* determined. * determined.
* @throws BadLocationException * @throws BadLocationException
*/ */
public StringBuffer computeContinuationLineIndentation(int offset) throws BadLocationException { public StringBuilder computeContinuationLineIndentation(int offset) throws BadLocationException {
StringBuffer reference= getLeadingWhitespace(offset); StringBuilder reference= getLeadingWhitespace(offset);
IRegion line= fDocument.getLineInformationOfOffset(offset); IRegion line= fDocument.getLineInformationOfOffset(offset);
String string= fDocument.get(line.getOffset(), offset - line.getOffset()); String string= fDocument.get(line.getOffset(), offset - line.getOffset());
if (string.trim().length() == 0) if (string.trim().length() == 0)
@ -534,7 +534,7 @@ public final class CIndenter {
* @param indentLength the maximum visual indentation length * @param indentLength the maximum visual indentation length
* @return the stripped <code>reference</code> * @return the stripped <code>reference</code>
*/ */
private StringBuffer stripExceedingChars(StringBuffer reference, int indentLength) { private StringBuilder stripExceedingChars(StringBuilder reference, int indentLength) {
final int tabSize= fPrefs.prefTabSize; final int tabSize= fPrefs.prefTabSize;
int measured= 0; int measured= 0;
int chars= reference.length(); int chars= reference.length();
@ -560,15 +560,15 @@ public final class CIndenter {
/** /**
* Returns the indentation of the line at <code>offset</code> as a * Returns the indentation of the line at <code>offset</code> as a
* <code>StringBuffer</code>. If the offset is not valid, the empty string * <code>StringBuilder</code>. If the offset is not valid, the empty string
* is returned. * is returned.
* *
* @param offset the offset in the document * @param offset the offset in the document
* @return the indentation (leading whitespace) of the line in which * @return the indentation (leading whitespace) of the line in which
* <code>offset</code> is located * <code>offset</code> is located
*/ */
private StringBuffer getLeadingWhitespace(int offset) { private StringBuilder getLeadingWhitespace(int offset) {
StringBuffer indent= new StringBuffer(); StringBuilder indent= new StringBuilder();
try { try {
IRegion line= fDocument.getLineInformationOfOffset(offset); IRegion line= fDocument.getLineInformationOfOffset(offset);
int lineOffset= line.getOffset(); int lineOffset= line.getOffset();
@ -600,10 +600,10 @@ public final class CIndenter {
* @return the indentation corresponding to the document content specified * @return the indentation corresponding to the document content specified
* by <code>start</code> and <code>indent</code> * by <code>start</code> and <code>indent</code>
*/ */
private StringBuffer createIndent(int start, final int indent, final boolean convertSpaceRunsToTabs) { private StringBuilder createIndent(int start, final int indent, final boolean convertSpaceRunsToTabs) {
final boolean convertTabs= fPrefs.prefUseTabs && convertSpaceRunsToTabs; final boolean convertTabs= fPrefs.prefUseTabs && convertSpaceRunsToTabs;
final int tabLen= fPrefs.prefTabSize; final int tabLen= fPrefs.prefTabSize;
final StringBuffer ret= new StringBuffer(); final StringBuilder ret= new StringBuilder();
try { try {
int spaces= 0; int spaces= 0;
while (start < indent) { while (start < indent) {
@ -643,7 +643,7 @@ public final class CIndenter {
* @return the modified <code>buffer</code> reflecting the indentation * @return the modified <code>buffer</code> reflecting the indentation
* adapted to <code>additional</code> * adapted to <code>additional</code>
*/ */
public StringBuffer createReusingIndent(StringBuffer buffer, int additional) { public StringBuilder createReusingIndent(StringBuilder buffer, int additional) {
int refLength= computeVisualLength(buffer); int refLength= computeVisualLength(buffer);
int addLength= fPrefs.prefIndentationSize * additional; // may be < 0 int addLength= fPrefs.prefIndentationSize * additional; // may be < 0
int totalLength= Math.max(0, refLength + addLength); int totalLength= Math.max(0, refLength + addLength);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others. * Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -44,7 +44,7 @@ public class CStringAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy
*/ */
private String displayString(String inputString, CharSequence indentation, String delimiter) { private String displayString(String inputString, CharSequence indentation, String delimiter) {
int length = inputString.length(); int length = inputString.length();
StringBuffer buffer = new StringBuffer(length); StringBuilder buffer = new StringBuilder(length);
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(inputString, "\n\r", true); //$NON-NLS-1$ java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(inputString, "\n\r", true); //$NON-NLS-1$
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken(); String token = tokenizer.nextToken();
@ -73,7 +73,7 @@ public class CStringAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy
continue; continue;
} }
StringBuffer tokenBuffer = new StringBuffer(); StringBuilder tokenBuffer = new StringBuilder();
for (int i = 0; i < token.length(); i++){ for (int i = 0; i < token.length(); i++){
char c = token.charAt(i); char c = token.charAt(i);
switch (c) { switch (c) {
@ -143,9 +143,9 @@ public class CStringAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy
CHeuristicScanner scanner = new CHeuristicScanner(document); CHeuristicScanner scanner = new CHeuristicScanner(document);
CIndenter indenter = new CIndenter(document, scanner, fProject); CIndenter indenter = new CIndenter(document, scanner, fProject);
StringBuffer indentation = indenter.computeContinuationLineIndentation(offset); StringBuilder indentation = indenter.computeContinuationLineIndentation(offset);
if (indentation == null) if (indentation == null)
indentation = new StringBuffer(); indentation = new StringBuilder();
String delimiter= TextUtilities.getDefaultLineDelimiter(document); String delimiter= TextUtilities.getDefaultLineDelimiter(document);
IPreferenceStore preferenceStore= CUIPlugin.getDefault().getPreferenceStore(); IPreferenceStore preferenceStore= CUIPlugin.getDefault().getPreferenceStore();