mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Fix for 225858: Code formatter differences from CDT 4.0.x
This commit is contained in:
parent
076444ffe0
commit
3d6501658c
6 changed files with 53 additions and 20 deletions
|
@ -129,6 +129,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.internal.formatter.align.Alignment;
|
||||
import org.eclipse.cdt.internal.formatter.align.AlignmentException;
|
||||
import org.eclipse.cdt.internal.formatter.scanner.Scanner;
|
||||
|
@ -2167,19 +2168,20 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
scribe.printNextToken(Token.tCOLONCOLON);
|
||||
}
|
||||
scribe.printNextToken(Token.t_new);
|
||||
scribe.space();
|
||||
|
||||
// placement
|
||||
final IASTExpression newPlacement= node.getNewPlacement();
|
||||
if (newPlacement != null) {
|
||||
formatParenthesizedExpression(newPlacement);
|
||||
}
|
||||
|
||||
// type-id
|
||||
scribe.space();
|
||||
final IASTTypeId typeId= node.getTypeId();
|
||||
final boolean expectParen= !node.isNewTypeId() && peekNextToken() == Token.tLPAREN;
|
||||
if (expectParen) {
|
||||
scribe.printNextToken(Token.tLPAREN, scribe.printComment());
|
||||
} else {
|
||||
scribe.space();
|
||||
scribe.printNextToken(Token.tLPAREN, false);
|
||||
}
|
||||
typeId.accept(this);
|
||||
if (expectParen) {
|
||||
|
@ -2486,7 +2488,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
|
||||
if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) {
|
||||
if (preferences.insert_space_after_closing_angle_bracket_in_template_arguments) {
|
||||
scribe.space();
|
||||
// avoid explicit space if followed by pointer operator
|
||||
int nextToken= peekNextToken();
|
||||
if (nextToken != IToken.tSTAR && nextToken != IToken.tAMPER) {
|
||||
scribe.space();
|
||||
}
|
||||
} else {
|
||||
scribe.printComment();
|
||||
scribe.needSpace= false;
|
||||
|
|
|
@ -1737,6 +1737,7 @@ public class DefaultCodeFormatterOptions {
|
|||
public void setWhitesmitsSettings() {
|
||||
setDefaultSettings();
|
||||
this.alignment_for_expressions_in_initializer_list = Alignment.M_ONE_PER_LINE_SPLIT;
|
||||
this.alignment_for_enumerator_list = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE;
|
||||
|
||||
this.brace_position_for_initializer_list = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED;
|
||||
this.brace_position_for_block = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED;
|
||||
|
|
|
@ -414,7 +414,7 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
//void f() {
|
||||
// int *px = ::new int(0);
|
||||
// int py[] = new int[5](0, 1, 2, 3, 4);
|
||||
// int *pz[] = new(px) int(0);
|
||||
// int *pz[] = new (px) int(0);
|
||||
// delete[] py;
|
||||
// ::delete px;
|
||||
//}
|
||||
|
@ -601,4 +601,28 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//enum Tthe3rdtestIds
|
||||
//{
|
||||
//ECommand1 = 0x6001,
|
||||
//ECommand2,
|
||||
//EHelp,
|
||||
//EAbout
|
||||
//};
|
||||
//
|
||||
//CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
|
||||
|
||||
//enum Tthe3rdtestIds
|
||||
// {
|
||||
// ECommand1 = 0x6001,
|
||||
// ECommand2,
|
||||
// EHelp,
|
||||
// EAbout
|
||||
// };
|
||||
//
|
||||
//CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
|
||||
public void testFormatterRegressions_Bug225858() throws Exception {
|
||||
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
|
||||
assertFormatterResult();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,6 +212,8 @@ final class FormatterMessages extends NLS {
|
|||
public static String LineWrappingTabPage_parameters;
|
||||
public static String LineWrappingTabPage_arguments;
|
||||
public static String LineWrappingTabPage_throws_clause;
|
||||
public static String LineWrappingTabPage_enum_decls;
|
||||
public static String LineWrappingTabPage_enumerator_list;
|
||||
public static String LineWrappingTabPage_initializer_list;
|
||||
public static String LineWrappingTabPage_conditionals;
|
||||
// public static String LineWrappingTabPage_binary_exprs;
|
||||
|
|
|
@ -242,16 +242,18 @@ LineWrappingTabPage_parameters=Parameters
|
|||
LineWrappingTabPage_arguments=Arguments
|
||||
LineWrappingTabPage_throws_clause=Exception specification
|
||||
#LineWrappingTabPage_object_allocation=Object allocation arguments
|
||||
LineWrappingTabPage_initializer_list=Initializer List
|
||||
LineWrappingTabPage_enum_decls='enum' declaration
|
||||
LineWrappingTabPage_enumerator_list=Enumerator list
|
||||
LineWrappingTabPage_initializer_list=Initializer list
|
||||
LineWrappingTabPage_conditionals=Conditionals
|
||||
#LineWrappingTabPage_binary_exprs=Binary expressions
|
||||
LineWrappingTabPage_indentation_default=Default indentation
|
||||
LineWrappingTabPage_indentation_on_column=Indent on column
|
||||
LineWrappingTabPage_indentation_by_one=Indent by one
|
||||
LineWrappingTabPage_class_decls=Class Declarations
|
||||
LineWrappingTabPage_method_decls=Function Declarations
|
||||
LineWrappingTabPage_class_decls=Class declarations
|
||||
LineWrappingTabPage_method_decls=Function declarations
|
||||
#LineWrappingTabPage_constructor_decls=Constructor declarations
|
||||
LineWrappingTabPage_function_calls=Function Calls
|
||||
LineWrappingTabPage_function_calls=Function calls
|
||||
LineWrappingTabPage_expressions=Expressions
|
||||
#LineWrappingTabPage_statements=Statements
|
||||
LineWrappingTabPage_wrapping_policy_label_text=Lin&e wrapping policy:
|
||||
|
|
|
@ -455,14 +455,12 @@ public class LineWrappingTabPage extends FormatterTabPage {
|
|||
// FormatterMessages.LineWrappingTabPage_enum_superinterfaces
|
||||
// );
|
||||
//
|
||||
// private final Category fEnumConstantsCategory= new Category(
|
||||
// DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
|
||||
// "enum Example {" + //$NON-NLS-1$
|
||||
// "CANCELLED, RUNNING, WAITING, FINISHED }" + //$NON-NLS-1$
|
||||
// "enum Example {" + //$NON-NLS-1$
|
||||
// "GREEN(0, 255, 0), RED(255, 0, 0) }", //$NON-NLS-1$
|
||||
// FormatterMessages.LineWrappingTabPage_enum_constants
|
||||
// );
|
||||
private final Category fEnumeratorsCategory= new Category(
|
||||
DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUMERATOR_LIST,
|
||||
"enum Example {" + //$NON-NLS-1$
|
||||
"CANCELLED, RUNNING, WAITING, FINISHED };", //$NON-NLS-1$
|
||||
FormatterMessages.LineWrappingTabPage_enumerator_list
|
||||
);
|
||||
//
|
||||
// private final Category fAssignmentCategory= new Category(
|
||||
// DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT,
|
||||
|
@ -567,8 +565,8 @@ public class LineWrappingTabPage extends FormatterTabPage {
|
|||
methodDeclarations.children.add(fMethodDeclarationsParametersCategory);
|
||||
methodDeclarations.children.add(fMethodThrowsClauseCategory);
|
||||
|
||||
// final Category enumDeclarations= new Category(FormatterMessages.LineWrappingTabPage_enum_decls);
|
||||
// enumDeclarations.children.add(fEnumConstantsCategory);
|
||||
final Category enumDeclarations= new Category(FormatterMessages.LineWrappingTabPage_enum_decls);
|
||||
enumDeclarations.children.add(fEnumeratorsCategory);
|
||||
// enumDeclarations.children.add(fEnumDeclInterfacesCategory);
|
||||
// enumDeclarations.children.add(fEnumConstArgumentsCategory);
|
||||
|
||||
|
@ -592,7 +590,7 @@ public class LineWrappingTabPage extends FormatterTabPage {
|
|||
root.add(classDeclarations);
|
||||
// root.add(constructorDeclarations);
|
||||
root.add(methodDeclarations);
|
||||
// root.add(enumDeclarations);
|
||||
root.add(enumDeclarations);
|
||||
root.add(functionCalls);
|
||||
root.add(expressions);
|
||||
// root.add(statements);
|
||||
|
|
Loading…
Add table
Reference in a new issue