Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-03-15 22:43:51 -0400
committerSergey Prigogin2011-03-15 22:43:51 -0400
commite23e0a92387c9cfa46447e6fb185cbed73710ba0 (patch)
tree3909d812a99a3d66bbeef25870c3524ab29ddd61
parent199adb3ec55dbb839aab228415e1478ab1a6f760 (diff)
downloadorg.eclipse.cdt-e23e0a92387c9cfa46447e6fb185cbed73710ba0.tar.gz
org.eclipse.cdt-e23e0a92387c9cfa46447e6fb185cbed73710ba0.tar.xz
org.eclipse.cdt-e23e0a92387c9cfa46447e6fb185cbed73710ba0.zip
Fixed a corner case in function call formatting.
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java53
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java2
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java21
3 files changed, 43 insertions, 33 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
index 5cc81b81fd..1000370213 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
@@ -170,7 +170,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private static class ListOptions {
final int fMode;
- boolean fUseFallbackMode;
+ boolean fInsertNewLineBeforeListIfNecessary;
boolean fSpaceBeforeComma;
boolean fSpaceAfterComma = true;
boolean fSpaceAfterOpeningParen;
@@ -1457,7 +1457,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private ListOptions createListOptionsForFunctionDeclarationParameters() {
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.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_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) {
scribe.space();
}
- Alignment retryAlignment = null;
+ Alignment wrapperAlignment = null;
- int fallbackMode = options.fUseFallbackMode ?
- getFallbackAlignmentMode(options.fMode) : options.fMode;
- if (fallbackMode != options.fMode) {
- retryAlignment = scribe.createAlignment(
- Alignment.LIST_FALLBACK_TRAP,
- Alignment.M_ONE_PER_LINE_SPLIT,
+ final int continuationIndentation= options.fContinuationIndentation >= 0 ?
+ options.fContinuationIndentation : preferences.continuation_indentation;
+ if (options.fInsertNewLineBeforeListIfNecessary &&
+ (options.fMode & Alignment.M_INDENT_ON_COLUMN) != 0) {
+ wrapperAlignment = scribe.createAlignment(
+ Alignment.LIST_WRAPPER,
+ Alignment.M_COMPACT_FIRST_BREAK_SPLIT,
Alignment.R_INNERMOST,
1,
scribe.scanner.getCurrentPosition(),
- 0,
+ continuationIndentation,
false);
- scribe.enterAlignment(retryAlignment);
+ scribe.enterAlignment(wrapperAlignment);
}
boolean success = false;
- int mode = options.fMode;
do {
- if (retryAlignment != null)
- scribe.alignFragment(retryAlignment, 0);
+ if (wrapperAlignment != null)
+ scribe.alignFragment(wrapperAlignment, 0);
try {
- final int continuationIndentation= options.fContinuationIndentation >= 0 ?
- options.fContinuationIndentation : preferences.continuation_indentation;
Alignment alignment = scribe.createAlignment(
Alignment.LIST_ELEMENTS_PREFIX +
(elements.isEmpty() ? "ellipsis" : elements.get(0).getClass().getSimpleName()), //$NON-NLS-1$
- mode,
+ options.fMode,
options.fTieBreakRule,
elementsLength + (addEllipsis ? 1 : 0),
scribe.scanner.getCurrentPosition(),
- continuationIndentation,
+ wrapperAlignment == null ? continuationIndentation : 0,
false);
scribe.enterAlignment(alignment);
boolean ok = false;
@@ -2082,27 +2080,18 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.exitAlignment(alignment, true);
success = true;
} catch (AlignmentException e) {
- if (retryAlignment == null)
+ if (wrapperAlignment == null)
throw e;
scribe.redoAlignment(e);
}
- mode = fallbackMode;
- } while (!success);
- if (retryAlignment != null)
- scribe.exitAlignment(retryAlignment, true);
+ } while (wrapperAlignment != null && !success);
+ if (wrapperAlignment != null)
+ scribe.exitAlignment(wrapperAlignment, true);
} else if (tailFormatter != null) {
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) {
scribe.printNextToken(Token.t_try, scribe.printComment());
final IASTStatement tryBody= node.getTryBody();
@@ -2256,7 +2245,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
expressions= Collections.emptyList();
}
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.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_invocation;
options.fSpaceBeforeClosingParen= preferences.insert_space_before_closing_paren_in_method_invocation;
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java
index f3137c74c0..c0a9218b47 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/align/Alignment.java
@@ -31,7 +31,7 @@ public class Alignment {
public static final String FIELD_REFERENCE = "fieldReference"; //$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_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 TRAILING_TEXT = "trailingText"; //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
index 03c402206c..8cb7927df0 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
@@ -1080,6 +1080,27 @@ public class CodeFormatterTest extends BaseUITestCase {
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 test() {

Back to the top