1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55:39 +02:00

Bug 322776 - [formatter] Add option to not join already wrapped lines

Bug 325787 - [formatter] No option to define indentation policy for assignment expression
This commit is contained in:
Anton Leherbauer 2010-11-03 09:55:47 +00:00
parent defc8a8a4a
commit 8f01b54586
9 changed files with 302 additions and 169 deletions

View file

@ -109,26 +109,28 @@ public class DefaultCodeFormatterConstants {
* @see #createAlignmentValue(boolean, int, int) * @see #createAlignmentValue(boolean, int, int)
*/ */
public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION = CCorePlugin.PLUGIN_ID + ".formatter.alignment_for_arguments_in_method_invocation"; //$NON-NLS-1$ public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION = CCorePlugin.PLUGIN_ID + ".formatter.alignment_for_arguments_in_method_invocation"; //$NON-NLS-1$
// /** /**
// * <pre> * <pre>
// * FORMATTER / Option for alignment of assignment * FORMATTER / Option for alignment of assignment
// * - option id: "org.eclipse.cdt.core.formatter.alignment_for_assignment" * - option id: "org.eclipse.cdt.core.formatter.alignment_for_assignment"
// * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
// * - default: createAlignmentValue(false, M_NO_ALIGNMENT, INDENT_DEFAULT) * - default: createAlignmentValue(false, M_NO_ALIGNMENT, INDENT_DEFAULT)
// * </pre> * </pre>
// * @see #createAlignmentValue(boolean, int, int) * @see #createAlignmentValue(boolean, int, int)
// */ * @since 5.3
// public static final String FORMATTER_ALIGNMENT_FOR_ASSIGNMENT = CCorePlugin.PLUGIN_ID + ".formatter.alignment_for_assignment"; //$NON-NLS-1$ */
// /** public static final String FORMATTER_ALIGNMENT_FOR_ASSIGNMENT = CCorePlugin.PLUGIN_ID + ".formatter.alignment_for_assignment"; //$NON-NLS-1$
// * <pre> /**
// * FORMATTER / Option for alignment of binary expression * <pre>
// * - option id: "org.eclipse.cdt.core.formatter.alignment_for_binary_expression" * FORMATTER / Option for alignment of binary expression
// * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call * - option id: "org.eclipse.cdt.core.formatter.alignment_for_binary_expression"
// * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT) * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
// * </pre> * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
// * @see #createAlignmentValue(boolean, int, int) * </pre>
// */ * @see #createAlignmentValue(boolean, int, int)
// public static final String FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION = CCorePlugin.PLUGIN_ID + ".formatter.alignment_for_binary_expression"; //$NON-NLS-1$ * @since 5.3
*/
public static final String FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION = CCorePlugin.PLUGIN_ID + ".formatter.alignment_for_binary_expression"; //$NON-NLS-1$
/** /**
* <pre> * <pre>
* FORMATTER / Option for alignment of compact if * FORMATTER / Option for alignment of compact if
@ -2037,6 +2039,16 @@ public class DefaultCodeFormatterConstants {
* </pre> * </pre>
*/ */
public static final String FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE = CCorePlugin.PLUGIN_ID + ".formatter.number_of_empty_lines_to_preserve"; //$NON-NLS-1$ public static final String FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE = CCorePlugin.PLUGIN_ID + ".formatter.number_of_empty_lines_to_preserve"; //$NON-NLS-1$
/**
* <pre>
* FORMATTER / Option to specify whether the formatter can join wrapped lines or not
* - option id: "org.eclipse.cdt.core.formatter.join_wrapped_lines"
* - possible values: { TRUE, FALSE }
* - default: TRUE
* </pre>
* @since 5.3
*/
public static final String FORMATTER_JOIN_WRAPPED_LINES = CCorePlugin.PLUGIN_ID + ".formatter.join_wrapped_lines"; //$NON-NLS-1$
/** /**
* <pre> * <pre>
* FORMATTER / Option to specify whether or not empty statement should be on a new line * FORMATTER / Option to specify whether or not empty statement should be on a new line

View file

@ -472,7 +472,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.startNewLine(); scribe.startNewLine();
} else { } else {
// preserve newline if not explicitly requested // preserve newline if not explicitly requested
if (scribe.preserveNewLine()) { if (scribe.printCommentPreservingNewLines()) {
scribe.space(); scribe.space();
} }
} }
@ -1251,7 +1251,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
final List<IASTDeclarator> declarators= Arrays.asList(node.getDeclarators()); final List<IASTDeclarator> declarators= Arrays.asList(node.getDeclarators());
if (!declarators.isEmpty()) { if (!declarators.isEmpty()) {
if (declarators.size() == 1 && declarators.get(0) instanceof IASTFunctionDeclarator) { if (declarators.size() == 1 && declarators.get(0) instanceof IASTFunctionDeclarator) {
if (scribe.preserveNewLine()) { if (scribe.printCommentPreservingNewLines()) {
scribe.space(); scribe.space();
} }
} else { } else {
@ -1324,7 +1324,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
} else { } else {
// preserve newline if not explicitly requested // preserve newline if not explicitly requested
scribe.preserveNewLine(); scribe.printCommentPreservingNewLines();
} }
declaration.accept(this); declaration.accept(this);
@ -1795,8 +1795,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(IASTConditionalExpression node) { private int visit(IASTConditionalExpression node) {
node.getLogicalConditionExpression().accept(this); node.getLogicalConditionExpression().accept(this);
scribe.printTrailingComment();
Alignment conditionalExpressionAlignment =scribe.createAlignment( if (preferences.insert_space_before_question_in_conditional) {
scribe.space();
}
Alignment conditionalExpressionAlignment = scribe.createAlignment(
"conditionalExpression", //$NON-NLS-1$ "conditionalExpression", //$NON-NLS-1$
preferences.alignment_for_conditional_expression, preferences.alignment_for_conditional_expression,
2, 2,
@ -1807,7 +1810,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
do { do {
try { try {
scribe.alignFragment(conditionalExpressionAlignment, 0); scribe.alignFragment(conditionalExpressionAlignment, 0);
scribe.printNextToken(Token.tQUESTION, preferences.insert_space_before_question_in_conditional); scribe.printNextToken(Token.tQUESTION, false);
if (preferences.insert_space_after_question_in_conditional) { if (preferences.insert_space_after_question_in_conditional) {
scribe.space(); scribe.space();
@ -1961,8 +1964,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
// declaration initializer // declaration initializer
Alignment expressionAlignment= scribe.createAlignment( Alignment expressionAlignment= scribe.createAlignment(
"declarationInitializer", //$NON-NLS-1$ "declarationInitializer", //$NON-NLS-1$
// need configurable alignment preferences.alignment_for_assignment,
Alignment.M_COMPACT_SPLIT,
1, 1,
scribe.scanner.getCurrentPosition()); scribe.scanner.getCurrentPosition());
@ -2003,7 +2005,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
Alignment expressionAlignment= scribe.createAlignment( Alignment expressionAlignment= scribe.createAlignment(
"designatedInitializer", //$NON-NLS-1$ "designatedInitializer", //$NON-NLS-1$
Alignment.M_COMPACT_SPLIT, preferences.alignment_for_assignment,
1, 1,
scribe.scanner.getCurrentPosition()); scribe.scanner.getCurrentPosition());
@ -2141,21 +2143,26 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private int visit(IASTBinaryExpression node) { private int visit(IASTBinaryExpression node) {
final IASTExpression op1= node.getOperand1(); if (isAssignment(node)) {
// operand 1 return formatAssignment(node);
op1.accept(this); }
Alignment expressionAlignment= scribe.createAlignment( Alignment expressionAlignment= scribe.createAlignment(
"binaryExpression", //$NON-NLS-1$ "binaryExpression", //$NON-NLS-1$
// need configurable alignment preferences.alignment_for_binary_expression,
Alignment.M_COMPACT_SPLIT, 2,
1, scribe.scanner.getCurrentPosition());
scribe.scanner.getCurrentPosition());
scribe.enterAlignment(expressionAlignment); scribe.enterAlignment(expressionAlignment);
boolean ok = false; boolean ok = false;
do { do {
try { try {
scribe.alignFragment(expressionAlignment, 0); scribe.alignFragment(expressionAlignment, 0);
final IASTExpression op1= node.getOperand1();
// operand 1
op1.accept(this);
scribe.printTrailingComment();
scribe.alignFragment(expressionAlignment, 1);
// operator // operator
final int nextToken= peekNextToken(); final int nextToken= peekNextToken();
@ -2167,22 +2174,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
case IASTBinaryExpression.op_pmarrow: case IASTBinaryExpression.op_pmarrow:
scribe.printNextToken(nextToken, false); scribe.printNextToken(nextToken, false);
break; break;
case IASTBinaryExpression.op_assign:
case IASTBinaryExpression.op_binaryAndAssign:
case IASTBinaryExpression.op_binaryOrAssign:
case IASTBinaryExpression.op_binaryXorAssign:
case IASTBinaryExpression.op_divideAssign:
case IASTBinaryExpression.op_minusAssign:
case IASTBinaryExpression.op_moduloAssign:
case IASTBinaryExpression.op_multiplyAssign:
case IASTBinaryExpression.op_plusAssign:
case IASTBinaryExpression.op_shiftLeftAssign:
case IASTBinaryExpression.op_shiftRightAssign:
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator);
if (forceSpace || preferences.insert_space_after_assignment_operator) {
scribe.space();
}
break;
default: default:
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_binary_operator); scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_binary_operator);
if (forceSpace || preferences.insert_space_after_binary_operator) { if (forceSpace || preferences.insert_space_after_binary_operator) {
@ -2203,6 +2194,64 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int formatAssignment(IASTBinaryExpression node) {
final IASTExpression op1= node.getOperand1();
// operand 1
op1.accept(this);
Alignment expressionAlignment= scribe.createAlignment(
"assignmentExpression", //$NON-NLS-1$
preferences.alignment_for_assignment,
1,
scribe.scanner.getCurrentPosition());
scribe.enterAlignment(expressionAlignment);
boolean ok = false;
do {
try {
scribe.alignFragment(expressionAlignment, 0);
// operator
final int nextToken= peekNextToken();
// in case of C++ alternative operators, like 'and', 'not', etc. a space
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator);
if (forceSpace || preferences.insert_space_after_assignment_operator) {
scribe.space();
}
// operand 2
final IASTExpression op2= node.getOperand2();
op2.accept(this);
ok = true;
} catch (AlignmentException e) {
scribe.redoAlignment(e);
}
} while (!ok);
scribe.exitAlignment(expressionAlignment, true);
return PROCESS_SKIP;
}
private boolean isAssignment(IASTBinaryExpression node) {
switch (node.getOperator()) {
case IASTBinaryExpression.op_assign:
case IASTBinaryExpression.op_binaryAndAssign:
case IASTBinaryExpression.op_binaryOrAssign:
case IASTBinaryExpression.op_binaryXorAssign:
case IASTBinaryExpression.op_divideAssign:
case IASTBinaryExpression.op_minusAssign:
case IASTBinaryExpression.op_moduloAssign:
case IASTBinaryExpression.op_multiplyAssign:
case IASTBinaryExpression.op_plusAssign:
case IASTBinaryExpression.op_shiftLeftAssign:
case IASTBinaryExpression.op_shiftRightAssign:
return true;
}
return false;
}
private int visit(IASTLiteralExpression node) { private int visit(IASTLiteralExpression node) {
if (node.getKind() == IASTLiteralExpression.lk_string_literal) { if (node.getKind() == IASTLiteralExpression.lk_string_literal) {
// handle concatenation of string literals // handle concatenation of string literals
@ -3202,13 +3251,18 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private void formatLeftCurlyBrace(final int line, final String bracePosition) { private void formatLeftCurlyBrace(final int line, final String bracePosition) {
// deal with (quite unexpected) comments right before lcurly scribe.formatBrace = true;
scribe.printComment(); try {
if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition) // deal with (quite unexpected) comments right before lcurly
&& (scribe.line > line || scribe.column >= preferences.page_width)) scribe.printComment();
{ if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition)
scribe.startNewLine(); && (scribe.line > line || scribe.column >= preferences.page_width))
} {
scribe.startNewLine();
}
} finally {
scribe.formatBrace = false;
}
} }
private void formatOpeningBrace(String bracePosition, boolean insertSpaceBeforeBrace) { private void formatOpeningBrace(String bracePosition, boolean insertSpaceBeforeBrace) {

View file

@ -56,8 +56,8 @@ public class DefaultCodeFormatterOptions {
} }
public int alignment_for_arguments_in_method_invocation; public int alignment_for_arguments_in_method_invocation;
// public int alignment_for_assignment; public int alignment_for_assignment;
// public int alignment_for_binary_expression; public int alignment_for_binary_expression;
public int alignment_for_compact_if; public int alignment_for_compact_if;
public int alignment_for_conditional_expression; public int alignment_for_conditional_expression;
public int alignment_for_expressions_in_initializer_list; public int alignment_for_expressions_in_initializer_list;
@ -238,6 +238,7 @@ public class DefaultCodeFormatterOptions {
public boolean keep_simple_if_on_one_line; public boolean keep_simple_if_on_one_line;
public boolean keep_then_statement_on_same_line; public boolean keep_then_statement_on_same_line;
public int number_of_empty_lines_to_preserve; public int number_of_empty_lines_to_preserve;
public boolean join_wrapped_lines;
public boolean put_empty_statement_on_new_line; public boolean put_empty_statement_on_new_line;
public int tab_size; public int tab_size;
public int page_width; public int page_width;
@ -264,8 +265,8 @@ public class DefaultCodeFormatterOptions {
Map<String,String> options = new HashMap<String,String>(); Map<String,String> options = new HashMap<String,String>();
// options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_allocation_expression)); // options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_allocation_expression));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation));
// options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, getAlignment(this.alignment_for_assignment)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, getAlignment(this.alignment_for_assignment));
// options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, getAlignment(this.alignment_for_binary_expression)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, getAlignment(this.alignment_for_binary_expression));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF, getAlignment(this.alignment_for_compact_if)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF, getAlignment(this.alignment_for_compact_if));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, getAlignment(this.alignment_for_conditional_expression)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, getAlignment(this.alignment_for_conditional_expression));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_INITIALIZER_LIST, getAlignment(this.alignment_for_expressions_in_initializer_list)); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_INITIALIZER_LIST, getAlignment(this.alignment_for_expressions_in_initializer_list));
@ -439,6 +440,7 @@ public class DefaultCodeFormatterOptions {
options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_SIMPLE_IF_ON_ONE_LINE, this.keep_simple_if_on_one_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_SIMPLE_IF_ON_ONE_LINE, this.keep_simple_if_on_one_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_THEN_STATEMENT_ON_SAME_LINE, this.keep_then_statement_on_same_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_THEN_STATEMENT_ON_SAME_LINE, this.keep_then_statement_on_same_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, Integer.toString(this.number_of_empty_lines_to_preserve)); options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, Integer.toString(this.number_of_empty_lines_to_preserve));
options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, this.join_wrapped_lines ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, this.put_empty_statement_on_new_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, this.put_empty_statement_on_new_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(this.page_width)); options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(this.page_width));
switch(this.tab_char) { switch(this.tab_char) {
@ -478,26 +480,26 @@ public class DefaultCodeFormatterOptions {
this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
} }
} }
// final Object alignmentForAssignmentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT); final Object alignmentForAssignmentOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT);
// if (alignmentForAssignmentOption != null) { if (alignmentForAssignmentOption != null) {
// try { try {
// this.alignment_for_assignment = Integer.parseInt((String) alignmentForAssignmentOption); this.alignment_for_assignment = Integer.parseInt((String) alignmentForAssignmentOption);
// } catch (NumberFormatException e) { } catch (NumberFormatException e) {
// this.alignment_for_assignment = Alignment.M_ONE_PER_LINE_SPLIT; this.alignment_for_assignment = Alignment.M_ONE_PER_LINE_SPLIT;
// } catch (ClassCastException e) { } catch (ClassCastException e) {
// this.alignment_for_assignment = Alignment.M_ONE_PER_LINE_SPLIT; this.alignment_for_assignment = Alignment.M_ONE_PER_LINE_SPLIT;
// } }
// } }
// final Object alignmentForBinaryExpressionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION); final Object alignmentForBinaryExpressionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION);
// if (alignmentForBinaryExpressionOption != null) { if (alignmentForBinaryExpressionOption != null) {
// try { try {
// this.alignment_for_binary_expression = Integer.parseInt((String) alignmentForBinaryExpressionOption); this.alignment_for_binary_expression = Integer.parseInt((String) alignmentForBinaryExpressionOption);
// } catch (NumberFormatException e) { } catch (NumberFormatException e) {
// this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT; this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
// } catch (ClassCastException e) { } catch (ClassCastException e) {
// this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT; this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
// } }
// } }
final Object alignmentForCompactIfOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF); final Object alignmentForCompactIfOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF);
if (alignmentForCompactIfOption != null) { if (alignmentForCompactIfOption != null) {
try { try {
@ -1360,6 +1362,10 @@ public class DefaultCodeFormatterOptions {
this.number_of_empty_lines_to_preserve = 0; this.number_of_empty_lines_to_preserve = 0;
} }
} }
final Object joinWrappedLinesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES);
if (joinWrappedLinesOption != null) {
this.join_wrapped_lines = DefaultCodeFormatterConstants.TRUE.equals(joinWrappedLinesOption);
}
final Object putEmptyStatementOnNewLineOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE); final Object putEmptyStatementOnNewLineOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE);
if (putEmptyStatementOnNewLineOption != null) { if (putEmptyStatementOnNewLineOption != null) {
this.put_empty_statement_on_new_line = DefaultCodeFormatterConstants.TRUE.equals(putEmptyStatementOnNewLineOption); this.put_empty_statement_on_new_line = DefaultCodeFormatterConstants.TRUE.equals(putEmptyStatementOnNewLineOption);
@ -1403,9 +1409,9 @@ public class DefaultCodeFormatterOptions {
public void setDefaultSettings() { public void setDefaultSettings() {
// this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT; // this.alignment_for_arguments_in_allocation_expression = Alignment.M_COMPACT_SPLIT;
this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT; this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
// this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT; this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT;
// this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT; this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
// this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT; this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT;
this.alignment_for_conditional_expression = Alignment.M_NEXT_PER_LINE_SPLIT; this.alignment_for_conditional_expression = Alignment.M_NEXT_PER_LINE_SPLIT;
this.alignment_for_expressions_in_initializer_list = Alignment.M_COMPACT_SPLIT; this.alignment_for_expressions_in_initializer_list = Alignment.M_COMPACT_SPLIT;
this.alignment_for_declarator_list = Alignment.M_COMPACT_SPLIT; this.alignment_for_declarator_list = Alignment.M_COMPACT_SPLIT;
@ -1576,6 +1582,7 @@ public class DefaultCodeFormatterOptions {
this.keep_simple_if_on_one_line = false; this.keep_simple_if_on_one_line = false;
this.keep_then_statement_on_same_line = false; this.keep_then_statement_on_same_line = false;
this.number_of_empty_lines_to_preserve = 1; this.number_of_empty_lines_to_preserve = 1;
this.join_wrapped_lines = true;
this.put_empty_statement_on_new_line = true; this.put_empty_statement_on_new_line = true;
this.tab_size = 4; this.tab_size = 4;
this.page_width = 80; this.page_width = 80;
@ -1659,7 +1666,6 @@ public class DefaultCodeFormatterOptions {
this.keep_empty_initializer_list_on_one_line = false; this.keep_empty_initializer_list_on_one_line = false;
this.keep_simple_if_on_one_line = false; this.keep_simple_if_on_one_line = false;
this.keep_then_statement_on_same_line = false; this.keep_then_statement_on_same_line = false;
this.number_of_empty_lines_to_preserve = 1;
this.put_empty_statement_on_new_line = true; this.put_empty_statement_on_new_line = true;
this.tab_size = 4; this.tab_size = 4;
this.page_width = 80; this.page_width = 80;
@ -1732,7 +1738,6 @@ public class DefaultCodeFormatterOptions {
this.keep_empty_initializer_list_on_one_line = false; this.keep_empty_initializer_list_on_one_line = false;
this.keep_simple_if_on_one_line = false; this.keep_simple_if_on_one_line = false;
this.keep_then_statement_on_same_line = false; this.keep_then_statement_on_same_line = false;
this.number_of_empty_lines_to_preserve = 1;
this.put_empty_statement_on_new_line = true; this.put_empty_statement_on_new_line = true;
this.tab_size = 2; this.tab_size = 2;
this.page_width = 80; this.page_width = 80;
@ -1799,7 +1804,6 @@ public class DefaultCodeFormatterOptions {
this.keep_empty_initializer_list_on_one_line = false; this.keep_empty_initializer_list_on_one_line = false;
this.keep_simple_if_on_one_line = false; this.keep_simple_if_on_one_line = false;
this.keep_then_statement_on_same_line = false; this.keep_then_statement_on_same_line = false;
this.number_of_empty_lines_to_preserve = 1;
this.put_empty_statement_on_new_line = true; this.put_empty_statement_on_new_line = true;
this.tab_size = 8; this.tab_size = 8;
this.page_width = 80; this.page_width = 80;

View file

@ -65,10 +65,11 @@ public class Scribe {
private boolean preserveNewLines; private boolean preserveNewLines;
private boolean checkLineWrapping; private boolean checkLineWrapping;
public int lastNumberOfNewLines; public int lastNumberOfNewLines;
boolean formatBrace;
public int line; public int line;
public boolean needSpace= false; public boolean needSpace;
public boolean pendingSpace= false; public boolean pendingSpace;
public int tabLength; public int tabLength;
public int tabChar; public int tabChar;
@ -103,6 +104,7 @@ public class Scribe {
} }
lineSeparator= preferences.line_separator; lineSeparator= preferences.line_separator;
indentationLevel= preferences.initial_indentation_level * indentationSize; indentationLevel= preferences.initial_indentation_level * indentationSize;
preserveNewLines = false;
textRegionStart= offset; textRegionStart= offset;
textRegionEnd= offset + length - 1; textRegionEnd= offset + length - 1;
reset(); reset();
@ -424,8 +426,7 @@ public class Scribe {
public String getNewLine() { public String getNewLine() {
if (lastNumberOfNewLines >= 1) { if (lastNumberOfNewLines >= 1) {
column= 1; // ensure that the scribe is at the beginning of a new column= 1; // ensure that the scribe is at the beginning of a new line
// line
return EMPTY_STRING; return EMPTY_STRING;
} }
line++; line++;
@ -458,13 +459,26 @@ public class Scribe {
} }
private String getPreserveEmptyLines(int count) { private String getPreserveEmptyLines(int count) {
if (count > 0) { if (count == 0 && !preserveNewLines) {
if (preferences.number_of_empty_lines_to_preserve != 0) { // preserve line breaks in wrapping if specified
int linesToPreserve= Math.min(count, preferences.number_of_empty_lines_to_preserve); if ((!preferences.join_wrapped_lines) && lastNumberOfNewLines == 0) {
return getEmptyLines(linesToPreserve); // Create new line
} else { StringBuilder tempBuffer = new StringBuilder();
return getNewLine(); tempBuffer.append(getNewLine());
if (currentAlignment != null && !formatBrace) {
indentationLevel = currentAlignment.breakIndentationLevel;
}
// Print the computed indentation in the buffer
printIndentationIfNecessary(tempBuffer);
return tempBuffer.toString();
} }
return EMPTY_STRING;
}
if (preferences.number_of_empty_lines_to_preserve != 0) {
int linesToPreserve= Math.min(count, preferences.number_of_empty_lines_to_preserve);
return getEmptyLines(linesToPreserve);
} else if (preserveNewLines) { } else if (preserveNewLines) {
return getNewLine(); return getNewLine();
} }
@ -753,9 +767,6 @@ public class Scribe {
lastNumberOfNewLines= 0; lastNumberOfNewLines= 0;
printIndentationIfNecessary(); printIndentationIfNecessary();
if (considerSpaceIfAny) { if (considerSpaceIfAny) {
if (currentAlignment != null && currentAlignment.isIndentOnColumn(column)) {
needSpace= true;
}
space(); space();
} }
if (pendingSpace) { if (pendingSpace) {
@ -961,7 +972,7 @@ public class Scribe {
} else if (hasLineComment) { } else if (hasLineComment) {
preserveEmptyLines(count - 1, scanner.getCurrentTokenStartPosition()); preserveEmptyLines(count - 1, scanner.getCurrentTokenStartPosition());
addDeleteEdit(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition()); addDeleteEdit(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
} else if (count != 0 && preferences.number_of_empty_lines_to_preserve != 0) { } else if (count != 0 && (!preferences.join_wrapped_lines || preferences.number_of_empty_lines_to_preserve != 0)) {
String preservedEmptyLines= getPreserveEmptyLines(count - 1); String preservedEmptyLines= getPreserveEmptyLines(count - 1);
addReplaceEdit(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), addReplaceEdit(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
preservedEmptyLines); preservedEmptyLines);
@ -1230,7 +1241,8 @@ public class Scribe {
return; return;
} }
if (lastNumberOfNewLines >= 1) { if (lastNumberOfNewLines >= 1) {
column= 1; // ensure that the scribe is at the beginning of a new line // ensure that the scribe is at the beginning of a new line
column = 1;
return; return;
} }
addInsertEdit(insertPosition, lineSeparator); addInsertEdit(insertPosition, lineSeparator);
@ -1246,21 +1258,31 @@ public class Scribe {
} }
public void printNextToken(int expectedTokenType, boolean considerSpaceIfAny) { public void printNextToken(int expectedTokenType, boolean considerSpaceIfAny) {
printComment(); // Set brace flag, it's useful for the scribe while preserving line breaks
if (shouldSkip(scanner.getCurrentPosition())) { switch (expectedTokenType) {
return; case Token.tRBRACE:
case Token.tLBRACE:
formatBrace = true;
} }
currentToken= scanner.nextToken(); try {
if (currentToken == null || expectedTokenType != currentToken.type) { printComment();
if (pendingSpace) { if (shouldSkip(scanner.getCurrentPosition())) {
addInsertEdit(scanner.getCurrentTokenStartPosition(), SPACE); return;
} }
pendingSpace= false; currentToken= scanner.nextToken();
needSpace= true; if (currentToken == null || expectedTokenType != currentToken.type) {
throw new AbortFormatting( if (pendingSpace) {
"[" + (line+1) + "/" + column + "] unexpected token type, expecting:" + expectedTokenType + ", actual:" + currentToken);//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ addInsertEdit(scanner.getCurrentTokenStartPosition(), SPACE);
}
pendingSpace= false;
needSpace= true;
throw new AbortFormatting(
"[" + (line+1) + "/" + column + "] unexpected token type, expecting:" + expectedTokenType + ", actual:" + currentToken);//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
print(currentToken.getLength(), considerSpaceIfAny);
} finally {
formatBrace = false;
} }
print(currentToken.getLength(), considerSpaceIfAny);
} }
public void printNextToken(int[] expectedTokenTypes) { public void printNextToken(int[] expectedTokenTypes) {
@ -1596,16 +1618,6 @@ public class Scribe {
return !isFirstModifier; return !isFirstModifier;
} }
public boolean preserveNewLine() {
boolean savedPreserveNewLines= preserveNewLines;
try {
preserveNewLines= true;
return printComment();
} finally {
preserveNewLines= savedPreserveNewLines;
}
}
/** /**
* Skip to the next occurrence of the given token type. * Skip to the next occurrence of the given token type.
* If successful, the next token will be the epxected token, * If successful, the next token will be the epxected token,
@ -1672,12 +1684,12 @@ public class Scribe {
} }
public boolean printCommentPreservingNewLines() { public boolean printCommentPreservingNewLines() {
final boolean savedPreserveNL= this.preserveNewLines; final boolean savedPreserveNL= preserveNewLines;
this.preserveNewLines= true; preserveNewLines= true;
try { try {
return printComment(); return printComment();
} finally { } finally {
this.preserveNewLines= savedPreserveNL; preserveNewLines= savedPreserveNL;
} }
} }
@ -1729,7 +1741,6 @@ public class Scribe {
scanner.resetTo(offset, scannerEndPosition - 1); scanner.resetTo(offset, scannerEndPosition - 1);
} }
} }
} }
} }

View file

@ -222,6 +222,7 @@ public class CodeFormatterTest extends BaseUITestCase {
//int verylooooooooooooooooooooooooooooooooooongname = //int verylooooooooooooooooooooooooooooooooooongname =
// 0000000000000000000000000000000; // 0000000000000000000000000000000;
public void testLineWrappingOfInitializerExpression_Bug200961() throws Exception { public void testLineWrappingOfInitializerExpression_Bug200961() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, Integer.toString(Alignment.M_COMPACT_SPLIT));
assertFormatterResult(); assertFormatterResult();
} }
@ -1407,5 +1408,43 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testRangeBasedFor_Bug328472() throws Exception { public void testRangeBasedFor_Bug328472() throws Exception {
assertFormatterResult(); assertFormatterResult();
} }
//int table[][] = {
// {1,2,3,4},
// { 1, 2, 3 , 4},
//{ 1,2, 3,4 },
// {1, 2,3, 4}
// };
//int table[][] = {
// { 1, 2, 3, 4 },
// { 1, 2, 3, 4 },
// { 1, 2, 3, 4 },
// { 1, 2, 3, 4 }
//};
public void testKeepWrappedLines_Bug322776() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.FALSE);
assertFormatterResult();
}
//void f() {
//double confidence = 0.316030 //
//- 0.016315 * C_Count //
//+ 0.034336 * N_Count //
//+ 0.066810 * O_Count //
//+ 0.035674 * F_Count;
//}
//void f() {
// double confidence = 0.316030 //
// - 0.016315 * C_Count //
// + 0.034336 * N_Count //
// + 0.066810 * O_Count //
// + 0.035674 * F_Count;
//}
public void testAlignmentOfBinaryExpression_Bug325787() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
assertFormatterResult();
}
} }

View file

@ -205,7 +205,7 @@ final class FormatterMessages extends NLS {
public static String LineWrappingTabPage_enumerator_list; public static String LineWrappingTabPage_enumerator_list;
public static String LineWrappingTabPage_initializer_list; public static String LineWrappingTabPage_initializer_list;
public static String LineWrappingTabPage_conditionals; public static String LineWrappingTabPage_conditionals;
// public static String LineWrappingTabPage_binary_exprs; public static String LineWrappingTabPage_binary_exprs;
public static String LineWrappingTabPage_indentation_default; public static String LineWrappingTabPage_indentation_default;
public static String LineWrappingTabPage_indentation_on_column; public static String LineWrappingTabPage_indentation_on_column;
public static String LineWrappingTabPage_indentation_by_one; public static String LineWrappingTabPage_indentation_by_one;
@ -214,6 +214,7 @@ final class FormatterMessages extends NLS {
public static String LineWrappingTabPage_function_calls; public static String LineWrappingTabPage_function_calls;
public static String LineWrappingTabPage_expressions; public static String LineWrappingTabPage_expressions;
// public static String LineWrappingTabPage_statements; // public static String LineWrappingTabPage_statements;
public static String LineWrappingTabPage_do_not_join_lines;
public static String LineWrappingTabPage_base_clause_lowercase; public static String LineWrappingTabPage_base_clause_lowercase;
// public static String LineWrappingTabPage_compact_if_else_lowercase; // public static String LineWrappingTabPage_compact_if_else_lowercase;
@ -224,7 +225,7 @@ final class FormatterMessages extends NLS {
public static String LineWrappingTabPage_enumerator_list_lowercase; public static String LineWrappingTabPage_enumerator_list_lowercase;
public static String LineWrappingTabPage_initializer_list_lowercase; public static String LineWrappingTabPage_initializer_list_lowercase;
public static String LineWrappingTabPage_conditionals_lowercase; public static String LineWrappingTabPage_conditionals_lowercase;
// public static String LineWrappingTabPage_binary_exprs_lowercase; public static String LineWrappingTabPage_binary_exprs_lowercase;
public static String LineWrappingTabPage_indentation_default_lowercase; public static String LineWrappingTabPage_indentation_default_lowercase;
public static String LineWrappingTabPage_indentation_on_column_lowercase; public static String LineWrappingTabPage_indentation_on_column_lowercase;
public static String LineWrappingTabPage_indentation_by_one_lowercase; public static String LineWrappingTabPage_indentation_by_one_lowercase;
@ -233,7 +234,8 @@ final class FormatterMessages extends NLS {
public static String LineWrappingTabPage_function_calls_lowercase; public static String LineWrappingTabPage_function_calls_lowercase;
public static String LineWrappingTabPage_expressions_lowercase; public static String LineWrappingTabPage_expressions_lowercase;
// public static String LineWrappingTabPage_statements_lowercase; // public static String LineWrappingTabPage_statements_lowercase;
public static String LineWrappingTabPage_assignment_alignment_lowercase;
public static String LineWrappingTabPage_wrapping_policy_label_text; public static String LineWrappingTabPage_wrapping_policy_label_text;
public static String LineWrappingTabPage_indentation_policy_label_text; public static String LineWrappingTabPage_indentation_policy_label_text;
public static String LineWrappingTabPage_force_split_checkbox_text; public static String LineWrappingTabPage_force_split_checkbox_text;
@ -255,7 +257,7 @@ final class FormatterMessages extends NLS {
public static String LineWrappingTabPage_width_indent_option_default_indent_wrapped; public static String LineWrappingTabPage_width_indent_option_default_indent_wrapped;
public static String LineWrappingTabPage_width_indent_option_default_indent_array; public static String LineWrappingTabPage_width_indent_option_default_indent_array;
public static String LineWrappingTabPage_error_invalid_value; public static String LineWrappingTabPage_error_invalid_value;
// public static String LineWrappingTabPage_assignment_alignment; public static String LineWrappingTabPage_assignment_alignment;
public static String AlreadyExistsDialog_message_profile_already_exists; public static String AlreadyExistsDialog_message_profile_already_exists;
public static String AlreadyExistsDialog_message_profile_name_empty; public static String AlreadyExistsDialog_message_profile_name_empty;
public static String AlreadyExistsDialog_dialog_title; public static String AlreadyExistsDialog_dialog_title;

View file

@ -232,7 +232,7 @@ LineWrappingTabPage_enum_decls='enum' declaration
LineWrappingTabPage_enumerator_list=Enumerator list LineWrappingTabPage_enumerator_list=Enumerator list
LineWrappingTabPage_initializer_list=Initializer list LineWrappingTabPage_initializer_list=Initializer list
LineWrappingTabPage_conditionals=Conditionals LineWrappingTabPage_conditionals=Conditionals
#LineWrappingTabPage_binary_exprs=Binary expressions LineWrappingTabPage_binary_exprs=Binary expressions
LineWrappingTabPage_indentation_default=Default indentation LineWrappingTabPage_indentation_default=Default indentation
LineWrappingTabPage_indentation_on_column=Indent on column LineWrappingTabPage_indentation_on_column=Indent on column
LineWrappingTabPage_indentation_by_one=Indent by one LineWrappingTabPage_indentation_by_one=Indent by one
@ -241,6 +241,7 @@ LineWrappingTabPage_function_decls=Function declarations
LineWrappingTabPage_function_calls=Function calls LineWrappingTabPage_function_calls=Function calls
LineWrappingTabPage_expressions=Expressions LineWrappingTabPage_expressions=Expressions
#LineWrappingTabPage_statements=Statements #LineWrappingTabPage_statements=Statements
LineWrappingTabPage_do_not_join_lines=Never join already wrapped lin&es
#lower case table entries description; #lower case table entries description;
LineWrappingTabPage_base_clause_lowercase=base-clause LineWrappingTabPage_base_clause_lowercase=base-clause
@ -253,7 +254,7 @@ LineWrappingTabPage_enum_decls_lowercase='enum' declaration
LineWrappingTabPage_enumerator_list_lowercase=enumerator list LineWrappingTabPage_enumerator_list_lowercase=enumerator list
LineWrappingTabPage_initializer_list_lowercase=initializer list LineWrappingTabPage_initializer_list_lowercase=initializer list
LineWrappingTabPage_conditionals_lowercase=conditionals LineWrappingTabPage_conditionals_lowercase=conditionals
#LineWrappingTabPage_binary_exprs_lowercase=binary expressions LineWrappingTabPage_binary_exprs_lowercase=binary expressions
LineWrappingTabPage_indentation_default_lowercase=default indentation LineWrappingTabPage_indentation_default_lowercase=default indentation
LineWrappingTabPage_indentation_on_column_lowercase=indent on column LineWrappingTabPage_indentation_on_column_lowercase=indent on column
LineWrappingTabPage_indentation_by_one_lowercase=indent by one LineWrappingTabPage_indentation_by_one_lowercase=indent by one
@ -262,6 +263,7 @@ LineWrappingTabPage_function_decls_lowercase=function declarations
LineWrappingTabPage_function_calls_lowercase=function calls LineWrappingTabPage_function_calls_lowercase=function calls
LineWrappingTabPage_expressions_lowercase=expressions LineWrappingTabPage_expressions_lowercase=expressions
#LineWrappingTabPage_statements_lowercase=statements #LineWrappingTabPage_statements_lowercase=statements
LineWrappingTabPage_assignment_alignment_lowercase=assignments
LineWrappingTabPage_wrapping_policy_label_text=Lin&e wrapping policy: LineWrappingTabPage_wrapping_policy_label_text=Lin&e wrapping policy:
LineWrappingTabPage_indentation_policy_label_text=Indent&ation policy: LineWrappingTabPage_indentation_policy_label_text=Indent&ation policy:
@ -284,7 +286,7 @@ LineWrappingTabPage_width_indent_option_max_line_width=Ma&ximum line width:
LineWrappingTabPage_width_indent_option_default_indent_wrapped=Defa&ult indentation for wrapped lines: LineWrappingTabPage_width_indent_option_default_indent_wrapped=Defa&ult indentation for wrapped lines:
LineWrappingTabPage_width_indent_option_default_indent_array=Default indentation for initializer lists: LineWrappingTabPage_width_indent_option_default_indent_array=Default indentation for initializer lists:
LineWrappingTabPage_error_invalid_value=The key ''{0}'' contained an invalid value; resetting to defaults. LineWrappingTabPage_error_invalid_value=The key ''{0}'' contained an invalid value; resetting to defaults.
#LineWrappingTabPage_assignment_alignment=Assignments LineWrappingTabPage_assignment_alignment=Assignments
AlreadyExistsDialog_message_profile_already_exists=A profile with this name already exists. AlreadyExistsDialog_message_profile_already_exists=A profile with this name already exists.

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others. * Copyright (c) 2005, 2010 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
@ -21,12 +21,20 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
public abstract class FormatterTabPage extends ModifyDialogTabPage { public abstract class FormatterTabPage extends ModifyDialogTabPage {
private final static String SHOW_INVISIBLE_PREFERENCE_KEY= CUIPlugin.PLUGIN_ID + ".formatter_page.show_invisible_characters"; //$NON-NLS-1$ private final static String SHOW_INVISIBLE_PREFERENCE_KEY= CUIPlugin.PLUGIN_ID + ".formatter_page.show_invisible_characters"; //$NON-NLS-1$
/**
* Constant array for boolean true/false selection.
*
* @since 5.3
*/
protected static String[] TRUE_FALSE= { DefaultCodeFormatterConstants.TRUE, DefaultCodeFormatterConstants.FALSE };
private CPreview fPreview; private CPreview fPreview;
private final IDialogSettings fDialogSettings; private final IDialogSettings fDialogSettings;
private Button fShowInvisibleButton; private Button fShowInvisibleButton;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2009 IBM Corporation and others. * Copyright (c) 2000, 2010 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
@ -447,18 +447,18 @@ public class LineWrappingTabPage extends FormatterTabPage {
FormatterMessages.LineWrappingTabPage_conditionals_lowercase FormatterMessages.LineWrappingTabPage_conditionals_lowercase
); );
// private final Category fBinaryExpressionCategory= new Category( private final Category fBinaryExpressionCategory= new Category(
// DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
// "class Example extends AnotherClass {" + //$NON-NLS-1$ "class Example : AnotherClass {" + //$NON-NLS-1$
// "int foo() {" + //$NON-NLS-1$ "int foo() {" + //$NON-NLS-1$
// " int sum= 100 + 200 + 300 + 400 + 500 + 600 + 700 + 800;" + //$NON-NLS-1$ " int sum= 100 + 200 + 300 + 400 + 500 + 600 + 700 + 800;" + //$NON-NLS-1$
// " int product= 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10;" + //$NON-NLS-1$ " int product= 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10;" + //$NON-NLS-1$
// " boolean val= true && false && true && false && true;" + //$NON-NLS-1$ " bool val= true && false && true && false && true;" + //$NON-NLS-1$
// " return product / sum;}}", //$NON-NLS-1$ " return product / sum;}}", //$NON-NLS-1$
// FormatterMessages.LineWrappingTabPage_binary_exprs, FormatterMessages.LineWrappingTabPage_binary_exprs,
// FormatterMessages.LineWrappingTabPage_binary_exprs_lowercase FormatterMessages.LineWrappingTabPage_binary_exprs_lowercase
// ); );
//
// private final Category fEnumConstArgumentsCategory= new Category( // private final Category fEnumConstArgumentsCategory= new Category(
// DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT, // DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT,
// "enum Example {" + //$NON-NLS-1$ // "enum Example {" + //$NON-NLS-1$
@ -482,18 +482,18 @@ public class LineWrappingTabPage extends FormatterTabPage {
FormatterMessages.LineWrappingTabPage_enumerator_list, FormatterMessages.LineWrappingTabPage_enumerator_list,
FormatterMessages.LineWrappingTabPage_enumerator_list_lowercase FormatterMessages.LineWrappingTabPage_enumerator_list_lowercase
); );
//
// private final Category fAssignmentCategory= new Category( private final Category fAssignmentCategory= new Category(
// DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT,
// "class Example {" + //$NON-NLS-1$ "static char* string = \"TextTextText\";" + //$NON-NLS-1$
// "private static final String string = \"TextTextText\";" + //$NON-NLS-1$ "class Example {" + //$NON-NLS-1$
// "void foo() {" + //$NON-NLS-1$ "void foo() {" + //$NON-NLS-1$
// "for (int i = 0; i < 10; i++) {}" + //$NON-NLS-1$ "for (int i = 0; i < 10; i++) {}" + //$NON-NLS-1$
// "String s;" + //$NON-NLS-1$ "char* s;" + //$NON-NLS-1$
// "s = \"TextTextText\";}}", //$NON-NLS-1$ "s = \"TextTextText\";}}", //$NON-NLS-1$
// FormatterMessages.LineWrappingTabPage_assignment_alignment, FormatterMessages.LineWrappingTabPage_assignment_alignment,
// FormatterMessages.LineWrappingTabPage_assignment_alignment_lowercase FormatterMessages.LineWrappingTabPage_assignment_alignment_lowercase
// ); );
/** /**
* The default preview line width. * The default preview line width.
@ -600,10 +600,10 @@ public class LineWrappingTabPage extends FormatterTabPage {
// functionCalls.children.add(fQualifiedAllocationExpressionCategory); // functionCalls.children.add(fQualifiedAllocationExpressionCategory);
final Category expressions= new Category(FormatterMessages.LineWrappingTabPage_expressions,FormatterMessages.LineWrappingTabPage_expressions_lowercase); final Category expressions= new Category(FormatterMessages.LineWrappingTabPage_expressions,FormatterMessages.LineWrappingTabPage_expressions_lowercase);
// expressions.children.add(fBinaryExpressionCategory); expressions.children.add(fBinaryExpressionCategory);
expressions.children.add(fConditionalExpressionCategory); expressions.children.add(fConditionalExpressionCategory);
expressions.children.add(fInitializerListExpressionsCategory); expressions.children.add(fInitializerListExpressionsCategory);
// expressions.children.add(fAssignmentCategory); expressions.children.add(fAssignmentCategory);
// final Category statements= new Category(FormatterMessages.LineWrappingTabPage_statements); // final Category statements= new Category(FormatterMessages.LineWrappingTabPage_statements);
// statements.children.add(fCompactIfCategory); // statements.children.add(fCompactIfCategory);
@ -631,6 +631,7 @@ public class LineWrappingTabPage extends FormatterTabPage {
createNumberPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_width_indent_option_max_line_width, DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, 0, 9999); createNumberPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_width_indent_option_max_line_width, DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, 0, 9999);
createNumberPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_width_indent_option_default_indent_wrapped, DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, 0, 9999); createNumberPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_width_indent_option_default_indent_wrapped, DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, 0, 9999);
createNumberPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_width_indent_option_default_indent_array, DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_INITIALIZER_LIST, 0, 9999); createNumberPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_width_indent_option_default_indent_array, DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_INITIALIZER_LIST, 0, 9999);
createCheckboxPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_do_not_join_lines, DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, TRUE_FALSE);
fCategoriesViewer= new TreeViewer(composite /*categoryGroup*/, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL ); fCategoriesViewer= new TreeViewer(composite /*categoryGroup*/, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL );
fCategoriesViewer.setContentProvider(new ITreeContentProvider() { fCategoriesViewer.setContentProvider(new ITreeContentProvider() {