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:
parent
cd3776c4f6
commit
1b637c4f8a
2 changed files with 89 additions and 61 deletions
|
@ -2221,6 +2221,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
// operand 1
|
// operand 1
|
||||||
op1.accept(this);
|
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(
|
Alignment expressionAlignment= scribe.createAlignment(
|
||||||
"assignmentExpression", //$NON-NLS-1$
|
"assignmentExpression", //$NON-NLS-1$
|
||||||
preferences.alignment_for_assignment,
|
preferences.alignment_for_assignment,
|
||||||
|
@ -2233,16 +2243,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
try {
|
try {
|
||||||
scribe.alignFragment(expressionAlignment, 0);
|
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
|
// operand 2
|
||||||
final IASTExpression op2= node.getOperand2();
|
final IASTExpression op2= node.getOperand2();
|
||||||
op2.accept(this);
|
op2.accept(this);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.text;
|
package org.eclipse.cdt.ui.tests.text;
|
||||||
|
|
||||||
|
@ -38,7 +39,6 @@ import org.eclipse.cdt.internal.formatter.align.Alignment;
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class CodeFormatterTest extends BaseUITestCase {
|
public class CodeFormatterTest extends BaseUITestCase {
|
||||||
|
|
||||||
private Map<String, Object> fOptions;
|
private Map<String, Object> fOptions;
|
||||||
private Map<String, String> fDefaultOptions;
|
private Map<String, String> fDefaultOptions;
|
||||||
|
|
||||||
|
@ -580,6 +580,34 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
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(...){}}
|
//int foo(){try{}catch(...){}}
|
||||||
//float* bar();
|
//float* bar();
|
||||||
//template<typename _CharT, typename _Traits>class basic_ios : public ios_base{public:
|
//template<typename _CharT, typename _Traits>class basic_ios : public ios_base{public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue