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 fb71249cb16..c1841152ccd 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 @@ -129,6 +129,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.internal.formatter.align.Alignment; import org.eclipse.cdt.internal.formatter.align.AlignmentException; import org.eclipse.cdt.internal.formatter.scanner.Scanner; @@ -2167,19 +2168,20 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.printNextToken(Token.tCOLONCOLON); } scribe.printNextToken(Token.t_new); + scribe.space(); // placement final IASTExpression newPlacement= node.getNewPlacement(); if (newPlacement != null) { formatParenthesizedExpression(newPlacement); } + // type-id + scribe.space(); final IASTTypeId typeId= node.getTypeId(); final boolean expectParen= !node.isNewTypeId() && peekNextToken() == Token.tLPAREN; if (expectParen) { - scribe.printNextToken(Token.tLPAREN, scribe.printComment()); - } else { - scribe.space(); + scribe.printNextToken(Token.tLPAREN, false); } typeId.accept(this); if (expectParen) { @@ -2486,7 +2488,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments); if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) { if (preferences.insert_space_after_closing_angle_bracket_in_template_arguments) { - scribe.space(); + // avoid explicit space if followed by pointer operator + int nextToken= peekNextToken(); + if (nextToken != IToken.tSTAR && nextToken != IToken.tAMPER) { + scribe.space(); + } } else { scribe.printComment(); scribe.needSpace= false; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java index 0b5cba9d4e7..097b03b7e6c 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java @@ -1737,6 +1737,7 @@ public class DefaultCodeFormatterOptions { public void setWhitesmitsSettings() { setDefaultSettings(); this.alignment_for_expressions_in_initializer_list = Alignment.M_ONE_PER_LINE_SPLIT; + this.alignment_for_enumerator_list = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE; this.brace_position_for_initializer_list = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; this.brace_position_for_block = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; 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 0f3c3bce9b8..e53d176c029 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 @@ -414,7 +414,7 @@ public class CodeFormatterTest extends BaseUITestCase { //void f() { // int *px = ::new int(0); // int py[] = new int[5](0, 1, 2, 3, 4); - // int *pz[] = new(px) int(0); + // int *pz[] = new (px) int(0); // delete[] py; // ::delete px; //} @@ -601,4 +601,28 @@ public class CodeFormatterTest extends BaseUITestCase { fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap(); assertFormatterResult(); } + + //enum Tthe3rdtestIds + //{ + //ECommand1 = 0x6001, + //ECommand2, + //EHelp, + //EAbout + //}; + // + //CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); + + //enum Tthe3rdtestIds + // { + // ECommand1 = 0x6001, + // ECommand2, + // EHelp, + // EAbout + // }; + // + //CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); + public void testFormatterRegressions_Bug225858() throws Exception { + fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap(); + assertFormatterResult(); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.java index 8d5af919ffc..af3845098be 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.java @@ -212,6 +212,8 @@ final class FormatterMessages extends NLS { public static String LineWrappingTabPage_parameters; public static String LineWrappingTabPage_arguments; public static String LineWrappingTabPage_throws_clause; + public static String LineWrappingTabPage_enum_decls; + public static String LineWrappingTabPage_enumerator_list; public static String LineWrappingTabPage_initializer_list; public static String LineWrappingTabPage_conditionals; // public static String LineWrappingTabPage_binary_exprs; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.properties index 6064e69a79e..08076cbc9e4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/FormatterMessages.properties @@ -242,16 +242,18 @@ LineWrappingTabPage_parameters=Parameters LineWrappingTabPage_arguments=Arguments LineWrappingTabPage_throws_clause=Exception specification #LineWrappingTabPage_object_allocation=Object allocation arguments -LineWrappingTabPage_initializer_list=Initializer List +LineWrappingTabPage_enum_decls='enum' declaration +LineWrappingTabPage_enumerator_list=Enumerator list +LineWrappingTabPage_initializer_list=Initializer list LineWrappingTabPage_conditionals=Conditionals #LineWrappingTabPage_binary_exprs=Binary expressions LineWrappingTabPage_indentation_default=Default indentation LineWrappingTabPage_indentation_on_column=Indent on column LineWrappingTabPage_indentation_by_one=Indent by one -LineWrappingTabPage_class_decls=Class Declarations -LineWrappingTabPage_method_decls=Function Declarations +LineWrappingTabPage_class_decls=Class declarations +LineWrappingTabPage_method_decls=Function declarations #LineWrappingTabPage_constructor_decls=Constructor declarations -LineWrappingTabPage_function_calls=Function Calls +LineWrappingTabPage_function_calls=Function calls LineWrappingTabPage_expressions=Expressions #LineWrappingTabPage_statements=Statements LineWrappingTabPage_wrapping_policy_label_text=Lin&e wrapping policy: diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/LineWrappingTabPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/LineWrappingTabPage.java index c2655b2079a..f8f6d9913e2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/LineWrappingTabPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/LineWrappingTabPage.java @@ -455,14 +455,12 @@ public class LineWrappingTabPage extends FormatterTabPage { // FormatterMessages.LineWrappingTabPage_enum_superinterfaces // ); // -// private final Category fEnumConstantsCategory= new Category( -// DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, -// "enum Example {" + //$NON-NLS-1$ -// "CANCELLED, RUNNING, WAITING, FINISHED }" + //$NON-NLS-1$ -// "enum Example {" + //$NON-NLS-1$ -// "GREEN(0, 255, 0), RED(255, 0, 0) }", //$NON-NLS-1$ -// FormatterMessages.LineWrappingTabPage_enum_constants -// ); + private final Category fEnumeratorsCategory= new Category( + DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUMERATOR_LIST, + "enum Example {" + //$NON-NLS-1$ + "CANCELLED, RUNNING, WAITING, FINISHED };", //$NON-NLS-1$ + FormatterMessages.LineWrappingTabPage_enumerator_list + ); // // private final Category fAssignmentCategory= new Category( // DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, @@ -567,8 +565,8 @@ public class LineWrappingTabPage extends FormatterTabPage { methodDeclarations.children.add(fMethodDeclarationsParametersCategory); methodDeclarations.children.add(fMethodThrowsClauseCategory); -// final Category enumDeclarations= new Category(FormatterMessages.LineWrappingTabPage_enum_decls); -// enumDeclarations.children.add(fEnumConstantsCategory); + final Category enumDeclarations= new Category(FormatterMessages.LineWrappingTabPage_enum_decls); + enumDeclarations.children.add(fEnumeratorsCategory); // enumDeclarations.children.add(fEnumDeclInterfacesCategory); // enumDeclarations.children.add(fEnumConstArgumentsCategory); @@ -592,7 +590,7 @@ public class LineWrappingTabPage extends FormatterTabPage { root.add(classDeclarations); // root.add(constructorDeclarations); root.add(methodDeclarations); -// root.add(enumDeclarations); + root.add(enumDeclarations); root.add(functionCalls); root.add(expressions); // root.add(statements);