1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Indentation of conditional expression. Bug 283970.

This commit is contained in:
Sergey Prigogin 2009-07-20 06:19:16 +00:00
parent 2fcc072972
commit ca169204ad
2 changed files with 122 additions and 38 deletions

View file

@ -88,7 +88,7 @@ public class CIndenterTest extends BaseUITestCase {
//foo(arg,
// "string");
public void testStringLiteralAsLastArgument_Bug192412_1() throws Exception {
public void testStringLiteralAsLastArgument_1_Bug192412() throws Exception {
assertIndenterResult();
}
@ -97,7 +97,7 @@ public class CIndenterTest extends BaseUITestCase {
//a::foo(arg,
// "string");
public void testStringLiteralAsLastArgument_Bug192412_2() throws Exception {
public void testStringLiteralAsLastArgument_2_Bug192412() throws Exception {
assertIndenterResult();
}
@ -106,7 +106,7 @@ public class CIndenterTest extends BaseUITestCase {
//a::foo(arg,
// "string");
public void testStringLiteralAsLastArgument_Bug192412_3() throws Exception {
public void testStringLiteralAsLastArgument_3_Bug192412() throws Exception {
assertIndenterResult();
}
@ -117,7 +117,7 @@ public class CIndenterTest extends BaseUITestCase {
//if (1)
// foo->bar();
//dontIndent();
public void testIndentationAfterArrowOperator_Bug192412_4() throws Exception {
public void testIndentationAfterArrowOperator_Bug192412() throws Exception {
assertIndenterResult();
}
@ -128,7 +128,7 @@ public class CIndenterTest extends BaseUITestCase {
//if (1)
// foo>>bar;
//dontIndent();
public void testIndentationAfterShiftRight_Bug192412_5() throws Exception {
public void testIndentationAfterShiftRight_Bug192412() throws Exception {
assertIndenterResult();
}
@ -139,7 +139,7 @@ public class CIndenterTest extends BaseUITestCase {
//if (1)
// foo >= bar();
//dontIndent();
public void testIndentationAfterGreaterOrEquals_Bug192412_6() throws Exception {
public void testIndentationAfterGreaterOrEquals_Bug192412() throws Exception {
assertIndenterResult();
}
@ -152,7 +152,7 @@ public class CIndenterTest extends BaseUITestCase {
// const BinFileParser::Exception& exp)
//{
//}
public void testOperatorMethodBody_Bug192412_7() throws Exception {
public void testOperatorMethodBody_1_Bug192412() throws Exception {
assertIndenterResult();
}
@ -165,7 +165,7 @@ public class CIndenterTest extends BaseUITestCase {
// const BinFileParser::Exception& exp)
//{
//}
public void testOperatorMethodBody_Bug192412_8() throws Exception {
public void testOperatorMethodBody_2_Bug192412() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION,
DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT,
@ -319,7 +319,26 @@ public class CIndenterTest extends BaseUITestCase {
// g(0) {
// }
//};
public void testConstructorBodyWithInitializer_Bug194586() throws Exception {
public void testConstructorBodyWithInitializer_1_Bug194586() throws Exception {
assertIndenterResult();
}
//class A {
//public:
//A(int a, int b) :
//f(0),
//g(0) {
//}
//};
//class A {
//public:
// A(int a, int b) :
// f(0),
// g(0) {
// }
//};
public void testConstructorBodyWithInitializer_2() throws Exception {
assertIndenterResult();
}
@ -417,7 +436,7 @@ public class CIndenterTest extends BaseUITestCase {
// private:
// int a;
//};
public void testClassDeclaration_278713() throws Exception {
public void testClassDeclaration_Bug278713() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER,
DefaultCodeFormatterConstants.TRUE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER,
@ -466,7 +485,7 @@ public class CIndenterTest extends BaseUITestCase {
//union DisUnion
// {
// };
public void testIndentedClass_Bug210417() throws Exception {
public void testIndentedClass_1_Bug210417() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION,
DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED);
assertIndenterResult();
@ -481,7 +500,7 @@ public class CIndenterTest extends BaseUITestCase {
//class MyClass : public Base
// {
// };
public void testIndentedClass_Bug210417_2() throws Exception {
public void testIndentedClass_2_Bug210417() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION,
DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED);
assertIndenterResult();
@ -496,7 +515,7 @@ public class CIndenterTest extends BaseUITestCase {
//class MyClass : public Base, public OtherBase
// {
// };
public void testIndentedClass_Bug210417_3() throws Exception {
public void testIndentedClass_3_Bug210417() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION,
DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED);
assertIndenterResult();
@ -511,7 +530,7 @@ public class CIndenterTest extends BaseUITestCase {
//class MyClass : public Base, public OtherBase
// {
// };
public void testIndentedClass_Bug210417_4() throws Exception {
public void testIndentedClass_4_Bug210417() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION,
DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED);
assertIndenterResult();
@ -522,7 +541,7 @@ public class CIndenterTest extends BaseUITestCase {
//x =
// 0;
public void testWrappedAssignment_277624_1() throws Exception {
public void testWrappedAssignment_1_Bug277624() throws Exception {
assertIndenterResult();
}
@ -537,7 +556,7 @@ public class CIndenterTest extends BaseUITestCase {
// x = 2 +
// 2 +
// 2;
public void testWrappedAssignment_277624_2() throws Exception {
public void testWrappedAssignment_2_Bug277624() throws Exception {
assertIndenterResult();
}
@ -548,16 +567,29 @@ public class CIndenterTest extends BaseUITestCase {
//if (1 > 0) {
// double d = a * b /
// c;
public void testWrappedAssignment_277624_3() throws Exception {
public void testWrappedAssignment_3_Bug277624() throws Exception {
assertIndenterResult();
}
//int x = 1 < 2 ?
//f(0) :
//1;
//g();
//int x = 1 < 2 ?
// f(0) :
// 1;
//g();
public void testConditionalExpression_Bug283970() throws Exception {
assertIndenterResult();
}
//for (int i = 0;
//i < 2; i++)
//for (int i = 0;
// i < 2; i++)
public void testWrappedFor_277625_1() throws Exception {
public void testWrappedFor_1_Bug277625() throws Exception {
assertIndenterResult();
}
@ -566,7 +598,7 @@ public class CIndenterTest extends BaseUITestCase {
//for (int i = 0; i < 2;
// i++)
public void testWrappedFor_277625_2() throws Exception {
public void testWrappedFor_2_Bug277625() throws Exception {
assertIndenterResult();
}
@ -579,7 +611,7 @@ public class CIndenterTest extends BaseUITestCase {
// i < 2;
// i++)
//{
public void testWrappedFor_277625_3() throws Exception {
public void testWrappedFor_3_Bug277625() throws Exception {
assertIndenterResult();
}
@ -590,7 +622,7 @@ public class CIndenterTest extends BaseUITestCase {
//;
//for (hash_map<Node*, double>::const_iterator it = container_.begin();
// it != container_.end(); ++it) {
public void testWrappedFor_277625_4() throws Exception {
public void testWrappedFor_4_Bug277625() throws Exception {
assertIndenterResult();
}
@ -663,7 +695,7 @@ public class CIndenterTest extends BaseUITestCase {
//public:
// A();
// };
public void testWhiteSmithsAccessSpecifier_Bug204575_1() throws Exception {
public void testWhiteSmithsAccessSpecifier_1_Bug204575() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap());
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER, DefaultCodeFormatterConstants.FALSE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER, DefaultCodeFormatterConstants.TRUE);
@ -681,7 +713,7 @@ public class CIndenterTest extends BaseUITestCase {
// public:
// A();
// };
public void testWhiteSmithsAccessSpecifier_Bug204575_2() throws Exception {
public void testWhiteSmithsAccessSpecifier_2_Bug204575() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap());
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER, DefaultCodeFormatterConstants.TRUE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER, DefaultCodeFormatterConstants.FALSE);
@ -699,7 +731,7 @@ public class CIndenterTest extends BaseUITestCase {
// public:
// A();
// };
public void testWhiteSmithsAccessSpecifier_Bug204575_3() throws Exception {
public void testWhiteSmithsAccessSpecifier_3_Bug204575() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap());
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_ACCESS_SPECIFIER_COMPARE_TO_TYPE_HEADER, DefaultCodeFormatterConstants.TRUE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ACCESS_SPECIFIER, DefaultCodeFormatterConstants.TRUE);
@ -727,7 +759,7 @@ public class CIndenterTest extends BaseUITestCase {
// doOther();
// }
// }
public void testWhiteSmithsSwitch1() throws Exception {
public void testWhiteSmithsSwitch_1() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap());
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES, DefaultCodeFormatterConstants.TRUE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, DefaultCodeFormatterConstants.FALSE);
@ -756,7 +788,7 @@ public class CIndenterTest extends BaseUITestCase {
// doOther();
// }
// }
public void testWhiteSmithsSwitch2() throws Exception {
public void testWhiteSmithsSwitch_2() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap());
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES, DefaultCodeFormatterConstants.FALSE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, DefaultCodeFormatterConstants.TRUE);

View file

@ -960,6 +960,7 @@ public final class CIndenter {
nextToken();
}
int line= fLine;
switch (fToken) {
case Symbols.TokenGREATERTHAN:
case Symbols.TokenRBRACE:
@ -1002,18 +1003,27 @@ public final class CIndenter {
fIndent= fPrefs.prefBlockIndent;
return pos;
}
// TODO handle ternary deep indentation
fPosition= pos;
if (looksLikeConstructorInitializer()) {
fIndent= fPrefs.prefBlockIndent;
return pos;
}
fPosition= pos;
if (isConditional()) {
fPosition= offset;
fLine= line;
return skipToPreviousListItemOrListStart();
}
fPosition= pos;
return skipToStatementStart(danglingElse, false);
case Symbols.TokenQUESTIONMARK:
if (fPrefs.prefTernaryDeepAlign) {
setFirstElementAlignment(fPosition, offset + 1);
return fPosition;
} else {
fIndent= fPrefs.prefTernaryIndent;
return fPosition;
}
return fPosition;
// indentation for blockless introducers:
case Symbols.TokenDO:
@ -1026,7 +1036,6 @@ public final class CIndenter {
return skipToStatementStart(danglingElse, false);
case Symbols.TokenRPAREN:
int line= fLine;
if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) {
int scope= fPosition;
nextToken();
@ -1143,7 +1152,7 @@ public final class CIndenter {
/**
* Test whether the colon at the current position marks a type inheritance decl.
*
* @return <code>true</code> if this looks like a a type inheritance decl
* @return <code>true</code> if this looks like a type inheritance decl.
*/
private boolean looksLikeTypeInheritanceDecl() {
nextToken();
@ -1160,10 +1169,53 @@ public final class CIndenter {
return true;
}
break;
case Symbols.TokenRPAREN: // constructor initializer
case Symbols.TokenPUBLIC:
case Symbols.TokenPROTECTED:
case Symbols.TokenPRIVATE:
}
return false;
}
/**
* Test whether the colon at the current position marks a constructor initializer list.
*
* @return <code>true</code> if this looks like a constructor initializer list.
*/
private boolean looksLikeConstructorInitializer() {
nextToken();
if (fToken != Symbols.TokenRPAREN) {
return false;
}
if (!skipScope()) {
return false;
}
nextToken();
if (fToken == Symbols.TokenTHROW) {
nextToken();
if (fToken != Symbols.TokenRPAREN) {
return false;
}
if (!skipScope()) {
return false;
}
nextToken();
}
if (fToken != Symbols.TokenIDENT) {
return false;
}
nextToken();
switch (fToken) {
case Symbols.TokenCOLON:
nextToken();
switch (fToken) {
case Symbols.TokenCOLON: // A::A() :
case Symbols.TokenPUBLIC: // public: A() :
case Symbols.TokenPROTECTED:
case Symbols.TokenPRIVATE:
return true;
}
return false;
case Symbols.TokenLBRACE: // class A { A() :
case Symbols.TokenRBRACE:
case Symbols.TokenSEMICOLON:
return true;
}
return false;
@ -1249,9 +1301,9 @@ public final class CIndenter {
fIndent = fPrefs.prefContinuationIndent;
return fPosition;
}
//$FALL-THROUGH$
break;
case Symbols.TokenLBRACE:
case Symbols.TokenLBRACKET:
case Symbols.TokenSEMICOLON:
case Symbols.TokenEOF:
if (isInBlock)