1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Consistent formatting of assignment expressions and equals initializers.

This commit is contained in:
Sergey Prigogin 2011-01-28 22:56:17 +00:00
parent cd3776c4f6
commit 1b637c4f8a
2 changed files with 89 additions and 61 deletions

View file

@ -2221,6 +2221,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
// operand 1
op1.accept(this);
// operator
final int nextToken= peekNextToken();
// in case of C++ alternative operators, like 'and', 'not', etc. a space
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator);
if (forceSpace || preferences.insert_space_after_assignment_operator) {
scribe.space();
}
Alignment expressionAlignment= scribe.createAlignment(
"assignmentExpression", //$NON-NLS-1$
preferences.alignment_for_assignment,
@ -2233,16 +2243,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
try {
scribe.alignFragment(expressionAlignment, 0);
// operator
final int nextToken= peekNextToken();
// in case of C++ alternative operators, like 'and', 'not', etc. a space
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator);
if (forceSpace || preferences.insert_space_after_assignment_operator) {
scribe.space();
}
// operand 2
final IASTExpression op2= node.getOperand2();
op2.accept(this);

View file

@ -8,6 +8,7 @@
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
@ -38,7 +39,6 @@ import org.eclipse.cdt.internal.formatter.align.Alignment;
* @since 4.0
*/
public class CodeFormatterTest extends BaseUITestCase {
private Map<String, Object> fOptions;
private Map<String, String> fDefaultOptions;
@ -580,6 +580,34 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult();
}
//class ClassWithALongName {
//public:
//ClassWithALongName* methodWithAQuiteLongName();
//};
//
//void test() {
//ClassWithALongName* variable_with_a_long_name = variable_with_a_long_name->methodWithAQuiteLongName();
//variable_with_a_long_name = variable_with_a_long_name->methodWithAQuiteLongName();
//}
//class ClassWithALongName {
//public:
// ClassWithALongName* methodWithAQuiteLongName();
//};
//
//void test() {
// ClassWithALongName* variable_with_a_long_name =
// variable_with_a_long_name->methodWithAQuiteLongName();
// variable_with_a_long_name =
// variable_with_a_long_name->methodWithAQuiteLongName();
//}
public void testAssignment() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT,
Integer.toString(Alignment.M_COMPACT_SPLIT));
assertFormatterResult();
}
//int foo(){try{}catch(...){}}
//float* bar();
//template<typename _CharT, typename _Traits>class basic_ios : public ios_base{public: