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-26 15:24:10 -07:00
parent 0ebca71a1d
commit 168e1f4460

View file

@ -12,20 +12,16 @@
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
/** /**
* * This class is responsible for the string concatenation and the management of
* This class is responsible for the string concatination and the management of
* the indentations. * the indentations.
* *
* @since 5.0 * @since 5.0
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*
*/ */
public class Scribe { public class Scribe {
private int indentationLevel = 0; private int indentationLevel = 0;
private int indentationSize = 4; //HSR tcorbat: could be a tab character too - this is not a very elegant solution private int indentationSize = 4; //HSR tcorbat: could be a tab character too - this is not a very elegant solution
private StringBuffer buffer = new StringBuffer(); private StringBuilder buffer = new StringBuilder();
private boolean isAtLineBeginning = true; private boolean isAtLineBeginning = true;
private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
private String givenIndentation = null; private String givenIndentation = null;
@ -33,32 +29,32 @@ public class Scribe {
private boolean noNewLine = false; private boolean noNewLine = false;
private boolean noSemicolon = false; private boolean noSemicolon = false;
public void newLine(){ public void newLine() {
if(!noNewLine) { if (!noNewLine) {
isAtLineBeginning = true; isAtLineBeginning = true;
buffer.append(getNewline()); buffer.append(getNewline());
} }
} }
private void indent(){ private void indent() {
if( givenIndentation != null ){ if (givenIndentation != null) {
buffer.append( givenIndentation ); buffer.append(givenIndentation);
} }
printSpaces(indentationLevel * indentationSize); printSpaces(indentationLevel * indentationSize);
} }
private void indentIfNewLine(){ private void indentIfNewLine() {
if(isAtLineBeginning){ if (isAtLineBeginning) {
isAtLineBeginning = false; isAtLineBeginning = false;
indent(); indent();
} }
} }
private String getNewline(){ private String getNewline() {
return newLine; return newLine;
} }
public void print(String code){ public void print(String code) {
indentIfNewLine(); indentIfNewLine();
buffer.append(code); buffer.append(code);
} }
@ -78,15 +74,15 @@ public class Scribe {
newLine(); newLine();
} }
public void println(String code , char[] code2) { public void println(String code, char[] code2) {
print(code); print(code);
buffer.append(code2); buffer.append(code2);
newLine(); newLine();
} }
public void printSpaces(int number){ public void printSpaces(int number) {
indentIfNewLine(); indentIfNewLine();
for(int i = 0; i < number; ++i){ for (int i = 0; i < number; ++i) {
printSpace(); printSpace();
} }
} }
@ -95,18 +91,17 @@ public class Scribe {
noSemicolon = true; noSemicolon = true;
} }
public void printSemicolon(){ public void printSemicolon() {
if(!noSemicolon) { if (!noSemicolon) {
indentIfNewLine(); indentIfNewLine();
buffer.append(';'); buffer.append(';');
} } else {
else {
noSemicolon = false; noSemicolon = false;
} }
} }
@Override @Override
public String toString(){ public String toString() {
return buffer.toString(); return buffer.toString();
} }
@ -125,13 +120,13 @@ public class Scribe {
newLine(); newLine();
} }
public void printStringSpace(String code){ public void printStringSpace(String code) {
print(code); print(code);
printSpace(); printSpace();
} }
/** /**
* Prints a { to the Buffer an increases the Indentationlevel. * Prints a { to the Buffer an increases the indentation level.
*/ */
public void printLBrace() { public void printLBrace() {
print('{'); print('{');
@ -139,33 +134,33 @@ public class Scribe {
} }
/** /**
* Prints a } to the Buffer an decrease the Indentationlevel. * Prints a } to the Buffer an decrease the indentation level.
*/ */
public void printRBrace() { public void printRBrace() {
--indentationLevel; --indentationLevel;
print('}'); print('}');
} }
public void incrementIndentationLevel(){ public void incrementIndentationLevel() {
++indentationLevel; ++indentationLevel;
} }
public void decrementIndentationLevel(){ public void decrementIndentationLevel() {
if(indentationLevel>0) { if (indentationLevel > 0) {
--indentationLevel; --indentationLevel;
} }
} }
protected void noNewLines(){ protected void noNewLines() {
noNewLine = true; noNewLine = true;
} }
protected void newLines(){ protected void newLines() {
noNewLine = false; noNewLine = false;
} }
public void newLine(int i) { public void newLine(int i) {
while(i > 0) { while (i > 0) {
newLine(); newLine();
--i; --i;
} }
@ -184,6 +179,6 @@ public class Scribe {
} }
public void cleanCache() { public void cleanCache() {
buffer = new StringBuffer(); buffer = new StringBuilder();
} }
} }