diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java index 898d60a67c4..cf74c436986 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java @@ -566,15 +566,15 @@ public class DefaultCodeFormatterConstants { * */ public static final String FORMATTER_CONTINUATION_INDENTATION = CCorePlugin.PLUGIN_ID + ".formatter.continuation_indentation"; //$NON-NLS-1$ -// /** -// *
-// * FORMATTER / Option to set the continuation indentation inside array initializer -// * - option id: "org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer" -// * - possible values: "<n>", where n is zero or a positive integer -// * - default: "2" -// *-// */ -// public static final String FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.continuation_indentation_for_array_initializer"; //$NON-NLS-1$ + /** + *
+ * FORMATTER / Option to set the continuation indentation inside array initializer + * - option id: "org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer" + * - possible values: "<n>", where n is zero or a positive integer + * - default: "2" + *+ */ + public static final String FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.continuation_indentation_for_array_initializer"; //$NON-NLS-1$ // /** // *
// * FORMATTER / Option to indent body declarations compare to its enclosing enum constant header @@ -733,17 +733,17 @@ public class DefaultCodeFormatterConstants { // */ // public static final String FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_after_annotation";//$NON-NLS-1$ // -// /** -// *-// * FORMATTER / Option to insert a new line after the opening brace in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_after_opening_brace_in_array_initializer";//$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a new line after the opening brace in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_after_opening_brace_in_array_initializer";//$NON-NLS-1$ /** *@@ -767,17 +767,17 @@ public class DefaultCodeFormatterConstants { // * @see CCorePlugin#DO_NOT_INSERT // */ // public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_catch_in_try_statement"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a new line before the closing brace in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_closing_brace_in_array_initializer";//$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a new line before the closing brace in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_new_line_before_closing_brace_in_array_initializer";//$NON-NLS-1$ /** ** FORMATTER / Option to insert a new line before the else keyword in if statement @@ -1020,17 +1020,17 @@ public class DefaultCodeFormatterConstants { // * @see CCorePlugin#DO_NOT_INSERT // */ // public static final String FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ANNOTATION = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_after_comma_in_annotation"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a space after the comma in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_after_comma_in_array_initializer"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a space after the comma in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_after_comma_in_array_initializer"; //$NON-NLS-1$ // /** // *// * FORMATTER / Option to insert a space after the comma in the parameters of a constructor declaration @@ -1251,17 +1251,17 @@ public class DefaultCodeFormatterConstants { // * @see CCorePlugin#DO_NOT_INSERT // */ // public static final String FORMATTER_INSERT_SPACE_AFTER_OPENING_ANGLE_BRACKET_IN_TYPE_PARAMETERS = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_after_opening_angle_bracket_in_type_parameters";//$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a space after the opening brace in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_after_opening_brace_in_array_initializer"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a space after the opening brace in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_after_opening_brace_in_array_initializer"; //$NON-NLS-1$ // /** // *// * FORMATTER / Option to insert a space after the opening bracket inside an array allocation expression @@ -1537,17 +1537,17 @@ public class DefaultCodeFormatterConstants { // * @see CCorePlugin#DO_NOT_INSERT // */ // public static final String FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TYPE_PARAMETERS = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_closing_angle_bracket_in_type_parameters"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a space before the closing brace in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_closing_brace_in_array_initializer"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a space before the closing brace in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_closing_brace_in_array_initializer"; //$NON-NLS-1$ // /** // *// * FORMATTER / Option to insert a space before the closing bracket in an array allocation expression @@ -1768,17 +1768,17 @@ public class DefaultCodeFormatterConstants { // * @see CCorePlugin#DO_NOT_INSERT // */ // public static final String FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ANNOTATION = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_comma_in_annotation"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a space before comma in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_comma_in_array_initializer"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a space before comma in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_comma_in_array_initializer"; //$NON-NLS-1$ // /** // *// * FORMATTER / Option to insert a space before comma in the parameters of a constructor declaration @@ -2021,17 +2021,17 @@ public class DefaultCodeFormatterConstants { // * @see CCorePlugin#DO_NOT_INSERT // */ // public static final String FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ANONYMOUS_TYPE_DECLARATION = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_opening_brace_in_anonymous_type_declaration"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a space before the opening brace in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_opening_brace_in_array_initializer"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a space before the opening brace in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_before_opening_brace_in_array_initializer"; //$NON-NLS-1$ /** ** FORMATTER / Option to insert a space before the opening brace in a block @@ -2375,17 +2375,17 @@ public class DefaultCodeFormatterConstants { // * @see CCorePlugin#DO_NOT_INSERT // */ // public static final String FORMATTER_INSERT_SPACE_BETWEEN_BRACKETS_IN_ARRAY_TYPE_REFERENCE = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_between_brackets_in_array_type_reference"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to insert a space between empty braces in an array initializer -// * - option id: "org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" -// * - possible values: { INSERT, DO_NOT_INSERT } -// * - default: DO_NOT_INSERT -// *-// * @see CCorePlugin#INSERT -// * @see CCorePlugin#DO_NOT_INSERT -// */ -// public static final String FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_BRACES_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_between_empty_braces_in_array_initializer"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to insert a space between empty braces in an array initializer + * - option id: "org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: DO_NOT_INSERT + *+ * @see CCorePlugin#INSERT + * @see CCorePlugin#DO_NOT_INSERT + */ + public static final String FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_BRACES_IN_ARRAY_INITIALIZER = CCorePlugin.PLUGIN_ID + ".formatter.insert_space_between_empty_braces_in_array_initializer"; //$NON-NLS-1$ // /** // *// * FORMATTER / Option to insert a space between empty brackets in an array allocation expression @@ -2463,17 +2463,17 @@ public class DefaultCodeFormatterConstants { * @see #FALSE */ public static final String FORMATTER_KEEP_ELSE_STATEMENT_ON_SAME_LINE = CCorePlugin.PLUGIN_ID + ".formatter.keep_else_statement_on_same_line"; //$NON-NLS-1$ -// /** -// *-// * FORMATTER / Option to keep empty array initializer one one line -// * - option id: "org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line" -// * - possible values: { TRUE, FALSE } -// * - default: FALSE -// *-// * @see #TRUE -// * @see #FALSE -// */ -// public static final String FORMATTER_KEEP_EMPTY_ARRAY_INITIALIZER_ON_ONE_LINE = CCorePlugin.PLUGIN_ID + ".formatter.keep_empty_array_initializer_on_one_line"; //$NON-NLS-1$ + /** + *+ * FORMATTER / Option to keep empty array initializer one one line + * - option id: "org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line" + * - possible values: { TRUE, FALSE } + * - default: FALSE + *+ * @see #TRUE + * @see #FALSE + */ + public static final String FORMATTER_KEEP_EMPTY_ARRAY_INITIALIZER_ON_ONE_LINE = CCorePlugin.PLUGIN_ID + ".formatter.keep_empty_array_initializer_on_one_line"; //$NON-NLS-1$ /** ** FORMATTER / Option to keep guardian clause on one line 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 bdd55b5a029..28182043f53 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 @@ -21,6 +21,8 @@ import java.util.Stack; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; @@ -45,7 +47,10 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; +import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; @@ -73,14 +78,17 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement; @@ -214,16 +222,16 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } private final TextEdit failedToFormat(AbortFormatting e) { - if (DEBUG) { - String errorMessage= e.getMessage(); - if (errorMessage == null) { - if (e.nestedException != null) { - errorMessage= e.nestedException.getClass().getName(); - } else { - errorMessage= "Unknown error"; - } + String errorMessage= e.getMessage(); + if (errorMessage == null) { + if (e.nestedException != null) { + errorMessage= e.nestedException.getClass().getName(); + } else { + errorMessage= "Unknown error"; } - CCorePlugin.log(CCorePlugin.createStatus("Could not format: " + errorMessage, e.nestedException)); + } + CCorePlugin.log(CCorePlugin.createStatus("Could not format: " + errorMessage, e.nestedException)); + if (DEBUG) { System.out.println("COULD NOT FORMAT: " + e.getMessage()); System.out.println(scribe.scanner); //$NON-NLS-1$ System.out.println(scribe); @@ -346,8 +354,34 @@ public class CodeFormatterVisitor extends CPPASTVisitor { /* * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTInitializer) */ - public int visit(IASTInitializer initializer) { - formatNode(initializer); + public int visit(IASTInitializer node) { + IASTNodeLocation[] locations= node.getNodeLocations(); + if (locations.length == 0) { + return PROCESS_SKIP; + } else if (locations[0] instanceof IASTMacroExpansion) { + formatNode(node); + return PROCESS_SKIP; + } + if (node instanceof ICPPASTConstructorInitializer) { + visit((ICPPASTConstructorInitializer)node); + return PROCESS_SKIP; + } + + if (peekNextToken() == Token.tASSIGN) { + scribe.printNextToken(Token.tASSIGN, scribe.printComment()); + if (scribe.printComment()) { + scribe.space(); + } + } + if (node instanceof IASTInitializerExpression) { + visit((IASTInitializerExpression)node); + } else if (node instanceof IASTInitializerList) { + visit((IASTInitializerList)node); + } else if (node instanceof ICASTDesignatedInitializer) { + formatNode(node); + } else { + formatNode(node); + } return PROCESS_SKIP; } @@ -369,7 +403,22 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } else if (locations[0] instanceof IASTMacroExpansion) { formatNode(node); return PROCESS_SKIP; - } else + } + + // common to all declarators + scribe.printComment(); + formatPointers(node.getPointerOperators()); + IASTName name= node.getName(); + if (name != null) { + name.accept(this); + } + IASTDeclarator nestedDecl= node.getNestedDeclarator(); + if (nestedDecl != null) { + scribe.printNextToken(Token.tLPAREN, false); + nestedDecl.accept(this); + scribe.printNextToken(Token.tRPAREN, false); + } + if (node instanceof ICPPASTFunctionTryBlockDeclarator) { visit((IASTStandardFunctionDeclarator)node); skipNode(node); @@ -381,15 +430,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } else if (node instanceof ICASTKnRFunctionDeclarator) { visit((ICASTKnRFunctionDeclarator)node); } else if (node instanceof IASTFieldDeclarator) { - formatNode(node); - return PROCESS_SKIP; + visit((IASTFieldDeclarator)node); } else if (node instanceof IASTArrayDeclarator) { - formatNode(node); - return PROCESS_SKIP; - } else { - formatNode(node); - return PROCESS_SKIP; + visit((IASTArrayDeclarator)node); } + IASTInitializer initializer= node.getInitializer(); if (initializer != null) { initializer.accept(this); @@ -444,6 +489,12 @@ public class CodeFormatterVisitor extends CPPASTVisitor { visit((IASTFunctionCallExpression)node); } else if (node instanceof IASTExpressionList) { visit((IASTExpressionList)node); + } else if (node instanceof IASTTypeIdExpression) { + visit((IASTTypeIdExpression)node); + } else if (node instanceof IASTBinaryExpression) { + visit((IASTBinaryExpression)node); + } else if (node instanceof IASTLiteralExpression) { + visit((IASTLiteralExpression)node); } else if (node instanceof IASTProblemExpression) { visit((IASTProblemExpression)node); } else { @@ -629,6 +680,16 @@ public class CodeFormatterVisitor extends CPPASTVisitor { return PROCESS_SKIP; } + private int visit(ICPPASTConstructorInitializer node) { + scribe.printNextToken(Token.tLPAREN, false); + final IASTExpression value= node.getExpression(); + if (value != null) { + value.accept(this); + } + scribe.printNextToken(Token.tRPAREN, false); + return PROCESS_SKIP; + } + private int visit(ICPPASTConstructorChainInitializer node) { final IASTName member= node.getMemberInitializerId(); if (member!= null) { @@ -694,21 +755,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } private int visit(IASTStandardFunctionDeclarator node) { - scribe.printComment(); - - formatPointers(node.getPointerOperators()); - - IASTName name= node.getName(); - if (name != null) { - name.accept(this); - } - IASTDeclarator nestedDecl= node.getNestedDeclarator(); - if (nestedDecl != null) { - scribe.printNextToken(Token.tLPAREN, false); - nestedDecl.accept(this); - scribe.printNextToken(Token.tRPAREN, false); - } - final List parameters = Arrays.asList(node.getParameters()); final ListAlignment align= new ListAlignment(preferences.alignment_for_parameters_in_method_declaration); align.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_declaration; @@ -742,21 +788,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } private int visit(ICASTKnRFunctionDeclarator node) { - scribe.printComment(); - - formatPointers(node.getPointerOperators()); - - IASTName name= node.getName(); - if (name != null) { - name.accept(this); - } - IASTDeclarator nestedDecl= node.getNestedDeclarator(); - if (nestedDecl != null) { - scribe.printNextToken(Token.tLPAREN, false); - nestedDecl.accept(this); - scribe.printNextToken(Token.tRPAREN, false); - } - final List parameters= Arrays.asList(node.getParameterNames()); ListAlignment align= new ListAlignment(preferences.alignment_for_parameters_in_method_declaration); align.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_declaration; @@ -779,6 +810,32 @@ public class CodeFormatterVisitor extends CPPASTVisitor { return PROCESS_SKIP; } + private int visit(IASTFieldDeclarator node) { + IASTExpression bitFieldSizeExpr= node.getBitFieldSize(); + if (bitFieldSizeExpr != null) { + scribe.printNextToken(Token.tCOLON, true); + bitFieldSizeExpr.accept(this); + } + return PROCESS_SKIP; + } + + private int visit(IASTArrayDeclarator node) { + IASTArrayModifier[] arrayModifiers= node.getArrayModifiers(); + if (arrayModifiers != null) { + for (int i = 0; i < arrayModifiers.length; i++) { + IASTArrayModifier arrayModifier = arrayModifiers[i]; + scribe.printNextToken(Token.tLBRACKET, scribe.printComment()); + try { + arrayModifier.accept(this); + } catch (ASTProblemException e) { + scribe.skipToToken(Token.tRBRACKET); + } + scribe.printNextToken(Token.tRBRACKET, scribe.printComment()); + } + } + return PROCESS_SKIP; + } + private int visit(IASTSimpleDeclaration node) { IASTDeclSpecifier declSpec= node.getDeclSpecifier(); declSpec.accept(this); @@ -1014,7 +1071,12 @@ public class CodeFormatterVisitor extends CPPASTVisitor { break; } } else if (token == Token.tRPAREN) { - break; + if (encloseInParen) { + break; + } + if (!scribe.skipToToken(Token.tCOMMA)) { + break; + } } scribe.printNextToken(Token.tCOMMA, align.fSpaceBeforeComma); scribe.printTrailingComment(); @@ -1134,6 +1196,84 @@ public class CodeFormatterVisitor extends CPPASTVisitor { return PROCESS_SKIP; } + private int visit(IASTTypeIdExpression node) { + scribe.printNextToken(peekNextToken()); + scribe.printNextToken(Token.tLPAREN); + node.getTypeId().accept(this); + scribe.printNextToken(Token.tRPAREN); + return PROCESS_SKIP; + } + + private int visit(IASTInitializerExpression node) { + node.getExpression().accept(this); + return PROCESS_SKIP; + } + + private int visit(IASTInitializerList node) { + scribe.printComment(); + + final List initializers = Arrays.asList(node.getInitializers()); + if (initializers.isEmpty() && preferences.keep_empty_array_initializer_on_one_line) { + scribe.printNextToken(Token.tLBRACE, preferences.insert_space_before_opening_brace_in_array_initializer); + scribe.printNextToken(Token.tLBRACE, preferences.insert_space_between_empty_braces_in_array_initializer); + } else { + final int line= scribe.line; + final String brace_position= preferences.brace_position_for_array_initializer; + formatLeftCurlyBrace(line, brace_position); + formatOpeningBrace(brace_position, preferences.insert_space_before_opening_brace_in_array_initializer); + if (preferences.insert_new_line_after_opening_brace_in_array_initializer) { + scribe.printNewLine(); + } + if (preferences.insert_space_after_opening_brace_in_array_initializer) { + scribe.space(); + } + int indents= preferences.continuation_indentation_for_array_initializer; + while (indents-- > 0) { + scribe.indent(); + } + + final ListAlignment align= new ListAlignment(preferences.alignment_for_expressions_in_array_initializer); + align.fSpaceBeforeComma= preferences.insert_space_before_comma_in_array_initializer; + align.fSpaceAfterComma= preferences.insert_space_after_comma_in_array_initializer; + formatList(initializers, align, false, false); + + indents= preferences.continuation_indentation_for_array_initializer; + while (indents-- > 0) { + scribe.unIndent(); + } + if (preferences.insert_new_line_before_closing_brace_in_array_initializer) { + scribe.startNewLine(); + } + if (preferences.insert_space_before_closing_brace_in_array_initializer) { + scribe.space(); + } + formatClosingBrace(brace_position); + } + scribe.printTrailingComment(); + return PROCESS_SKIP; + } + + private int visit(IASTBinaryExpression node) { + // TODO binary expression alignment! + final IASTExpression op1= node.getOperand1(); + // operand 1 + op1.accept(this); + // operator + scribe.printNextToken(peekNextToken(), scribe.printComment()); + if (scribe.printComment()) { + scribe.space(); + } + // operand 2 + final IASTExpression op2= node.getOperand2(); + op2.accept(this); + return PROCESS_SKIP; + } + + private int visit(IASTLiteralExpression node) { + scribe.printNextToken(peekNextToken(), scribe.printComment()); + return PROCESS_SKIP; + } + private int visit(IASTContinueStatement node) { scribe.printNextToken(Token.t_continue); scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon); @@ -1563,26 +1703,44 @@ public class CodeFormatterVisitor extends CPPASTVisitor { if (scribe.printComment()) { scribe.space(); } - IASTNodeLocation location= node.getFileLocation(); - if (location != null) { - scribe.printRaw(location.getNodeOffset(), location.getNodeLength()); - } else { - formatLocations(node.getNodeLocations()); + final IASTNodeLocation[] locations= node.getNodeLocations(); + final IASTNodeLocation minLocation= getMinFileLocation(locations); + if (minLocation != null) { + final IASTNodeLocation maxLocation= getMaxFileLocation(locations); + if (maxLocation != null) { + final int startOffset= minLocation.getNodeOffset(); + final int endOffset= maxLocation.getNodeOffset() + maxLocation.getNodeLength(); + scribe.printRaw(minLocation.getNodeOffset(), endOffset - startOffset); + } } } - private void formatLocations(IASTNodeLocation[] locations) { - for (int i = 0; i < locations.length; i++) { - IASTNodeLocation location = locations[i]; - if (location instanceof IASTMacroExpansion) { - IASTNodeLocation[] expansionLocations= ((IASTMacroExpansion)location).getExpansionLocations(); - formatLocations(expansionLocations); - } else if (location instanceof IASTFileLocation) { - if (fTranslationUnitFile.equals(((IASTFileLocation)location).getFileName())) { - scribe.printRaw(location.getNodeOffset(), location.getNodeLength()); - } - } + private static IASTFileLocation getMaxFileLocation(IASTNodeLocation[] locations) { + if (locations == null || locations.length == 0) { + return null; } + final IASTNodeLocation nodeLocation= locations[locations.length-1]; + if (nodeLocation instanceof IASTFileLocation) { + return (IASTFileLocation)nodeLocation; + } else if (nodeLocation instanceof IASTMacroExpansion) { + IASTNodeLocation[] macroLocations= ((IASTMacroExpansion)nodeLocation).getExpansionLocations(); + return getMaxFileLocation(macroLocations); + } + return null; + } + + private static IASTFileLocation getMinFileLocation(IASTNodeLocation[] locations) { + if (locations == null || locations.length == 0) { + return null; + } + final IASTNodeLocation nodeLocation= locations[0]; + if (nodeLocation instanceof IASTFileLocation) { + return (IASTFileLocation)nodeLocation; + } else if (nodeLocation instanceof IASTMacroExpansion) { + IASTNodeLocation[] macroLocations= ((IASTMacroExpansion)nodeLocation).getExpansionLocations(); + return getMinFileLocation(macroLocations); + } + return null; } private void exitAlignments() { @@ -1590,29 +1748,30 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.exitAlignment(scribe.currentAlignment, true); } } + private void skipNode(IASTNode node) { - IASTNodeLocation location= node.getFileLocation(); - if (location == null) { - return; - } - int endOffset= location.getNodeOffset() + location.getNodeLength(); - int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1; - int restLength= endOffset - currentOffset; - if (restLength > 0) { - scribe.printRaw(currentOffset, restLength); + final IASTNodeLocation[] locations= node.getNodeLocations(); + final IASTNodeLocation maxLocation= getMaxFileLocation(locations); + if (maxLocation != null) { + final int endOffset= maxLocation.getNodeOffset() + maxLocation.getNodeLength(); + final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1; + final int restLength= endOffset - currentOffset; + if (restLength > 0) { + scribe.printRaw(currentOffset, restLength); + } } } private void skipToNode(IASTNode node) { - IASTNodeLocation location= node.getFileLocation(); - if (location == null) { - return; - } - int endOffset= location.getNodeOffset(); - int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1; - int restLength= endOffset - currentOffset; - if (restLength > 0) { - scribe.printRaw(currentOffset, restLength); + final IASTNodeLocation[] locations= node.getNodeLocations(); + final IASTNodeLocation minLocation= getMinFileLocation(locations); + if (minLocation != null) { + final int startOffset= minLocation.getNodeOffset(); + final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1; + final int restLength= startOffset - currentOffset; + if (restLength > 0) { + scribe.printRaw(currentOffset, restLength); + } } } @@ -1700,10 +1859,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.printTrailingComment(); } - private void formatClosingBrace(String block_brace_position) { + private void formatClosingBrace(String brace_position) { scribe.printNextToken(Token.tRBRACE); scribe.printTrailingComment(); - if (DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(block_brace_position)) { + if (DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(brace_position)) { scribe.unIndent(); } } 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 c02c3ee470a..4a0a2447647 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 @@ -55,8 +55,7 @@ public class DefaultCodeFormatterOptions { return options; } - - // public int alignment_for_arguments_in_allocation_expression; +// public int alignment_for_arguments_in_allocation_expression; // public int alignment_for_arguments_in_enum_constant; // public int alignment_for_arguments_in_explicit_constructor_call; public int alignment_for_arguments_in_method_invocation; @@ -89,7 +88,7 @@ public class DefaultCodeFormatterOptions { public String brace_position_for_switch; public int continuation_indentation; -// public int continuation_indentation_for_array_initializer; + public int continuation_indentation_for_array_initializer; // public int blank_lines_after_includes; // public int blank_lines_before_field; @@ -121,10 +120,10 @@ public class DefaultCodeFormatterOptions { public boolean indent_switchstatements_compare_to_switch; public int indentation_size; -// public boolean insert_new_line_after_opening_brace_in_array_initializer; + public boolean insert_new_line_after_opening_brace_in_array_initializer; public boolean insert_new_line_at_end_of_file_if_missing; // public boolean insert_new_line_before_catch_in_try_statement; -// public boolean insert_new_line_before_closing_brace_in_array_initializer; + public boolean insert_new_line_before_closing_brace_in_array_initializer; public boolean insert_new_line_before_else_in_if_statement; // public boolean insert_new_line_before_finally_in_try_statement; public boolean insert_new_line_before_while_in_do_statement; @@ -145,7 +144,7 @@ public class DefaultCodeFormatterOptions { // public boolean insert_space_after_colon_in_for; // public boolean insert_space_after_colon_in_labeled_statement; // public boolean insert_space_after_comma_in_allocation_expression; -// public boolean insert_space_after_comma_in_array_initializer; + public boolean insert_space_after_comma_in_array_initializer; // public boolean insert_space_after_comma_in_constructor_declaration_parameters; // public boolean insert_space_after_comma_in_constructor_declaration_throws; // public boolean insert_space_after_comma_in_enum_constant_arguments; @@ -168,7 +167,7 @@ public class DefaultCodeFormatterOptions { // public boolean insert_space_after_opening_angle_bracket_in_type_parameters; // public boolean insert_space_after_opening_bracket_in_array_allocation_expression; // public boolean insert_space_after_opening_bracket_in_array_reference; -// public boolean insert_space_after_opening_brace_in_array_initializer; + public boolean insert_space_after_opening_brace_in_array_initializer; // public boolean insert_space_after_opening_paren_in_cast; // public boolean insert_space_after_opening_paren_in_catch; // public boolean insert_space_after_opening_paren_in_constructor_declaration; @@ -191,7 +190,7 @@ public class DefaultCodeFormatterOptions { // public boolean insert_space_before_closing_angle_bracket_in_parameterized_type_reference; // public boolean insert_space_before_closing_angle_bracket_in_type_arguments; // public boolean insert_space_before_closing_angle_bracket_in_type_parameters; -// public boolean insert_space_before_closing_brace_in_array_initializer; + public boolean insert_space_before_closing_brace_in_array_initializer; // public boolean insert_space_before_closing_bracket_in_array_allocation_expression; // public boolean insert_space_before_closing_bracket_in_array_reference; // public boolean insert_space_before_closing_paren_in_cast; @@ -211,7 +210,7 @@ public class DefaultCodeFormatterOptions { // public boolean insert_space_before_colon_in_for; // public boolean insert_space_before_colon_in_labeled_statement; // public boolean insert_space_before_comma_in_allocation_expression; -// public boolean insert_space_before_comma_in_array_initializer; + public boolean insert_space_before_comma_in_array_initializer; // public boolean insert_space_before_comma_in_constructor_declaration_parameters; // public boolean insert_space_before_comma_in_constructor_declaration_throws; // public boolean insert_space_before_comma_in_enum_constant_arguments; @@ -233,7 +232,7 @@ public class DefaultCodeFormatterOptions { // public boolean insert_space_before_opening_angle_bracket_in_parameterized_type_reference; // public boolean insert_space_before_opening_angle_bracket_in_type_arguments; // public boolean insert_space_before_opening_angle_bracket_in_type_parameters; -// public boolean insert_space_before_opening_brace_in_array_initializer; + public boolean insert_space_before_opening_brace_in_array_initializer; public boolean insert_space_before_opening_brace_in_block; // public boolean insert_space_before_opening_brace_in_constructor_declaration; // public boolean insert_space_before_opening_brace_in_enum_constant; @@ -262,7 +261,7 @@ public class DefaultCodeFormatterOptions { public boolean insert_space_before_semicolon_in_for; // public boolean insert_space_before_unary_operator; // public boolean insert_space_between_brackets_in_array_type_reference; -// public boolean insert_space_between_empty_braces_in_array_initializer; + public boolean insert_space_between_empty_braces_in_array_initializer; // public boolean insert_space_between_empty_brackets_in_array_allocation_expression; // public boolean insert_space_between_empty_parens_in_constructor_declaration; // public boolean insert_space_between_empty_parens_in_enum_constant; @@ -271,7 +270,7 @@ public class DefaultCodeFormatterOptions { public boolean compact_else_if; public boolean keep_guardian_clause_on_one_line; public boolean keep_else_statement_on_same_line; -// public boolean keep_empty_array_initializer_on_one_line; + public boolean keep_empty_array_initializer_on_one_line; public boolean keep_simple_if_on_one_line; public boolean keep_then_statement_on_same_line; public int number_of_empty_lines_to_preserve; @@ -335,7 +334,7 @@ public class DefaultCodeFormatterOptions { // options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE, this.comment_format_source ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); // options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length)); options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, Integer.toString(this.continuation_indentation)); -// options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, Integer.toString(this.continuation_indentation_for_array_initializer)); + options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, Integer.toString(this.continuation_indentation_for_array_initializer)); // options.put(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_IMPORTS, Integer.toString(this.blank_lines_after_includes)); // options.put(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_FIELD, Integer.toString(this.blank_lines_before_field)); // options.put(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_FIRST_CLASS_BODY_DECLARATION, Integer.toString(this.blank_lines_before_first_class_body_declaration)); @@ -357,10 +356,10 @@ public class DefaultCodeFormatterOptions { options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES, this.indent_switchstatements_compare_to_cases ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, this.indent_switchstatements_compare_to_switch ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, Integer.toString(this.indentation_size)); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, this.insert_new_line_after_opening_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, this.insert_new_line_after_opening_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING, this.insert_new_line_at_end_of_file_if_missing ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT, this.insert_new_line_before_catch_in_try_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, this.insert_new_line_before_closing_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, this.insert_new_line_before_closing_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT, this.insert_new_line_before_else_in_if_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_FINALLY_IN_TRY_STATEMENT, this.insert_new_line_before_finally_in_try_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_WHILE_IN_DO_STATEMENT, this.insert_new_line_before_while_in_do_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -381,7 +380,7 @@ public class DefaultCodeFormatterOptions { // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COLON_IN_FOR, this.insert_space_after_colon_in_for ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COLON_IN_LABELED_STATEMENT, this.insert_space_after_colon_in_labeled_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ALLOCATION_EXPRESSION, this.insert_space_after_comma_in_allocation_expression? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ARRAY_INITIALIZER, this.insert_space_after_comma_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ARRAY_INITIALIZER, this.insert_space_after_comma_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_CONSTRUCTOR_DECLARATION_PARAMETERS, this.insert_space_after_comma_in_constructor_declaration_parameters? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_CONSTRUCTOR_DECLARATION_THROWS, this.insert_space_after_comma_in_constructor_declaration_throws? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ENUM_CONSTANT_ARGUMENTS, this.insert_space_after_comma_in_enum_constant_arguments ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -404,7 +403,7 @@ public class DefaultCodeFormatterOptions { // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_ANGLE_BRACKET_IN_TYPE_ARGUMENTS, this.insert_space_after_opening_angle_bracket_in_type_arguments? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_ANGLE_BRACKET_IN_TYPE_PARAMETERS, this.insert_space_after_opening_angle_bracket_in_type_parameters? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACKET_IN_ARRAY_REFERENCE, this.insert_space_after_opening_bracket_in_array_reference? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, this.insert_space_after_opening_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, this.insert_space_after_opening_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_CAST, this.insert_space_after_opening_paren_in_cast? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_CATCH, this.insert_space_after_opening_paren_in_catch? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_CONSTRUCTOR_DECLARATION, this.insert_space_after_opening_paren_in_constructor_declaration? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -427,7 +426,7 @@ public class DefaultCodeFormatterOptions { // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_PARAMETERIZED_TYPE_REFERENCE, this.insert_space_before_closing_angle_bracket_in_parameterized_type_reference? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TYPE_ARGUMENTS, this.insert_space_before_closing_angle_bracket_in_type_arguments? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TYPE_PARAMETERS, this.insert_space_before_closing_angle_bracket_in_type_parameters? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, this.insert_space_before_closing_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, this.insert_space_before_closing_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACKET_IN_ARRAY_ALLOCATION_EXPRESSION, this.insert_space_before_closing_bracket_in_array_allocation_expression? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACKET_IN_ARRAY_REFERENCE, this.insert_space_before_closing_bracket_in_array_reference? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_CAST, this.insert_space_before_closing_paren_in_cast? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -447,7 +446,7 @@ public class DefaultCodeFormatterOptions { // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_FOR, this.insert_space_before_colon_in_for ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_LABELED_STATEMENT, this.insert_space_before_colon_in_labeled_statement? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ALLOCATION_EXPRESSION, this.insert_space_before_comma_in_allocation_expression? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ARRAY_INITIALIZER, this.insert_space_before_comma_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ARRAY_INITIALIZER, this.insert_space_before_comma_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_CONSTRUCTOR_DECLARATION_PARAMETERS, this.insert_space_before_comma_in_constructor_declaration_parameters? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_CONSTRUCTOR_DECLARATION_THROWS, this.insert_space_before_comma_in_constructor_declaration_throws? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ENUM_CONSTANT_ARGUMENTS, this.insert_space_before_comma_in_enum_constant_arguments? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -468,7 +467,7 @@ public class DefaultCodeFormatterOptions { // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_ANGLE_BRACKET_IN_PARAMETERIZED_TYPE_REFERENCE, this.insert_space_before_opening_angle_bracket_in_parameterized_type_reference? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_ANGLE_BRACKET_IN_TYPE_ARGUMENTS, this.insert_space_before_opening_angle_bracket_in_type_arguments? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_ANGLE_BRACKET_IN_TYPE_PARAMETERS, this.insert_space_before_opening_angle_bracket_in_type_parameters? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER, this.insert_space_before_opening_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER, this.insert_space_before_opening_brace_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_BLOCK, this.insert_space_before_opening_brace_in_block? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_CONSTRUCTOR_DECLARATION, this.insert_space_before_opening_brace_in_constructor_declaration? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ENUM_CONSTANT, this.insert_space_before_opening_brace_in_enum_constant? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -498,7 +497,7 @@ public class DefaultCodeFormatterOptions { options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON_IN_FOR, this.insert_space_before_semicolon_in_for? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_UNARY_OPERATOR, this.insert_space_before_unary_operator? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_BRACKETS_IN_ARRAY_TYPE_REFERENCE, this.insert_space_between_brackets_in_array_type_reference? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); -// options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_BRACES_IN_ARRAY_INITIALIZER, this.insert_space_between_empty_braces_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_BRACES_IN_ARRAY_INITIALIZER, this.insert_space_between_empty_braces_in_array_initializer? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_BRACKETS_IN_ARRAY_ALLOCATION_EXPRESSION, this.insert_space_between_empty_brackets_in_array_allocation_expression? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_CONSTRUCTOR_DECLARATION, this.insert_space_between_empty_parens_in_constructor_declaration? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); // options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_ENUM_CONSTANT, this.insert_space_between_empty_parens_in_enum_constant? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT); @@ -507,7 +506,7 @@ public class DefaultCodeFormatterOptions { options.put(DefaultCodeFormatterConstants.FORMATTER_COMPACT_ELSE_IF, this.compact_else_if ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_GUARDIAN_CLAUSE_ON_ONE_LINE, this.keep_guardian_clause_on_one_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_ELSE_STATEMENT_ON_SAME_LINE, this.keep_else_statement_on_same_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); -// options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_EMPTY_ARRAY_INITIALIZER_ON_ONE_LINE, this.keep_empty_array_initializer_on_one_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); + options.put(DefaultCodeFormatterConstants.FORMATTER_KEEP_EMPTY_ARRAY_INITIALIZER_ON_ONE_LINE, this.keep_empty_array_initializer_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_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, Integer.toString(this.number_of_empty_lines_to_preserve)); @@ -804,16 +803,16 @@ public class DefaultCodeFormatterOptions { this.continuation_indentation = 2; } } -// final Object continuationIndentationForArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER); -// if (continuationIndentationForArrayInitializerOption != null) { -// try { -// this.continuation_indentation_for_array_initializer = Integer.parseInt((String) continuationIndentationForArrayInitializerOption); -// } catch (NumberFormatException e) { -// this.continuation_indentation_for_array_initializer = 2; -// } catch(ClassCastException e) { -// this.continuation_indentation_for_array_initializer = 2; -// } -// } + final Object continuationIndentationForArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER); + if (continuationIndentationForArrayInitializerOption != null) { + try { + this.continuation_indentation_for_array_initializer = Integer.parseInt((String) continuationIndentationForArrayInitializerOption); + } catch (NumberFormatException e) { + this.continuation_indentation_for_array_initializer = 2; + } catch(ClassCastException e) { + this.continuation_indentation_for_array_initializer = 2; + } + } // final Object blankLinesAfterIncludesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_IMPORTS); // if (blankLinesAfterIncludesOption != null) { // try { @@ -988,10 +987,10 @@ public class DefaultCodeFormatterOptions { this.indentation_size = 4; } } -// final Object insertNewLineAfterOpeningBraceInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER); -// if (insertNewLineAfterOpeningBraceInArrayInitializerOption != null) { -// this.insert_new_line_after_opening_brace_in_array_initializer = CCorePlugin.INSERT.equals(insertNewLineAfterOpeningBraceInArrayInitializerOption); -// } + final Object insertNewLineAfterOpeningBraceInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER); + if (insertNewLineAfterOpeningBraceInArrayInitializerOption != null) { + this.insert_new_line_after_opening_brace_in_array_initializer = CCorePlugin.INSERT.equals(insertNewLineAfterOpeningBraceInArrayInitializerOption); + } final Object insertNewLineAtEndOfFileIfMissingOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING); if (insertNewLineAtEndOfFileIfMissingOption != null) { this.insert_new_line_at_end_of_file_if_missing = CCorePlugin.INSERT.equals(insertNewLineAtEndOfFileIfMissingOption); @@ -1000,10 +999,10 @@ public class DefaultCodeFormatterOptions { // if (insertNewLineBeforeCatchInTryStatementOption != null) { // this.insert_new_line_before_catch_in_try_statement = CCorePlugin.INSERT.equals(insertNewLineBeforeCatchInTryStatementOption); // } -// final Object insertNewLineBeforeClosingBraceInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER); -// if (insertNewLineBeforeClosingBraceInArrayInitializerOption != null) { -// this.insert_new_line_before_closing_brace_in_array_initializer = CCorePlugin.INSERT.equals(insertNewLineBeforeClosingBraceInArrayInitializerOption); -// } + final Object insertNewLineBeforeClosingBraceInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER); + if (insertNewLineBeforeClosingBraceInArrayInitializerOption != null) { + this.insert_new_line_before_closing_brace_in_array_initializer = CCorePlugin.INSERT.equals(insertNewLineBeforeClosingBraceInArrayInitializerOption); + } final Object insertNewLineBeforeElseInIfStatementOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT); if (insertNewLineBeforeElseInIfStatementOption != null) { this.insert_new_line_before_else_in_if_statement = CCorePlugin.INSERT.equals(insertNewLineBeforeElseInIfStatementOption); @@ -1084,10 +1083,10 @@ public class DefaultCodeFormatterOptions { // if (insertSpaceAfterCommaInAllocationExpressionOption != null) { // this.insert_space_after_comma_in_allocation_expression = CCorePlugin.INSERT.equals(insertSpaceAfterCommaInAllocationExpressionOption); // } -// final Object insertSpaceAfterCommaInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ARRAY_INITIALIZER); -// if (insertSpaceAfterCommaInArrayInitializerOption != null) { -// this.insert_space_after_comma_in_array_initializer = CCorePlugin.INSERT.equals(insertSpaceAfterCommaInArrayInitializerOption); -// } + final Object insertSpaceAfterCommaInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ARRAY_INITIALIZER); + if (insertSpaceAfterCommaInArrayInitializerOption != null) { + this.insert_space_after_comma_in_array_initializer = CCorePlugin.INSERT.equals(insertSpaceAfterCommaInArrayInitializerOption); + } // final Object insertSpaceAfterCommaInConstructorDeclarationParametersOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_CONSTRUCTOR_DECLARATION_PARAMETERS); // if (insertSpaceAfterCommaInConstructorDeclarationParametersOption != null) { // this.insert_space_after_comma_in_constructor_declaration_parameters = CCorePlugin.INSERT.equals(insertSpaceAfterCommaInConstructorDeclarationParametersOption); @@ -1176,10 +1175,10 @@ public class DefaultCodeFormatterOptions { // if (insertSpaceAfterOpeningBracketInArrayReferenceOption != null) { // this.insert_space_after_opening_bracket_in_array_reference = CCorePlugin.INSERT.equals(insertSpaceAfterOpeningBracketInArrayReferenceOption); // } -// final Object insertSpaceAfterOpeningBraceInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER); -// if (insertSpaceAfterOpeningBraceInArrayInitializerOption != null) { -// this.insert_space_after_opening_brace_in_array_initializer = CCorePlugin.INSERT.equals(insertSpaceAfterOpeningBraceInArrayInitializerOption); -// } + final Object insertSpaceAfterOpeningBraceInArrayInitializerOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER); + if (insertSpaceAfterOpeningBraceInArrayInitializerOption != null) { + this.insert_space_after_opening_brace_in_array_initializer = CCorePlugin.INSERT.equals(insertSpaceAfterOpeningBraceInArrayInitializerOption); + } // final Object insertSpaceAfterOpeningParenInCastOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_CAST); // if (insertSpaceAfterOpeningParenInCastOption != null) { // this.insert_space_after_opening_paren_in_cast = CCorePlugin.INSERT.equals(insertSpaceAfterOpeningParenInCastOption); @@ -1691,7 +1690,7 @@ public class DefaultCodeFormatterOptions { // this.comment_insert_new_line_for_parameter = true; // this.comment_line_length = 80; this.continuation_indentation = 2; -// this.continuation_indentation_for_array_initializer = 2; + this.continuation_indentation_for_array_initializer = 2; // this.blank_lines_after_includes = 1; // this.blank_lines_before_field = 1; // this.blank_lines_before_first_class_body_declaration = 0; @@ -1712,10 +1711,10 @@ public class DefaultCodeFormatterOptions { this.indent_switchstatements_compare_to_cases = true; this.indent_switchstatements_compare_to_switch = false; this.indentation_size = 4; -// this.insert_new_line_after_opening_brace_in_array_initializer = false; + this.insert_new_line_after_opening_brace_in_array_initializer = false; this.insert_new_line_at_end_of_file_if_missing = false; // this.insert_new_line_before_catch_in_try_statement = false; -// this.insert_new_line_before_closing_brace_in_array_initializer = false; + this.insert_new_line_before_closing_brace_in_array_initializer = false; this.insert_new_line_before_else_in_if_statement = false; // this.insert_new_line_before_finally_in_try_statement = false; this.insert_new_line_before_while_in_do_statement = false; @@ -1736,7 +1735,7 @@ public class DefaultCodeFormatterOptions { // this.insert_space_after_colon_in_for = true; // this.insert_space_after_colon_in_labeled_statement = true; // this.insert_space_after_comma_in_allocation_expression = true; -// this.insert_space_after_comma_in_array_initializer = true; + this.insert_space_after_comma_in_array_initializer = true; // this.insert_space_after_comma_in_constructor_declaration_parameters = true; // this.insert_space_after_comma_in_constructor_declaration_throws = true; // this.insert_space_after_comma_in_enum_constant_arguments = true; @@ -1759,7 +1758,7 @@ public class DefaultCodeFormatterOptions { // this.insert_space_after_opening_angle_bracket_in_type_parameters = false; // this.insert_space_after_opening_bracket_in_array_allocation_expression = false; // this.insert_space_after_opening_bracket_in_array_reference = false; -// this.insert_space_after_opening_brace_in_array_initializer = true; + this.insert_space_after_opening_brace_in_array_initializer = true; // this.insert_space_after_opening_paren_in_cast = false; // this.insert_space_after_opening_paren_in_catch = false; // this.insert_space_after_opening_paren_in_constructor_declaration = false; @@ -1782,7 +1781,7 @@ public class DefaultCodeFormatterOptions { // this.insert_space_before_closing_angle_bracket_in_parameterized_type_reference = false; // this.insert_space_before_closing_angle_bracket_in_type_arguments = false; // this.insert_space_before_closing_angle_bracket_in_type_parameters = false; -// this.insert_space_before_closing_brace_in_array_initializer = true; + this.insert_space_before_closing_brace_in_array_initializer = true; // this.insert_space_before_closing_bracket_in_array_allocation_expression = false; // this.insert_space_before_closing_bracket_in_array_reference = false; // this.insert_space_before_closing_paren_in_cast = false; @@ -1802,7 +1801,7 @@ public class DefaultCodeFormatterOptions { // this.insert_space_before_colon_in_for = true; // this.insert_space_before_colon_in_labeled_statement = false; // this.insert_space_before_comma_in_allocation_expression = false; -// this.insert_space_before_comma_in_array_initializer = false; + this.insert_space_before_comma_in_array_initializer = false; // this.insert_space_before_comma_in_constructor_declaration_parameters = false; // this.insert_space_before_comma_in_constructor_declaration_throws = false; // this.insert_space_before_comma_in_enum_constant_arguments = false; @@ -1824,7 +1823,7 @@ public class DefaultCodeFormatterOptions { // this.insert_space_before_opening_angle_bracket_in_parameterized_type_reference = false; // this.insert_space_before_opening_angle_bracket_in_type_arguments = false; // this.insert_space_before_opening_angle_bracket_in_type_parameters = false; -// this.insert_space_before_opening_brace_in_array_initializer = true; + this.insert_space_before_opening_brace_in_array_initializer = true; this.insert_space_before_opening_brace_in_block = true; // this.insert_space_before_opening_brace_in_constructor_declaration = true; // this.insert_space_before_opening_brace_in_enum_constant = true; @@ -1853,7 +1852,7 @@ public class DefaultCodeFormatterOptions { this.insert_space_before_semicolon_in_for = false; // this.insert_space_before_unary_operator = false; // this.insert_space_between_brackets_in_array_type_reference = false; -// this.insert_space_between_empty_braces_in_array_initializer = false; + this.insert_space_between_empty_braces_in_array_initializer = false; // this.insert_space_between_empty_brackets_in_array_allocation_expression = false; // this.insert_space_between_empty_parens_in_constructor_declaration = false; // this.insert_space_between_empty_parens_in_enum_constant = false; @@ -1862,7 +1861,7 @@ public class DefaultCodeFormatterOptions { this.compact_else_if = true; this.keep_guardian_clause_on_one_line = false; this.keep_else_statement_on_same_line = false; -// this.keep_empty_array_initializer_on_one_line = false; + this.keep_empty_array_initializer_on_one_line = false; this.keep_simple_if_on_one_line = false; this.keep_then_statement_on_same_line = false; this.number_of_empty_lines_to_preserve = 1; @@ -1938,10 +1937,10 @@ public class DefaultCodeFormatterOptions { this.indent_switchstatements_compare_to_switch = false; this.indentation_size = 4; -// this.insert_new_line_after_opening_brace_in_array_initializer = false; + this.insert_new_line_after_opening_brace_in_array_initializer = false; this.insert_new_line_at_end_of_file_if_missing = false; // this.insert_new_line_before_catch_in_try_statement = false; -// this.insert_new_line_before_closing_brace_in_array_initializer = false; + this.insert_new_line_before_closing_brace_in_array_initializer = false; this.insert_new_line_before_else_in_if_statement = true; // this.insert_new_line_before_finally_in_try_statement = false; this.insert_new_line_before_while_in_do_statement = false; @@ -1954,7 +1953,7 @@ public class DefaultCodeFormatterOptions { this.compact_else_if = true; this.keep_guardian_clause_on_one_line = false; this.keep_else_statement_on_same_line = false; -// this.keep_empty_array_initializer_on_one_line = false; + this.keep_empty_array_initializer_on_one_line = false; this.keep_simple_if_on_one_line = false; this.keep_then_statement_on_same_line = false; this.number_of_empty_lines_to_preserve = 1; @@ -2012,10 +2011,10 @@ public class DefaultCodeFormatterOptions { this.indent_switchstatements_compare_to_switch = false; this.indentation_size = 8; -// this.insert_new_line_after_opening_brace_in_array_initializer = false; + this.insert_new_line_after_opening_brace_in_array_initializer = false; this.insert_new_line_at_end_of_file_if_missing = false; // this.insert_new_line_before_catch_in_try_statement = false; -// this.insert_new_line_before_closing_brace_in_array_initializer = false; + this.insert_new_line_before_closing_brace_in_array_initializer = false; this.insert_new_line_before_else_in_if_statement = true; // this.insert_new_line_before_finally_in_try_statement = false; this.insert_new_line_before_while_in_do_statement = false; @@ -2028,7 +2027,7 @@ public class DefaultCodeFormatterOptions { this.compact_else_if = true; this.keep_guardian_clause_on_one_line = false; this.keep_else_statement_on_same_line = false; -// this.keep_empty_array_initializer_on_one_line = false; + this.keep_empty_array_initializer_on_one_line = false; this.keep_simple_if_on_one_line = false; this.keep_then_statement_on_same_line = false; this.number_of_empty_lines_to_preserve = 1; @@ -2061,6 +2060,8 @@ public class DefaultCodeFormatterOptions { */ public void setWhitesmitsSettings() { setDefaultSettings(); + this.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT; + this.brace_position_for_array_initializer = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; this.brace_position_for_block = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; this.brace_position_for_block_in_case = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED; @@ -2084,12 +2085,12 @@ public class DefaultCodeFormatterOptions { this.indent_switchstatements_compare_to_switch = false; this.indentation_size = 4; -// this.insert_new_line_after_opening_brace_in_array_initializer = false; + this.insert_new_line_after_opening_brace_in_array_initializer = true; this.insert_new_line_at_end_of_file_if_missing = false; -// this.insert_new_line_before_catch_in_try_statement = false; -// this.insert_new_line_before_closing_brace_in_array_initializer = false; +// this.insert_new_line_before_catch_in_try_statement = true; + this.insert_new_line_before_closing_brace_in_array_initializer = true; this.insert_new_line_before_else_in_if_statement = true; -// this.insert_new_line_before_finally_in_try_statement = false; +// this.insert_new_line_before_finally_in_try_statement = true; this.insert_new_line_before_while_in_do_statement = true; this.insert_new_line_in_empty_block = true; // this.insert_new_line_in_empty_enum_constant = true; @@ -2100,7 +2101,7 @@ public class DefaultCodeFormatterOptions { this.compact_else_if = false; this.keep_guardian_clause_on_one_line = false; this.keep_else_statement_on_same_line = false; -// this.keep_empty_array_initializer_on_one_line = false; + this.keep_empty_array_initializer_on_one_line = false; this.keep_simple_if_on_one_line = false; this.keep_then_statement_on_same_line = false; this.number_of_empty_lines_to_preserve = 1; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java index f4050373d35..661eaf7ea72 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java @@ -643,7 +643,7 @@ public class Scribe { switch (currentToken.type) { case Token.tLBRACE: scanner.resetTo(scanner.getCurrentTokenStartPosition(), scannerEndPosition-1); - formatOpeningBrace(formatter.preferences.brace_position_for_block, hasWhitespace); + formatOpeningBrace(formatter.preferences.brace_position_for_block, formatter.preferences.insert_space_before_opening_brace_in_block); if (formatter.preferences.indent_statements_compare_to_block) { indent(); } @@ -1543,13 +1543,17 @@ public class Scribe { while ((currentToken= scanner.nextToken()) != null) { switch (currentToken.type) { case Token.tLBRACE: - ++braceLevel; + if (expectedTokenType != Token.tLBRACE) { + ++braceLevel; + } break; case Token.tRBRACE: --braceLevel; break; case Token.tLPAREN: - ++parenLevel; + if (expectedTokenType != Token.tLPAREN) { + ++parenLevel; + } break; case Token.tRPAREN: --parenLevel; diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp index 2d343faaa67..5114e384474 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/After.cpp @@ -3,3 +3,5 @@ struct x { }; struct x getX() { } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171520 +int bug=sizeof(int); diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/Before.cpp index 2f189437d72..480253bb29c 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/Before.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/bugs/Before.cpp @@ -1,3 +1,5 @@ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=169382 struct x {}; struct x getX() {} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171520 +int bug=sizeof(int); diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/After.cpp index d595123b02e..0c900825798 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/After.cpp @@ -41,3 +41,21 @@ int foo(int bar) const { } } } // end namespace FOO +/* + * Line Wrapping + */ +int array[]= { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1000, + 2000, 3000, 4000, 5000 }; +int compare(int argument, int otherArgument) { + return argument+otherArgument > argument*otherArgument+1000000 ? 100000+50000 + : 200000-30000; +} +class Other { + static void bar(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, + int arg7, int arg8, int arg9) { + } +}; +void foo() { + Other::bar(100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, + 900000); +} diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/Before.cpp index a48488347f2..97138157acc 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/Before.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/preview/Before.cpp @@ -3,3 +3,10 @@ */ #includeclass Point {public:Point(double xc, double yc) : x(xc), y(yc) {}double distance(const Point& other) const;int compareX(const Point& other) const;double x;double y;};double Point::distance(const Point& other) const {double dx = x - other.x;double dy = y - other.y;return sqrt(dx * dx + dy * dy);}int Point::compareX(const Point& other) const {if (x < other.x) {return -1;} else if (x > other.x) {return 1;} else {return 0;}}namespace FOO {int foo(int bar) const {switch (bar) {case 0:++bar;break;case 1:--bar;default: {bar += bar;break;}}}} // end namespace FOO +/* + * Line Wrapping + */ +int array[]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1000, 2000, 3000, 4000, 5000}; +int compare(int argument, int otherArgument) {return argument+otherArgument > argument*otherArgument+1000000 ? 100000+50000 : 200000-30000;} +class Other {static void bar(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9) {}}; +void foo() {Other::bar(100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000);} diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp index 948e82d05af..9f83e44878f 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp @@ -1,12 +1,21 @@ -#include +//#include +#ifndef SIMPLE_H +#define SIMPLE_H -const SimpleStruct simpleStruct = -{ - 1 - , "mySimple" - , 0.1232 +struct SimpleStruct { + int num; + char name[ ]; + float floatNum; }; +void SimpleStruct_construct( struct SimpleStruct * const this ); + +int SimpleStruct_doSomething( const struct SimpleStruct * const this ); + +#endif /* SIMPLE_H */ + +const SimpleStruct simpleStruct = { 1, "mySimple", 0.1232 }; + #define SIZEOF( A, B ) sizeof( A.B ) #define FOREVER \ @@ -15,25 +24,13 @@ const SimpleStruct simpleStruct = \ } -const OtherStruct array[] = -{ - { +const SimpleStruct array[] = { { SIZEOF( simpleStruct, num ), #if FOO - "foo" + "foo" # else - "bar" + "bar" #endif - , SIZEOF( simpleStruct, num ) - , &t_int - , 0 - } - , { - "name" - , SIZEOF( simpleStruct, floatnum ) - , &t_float - , 1 - } -}; + , 0.5 }, { SIZEOF( simpleStruct, floatNum ), "name", 1.1 } }; // single line outside scope diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/Before.cpp index e1578fe118a..d1781c39bcd 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/Before.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/Before.cpp @@ -1,4 +1,21 @@ -#include +//#include +#ifndef SIMPLE_H +#define SIMPLE_H + +struct SimpleStruct +{ + int num; + char name[ ]; + float floatNum; +}; + + +void SimpleStruct_construct( struct SimpleStruct * const this ); + +int SimpleStruct_doSomething( const struct SimpleStruct * const this ); + +#endif /* SIMPLE_H */ + const SimpleStruct simpleStruct = { @@ -15,23 +32,21 @@ const SimpleStruct simpleStruct = \ } -const OtherStruct array[] = +const SimpleStruct array[] = { { + SIZEOF( simpleStruct, num ), #if FOO "foo" # else "bar" #endif - , SIZEOF( simpleStruct, num ) - , &t_int - , 0 + , 0.5 } , { - "name" - , SIZEOF( simpleStruct, floatnum ) - , &t_float - , 1 + SIZEOF( simpleStruct, floatNum ) +, "name" + , 1.1 } }; diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/After.cpp index 2792a676739..f6f53ba28db 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/templates/After.cpp @@ -67,7 +67,7 @@ template char // an instantiation, not a template: complex - cf(0,0); + cf(0, 0); //template > //Dictionary* TheSpellCheckDictionary; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorActionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorActionContributor.java index cd9468440e7..473447ceb92 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorActionContributor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorActionContributor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,7 +17,6 @@ import java.util.ResourceBundle; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.text.ITextOperationTarget; import org.eclipse.ui.IActionBars; @@ -35,13 +34,13 @@ import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction; public class CEditorActionContributor extends TextEditorActionContributor { - protected CEditor fCEditor; - protected RetargetTextEditorAction fContentAssist; - protected RetargetTextEditorAction fFormatter; - protected RetargetTextEditorAction fAddInclude; -// protected RetargetTextEditorAction fOpenOnSelection; - protected RetargetTextEditorAction fShiftLeft; - protected RetargetTextEditorAction fShiftRight; + private RetargetTextEditorAction fContentAssist; + private RetargetTextEditorAction fContextInformation; + private RetargetTextEditorAction fFormatter; + private RetargetTextEditorAction fAddInclude; +// private RetargetTextEditorAction fOpenOnSelection; + private RetargetTextEditorAction fShiftLeft; + private RetargetTextEditorAction fShiftRight; private TogglePresentationAction fTogglePresentation; private GotoAnnotationAction fPreviousAnnotation; private GotoAnnotationAction fNextAnnotation; @@ -49,6 +48,7 @@ public class CEditorActionContributor extends TextEditorActionContributor { private RetargetTextEditorAction fGotoNextMemberAction; private RetargetTextEditorAction fGotoPreviousMemberAction; private RetargetTextEditorAction fToggleInsertModeAction; + private RetargetTextEditorAction fShowOutline; public CEditorActionContributor() { super(); @@ -66,6 +66,9 @@ public class CEditorActionContributor extends TextEditorActionContributor { fContentAssist = new RetargetTextEditorAction(bundle, "ContentAssistProposal."); //$NON-NLS-1$ fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + fContextInformation = new RetargetTextEditorAction(bundle, "ContentAssistContextInformation."); //$NON-NLS-1$ + fContextInformation.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); + fFormatter = new RetargetTextEditorAction(bundle, "Format."); //$NON-NLS-1$ fFormatter.setActionDefinitionId(ICEditorActionDefinitionIds.FORMAT); @@ -93,8 +96,11 @@ public class CEditorActionContributor extends TextEditorActionContributor { fToggleInsertModeAction= new RetargetTextEditorAction(bundle, "ToggleInsertMode.", IAction.AS_CHECK_BOX); //$NON-NLS-1$ fToggleInsertModeAction.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_INSERT_MODE); - } + fShowOutline= new RetargetTextEditorAction(bundle, "OpenOutline."); //$NON-NLS-1$ + fShowOutline.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE); + + } /* * @see org.eclipse.ui.texteditor.BasicTextEditorActionContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager) @@ -105,18 +111,26 @@ public class CEditorActionContributor extends TextEditorActionContributor { IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); if (editMenu != null) { - editMenu.add(fShiftRight); - editMenu.add(fShiftLeft); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_ASSIST, fContentAssist); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_ASSIST, fContextInformation); - editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE)); - editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContentAssist); - editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fAddInclude); - editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fFormatter); -// editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fOpenOnSelection); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftRight); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftLeft); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fFormatter); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator()); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fAddInclude); + editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator()); editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction); + } + + IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); + if (navigateMenu != null) { + navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline); +// navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenHierarchy); +// navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenOnSelection); - IMenuManager gotoMenu= menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$ + IMenuManager gotoMenu= navigateMenu.findMenuUsingPath(IWorkbenchActionConstants.GO_TO); if (gotoMenu != null) { gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$ gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$ @@ -124,6 +138,7 @@ public class CEditorActionContributor extends TextEditorActionContributor { gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$ } } + } /** @@ -140,7 +155,6 @@ public class CEditorActionContributor extends TextEditorActionContributor { bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation); } - /* * @see org.eclipse.ui.editors.text.TextEditorActionContributor#setActiveEditor(org.eclipse.ui.IEditorPart) */ @@ -160,6 +174,7 @@ public class CEditorActionContributor extends TextEditorActionContributor { fNextAnnotation.setEditor(textEditor); fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$ + fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$ fAddInclude.setAction(getAction(textEditor, "AddIncludeOnSelection")); //$NON-NLS-1$ // fOpenOnSelection.setAction(getAction(textEditor, "OpenOnSelection")); //$NON-NLS-1$ fFormatter.setAction(getAction(textEditor, "Format")); //$NON-NLS-1$ @@ -167,7 +182,9 @@ public class CEditorActionContributor extends TextEditorActionContributor { fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET)); fGotoNextMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER)); fGotoPreviousMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER)); - + + fShowOutline.setAction(getAction(textEditor, "OpenOutline")); //$NON-NLS-1$ + fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE)); if (part instanceof CEditor) { @@ -177,15 +194,6 @@ public class CEditorActionContributor extends TextEditorActionContributor { } - /* - * @see EditorActionBarContributor#contributeToStatusLine(IStatusLineManager) - * - * More code here only until we move to 2.0... - */ - public void contributeeToStatusLine(IStatusLineManager statusLineManager) { - super.contributeToStatusLine(statusLineManager); - } - /* (non-Javadoc) * @see org.eclipse.ui.IEditorActionBarContributor#dispose() */ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties index d8f14cbfca4..f07fd8dc952 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties @@ -1,5 +1,5 @@ ######################################### -# Copyright (c) 2005, 2006 IBM Corporation and others. +# Copyright (c) 2005, 2007 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -59,6 +59,10 @@ ContentAssistProposal.label=Co&ntent Assist ContentAssistProposal.tooltip=Content Assist ContentAssistProposal.description=Content Assist +ContentAssistContextInformation.label=Parameter &Hints +ContentAssistContextInformation.tooltip=Show Parameter Hints +ContentAssistContextInformation.description=Show Method Parameter Hints + ToggleComment.label=Comment/Uncomment ToggleComment.tooltip=Comment/Uncomment For the Selected Lines ToggleComment.description=Comment/Uncomment for the selected lines diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/BracesTabPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/BracesTabPage.java index dad079391a5..cbc411b0113 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/BracesTabPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/BracesTabPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,7 +12,10 @@ package org.eclipse.cdt.internal.ui.preferences.formatter; import java.util.Map; +import java.util.Observable; +import java.util.Observer; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; @@ -126,24 +129,24 @@ public class BracesTabPage extends ModifyDialogTabPage { createExtendedBracesCombo(group, numColumns, FormatterMessages.BracesTabPage_option_blocks_in_case, DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK_IN_CASE); createBracesCombo(group, numColumns, FormatterMessages.BracesTabPage_option_switch_case, DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_SWITCH); -// ComboPreference arrayInitOption= createBracesCombo(group, numColumns, FormatterMessages.BracesTabPage_option_array_initializer, DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ARRAY_INITIALIZER); -// final CheckboxPreference arrayInitCheckBox= createIndentedCheckboxPref(group, numColumns, FormatterMessages.BracesTabPage_option_keep_empty_array_initializer_on_one_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_EMPTY_ARRAY_INITIALIZER_ON_ONE_LINE, FALSE_TRUE); + ComboPreference arrayInitOption= createBracesCombo(group, numColumns, FormatterMessages.BracesTabPage_option_array_initializer, DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ARRAY_INITIALIZER); + final CheckboxPreference arrayInitCheckBox= createIndentedCheckboxPref(group, numColumns, FormatterMessages.BracesTabPage_option_keep_empty_array_initializer_on_one_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_EMPTY_ARRAY_INITIALIZER_ON_ONE_LINE, FALSE_TRUE); -// arrayInitOption.addObserver(new Observer() { -// public void update(Observable o, Object arg) { -// updateOptionEnablement((ComboPreference) o, arrayInitCheckBox); -// } -// }); -// updateOptionEnablement(arrayInitOption, arrayInitCheckBox); + arrayInitOption.addObserver(new Observer() { + public void update(Observable o, Object arg) { + updateOptionEnablement((ComboPreference) o, arrayInitCheckBox); + } + }); + updateOptionEnablement(arrayInitOption, arrayInitCheckBox); } -// /** -// * @param arrayInitOption -// * @param arrayInitCheckBox -// */ -// protected final void updateOptionEnablement(ComboPreference arrayInitOption, CheckboxPreference arrayInitCheckBox) { -// arrayInitCheckBox.setEnabled(!arrayInitOption.hasValue(DefaultCodeFormatterConstants.END_OF_LINE)); -// } + /** + * @param arrayInitOption + * @param arrayInitCheckBox + */ + protected final void updateOptionEnablement(ComboPreference arrayInitOption, CheckboxPreference arrayInitCheckBox) { + arrayInitCheckBox.setEnabled(!arrayInitOption.hasValue(DefaultCodeFormatterConstants.END_OF_LINE)); + } protected void initializePage() { fPreview.setPreviewText(PREVIEW); @@ -162,12 +165,12 @@ public class BracesTabPage extends ModifyDialogTabPage { return createComboPref(composite, numColumns, message, key, fExtendedBracePositions, fExtendedBracePositionNames); } -// private CheckboxPreference createIndentedCheckboxPref(Composite composite, int numColumns, String message, String key, String [] values) { -// CheckboxPreference pref= createCheckboxPref(composite, numColumns, message, key, values); -// GridData data= (GridData) pref.getControl().getLayoutData(); -// data.horizontalIndent= fPixelConverter.convertWidthInCharsToPixels(1); -// return pref; -// } + private CheckboxPreference createIndentedCheckboxPref(Composite composite, int numColumns, String message, String key, String [] values) { + CheckboxPreference pref= createCheckboxPref(composite, numColumns, message, key, values); + GridData data= (GridData) pref.getControl().getLayoutData(); + data.horizontalIndent= fPixelConverter.convertWidthInCharsToPixels(1); + return pref; + } protected void doUpdatePreview() { 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 a2fec885c11..a4b35ede331 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -299,7 +299,7 @@ final class FormatterMessages extends NLS { public static String LineWrappingTabPage_width_indent; public static String LineWrappingTabPage_width_indent_option_max_line_width; 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_enum_superinterfaces; // public static String LineWrappingTabPage_assignment_alignment; @@ -338,8 +338,8 @@ final class FormatterMessages extends NLS { public static String BracesTabPage_option_blocks; public static String BracesTabPage_option_blocks_in_case; public static String BracesTabPage_option_switch_case; -// public static String BracesTabPage_option_array_initializer; -// public static String BracesTabPage_option_keep_empty_array_initializer_on_one_line; + public static String BracesTabPage_option_array_initializer; + public static String BracesTabPage_option_keep_empty_array_initializer_on_one_line; // public static String BracesTabPage_option_enum_declaration; // public static String BracesTabPage_option_enumconst_declaration; // public static String BracesTabPage_option_annotation_type_declaration; 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 60ad012a98b..c83a3d39884 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 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2006 IBM Corporation and others. +# Copyright (c) 2000, 2007 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ # istvan@benedek-home.de - 103706 [formatter] indent empty lines # Aaron Luchko, aluchko@redhat.com - 105926 [Formatter] Exporting Unnamed profile fails silently # Sergey Prigogin, Google +# Anton Leherbauer (Wind River Systems) ############################################################################### @@ -44,7 +45,7 @@ #WhiteSpaceTabPage_localvars_before_comma=before comma in multiple local declarations #WhiteSpaceTabPage_localvars_after_comma=after comma in multiple local declarations -#WhiteSpaceTabPage_arrayinit=Array initializers +#WhiteSpaceTabPage_arrayinit=Initializer lists #WhiteSpaceTabPage_arraydecls=Array declarations #WhiteSpaceTabPage_arrayelem=Array element access #WhiteSpaceTabPage_arrayalloc=Array allocation @@ -216,13 +217,13 @@ #WhiteSpaceOptions_closing_bracket=Closing bracket #WhiteSpaceOptions_class_decl=Type declaration #WhiteSpaceOptions_anon_class_decl=Anonymous type declaration -#WhiteSpaceOptions_initializer=Array initializer +#WhiteSpaceOptions_initializer=Initializer lists #WhiteSpaceOptions_block=Block #WhiteSpaceOptions_array_decl=Array declaration #WhiteSpaceOptions_array_element_access=Array element access #WhiteSpaceOptions_array_alloc=Array allocation -#WhiteSpaceOptions_array_init=Array initializer +#WhiteSpaceOptions_array_init=Initializer list #WhiteSpaceOptions_arguments=Arguments #WhiteSpaceOptions_initialization=Initialization @@ -308,7 +309,7 @@ LineWrappingTabPage_arguments=Arguments #LineWrappingTabPage_throws_clause='throws' clause #LineWrappingTabPage_object_allocation=Object allocation arguments #LineWrappingTabPage_qualified_object_allocation=Qualified object allocation arguments -LineWrappingTabPage_array_init=Array initializers +LineWrappingTabPage_array_init=Initializer lists #LineWrappingTabPage_explicit_constructor_invocations=Explicit constructor invocations LineWrappingTabPage_conditionals=Conditionals #LineWrappingTabPage_binary_exprs=Binary expressions @@ -340,7 +341,7 @@ LineWrappingTabPage_splitting_wrap_always_except_first_only_if_necessary=Wrap al LineWrappingTabPage_width_indent=Line width and indentation levels 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_array=Default indentation for arra&y initializers: +LineWrappingTabPage_width_indent_option_default_indent_array=Default indentation for nitializer lists: LineWrappingTabPage_error_invalid_value=The key ''{0}'' contained an invalid value; resetting to defaults. #LineWrappingTabPage_enum_superinterfaces='implements' clause #LineWrappingTabPage_assignment_alignment=Assignments @@ -387,8 +388,8 @@ BracesTabPage_option_method_declaration=Met&hod declaration: BracesTabPage_option_blocks=&Blocks: BracesTabPage_option_blocks_in_case=Bloc&ks in case statement: BracesTabPage_option_switch_case='&switch' statement: -#BracesTabPage_option_array_initializer=Array initiali&zer: -#BracesTabPage_option_keep_empty_array_initializer_on_one_line=Keep empty array &initializer on one line +BracesTabPage_option_array_initializer=Initiali&zer list: +BracesTabPage_option_keep_empty_array_initializer_on_one_line=Keep empty &initializer list on one line #BracesTabPage_option_enum_declaration=&Enum declaration: #BracesTabPage_option_enumconst_declaration=Enum c&onstant body: #BracesTabPage_option_annotation_type_declaration=&Annotation type declaration: @@ -536,9 +537,9 @@ ModifyDialogTabPage_NumberPreference_error_invalid_value=Invalid value: Please e #NewLinesTabPage_empty_statement_group_title=Empty statements #NewLinesTabPage_emtpy_statement_group_option_empty_statement_on_new_line=Put empty &statement on new line -#NewLinesTabPage_arrayInitializer_group_title=Array initializers -#NewLinesTabPage_array_group_option_after_opening_brace_of_array_initializer=Insert new line after openin&g brace of array initializer -#NewLinesTabPage_array_group_option_before_closing_brace_of_array_initializer=Insert new line before closing brace of array initiali&zer +#NewLinesTabPage_arrayInitializer_group_title=Initializer lists +#NewLinesTabPage_array_group_option_after_opening_brace_of_array_initializer=Insert new line after openin&g brace of initializer list +#NewLinesTabPage_array_group_option_before_closing_brace_of_array_initializer=Insert new line before closing brace of initiali&zer list #NewLinesTabPage_annotations_group_title=Annotations #NewLinesTabPage_annotations_group_option_after_annotation=&Insert new line after annotations 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 aec851c971f..8c87db5a6cf 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -392,7 +392,7 @@ public class LineWrappingTabPage extends ModifyDialogTabPage { private final Category fMessageSendArgumentsCategory= new Category( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, - "class Other {static void bar(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) {}};"+ //$NON-NLS-1$ + "class Other {static void bar(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9) {}};"+ //$NON-NLS-1$ "void foo() {Other::bar(100, 200, 300, 400, 500, 600, 700, 800, 900);}", //$NON-NLS-1$ FormatterMessages.LineWrappingTabPage_arguments ); @@ -434,7 +434,7 @@ public class LineWrappingTabPage extends ModifyDialogTabPage { private final Category fArrayInitializerExpressionsCategory= new Category( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_ARRAY_INITIALIZER, - "int[] array= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};", //$NON-NLS-1$ + "int array[]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};", //$NON-NLS-1$ FormatterMessages.LineWrappingTabPage_array_init ); @@ -446,7 +446,7 @@ public class LineWrappingTabPage extends ModifyDialogTabPage { private final Category fConditionalExpressionCategory= new Category( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, - "int example(bool argument0, int otherArgument) {return argument ? 100000 : 200000;}}", //$NON-NLS-1$ + "int compare(int argument, int otherArgument) {return argument > argument ? 100000 : 200000;}", //$NON-NLS-1$ FormatterMessages.LineWrappingTabPage_conditionals ); @@ -615,7 +615,7 @@ public class LineWrappingTabPage extends ModifyDialogTabPage { root.add(methodDeclarations); // root.add(enumDeclarations); root.add(functionCalls); -// root.add(expressions); + root.add(expressions); // root.add(statements); return root; @@ -630,7 +630,7 @@ public class LineWrappingTabPage extends ModifyDialogTabPage { 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_array, DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, 0, 9999); + createNumberPref(lineWidthGroup, numColumns, FormatterMessages.LineWrappingTabPage_width_indent_option_default_indent_array, DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, 0, 9999); fCategoriesViewer= new TreeViewer(composite /*categoryGroup*/, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL ); fCategoriesViewer.setContentProvider(new ITreeContentProvider() {