mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Fixed a corner case in function call formatting.
This commit is contained in:
parent
199adb3ec5
commit
e23e0a9238
3 changed files with 43 additions and 33 deletions
|
@ -170,7 +170,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
|
|
||||||
private static class ListOptions {
|
private static class ListOptions {
|
||||||
final int fMode;
|
final int fMode;
|
||||||
boolean fUseFallbackMode;
|
boolean fInsertNewLineBeforeListIfNecessary;
|
||||||
boolean fSpaceBeforeComma;
|
boolean fSpaceBeforeComma;
|
||||||
boolean fSpaceAfterComma = true;
|
boolean fSpaceAfterComma = true;
|
||||||
boolean fSpaceAfterOpeningParen;
|
boolean fSpaceAfterOpeningParen;
|
||||||
|
@ -1457,7 +1457,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
|
|
||||||
private ListOptions createListOptionsForFunctionDeclarationParameters() {
|
private ListOptions createListOptionsForFunctionDeclarationParameters() {
|
||||||
final ListOptions options= new ListOptions(preferences.alignment_for_parameters_in_method_declaration);
|
final ListOptions options= new ListOptions(preferences.alignment_for_parameters_in_method_declaration);
|
||||||
options.fUseFallbackMode= true;
|
options.fInsertNewLineBeforeListIfNecessary= true;
|
||||||
options.fSpaceBeforeOpeningParen= preferences.insert_space_before_opening_paren_in_method_declaration;
|
options.fSpaceBeforeOpeningParen= preferences.insert_space_before_opening_paren_in_method_declaration;
|
||||||
options.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_declaration;
|
options.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_declaration;
|
||||||
options.fSpaceBeforeClosingParen= preferences.insert_space_before_closing_paren_in_method_declaration;
|
options.fSpaceBeforeClosingParen= preferences.insert_space_before_closing_paren_in_method_declaration;
|
||||||
|
@ -2003,38 +2003,36 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
if (options.fSpaceAfterOpeningParen) {
|
if (options.fSpaceAfterOpeningParen) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
Alignment retryAlignment = null;
|
Alignment wrapperAlignment = null;
|
||||||
|
|
||||||
int fallbackMode = options.fUseFallbackMode ?
|
final int continuationIndentation= options.fContinuationIndentation >= 0 ?
|
||||||
getFallbackAlignmentMode(options.fMode) : options.fMode;
|
options.fContinuationIndentation : preferences.continuation_indentation;
|
||||||
if (fallbackMode != options.fMode) {
|
if (options.fInsertNewLineBeforeListIfNecessary &&
|
||||||
retryAlignment = scribe.createAlignment(
|
(options.fMode & Alignment.M_INDENT_ON_COLUMN) != 0) {
|
||||||
Alignment.LIST_FALLBACK_TRAP,
|
wrapperAlignment = scribe.createAlignment(
|
||||||
Alignment.M_ONE_PER_LINE_SPLIT,
|
Alignment.LIST_WRAPPER,
|
||||||
|
Alignment.M_COMPACT_FIRST_BREAK_SPLIT,
|
||||||
Alignment.R_INNERMOST,
|
Alignment.R_INNERMOST,
|
||||||
1,
|
1,
|
||||||
scribe.scanner.getCurrentPosition(),
|
scribe.scanner.getCurrentPosition(),
|
||||||
0,
|
continuationIndentation,
|
||||||
false);
|
false);
|
||||||
scribe.enterAlignment(retryAlignment);
|
scribe.enterAlignment(wrapperAlignment);
|
||||||
}
|
}
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
int mode = options.fMode;
|
|
||||||
do {
|
do {
|
||||||
if (retryAlignment != null)
|
if (wrapperAlignment != null)
|
||||||
scribe.alignFragment(retryAlignment, 0);
|
scribe.alignFragment(wrapperAlignment, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int continuationIndentation= options.fContinuationIndentation >= 0 ?
|
|
||||||
options.fContinuationIndentation : preferences.continuation_indentation;
|
|
||||||
Alignment alignment = scribe.createAlignment(
|
Alignment alignment = scribe.createAlignment(
|
||||||
Alignment.LIST_ELEMENTS_PREFIX +
|
Alignment.LIST_ELEMENTS_PREFIX +
|
||||||
(elements.isEmpty() ? "ellipsis" : elements.get(0).getClass().getSimpleName()), //$NON-NLS-1$
|
(elements.isEmpty() ? "ellipsis" : elements.get(0).getClass().getSimpleName()), //$NON-NLS-1$
|
||||||
mode,
|
options.fMode,
|
||||||
options.fTieBreakRule,
|
options.fTieBreakRule,
|
||||||
elementsLength + (addEllipsis ? 1 : 0),
|
elementsLength + (addEllipsis ? 1 : 0),
|
||||||
scribe.scanner.getCurrentPosition(),
|
scribe.scanner.getCurrentPosition(),
|
||||||
continuationIndentation,
|
wrapperAlignment == null ? continuationIndentation : 0,
|
||||||
false);
|
false);
|
||||||
scribe.enterAlignment(alignment);
|
scribe.enterAlignment(alignment);
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
|
@ -2082,27 +2080,18 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
scribe.exitAlignment(alignment, true);
|
scribe.exitAlignment(alignment, true);
|
||||||
success = true;
|
success = true;
|
||||||
} catch (AlignmentException e) {
|
} catch (AlignmentException e) {
|
||||||
if (retryAlignment == null)
|
if (wrapperAlignment == null)
|
||||||
throw e;
|
throw e;
|
||||||
scribe.redoAlignment(e);
|
scribe.redoAlignment(e);
|
||||||
}
|
}
|
||||||
mode = fallbackMode;
|
} while (wrapperAlignment != null && !success);
|
||||||
} while (!success);
|
if (wrapperAlignment != null)
|
||||||
if (retryAlignment != null)
|
scribe.exitAlignment(wrapperAlignment, true);
|
||||||
scribe.exitAlignment(retryAlignment, true);
|
|
||||||
} else if (tailFormatter != null) {
|
} else if (tailFormatter != null) {
|
||||||
tailFormatter.run();
|
tailFormatter.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getFallbackAlignmentMode(int alignmentMode) {
|
|
||||||
switch (alignmentMode & Alignment.SPLIT_MASK) {
|
|
||||||
case Alignment.M_COMPACT_SPLIT:
|
|
||||||
alignmentMode = Alignment.M_COMPACT_FIRST_BREAK_SPLIT | (alignmentMode & ~Alignment.SPLIT_MASK);
|
|
||||||
}
|
|
||||||
return alignmentMode & ~Alignment.M_INDENT_ON_COLUMN;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int visit(ICPPASTTryBlockStatement node) {
|
private int visit(ICPPASTTryBlockStatement node) {
|
||||||
scribe.printNextToken(Token.t_try, scribe.printComment());
|
scribe.printNextToken(Token.t_try, scribe.printComment());
|
||||||
final IASTStatement tryBody= node.getTryBody();
|
final IASTStatement tryBody= node.getTryBody();
|
||||||
|
@ -2256,7 +2245,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
expressions= Collections.emptyList();
|
expressions= Collections.emptyList();
|
||||||
}
|
}
|
||||||
final ListOptions options= new ListOptions(preferences.alignment_for_arguments_in_method_invocation);
|
final ListOptions options= new ListOptions(preferences.alignment_for_arguments_in_method_invocation);
|
||||||
options.fUseFallbackMode= true;
|
options.fInsertNewLineBeforeListIfNecessary= true;
|
||||||
options.fSpaceBeforeOpeningParen= preferences.insert_space_before_opening_paren_in_method_invocation;
|
options.fSpaceBeforeOpeningParen= preferences.insert_space_before_opening_paren_in_method_invocation;
|
||||||
options.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_invocation;
|
options.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_invocation;
|
||||||
options.fSpaceBeforeClosingParen= preferences.insert_space_before_closing_paren_in_method_invocation;
|
options.fSpaceBeforeClosingParen= preferences.insert_space_before_closing_paren_in_method_invocation;
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class Alignment {
|
||||||
public static final String FIELD_REFERENCE = "fieldReference"; //$NON-NLS-1$
|
public static final String FIELD_REFERENCE = "fieldReference"; //$NON-NLS-1$
|
||||||
public static final String FOR = "for"; //$NON-NLS-1$
|
public static final String FOR = "for"; //$NON-NLS-1$
|
||||||
public static final String LIST_ELEMENTS_PREFIX = "listElements_"; //$NON-NLS-1$
|
public static final String LIST_ELEMENTS_PREFIX = "listElements_"; //$NON-NLS-1$
|
||||||
public static final String LIST_FALLBACK_TRAP = "listFallbackTrap"; //$NON-NLS-1$
|
public static final String LIST_WRAPPER = "listWrapper"; //$NON-NLS-1$
|
||||||
public static final String MACRO_ARGUMENTS = "macroArguments"; //$NON-NLS-1$
|
public static final String MACRO_ARGUMENTS = "macroArguments"; //$NON-NLS-1$
|
||||||
public static final String TRAILING_TEXT = "trailingText"; //$NON-NLS-1$
|
public static final String TRAILING_TEXT = "trailingText"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
|
@ -1080,6 +1080,27 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void function(int);
|
||||||
|
//int function_with_a_looooooooooooooooooooooooooooooooong_name(int);
|
||||||
|
//
|
||||||
|
//void test() {
|
||||||
|
//function(function_with_a_looooooooooooooooooooooooooooooooong_name(1000000));
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void function(int);
|
||||||
|
//int function_with_a_looooooooooooooooooooooooooooooooong_name(int);
|
||||||
|
//
|
||||||
|
//void test() {
|
||||||
|
// function(function_with_a_looooooooooooooooooooooooooooooooong_name(
|
||||||
|
// 1000000));
|
||||||
|
//}
|
||||||
|
public void testFunctionCall_3() throws Exception {
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
|
||||||
|
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
|
|
||||||
//void function(const char* s);
|
//void function(const char* s);
|
||||||
//
|
//
|
||||||
//void test() {
|
//void test() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue