1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-14 03:35:37 +02:00

Formatter fixes.

This commit is contained in:
Sergey Prigogin 2011-03-29 06:36:51 +00:00
parent adcb6b9e67
commit f5b0005a75
2 changed files with 16 additions and 19 deletions

View file

@ -1340,7 +1340,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(ICPPASTFunctionDeclarator node) { private int visit(ICPPASTFunctionDeclarator node) {
final List<ICPPASTParameterDeclaration> parameters = Arrays.asList(node.getParameters()); final List<ICPPASTParameterDeclaration> parameters = Arrays.asList(node.getParameters());
final ListOptions options = createListOptionsForFunctionDeclarationParameters(); final ListOptions options = createListOptionsForFunctionDeclarationParameters();
Runnable tailFormatter = scribe.getTailFormatter(); Runnable tailFormatter = scribe.takeTailFormatter();
formatList(parameters, options, true, node.takesVarArgs(), formatList(parameters, options, true, node.takesVarArgs(),
new CPPFunctionDeclaratorTailFormatter(node, tailFormatter)); new CPPFunctionDeclaratorTailFormatter(node, tailFormatter));
@ -2251,7 +2251,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
options.fSpaceBeforeSeparator= preferences.insert_space_before_comma_in_method_invocation_arguments; options.fSpaceBeforeSeparator= preferences.insert_space_before_comma_in_method_invocation_arguments;
options.fSpaceAfterSeparator= preferences.insert_space_after_comma_in_method_invocation_arguments; options.fSpaceAfterSeparator= preferences.insert_space_after_comma_in_method_invocation_arguments;
options.fTieBreakRule = Alignment.R_OUTERMOST; options.fTieBreakRule = Alignment.R_OUTERMOST;
formatList(expressions, options, true, false, scribe.getTailFormatter()); formatList(expressions, options, true, false, scribe.takeTailFormatter());
} }
private int visit(IASTExpressionList node) { private int visit(IASTExpressionList node) {
@ -2538,7 +2538,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return formatOverloadedLeftShiftChain(node); return formatOverloadedLeftShiftChain(node);
} }
Runnable tailFormatter = scribe.getTailFormatter(); Runnable tailFormatter = scribe.takeTailFormatter();
Alignment expressionAlignment= scribe.createAlignment( Alignment expressionAlignment= scribe.createAlignment(
Alignment.BINARY_EXPRESSION, Alignment.BINARY_EXPRESSION,

View file

@ -144,8 +144,9 @@ public class Alignment {
public int tieBreakRule; public int tieBreakRule;
// Alignment effects on a per fragment basis // Alignment effects on a per fragment basis
public static int NONE = 0; public static final int NONE = 0;
public static int BREAK = 1; public static final int BREAK = 1;
public static final int BREAK_NOT_ALLOWED = 2;
// Chunk kind // Chunk kind
public static final int CHUNK_FIELD = 1; public static final int CHUNK_FIELD = 1;
@ -164,8 +165,10 @@ public class Alignment {
this.scribe = scribe; this.scribe = scribe;
this.originalIndentationLevel = this.scribe.indentationLevel; this.originalIndentationLevel = this.scribe.indentationLevel;
this.wasSplit = false; this.wasSplit = false;
this.fragmentIndentations = new int[this.fragmentCount];
this.fragmentBreaks = new int[this.fragmentCount];
// initialize the break indentation level, using modes and continuationIndentationLevel preference // Initialize the break indentation level, using modes and continuationIndentationLevel preference
final int indentSize = this.scribe.indentationSize; final int indentSize = this.scribe.indentationSize;
int currentColumn = this.location.outputColumn; int currentColumn = this.location.outputColumn;
if (currentColumn == 1) { if (currentColumn == 1) {
@ -173,23 +176,23 @@ public class Alignment {
} }
if ((mode & M_INDENT_ON_COLUMN) != 0) { if ((mode & M_INDENT_ON_COLUMN) != 0) {
// indent broken fragments at next indentation level, based on current column // Indent broken fragments at next indentation level, based on current column
this.breakIndentationLevel = this.scribe.getNextIndentationLevel(currentColumn); this.breakIndentationLevel = this.scribe.getNextIndentationLevel(currentColumn);
if (this.breakIndentationLevel == this.location.outputIndentationLevel) { if (this.breakIndentationLevel == this.location.outputIndentationLevel) {
this.breakIndentationLevel += continuationIndent * indentSize; this.breakIndentationLevel += continuationIndent * indentSize;
} }
if (continuationIndent == 0) {
this.fragmentBreaks[0] = BREAK_NOT_ALLOWED;
}
} else if ((mode & M_INDENT_BY_ONE) != 0) { } else if ((mode & M_INDENT_BY_ONE) != 0) {
// indent broken fragments exactly one level deeper than current indentation // Indent broken fragments exactly one level deeper than current indentation
this.breakIndentationLevel = this.location.outputIndentationLevel + indentSize; this.breakIndentationLevel = this.location.outputIndentationLevel + indentSize;
} else { } else {
this.breakIndentationLevel = this.location.outputIndentationLevel + continuationIndent * indentSize; this.breakIndentationLevel = this.location.outputIndentationLevel + continuationIndent * indentSize;
} }
this.shiftBreakIndentationLevel = this.breakIndentationLevel + indentSize; this.shiftBreakIndentationLevel = this.breakIndentationLevel + indentSize;
this.fragmentIndentations = new int[this.fragmentCount]; // Check for forced alignments
this.fragmentBreaks = new int[this.fragmentCount];
// check for forced alignments
if ((this.mode & M_FORCE) != 0) { if ((this.mode & M_FORCE) != 0) {
couldBreak(); couldBreak();
} }
@ -273,12 +276,6 @@ public class Alignment {
case M_COMPACT_SPLIT: case M_COMPACT_SPLIT:
i = this.fragmentIndex; i = this.fragmentIndex;
do { do {
if (i == 0 && (mode & M_INDENT_ON_COLUMN) != 0 &&
name.startsWith(LIST_ELEMENTS_PREFIX)) {
// Don't split the line before the first element of the list if the list
// elements are indented on column.
break;
}
if (this.fragmentBreaks[i] == NONE) { if (this.fragmentBreaks[i] == NONE) {
this.fragmentBreaks[i] = BREAK; this.fragmentBreaks[i] = BREAK;
this.fragmentIndentations[i] = this.breakIndentationLevel; this.fragmentIndentations[i] = this.breakIndentationLevel;