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

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-01-18 00:49:39 +00:00
parent 0d4ca399d0
commit ea13804fa6
3 changed files with 34 additions and 42 deletions

View file

@ -3313,8 +3313,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
// deal with (quite unexpected) comments right before lcurly // deal with (quite unexpected) comments right before lcurly
scribe.printComment(); scribe.printComment();
if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition) if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition)
&& (scribe.line > line || scribe.column >= preferences.page_width)) && (scribe.line > line || scribe.column >= preferences.page_width)) {
{
scribe.startNewLine(); scribe.startNewLine();
} }
} finally { } finally {

View file

@ -515,7 +515,8 @@ public class Scribe {
public void handleLineTooLong() { public void handleLineTooLong() {
// search for closest breakable alignment, using tiebreak rules // search for closest breakable alignment, using tiebreak rules
// look for outermost breakable one // look for outermost breakable one
int relativeDepth= 0, outerMostDepth= -1; int relativeDepth= 0;
int outerMostDepth= -1;
Alignment targetAlignment= currentAlignment; Alignment targetAlignment= currentAlignment;
while (targetAlignment != null) { while (targetAlignment != null) {
if (targetAlignment.tieBreakRule == Alignment.R_OUTERMOST && targetAlignment.couldBreak()) { if (targetAlignment.tieBreakRule == Alignment.R_OUTERMOST && targetAlignment.couldBreak()) {
@ -1324,7 +1325,7 @@ public class Scribe {
print(currentToken.getLength(), considerSpaceIfAny); print(currentToken.getLength(), considerSpaceIfAny);
} }
private void printRule(StringBuilder stringBuffer) { private void printRuler(StringBuilder stringBuffer) {
for (int i= 0; i < pageWidth; i++) { for (int i= 0; i < pageWidth; i++) {
if ((i % tabLength) == 0) { if ((i % tabLength) == 0) {
stringBuffer.append('+'); stringBuffer.append('+');
@ -1520,15 +1521,13 @@ public class Scribe {
buffer buffer
.append(") - (tabSize = " + tabLength + ")")//$NON-NLS-1$//$NON-NLS-2$ .append(") - (tabSize = " + tabLength + ")")//$NON-NLS-1$//$NON-NLS-2$
.append(lineSeparator) .append(lineSeparator)
.append( .append("(line = " + line + ") - (column = " + column + ") - (identationLevel = " + indentationLevel + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"(line = " + line + ") - (column = " + column + ") - (identationLevel = " + indentationLevel + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
.append(lineSeparator) .append(lineSeparator)
.append( .append("(needSpace = " + needSpace + ") - (lastNumberOfNewLines = " + lastNumberOfNewLines + ") - (checkLineWrapping = " + checkLineWrapping + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"(needSpace = " + needSpace + ") - (lastNumberOfNewLines = " + lastNumberOfNewLines + ") - (checkLineWrapping = " + checkLineWrapping + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
.append(lineSeparator).append( .append(lineSeparator).append(
"==================================================================================") //$NON-NLS-1$ "==================================================================================") //$NON-NLS-1$
.append(lineSeparator); .append(lineSeparator);
printRule(buffer); printRuler(buffer);
return buffer.toString(); return buffer.toString();
} }

View file

@ -13,14 +13,12 @@ package org.eclipse.cdt.internal.formatter.align;
import org.eclipse.cdt.internal.formatter.Location; import org.eclipse.cdt.internal.formatter.Location;
import org.eclipse.cdt.internal.formatter.Scribe; import org.eclipse.cdt.internal.formatter.Scribe;
/** /**
* Alignment management * Alignment management
* *
* @since 4.0 * @since 4.0
*/ */
public class Alignment { public class Alignment {
// name of alignment // name of alignment
public String name; public String name;
@ -78,7 +76,7 @@ public class Alignment {
* <li> #fragment4, </li> * <li> #fragment4, </li>
* </ul> * </ul>
*/ */
public static final int M_ONE_PER_LINE_SPLIT = 32+16; // one fragment per line public static final int M_ONE_PER_LINE_SPLIT = 32 + 16; // one fragment per line
/** /**
* foobar(<ul> * foobar(<ul>
@ -96,7 +94,7 @@ public class Alignment {
* <li> #fragment4, </li> * <li> #fragment4, </li>
* </ul> * </ul>
*/ */
public static final int M_NEXT_PER_LINE_SPLIT = 64+16; // one per line, except first fragment (if possible) public static final int M_NEXT_PER_LINE_SPLIT = 64 + 16; // one per line, except first fragment (if possible)
//64+32 //64+32
//64+32+16 //64+32+16
@ -133,8 +131,7 @@ public class Alignment {
public static final int CHUNK_ENUM = 4; public static final int CHUNK_ENUM = 4;
// location to align and break on. // location to align and break on.
public Alignment(String name, int mode, int tieBreakRule, Scribe scribe, int fragmentCount, int sourceRestart, int continuationIndent){ public Alignment(String name, int mode, int tieBreakRule, Scribe scribe, int fragmentCount, int sourceRestart, int continuationIndent) {
this.name = name; this.name = name;
this.location = new Location(scribe, sourceRestart); this.location = new Location(scribe, sourceRestart);
this.mode = mode; this.mode = mode;
@ -196,7 +193,7 @@ public class Alignment {
if (currentIndentation > fragmentIndentation) { if (currentIndentation > fragmentIndentation) {
this.fragmentIndentations[this.fragmentIndex] = currentIndentation; this.fragmentIndentations[this.fragmentIndex] = currentIndentation;
if (fragmentIndentation != 0) { if (fragmentIndentation != 0) {
for (int i = this.fragmentIndex+1; i < this.fragmentCount; i++) { for (int i = this.fragmentIndex + 1; i < this.fragmentCount; i++) {
this.fragmentIndentations[i] = 0; this.fragmentIndentations[i] = 0;
} }
this.needRedoColumnAlignment = true; this.needRedoColumnAlignment = true;
@ -204,16 +201,15 @@ public class Alignment {
} }
// backtrack only once all fragments got checked // backtrack only once all fragments got checked
if (this.needRedoColumnAlignment && this.fragmentIndex == this.fragmentCount-1) { // alignment too small if (this.needRedoColumnAlignment && this.fragmentIndex == this.fragmentCount-1) { // alignment too small
// if (CodeFormatterVisitor.DEBUG) {
// if (CodeFormatterVisitor.DEBUG){
// System.out.println("ALIGNMENT TOO SMALL"); // System.out.println("ALIGNMENT TOO SMALL");
// System.out.println(this); // System.out.println(this);
// } // }
this.needRedoColumnAlignment = false; this.needRedoColumnAlignment = false;
int relativeDepth = 0; int relativeDepth = 0;
Alignment targetAlignment = this.scribe.memberAlignment; Alignment targetAlignment = this.scribe.memberAlignment;
while (targetAlignment != null){ while (targetAlignment != null) {
if (targetAlignment == this){ if (targetAlignment == this) {
throw new AlignmentException(AlignmentException.ALIGN_TOO_SMALL, relativeDepth); throw new AlignmentException(AlignmentException.ALIGN_TOO_SMALL, relativeDepth);
} }
targetAlignment = targetAlignment.enclosing; targetAlignment = targetAlignment.enclosing;
@ -223,16 +219,16 @@ public class Alignment {
} }
} }
public boolean couldBreak(){ public boolean couldBreak() {
int i; int i;
switch(mode & SPLIT_MASK){ switch (mode & SPLIT_MASK) {
/* # aligned fragment /* # aligned fragment
* foo( * foo(
* #AAAAA, #BBBBB, * #AAAAA, #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_COMPACT_FIRST_BREAK_SPLIT : case M_COMPACT_FIRST_BREAK_SPLIT:
if (this.fragmentBreaks[0] == NONE) { if (this.fragmentBreaks[0] == NONE) {
this.fragmentBreaks[0] = BREAK; this.fragmentBreaks[0] = BREAK;
this.fragmentIndentations[0] = this.breakIndentationLevel; this.fragmentIndentations[0] = this.breakIndentationLevel;
@ -251,7 +247,7 @@ public class Alignment {
* foo(#AAAAA, #BBBBB, * foo(#AAAAA, #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_COMPACT_SPLIT : case M_COMPACT_SPLIT:
i = this.fragmentIndex; i = this.fragmentIndex;
do { do {
if (this.fragmentBreaks[i] == NONE) { if (this.fragmentBreaks[i] == NONE) {
@ -268,11 +264,11 @@ public class Alignment {
* #BBBBB, * #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_NEXT_SHIFTED_SPLIT : case M_NEXT_SHIFTED_SPLIT:
if (this.fragmentBreaks[0] == NONE) { if (this.fragmentBreaks[0] == NONE) {
this.fragmentBreaks[0] = BREAK; this.fragmentBreaks[0] = BREAK;
this.fragmentIndentations[0] = this.breakIndentationLevel; this.fragmentIndentations[0] = this.breakIndentationLevel;
for (i = 1; i < this.fragmentCount; i++){ for (i = 1; i < this.fragmentCount; i++) {
this.fragmentBreaks[i] = BREAK; this.fragmentBreaks[i] = BREAK;
this.fragmentIndentations[i] = this.shiftBreakIndentationLevel; this.fragmentIndentations[i] = this.shiftBreakIndentationLevel;
} }
@ -286,9 +282,9 @@ public class Alignment {
* #BBBBB, * #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_ONE_PER_LINE_SPLIT : case M_ONE_PER_LINE_SPLIT:
if (this.fragmentBreaks[0] == NONE) { if (this.fragmentBreaks[0] == NONE) {
for (i = 0; i < this.fragmentCount; i++){ for (i = 0; i < this.fragmentCount; i++) {
this.fragmentBreaks[i] = BREAK; this.fragmentBreaks[i] = BREAK;
this.fragmentIndentations[i] = this.breakIndentationLevel; this.fragmentIndentations[i] = this.breakIndentationLevel;
} }
@ -300,7 +296,7 @@ public class Alignment {
* #BBBBB, * #BBBBB,
* #CCCC); * #CCCC);
*/ */
case M_NEXT_PER_LINE_SPLIT : case M_NEXT_PER_LINE_SPLIT:
if (this.fragmentBreaks[0] == NONE) { if (this.fragmentBreaks[0] == NONE) {
if (this.fragmentCount > 1 if (this.fragmentCount > 1
&& this.fragmentBreaks[1] == NONE) { && this.fragmentBreaks[1] == NONE) {
@ -320,7 +316,6 @@ public class Alignment {
} }
public Alignment getAlignment(String targetName) { public Alignment getAlignment(String targetName) {
if (targetName.equals(this.name)) return this; if (targetName.equals(this.name)) return this;
if (this.enclosing == null) return null; if (this.enclosing == null) return null;
@ -328,14 +323,14 @@ public class Alignment {
} }
// perform alignment effect for current fragment // perform alignment effect for current fragment
public void performFragmentEffect(){ public void performFragmentEffect() {
if ((this.mode & M_MULTICOLUMN) == 0) { if ((this.mode & M_MULTICOLUMN) == 0) {
switch(this.mode & SPLIT_MASK) { switch (this.mode & SPLIT_MASK) {
case Alignment.M_COMPACT_SPLIT : case Alignment.M_COMPACT_SPLIT:
case Alignment.M_COMPACT_FIRST_BREAK_SPLIT : case Alignment.M_COMPACT_FIRST_BREAK_SPLIT:
case Alignment.M_NEXT_PER_LINE_SPLIT : case Alignment.M_NEXT_PER_LINE_SPLIT:
case Alignment.M_NEXT_SHIFTED_SPLIT : case Alignment.M_NEXT_SHIFTED_SPLIT:
case Alignment.M_ONE_PER_LINE_SPLIT : case Alignment.M_ONE_PER_LINE_SPLIT:
break; break;
default: default:
return; return;
@ -357,8 +352,7 @@ public class Alignment {
// reset fragment indentation/break status // reset fragment indentation/break status
public void reset() { public void reset() {
if (fragmentCount > 0) {
if (fragmentCount > 0){
this.fragmentIndentations = new int[this.fragmentCount]; this.fragmentIndentations = new int[this.fragmentCount];
this.fragmentBreaks = new int[this.fragmentCount]; this.fragmentBreaks = new int[this.fragmentCount];
} }
@ -369,7 +363,7 @@ public class Alignment {
} }
} }
public void toFragmentsString(StringBuffer buffer){ public void toFragmentsString(StringBuffer buffer) {
// default implementation // default implementation
} }
@ -390,7 +384,7 @@ public class Alignment {
} }
buffer.append('\n'); buffer.append('\n');
for (int i = 0; i < this.fragmentCount; i++){ for (int i = 0; i < this.fragmentCount; i++) {
buffer buffer
.append(" - fragment ") //$NON-NLS-1$ .append(" - fragment ") //$NON-NLS-1$
.append(i) .append(i)
@ -407,7 +401,7 @@ public class Alignment {
} }
public void update() { public void update() {
for (int i = 1; i < this.fragmentCount; i++){ for (int i = 1; i < this.fragmentCount; i++) {
if (this.fragmentBreaks[i] == BREAK) { if (this.fragmentBreaks[i] == BREAK) {
this.fragmentIndentations[i] = this.breakIndentationLevel; this.fragmentIndentations[i] = this.breakIndentationLevel;
} }