mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Code formatter fixes.
This commit is contained in:
parent
7dba3181b9
commit
ee055684b2
5 changed files with 27 additions and 7 deletions
|
@ -146,7 +146,7 @@ public class DefaultCodeFormatterConstants {
|
|||
* FORMATTER / Option for alignment of conditional expression
|
||||
* - option id: "org.eclipse.cdt.core.formatter.alignment_for_conditional_expression"
|
||||
* - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
|
||||
* - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_ON_COLUMN)
|
||||
* - default: createAlignmentValue(false, WRAP_COMPACT_FIRST_BREAK, INDENT_ON_COLUMN)
|
||||
* </pre>
|
||||
* @see #createAlignmentValue(boolean, int, int)
|
||||
*/
|
||||
|
|
|
@ -2622,8 +2622,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
|
||||
private int formatAssignment(IASTBinaryExpression node) {
|
||||
Runnable tailFormatter = scribe.takeTailFormatter();
|
||||
final IASTExpression op1= node.getOperand1();
|
||||
// operand 1
|
||||
// Operand 1
|
||||
op1.accept(this);
|
||||
|
||||
// In case of macros we may have already passed the equal sign position.
|
||||
|
@ -2652,10 +2653,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
try {
|
||||
scribe.alignFragment(expressionAlignment, 0);
|
||||
|
||||
// operand 2
|
||||
scribe.setTailFormatter(tailFormatter);
|
||||
// Operand 2
|
||||
final IASTExpression op2= node.getOperand2();
|
||||
op2.accept(this);
|
||||
|
||||
scribe.runTailFormatter();
|
||||
ok = true;
|
||||
} catch (AlignmentException e) {
|
||||
scribe.redoAlignment(e);
|
||||
|
|
|
@ -530,9 +530,9 @@ public class DefaultCodeFormatterOptions {
|
|||
try {
|
||||
this.alignment_for_conditional_expression = Integer.parseInt((String) alignmentForConditionalExpressionOption);
|
||||
} catch (NumberFormatException e) {
|
||||
this.alignment_for_conditional_expression = Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN;
|
||||
this.alignment_for_conditional_expression = Alignment.M_COMPACT_FIRST_BREAK_SPLIT | Alignment.M_INDENT_ON_COLUMN;
|
||||
} catch (ClassCastException e) {
|
||||
this.alignment_for_conditional_expression = Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN;
|
||||
this.alignment_for_conditional_expression = Alignment.M_COMPACT_FIRST_BREAK_SPLIT | Alignment.M_INDENT_ON_COLUMN;
|
||||
}
|
||||
}
|
||||
final Object alignmentForConditionalExpressionChainOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION_CHAIN);
|
||||
|
@ -1496,7 +1496,7 @@ public class DefaultCodeFormatterOptions {
|
|||
this.alignment_for_base_clause_in_type_declaration = Alignment.M_NEXT_PER_LINE_SPLIT;
|
||||
this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
|
||||
this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT;
|
||||
this.alignment_for_conditional_expression = Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN;
|
||||
this.alignment_for_conditional_expression = Alignment.M_COMPACT_FIRST_BREAK_SPLIT | Alignment.M_INDENT_ON_COLUMN;
|
||||
this.alignment_for_conditional_expression_chain = Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN;
|
||||
this.alignment_for_declarator_list = Alignment.M_COMPACT_SPLIT;
|
||||
this.alignment_for_enumerator_list = Alignment.M_ONE_PER_LINE_SPLIT;
|
||||
|
|
|
@ -268,6 +268,15 @@ public class Alignment {
|
|||
*/
|
||||
case M_COMPACT_FIRST_BREAK_SPLIT:
|
||||
if (this.fragmentBreaks[0] == NONE) {
|
||||
if ((this.mode & M_INDENT_ON_COLUMN) != 0) {
|
||||
if (this.breakIndentationLevel <= this.alternativeBreakIndentationLevel) {
|
||||
// Does not make sense to break here unless indentation is reduced.
|
||||
break;
|
||||
}
|
||||
// Change break indentation level and erase previously created breaks.
|
||||
this.breakIndentationLevel = this.alternativeBreakIndentationLevel;
|
||||
eraseExistingBreaks(0);
|
||||
}
|
||||
this.fragmentBreaks[0] = BREAK;
|
||||
this.fragmentIndentations[0] = this.breakIndentationLevel;
|
||||
return wasSplit = true;
|
||||
|
|
|
@ -2084,6 +2084,9 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
//int variable2 = 1000000 < 2000000 ? 3000000 + 40000000 : 8000000 + 900000000;
|
||||
//int variable3 = 1000000 < 2000000 ? 3000000 + 4000000 + 5000000 + 6000000 + 7000000 : 8000000 + 9000000;
|
||||
//int variable4 = 1000000 < 2000000 ? 3000000 + 4000000 + 5000000 + 6000000 + 7000000 : 8000000 + 90000000;
|
||||
//int variable5;
|
||||
//variable5 = 10000000 < 2000000 ? 3000000 + 4000000 + 5000000 + 6000000 : 700000;
|
||||
//variable5 = 10000000 < 2000000 ? 3000000 + 4000000 + 5000000 + 6000000 : 7000000;
|
||||
//}
|
||||
|
||||
//void test() {
|
||||
|
@ -2098,6 +2101,12 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
// 1000000 < 2000000 ?
|
||||
// 3000000 + 4000000 + 5000000 + 6000000 + 7000000 :
|
||||
// 8000000 + 90000000;
|
||||
// int variable5;
|
||||
// variable5 =
|
||||
// 10000000 < 2000000 ? 3000000 + 4000000 + 5000000 + 6000000 : 700000;
|
||||
// variable5 =
|
||||
// 10000000 < 2000000 ?
|
||||
// 3000000 + 4000000 + 5000000 + 6000000 : 7000000;
|
||||
//}
|
||||
public void testConditionalExpression() throws Exception {
|
||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||
|
|
Loading…
Add table
Reference in a new issue