mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 461435 - Added options to format pointers in methods
Rules used: 1) Default is right alignment to be compliant with built-in formatter rules; 2) Pointer with declarator without name will be always left alignment unless there's a nested declarator; 3) Return value of methods/functions is always left alignment; 4) If left alignment is selected, if space after comma is selected too for a declaration list, space is always forced after the comma. Change-Id: I82d5ad130e665e5357644cc59655a558f3fb732f Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
parent
826a0b2c0e
commit
f893b77dba
26 changed files with 456 additions and 251 deletions
|
@ -543,7 +543,7 @@ public class DefaultCodeFormatterConstants {
|
|||
* @see #NEXT_LINE
|
||||
* @see #NEXT_LINE_SHIFTED
|
||||
* @see #NEXT_LINE_ON_WRAP
|
||||
* @since 6.7
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_BRACE_POSITION_FOR_LINKAGE_DECLARATION = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.brace_position_for_linkage_declaration"; //$NON-NLS-1$
|
||||
|
@ -760,7 +760,7 @@ public class DefaultCodeFormatterConstants {
|
|||
* </pre>
|
||||
* @see #TRUE
|
||||
* @see #FALSE
|
||||
* @since 6.7
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_LINKAGE = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.indent_body_declarations_compare_to_linkage"; //$NON-NLS-1$
|
||||
|
@ -941,6 +941,7 @@ public class DefaultCodeFormatterConstants {
|
|||
* </pre>
|
||||
* @see CCorePlugin#INSERT
|
||||
* @see CCorePlugin#DO_NOT_INSERT
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_INSERT_NEW_LINE_AFTER_COLON_IN_CONSTRUCTOR_INITIALIZER_LIST = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.insert_new_line_after_colon_in_constructor_initializer_list"; //$NON-NLS-1$
|
||||
|
@ -2004,6 +2005,58 @@ public class DefaultCodeFormatterConstants {
|
|||
*/
|
||||
public static final String FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_METHOD_DECLARATION = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.insert_space_before_opening_brace_in_method_declaration"; //$NON-NLS-1$
|
||||
/**
|
||||
* <pre>
|
||||
* FORMATTER / Option to insert a space before a pointer in a method declaration
|
||||
* - option id: "org.eclipse.cdt.core.formatter.insert_space_before_pointer_in_method_declaration"
|
||||
* - possible values: { INSERT, DO_NOT_INSERT }
|
||||
* - default: INSERT
|
||||
* </pre>
|
||||
* @see CCorePlugin#INSERT
|
||||
* @see CCorePlugin#DO_NOT_INSERT
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_METHOD_DECLARATION = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.insert_space_before_pointer_in_method_declaration"; //$NON-NLS-1$
|
||||
/**
|
||||
* <pre>
|
||||
* FORMATTER / Option to insert a space after a pointer in a method declaration
|
||||
* - option id: "org.eclipse.cdt.core.formatter.insert_space_after_pointer_in_method_declaration"
|
||||
* - possible values: { INSERT, DO_NOT_INSERT }
|
||||
* - default: INSERT
|
||||
* </pre>
|
||||
* @see CCorePlugin#INSERT
|
||||
* @see CCorePlugin#DO_NOT_INSERT
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_METHOD_DECLARATION = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.insert_space_after_pointer_in_method_declaration"; //$NON-NLS-1$
|
||||
/**
|
||||
* <pre>
|
||||
* FORMATTER / Option to insert a space after a pointer in a declarator list
|
||||
* - option id: "org.eclipse.cdt.core.formatter.insert_space_after_pointer_in_declarator_list"
|
||||
* - possible values: { INSERT, DO_NOT_INSERT }
|
||||
* - default: INSERT
|
||||
* </pre>
|
||||
* @see CCorePlugin#INSERT
|
||||
* @see CCorePlugin#DO_NOT_INSERT
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_DECLARATOR_LIST = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.insert_space_after_pointer_in_declarator_list"; //$NON-NLS-1$
|
||||
/**
|
||||
* <pre>
|
||||
* FORMATTER / Option to insert a space before a pointer in a declarator list
|
||||
* - option id: "org.eclipse.cdt.core.formatter.insert_space_before_pointer_in_declarator_list"
|
||||
* - possible values: { INSERT, DO_NOT_INSERT }
|
||||
* - default: INSERT
|
||||
* </pre>
|
||||
* @see CCorePlugin#INSERT
|
||||
* @see CCorePlugin#DO_NOT_INSERT
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_DECLARATOR_LIST = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.insert_space_before_pointer_in_declarator_list"; //$NON-NLS-1$
|
||||
/**
|
||||
* <pre>
|
||||
* FORMATTER / Option to insert a space before the opening brace in a switch statement
|
||||
|
@ -2049,7 +2102,7 @@ public class DefaultCodeFormatterConstants {
|
|||
* </pre>
|
||||
* @see CCorePlugin#INSERT
|
||||
* @see CCorePlugin#DO_NOT_INSERT
|
||||
* @since 6.7
|
||||
* @since 6.8
|
||||
*/
|
||||
public static final String FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_LINKAGE_DECLARATION = CCorePlugin.PLUGIN_ID
|
||||
+ ".formatter.insert_space_before_opening_brace_in_linkage_declaration"; //$NON-NLS-1$
|
||||
|
|
|
@ -168,6 +168,8 @@ public class DefaultCodeFormatterOptions {
|
|||
public boolean insert_space_after_comma_in_method_invocation_arguments;
|
||||
public boolean insert_space_after_comma_in_method_declaration_parameters;
|
||||
public boolean insert_space_after_comma_in_method_declaration_throws;
|
||||
public boolean insert_space_after_pointer_in_declarator_list;
|
||||
public boolean insert_space_before_pointer_in_declarator_list;
|
||||
public boolean insert_space_after_comma_in_declarator_list;
|
||||
public boolean insert_space_after_comma_in_expression_list;
|
||||
public boolean insert_space_after_comma_in_base_types;
|
||||
|
@ -234,6 +236,8 @@ public class DefaultCodeFormatterOptions {
|
|||
public boolean insert_space_before_opening_brace_in_initializer_list;
|
||||
public boolean insert_space_before_opening_brace_in_block;
|
||||
public boolean insert_space_before_opening_brace_in_method_declaration;
|
||||
public boolean insert_space_before_pointer_in_method_declaration;
|
||||
public boolean insert_space_after_pointer_in_method_declaration;
|
||||
public boolean insert_space_before_opening_brace_in_type_declaration;
|
||||
public boolean insert_space_before_opening_brace_in_namespace_declaration;
|
||||
/**
|
||||
|
@ -646,6 +650,15 @@ public class DefaultCodeFormatterOptions {
|
|||
options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_METHOD_DECLARATION,
|
||||
this.insert_space_before_opening_brace_in_method_declaration ? CCorePlugin.INSERT
|
||||
: CCorePlugin.DO_NOT_INSERT);
|
||||
options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_METHOD_DECLARATION,
|
||||
this.insert_space_before_pointer_in_method_declaration ? CCorePlugin.INSERT
|
||||
: CCorePlugin.DO_NOT_INSERT);
|
||||
options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_METHOD_DECLARATION,
|
||||
this.insert_space_after_pointer_in_method_declaration ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT);
|
||||
options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_DECLARATOR_LIST,
|
||||
this.insert_space_after_pointer_in_declarator_list ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT);
|
||||
options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_DECLARATOR_LIST,
|
||||
this.insert_space_before_pointer_in_declarator_list ? CCorePlugin.INSERT : CCorePlugin.DO_NOT_INSERT);
|
||||
options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_TYPE_DECLARATION,
|
||||
this.insert_space_before_opening_brace_in_type_declaration ? CCorePlugin.INSERT
|
||||
: CCorePlugin.DO_NOT_INSERT);
|
||||
|
@ -1847,6 +1860,30 @@ public class DefaultCodeFormatterOptions {
|
|||
this.insert_space_before_opening_brace_in_method_declaration = CCorePlugin.INSERT
|
||||
.equals(insertSpaceBeforeOpeningBraceInMethodDeclarationOption);
|
||||
}
|
||||
final Object insertSpaceBeforePointerInMethodDeclarationOption = settings
|
||||
.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_METHOD_DECLARATION);
|
||||
if (insertSpaceBeforePointerInMethodDeclarationOption != null) {
|
||||
this.insert_space_before_pointer_in_method_declaration = CCorePlugin.INSERT
|
||||
.equals(insertSpaceBeforePointerInMethodDeclarationOption);
|
||||
}
|
||||
final Object insertSpaceAfterPointerInMethodDeclarationOption = settings
|
||||
.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_METHOD_DECLARATION);
|
||||
if (insertSpaceAfterPointerInMethodDeclarationOption != null) {
|
||||
this.insert_space_after_pointer_in_method_declaration = CCorePlugin.INSERT
|
||||
.equals(insertSpaceAfterPointerInMethodDeclarationOption);
|
||||
}
|
||||
final Object insertSpaceAfterPointerInDeclaratorListOption = settings
|
||||
.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_DECLARATOR_LIST);
|
||||
if (insertSpaceAfterPointerInDeclaratorListOption != null) {
|
||||
this.insert_space_after_pointer_in_declarator_list = CCorePlugin.INSERT
|
||||
.equals(insertSpaceAfterPointerInDeclaratorListOption);
|
||||
}
|
||||
final Object insertSpaceBeforePointerInDeclaratorListOption = settings
|
||||
.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_DECLARATOR_LIST);
|
||||
if (insertSpaceBeforePointerInDeclaratorListOption != null) {
|
||||
this.insert_space_before_pointer_in_declarator_list = CCorePlugin.INSERT
|
||||
.equals(insertSpaceBeforePointerInDeclaratorListOption);
|
||||
}
|
||||
final Object insertSpaceBeforeOpeningBraceInTypeDeclarationOption = settings
|
||||
.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_TYPE_DECLARATION);
|
||||
if (insertSpaceBeforeOpeningBraceInTypeDeclarationOption != null) {
|
||||
|
@ -2259,6 +2296,10 @@ public class DefaultCodeFormatterOptions {
|
|||
this.insert_space_before_opening_brace_in_initializer_list = true;
|
||||
this.insert_space_before_opening_brace_in_block = true;
|
||||
this.insert_space_before_opening_brace_in_method_declaration = true;
|
||||
this.insert_space_before_pointer_in_method_declaration = true;
|
||||
this.insert_space_after_pointer_in_method_declaration = false;
|
||||
this.insert_space_before_pointer_in_declarator_list = true;
|
||||
this.insert_space_after_pointer_in_declarator_list = false;
|
||||
this.insert_space_before_opening_brace_in_switch = true;
|
||||
this.insert_space_before_opening_brace_in_type_declaration = true;
|
||||
this.insert_space_before_opening_brace_in_namespace_declaration = true;
|
||||
|
|
|
@ -303,7 +303,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
boolean needSpace = skipConstVolatileRestrict();
|
||||
boolean needSpace = skipConstVolatileRestrict(true);
|
||||
int token = peekNextToken();
|
||||
// Ref-qualifier.
|
||||
if (token == Token.tAMPER || token == Token.tAND) {
|
||||
|
@ -830,9 +830,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (name != null && name.getSimpleID().length != 0 || nestedDecl != null) {
|
||||
if (node.getPropertyInParent() != IASTDeclarator.NESTED_DECLARATOR && isFirstDeclarator(node)) {
|
||||
// Preserve non-space between pointer operator and name or nested declarator.
|
||||
if (pointerOperators.length == 0 || scribe.printComment()) {
|
||||
if (pointerOperators.length == 0) {
|
||||
scribe.space();
|
||||
}
|
||||
} else
|
||||
scribe.printComment();
|
||||
}
|
||||
if (name != null)
|
||||
name.accept(this);
|
||||
|
@ -1544,11 +1545,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
}
|
||||
|
||||
private boolean skipConstVolatileRestrict() {
|
||||
private boolean skipConstVolatileRestrict(boolean spaceBefore) {
|
||||
boolean skipped = false;
|
||||
int token = peekNextToken();
|
||||
while (token == Token.t_const || token == Token.t_volatile || token == Token.t_restrict) {
|
||||
scribe.printNextToken(token, true);
|
||||
scribe.printNextToken(token, spaceBefore);
|
||||
token = peekNextToken();
|
||||
skipped = true;
|
||||
}
|
||||
|
@ -1642,6 +1643,61 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Align pointers according to user formatter rule. Pointers (or references) can be
|
||||
* left, center or right alignment. Pointers with implicit name will be always left
|
||||
* aligned unless they have nested declarators.
|
||||
* @param pointers The list of all pointers
|
||||
* @param pointer The pointer to be formatted
|
||||
* @param token The token to be used: and, amper, star.
|
||||
*/
|
||||
private boolean alignPointer(IASTPointerOperator[] pointers, IASTPointerOperator pointer, int token) {
|
||||
boolean firstPtr = pointer == pointers[0];
|
||||
boolean lastPtr = pointers.length == 1 || pointer == pointers[pointers.length - 1];
|
||||
TrailingTokenFormatter tailFormatter = null;
|
||||
IASTNode parent = pointer.getParent();
|
||||
boolean needSpace = false;
|
||||
if (parent instanceof IASTFunctionDeclarator) {
|
||||
tailFormatter = new TrailingTokenFormatter(token, pointer.getParent(), false, true);
|
||||
tailFormatter.run();
|
||||
} else {
|
||||
if (parent instanceof IASTDeclarator) {
|
||||
char[] simpleId = ((IASTDeclarator) parent).getName().getSimpleID();
|
||||
IASTDeclarator nested = ((IASTDeclarator) parent).getNestedDeclarator();
|
||||
if ((simpleId == null || simpleId.length == 0) && nested == null) {
|
||||
needSpace = true;
|
||||
tailFormatter = new TrailingTokenFormatter(token, pointer.getParent(), false, false);
|
||||
tailFormatter.run();
|
||||
return needSpace;
|
||||
}
|
||||
}
|
||||
if (parent != null && parent.getParent() instanceof IASTParameterDeclaration) {
|
||||
needSpace = this.preferences.insert_space_after_pointer_in_method_declaration && lastPtr;
|
||||
tailFormatter = new TrailingTokenFormatter(token, pointer.getParent(),
|
||||
this.preferences.insert_space_before_pointer_in_method_declaration && firstPtr,
|
||||
this.preferences.insert_space_after_pointer_in_method_declaration && lastPtr);
|
||||
tailFormatter.run();
|
||||
} else if (parent != null && parent.getParent() instanceof IASTSimpleDeclaration) {
|
||||
needSpace = this.preferences.insert_space_after_pointer_in_declarator_list && lastPtr;
|
||||
IASTSimpleDeclaration simple = (IASTSimpleDeclaration) parent.getParent();
|
||||
IASTDeclarator[] declarators = simple.getDeclarators();
|
||||
boolean first = declarators.length == 0 || declarators[0].getPointerOperators() == pointers;
|
||||
tailFormatter = new TrailingTokenFormatter(token, pointer.getParent(),
|
||||
first ? this.preferences.insert_space_before_pointer_in_declarator_list && firstPtr
|
||||
: (this.preferences.insert_space_before_pointer_in_declarator_list
|
||||
|| this.preferences.insert_space_after_comma_in_declarator_list) && firstPtr,
|
||||
this.preferences.insert_space_after_pointer_in_declarator_list && lastPtr);
|
||||
tailFormatter.run();
|
||||
} else
|
||||
scribe.printNextToken(token, false);
|
||||
}
|
||||
return needSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format pointers operators
|
||||
* @param pointers The list of pointers
|
||||
*/
|
||||
private void formatPointers(IASTPointerOperator[] pointers) {
|
||||
for (IASTPointerOperator pointer : pointers) {
|
||||
if (scribe.printComment()) {
|
||||
|
@ -1652,9 +1708,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
if (pointer instanceof ICPPASTReferenceOperator) {
|
||||
if (((ICPPASTReferenceOperator) pointer).isRValueReference()) {
|
||||
scribe.printNextToken(Token.tAND, false);
|
||||
alignPointer(pointers, pointer, Token.tAND);
|
||||
} else {
|
||||
scribe.printNextToken(Token.tAMPER, false);
|
||||
alignPointer(pointers, pointer, Token.tAMPER);
|
||||
}
|
||||
} else if (pointer instanceof ICPPASTPointerToMember) {
|
||||
final ICPPASTPointerToMember ptrToMember = (ICPPASTPointerToMember) pointer;
|
||||
|
@ -1663,12 +1719,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
name.accept(this);
|
||||
}
|
||||
scribe.printNextToken(Token.tSTAR, false);
|
||||
if (skipConstVolatileRestrict()) {
|
||||
if (skipConstVolatileRestrict(false)) {
|
||||
scribe.space();
|
||||
}
|
||||
} else {
|
||||
scribe.printNextToken(Token.tSTAR, false);
|
||||
if (skipConstVolatileRestrict()) {
|
||||
boolean needSpace = alignPointer(pointers, pointer, Token.tSTAR);
|
||||
if (skipConstVolatileRestrict(needSpace)) {
|
||||
scribe.space();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,8 @@ final class FormatterMessages extends NLS {
|
|||
public static String WhiteSpaceTabPage_after_opening_brace;
|
||||
public static String WhiteSpaceTabPage_after_closing_brace;
|
||||
public static String WhiteSpaceTabPage_before_opening_brace;
|
||||
public static String WhiteSpaceTabPage_before_pointer;
|
||||
public static String WhiteSpaceTabPage_after_pointer;
|
||||
public static String WhiteSpaceTabPage_before_closing_brace;
|
||||
public static String WhiteSpaceTabPage_between_empty_braces;
|
||||
public static String WhiteSpaceTabPage_after_opening_paren;
|
||||
|
@ -128,6 +130,7 @@ final class FormatterMessages extends NLS {
|
|||
public static String WhiteSpaceOptions_prefix_operator;
|
||||
public static String WhiteSpaceOptions_postfix_operator;
|
||||
public static String WhiteSpaceOptions_opening_paren;
|
||||
public static String WhiteSpaceOptions_pointer;
|
||||
public static String WhiteSpaceOptions_catch;
|
||||
public static String WhiteSpaceOptions_for;
|
||||
public static String WhiteSpaceOptions_if;
|
||||
|
@ -170,6 +173,8 @@ final class FormatterMessages extends NLS {
|
|||
public static String WhiteSpaceOptions_case;
|
||||
public static String WhiteSpaceOptions_default;
|
||||
public static String WhiteSpaceOptions_statements;
|
||||
public static String WhiteSpaceOptions_before_pointer;
|
||||
public static String WhiteSpaceOptions_after_pointer;
|
||||
public static String WhiteSpaceOptions_before_opening_paren;
|
||||
public static String WhiteSpaceOptions_after_opening_paren;
|
||||
public static String WhiteSpaceOptions_before_closing_paren;
|
||||
|
|
|
@ -92,6 +92,8 @@ WhiteSpaceTabPage_after_closing_brace=after closing brace
|
|||
WhiteSpaceTabPage_before_opening_brace=before opening brace
|
||||
WhiteSpaceTabPage_before_closing_brace=before closing brace
|
||||
WhiteSpaceTabPage_between_empty_braces=between empty braces
|
||||
WhiteSpaceTabPage_before_pointer=before pointers
|
||||
WhiteSpaceTabPage_after_pointer=after pointers
|
||||
|
||||
WhiteSpaceTabPage_after_opening_paren=after opening parenthesis
|
||||
WhiteSpaceTabPage_after_closing_paren=after closing parenthesis
|
||||
|
@ -139,6 +141,10 @@ WhiteSpaceOptions_unary_operator=Unary operator
|
|||
WhiteSpaceOptions_prefix_operator=Prefix operator
|
||||
WhiteSpaceOptions_postfix_operator=Postfix operator
|
||||
|
||||
WhiteSpaceOptions_pointer=Pointer
|
||||
WhiteSpaceOptions_before_pointer=Before pointer
|
||||
WhiteSpaceOptions_after_pointer=After pointer
|
||||
|
||||
WhiteSpaceOptions_opening_paren=Opening parenthesis
|
||||
WhiteSpaceOptions_catch='catch'
|
||||
WhiteSpaceOptions_for='for'
|
||||
|
|
|
@ -177,7 +177,8 @@ public final class WhiteSpaceOptions {
|
|||
|
||||
private final PreviewSnippet METHOD_DECL_PREVIEW = new PreviewSnippet(CodeFormatter.K_CLASS_BODY_DECLARATIONS,
|
||||
"void foo() throw(E0, E1) {}" + //$NON-NLS-1$
|
||||
"void bar(int x, int y) throw() {}"); //$NON-NLS-1$
|
||||
"void bar(int x, int y) throw() {}" + //$NON-NLS-1$
|
||||
"void* baz(int* x, int& y) {return 0;}"); //$NON-NLS-1$
|
||||
|
||||
private final PreviewSnippet INITIALIZER_LIST_PREVIEW = new PreviewSnippet(CodeFormatter.K_STATEMENTS,
|
||||
"int array[]= {1, 2, 3};"); //$NON-NLS-1$
|
||||
|
@ -213,7 +214,7 @@ public final class WhiteSpaceOptions {
|
|||
"a= 0, b= 1, c= 2, d= 3;"); //$NON-NLS-1$
|
||||
|
||||
private final PreviewSnippet DECLARATOR_LIST_PREVIEW = new PreviewSnippet(CodeFormatter.K_STATEMENTS,
|
||||
"int a=0,b=1,c=2,d=3;"); //$NON-NLS-1$
|
||||
"int a=0,b=1,c=2,d=3;\nint *e, *f;"); //$NON-NLS-1$
|
||||
|
||||
private final PreviewSnippet BLOCK_PREVIEW = new PreviewSnippet(CodeFormatter.K_STATEMENTS,
|
||||
"if (true) { return 1; } else { return 2; }"); //$NON-NLS-1$
|
||||
|
@ -242,6 +243,13 @@ public final class WhiteSpaceOptions {
|
|||
|
||||
InnerNode element;
|
||||
|
||||
element = new InnerNode(null, workingValues, FormatterMessages.WhiteSpaceOptions_pointer);
|
||||
createBeforePointerTree(workingValues,
|
||||
createChild(element, workingValues, FormatterMessages.WhiteSpaceOptions_before));
|
||||
createAfterPointerTree(workingValues,
|
||||
createChild(element, workingValues, FormatterMessages.WhiteSpaceOptions_after));
|
||||
roots.add(element);
|
||||
|
||||
element = new InnerNode(null, workingValues, FormatterMessages.WhiteSpaceOptions_opening_paren);
|
||||
createBeforeOpenParenTree(workingValues,
|
||||
createChild(element, workingValues, FormatterMessages.WhiteSpaceOptions_before));
|
||||
|
@ -344,6 +352,12 @@ public final class WhiteSpaceOptions {
|
|||
|
||||
InnerNode parent;
|
||||
|
||||
parent = createParentNode(roots, workingValues, FormatterMessages.WhiteSpaceOptions_before_pointer);
|
||||
createBeforePointerTree(workingValues, parent);
|
||||
|
||||
parent = createParentNode(roots, workingValues, FormatterMessages.WhiteSpaceOptions_after_pointer);
|
||||
createAfterPointerTree(workingValues, parent);
|
||||
|
||||
parent = createParentNode(roots, workingValues, FormatterMessages.WhiteSpaceOptions_before_opening_paren);
|
||||
createBeforeOpenParenTree(workingValues, parent);
|
||||
|
||||
|
@ -675,6 +689,25 @@ public final class WhiteSpaceOptions {
|
|||
PAREN_EXPR_PREVIEW);
|
||||
}
|
||||
|
||||
private void createBeforePointerTree(Map<String, String> workingValues, final InnerNode parent) {
|
||||
|
||||
createOption(parent, workingValues, FormatterMessages.WhiteSpaceOptions_function,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_METHOD_DECLARATION,
|
||||
METHOD_DECL_PREVIEW);
|
||||
createOption(parent, workingValues, FormatterMessages.WhiteSpaceOptions_declarator_list,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_DECLARATOR_LIST,
|
||||
DECLARATOR_LIST_PREVIEW);
|
||||
}
|
||||
|
||||
private void createAfterPointerTree(Map<String, String> workingValues, final InnerNode parent) {
|
||||
createOption(parent, workingValues, FormatterMessages.WhiteSpaceOptions_function,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_METHOD_DECLARATION,
|
||||
METHOD_DECL_PREVIEW);
|
||||
createOption(parent, workingValues, FormatterMessages.WhiteSpaceTabPage_declarator_list,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_DECLARATOR_LIST,
|
||||
DECLARATOR_LIST_PREVIEW);
|
||||
}
|
||||
|
||||
private void createBeforeOpenParenTree(Map<String, String> workingValues, final InnerNode parent) {
|
||||
|
||||
createOption(parent, workingValues, FormatterMessages.WhiteSpaceOptions_catch,
|
||||
|
@ -956,7 +989,12 @@ public final class WhiteSpaceOptions {
|
|||
createOption(root, workingValues, FormatterMessages.WhiteSpaceTabPage_before_opening_brace,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_METHOD_DECLARATION,
|
||||
METHOD_DECL_PREVIEW);
|
||||
|
||||
createOption(root, workingValues, FormatterMessages.WhiteSpaceTabPage_before_pointer,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_METHOD_DECLARATION,
|
||||
METHOD_DECL_PREVIEW);
|
||||
createOption(root, workingValues, FormatterMessages.WhiteSpaceTabPage_after_pointer,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_METHOD_DECLARATION,
|
||||
METHOD_DECL_PREVIEW);
|
||||
createOption(root, workingValues, FormatterMessages.WhiteSpaceTabPage_before_comma_in_params,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_METHOD_DECLARATION_PARAMETERS,
|
||||
METHOD_DECL_PREVIEW);
|
||||
|
@ -1020,6 +1058,12 @@ public final class WhiteSpaceOptions {
|
|||
createOption(root, workingValues, FormatterMessages.WhiteSpaceTabPage_declarator_list_after_comma,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_DECLARATOR_LIST,
|
||||
DECLARATOR_LIST_PREVIEW);
|
||||
createOption(root, workingValues, FormatterMessages.WhiteSpaceTabPage_before_pointer,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_POINTER_IN_DECLARATOR_LIST,
|
||||
DECLARATOR_LIST_PREVIEW);
|
||||
createOption(root, workingValues, FormatterMessages.WhiteSpaceTabPage_after_pointer,
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_POINTER_IN_DECLARATOR_LIST,
|
||||
DECLARATOR_LIST_PREVIEW);
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue