From 214b66c2480a0bd73f8077a0a848a204b7685891 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 14 Oct 2010 11:03:30 +0000 Subject: [PATCH] Bug 325783 - [formatter] Function call arguments' indentation is wrong if there is a templated argument --- .../formatter/CodeFormatterVisitor.java | 4 +++ .../cdt/ui/tests/text/CodeFormatterTest.java | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) 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 4418947a272..db89cdcfccf 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 @@ -173,6 +173,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, public boolean fSpaceBetweenEmptyParen; public boolean fSpaceBeforeOpeningParen; public int fContinuationIndentation= -1; + public int fTieBreakRule = Alignment.R_INNERMOST; public ListAlignment(int mode) { fMode= mode; } @@ -1013,6 +1014,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, scribe.startNewLine(); scribe.indent(); final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT); + align.fTieBreakRule = Alignment.R_OUTERMOST; formatList(Arrays.asList(constructorChain), align, false, false); scribe.unIndent(); } @@ -1135,6 +1137,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, align.fSpaceBetweenEmptyParen= preferences.insert_space_between_empty_parens_in_method_declaration; align.fSpaceBeforeComma= preferences.insert_space_before_comma_in_method_declaration_parameters; align.fSpaceAfterComma= preferences.insert_space_after_comma_in_method_declaration_parameters; + align.fTieBreakRule = Alignment.R_OUTERMOST; formatList(parameters, align, true, node.takesVarArgs()); return PROCESS_SKIP; @@ -1655,6 +1658,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, Alignment listAlignment = scribe.createAlignment( "listElements_"+align, //$NON-NLS-1$ align.fMode, + align.fTieBreakRule, elementsLength + (addEllipsis ? 1 : 0), scribe.scanner.getCurrentPosition(), continuationIndentation, 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 9a743ed8ede..a43e0851306 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 @@ -1366,4 +1366,32 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //void extend_terminal_bond_to_label(vector &atom, const vector &letters, int n_letters, const vector &bond, int n_bond, const vector &label, int n_label, double avg, double maxh, double max_dist_double_bond); + + //void extend_terminal_bond_to_label(vector &atom, const vector &letters, int n_letters, + // const vector &bond, int n_bond, const vector &label, int n_label, + // double avg, double maxh, double max_dist_double_bond); + public void testWrappingOfTemplateIdAsParameterType_Bug325783() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION, + Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN)); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "120"); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + assertFormatterResult(); + } + + //void extend_terminal_bond_to_label(vector &atom, const vector &letters, int n_letters, const vector &bond, int n_bond, const vector &label, int n_label, double avg, double maxh, double max_dist_double_bond); + + //void extend_terminal_bond_to_label(vector &atom, + // const vector &letters, + // int n_letters, const vector &bond, + // int n_bond, const vector &label, + // int n_label, double avg, double maxh, + // double max_dist_double_bond); + public void testWrappingOfTemplateIdAsParameterType_Bug325783_2() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION, + Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN)); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "80"); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + assertFormatterResult(); + } }