mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Bug 304150 - case within switch indentation issue
Bug 303175 - enum with value-assignment indents badly
This commit is contained in:
parent
47804a071a
commit
9c9a82a646
4 changed files with 118 additions and 8 deletions
|
@ -850,4 +850,70 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
public void testIndentationOfConstructorBodyWithFieldInitializer_Bug298282() throws Exception {
|
public void testIndentationOfConstructorBodyWithFieldInitializer_Bug298282() throws Exception {
|
||||||
assertIndenterResult();
|
assertIndenterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//class A {
|
||||||
|
// enum E1 {
|
||||||
|
// a=1,
|
||||||
|
// b=2,
|
||||||
|
// c=3
|
||||||
|
// };
|
||||||
|
// enum E2 {
|
||||||
|
// x=1,
|
||||||
|
// y=2,
|
||||||
|
// z=3
|
||||||
|
// };
|
||||||
|
//};
|
||||||
|
|
||||||
|
//class A {
|
||||||
|
// enum E1 {
|
||||||
|
// a=1,
|
||||||
|
// b=2,
|
||||||
|
// c=3
|
||||||
|
// };
|
||||||
|
// enum E2 {
|
||||||
|
// x=1,
|
||||||
|
// y=2,
|
||||||
|
// z=3
|
||||||
|
// };
|
||||||
|
//};
|
||||||
|
public void testIndentationOfEnumeratorDeclWithInitializer_Bug303175() throws Exception {
|
||||||
|
assertIndenterResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
//void f() {
|
||||||
|
//switch(i) {
|
||||||
|
//case -2:
|
||||||
|
//f();
|
||||||
|
//break;
|
||||||
|
//case -1:
|
||||||
|
//f();
|
||||||
|
//break;
|
||||||
|
//case 0:
|
||||||
|
//f();
|
||||||
|
//break;
|
||||||
|
//case +1:
|
||||||
|
//f();
|
||||||
|
//break;
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void f() {
|
||||||
|
// switch(i) {
|
||||||
|
// case -2:
|
||||||
|
// f();
|
||||||
|
// break;
|
||||||
|
// case -1:
|
||||||
|
// f();
|
||||||
|
// break;
|
||||||
|
// case 0:
|
||||||
|
// f();
|
||||||
|
// break;
|
||||||
|
// case +1:
|
||||||
|
// f();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testIndentationOfCaseWithSignedConstant_Bug304150() throws Exception {
|
||||||
|
assertIndenterResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
private static final char RANGLE= '>';
|
private static final char RANGLE= '>';
|
||||||
private static final char DOT= '.';
|
private static final char DOT= '.';
|
||||||
private static final char MINUS= '-';
|
private static final char MINUS= '-';
|
||||||
|
private static final char PLUS= '+';
|
||||||
private static final char TILDE= '~';
|
private static final char TILDE= '~';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -385,6 +386,8 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
return TokenARROW;
|
return TokenARROW;
|
||||||
}
|
}
|
||||||
return TokenMINUS;
|
return TokenMINUS;
|
||||||
|
case PLUS:
|
||||||
|
return TokenPLUS;
|
||||||
case TILDE:
|
case TILDE:
|
||||||
return TokenTILDE;
|
return TokenTILDE;
|
||||||
}
|
}
|
||||||
|
@ -486,6 +489,8 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
return TokenDOT;
|
return TokenDOT;
|
||||||
case MINUS:
|
case MINUS:
|
||||||
return TokenMINUS;
|
return TokenMINUS;
|
||||||
|
case PLUS:
|
||||||
|
return TokenPLUS;
|
||||||
case TILDE:
|
case TILDE:
|
||||||
return TokenTILDE;
|
return TokenTILDE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1121,8 +1121,7 @@ public final class CIndenter {
|
||||||
}
|
}
|
||||||
if (fToken == Symbols.TokenCLASS
|
if (fToken == Symbols.TokenCLASS
|
||||||
|| fToken == Symbols.TokenSTRUCT
|
|| fToken == Symbols.TokenSTRUCT
|
||||||
|| fToken == Symbols.TokenUNION
|
|| fToken == Symbols.TokenUNION) {
|
||||||
|| fToken == Symbols.TokenENUM) {
|
|
||||||
// inside a type declaration? Only so if not preceded by '(' or ',' as in
|
// inside a type declaration? Only so if not preceded by '(' or ',' as in
|
||||||
// a parameter list. To be safe, only accept ';' or EOF
|
// a parameter list. To be safe, only accept ';' or EOF
|
||||||
int pos= fPosition;
|
int pos= fPosition;
|
||||||
|
@ -1154,6 +1153,9 @@ public final class CIndenter {
|
||||||
while (skipQualifiers()) {
|
while (skipQualifiers()) {
|
||||||
nextToken();
|
nextToken();
|
||||||
}
|
}
|
||||||
|
while (fToken == Symbols.TokenMINUS || fToken == Symbols.TokenPLUS) {
|
||||||
|
nextToken();
|
||||||
|
}
|
||||||
if (fToken == Symbols.TokenCASE) {
|
if (fToken == Symbols.TokenCASE) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1242,6 +1244,32 @@ public final class CIndenter {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the left brace at the current position marks an enum decl.
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if this looks like an enum decl.
|
||||||
|
*/
|
||||||
|
private boolean looksLikeEnumDeclaration() {
|
||||||
|
int pos = fPosition;
|
||||||
|
nextToken();
|
||||||
|
switch (fToken) {
|
||||||
|
case Symbols.TokenIDENT:
|
||||||
|
nextToken();
|
||||||
|
while (skipQualifiers()) {
|
||||||
|
nextToken();
|
||||||
|
}
|
||||||
|
switch (fToken) {
|
||||||
|
case Symbols.TokenENUM:
|
||||||
|
fPosition = pos;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fPosition = pos;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the colon at the current position marks an access specifier.
|
* Test whether the colon at the current position marks an access specifier.
|
||||||
*
|
*
|
||||||
|
@ -1294,7 +1322,6 @@ public final class CIndenter {
|
||||||
return fPosition;
|
return fPosition;
|
||||||
|
|
||||||
case Symbols.TokenCLASS:
|
case Symbols.TokenCLASS:
|
||||||
case Symbols.TokenENUM:
|
|
||||||
case Symbols.TokenSTRUCT:
|
case Symbols.TokenSTRUCT:
|
||||||
case Symbols.TokenUNION:
|
case Symbols.TokenUNION:
|
||||||
isTypeBody= true;
|
isTypeBody= true;
|
||||||
|
@ -1445,6 +1472,8 @@ public final class CIndenter {
|
||||||
continue;
|
continue;
|
||||||
case Symbols.TokenDOUBLECOLON:
|
case Symbols.TokenDOUBLECOLON:
|
||||||
case Symbols.TokenOTHER:
|
case Symbols.TokenOTHER:
|
||||||
|
case Symbols.TokenMINUS:
|
||||||
|
case Symbols.TokenPLUS:
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case Symbols.TokenQUESTIONMARK:
|
case Symbols.TokenQUESTIONMARK:
|
||||||
|
@ -1589,7 +1618,7 @@ public final class CIndenter {
|
||||||
int lineOffset= fDocument.getLineOffset(startLine);
|
int lineOffset= fDocument.getLineOffset(startLine);
|
||||||
int bound= Math.min(fDocument.getLength(), startPosition + 1);
|
int bound= Math.min(fDocument.getLength(), startPosition + 1);
|
||||||
if ((fToken == Symbols.TokenSEMICOLON || fToken == Symbols.TokenRBRACE ||
|
if ((fToken == Symbols.TokenSEMICOLON || fToken == Symbols.TokenRBRACE ||
|
||||||
fToken == Symbols.TokenLBRACE && !looksLikeArrayInitializerIntro()) &&
|
fToken == Symbols.TokenLBRACE && !looksLikeArrayInitializerIntro() && !looksLikeEnumDeclaration()) &&
|
||||||
(seenEqual || seenShiftLeft || seenRightParen)) {
|
(seenEqual || seenShiftLeft || seenRightParen)) {
|
||||||
fIndent = fPrefs.prefContinuationIndent;
|
fIndent = fPrefs.prefContinuationIndent;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1765,6 +1794,8 @@ public final class CIndenter {
|
||||||
fIndent= fPrefs.prefArrayIndent;
|
fIndent= fPrefs.prefArrayIndent;
|
||||||
} else if (isNamespace() || isLinkageSpec()) {
|
} else if (isNamespace() || isLinkageSpec()) {
|
||||||
fIndent= fPrefs.prefNamespaceBodyIndent;
|
fIndent= fPrefs.prefNamespaceBodyIndent;
|
||||||
|
} else if (looksLikeEnumDeclaration()) {
|
||||||
|
fIndent = fPrefs.prefTypeIndent;
|
||||||
} else {
|
} else {
|
||||||
int typeDeclPos = matchTypeDeclaration();
|
int typeDeclPos = matchTypeDeclaration();
|
||||||
if (typeDeclPos == CHeuristicScanner.NOT_FOUND) {
|
if (typeDeclPos == CHeuristicScanner.NOT_FOUND) {
|
||||||
|
@ -1853,6 +1884,7 @@ public final class CIndenter {
|
||||||
fPosition= pos;
|
fPosition= pos;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
fPosition= pos;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1863,18 +1895,19 @@ public final class CIndenter {
|
||||||
* @return <code>true</code> if the next elements look like the start of a namespace declaration.
|
* @return <code>true</code> if the next elements look like the start of a namespace declaration.
|
||||||
*/
|
*/
|
||||||
private boolean isNamespace() {
|
private boolean isNamespace() {
|
||||||
|
int pos = fPosition;
|
||||||
|
nextToken();
|
||||||
if (fToken == Symbols.TokenNAMESPACE) {
|
if (fToken == Symbols.TokenNAMESPACE) {
|
||||||
|
fPosition = pos;
|
||||||
return true; // Anonymous namespace
|
return true; // Anonymous namespace
|
||||||
} else if (fToken == Symbols.TokenIDENT) {
|
} else if (fToken == Symbols.TokenIDENT) {
|
||||||
int pos = fPosition;
|
|
||||||
int token = fToken;
|
|
||||||
nextToken(); // Get previous token
|
nextToken(); // Get previous token
|
||||||
if (fToken == Symbols.TokenNAMESPACE) {
|
if (fToken == Symbols.TokenNAMESPACE) {
|
||||||
|
fPosition = pos;
|
||||||
return true; // Named namespace
|
return true; // Named namespace
|
||||||
}
|
}
|
||||||
fToken = token;
|
|
||||||
fPosition = pos;
|
|
||||||
}
|
}
|
||||||
|
fPosition = pos;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1884,9 +1917,13 @@ public final class CIndenter {
|
||||||
* @return <code>true</code> if the next elements look like the start of a linkage spec.
|
* @return <code>true</code> if the next elements look like the start of a linkage spec.
|
||||||
*/
|
*/
|
||||||
private boolean isLinkageSpec() {
|
private boolean isLinkageSpec() {
|
||||||
|
int pos = fPosition;
|
||||||
|
nextToken();
|
||||||
if (fToken == Symbols.TokenEXTERN) {
|
if (fToken == Symbols.TokenEXTERN) {
|
||||||
|
fPosition = pos;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
fPosition = pos;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2126,6 +2163,7 @@ public final class CIndenter {
|
||||||
case Symbols.TokenGREATERTHAN:
|
case Symbols.TokenGREATERTHAN:
|
||||||
case Symbols.TokenLESSTHAN:
|
case Symbols.TokenLESSTHAN:
|
||||||
case Symbols.TokenMINUS:
|
case Symbols.TokenMINUS:
|
||||||
|
case Symbols.TokenPLUS:
|
||||||
case Symbols.TokenSHIFTRIGHT:
|
case Symbols.TokenSHIFTRIGHT:
|
||||||
case Symbols.TokenSHIFTLEFT:
|
case Symbols.TokenSHIFTLEFT:
|
||||||
case Symbols.TokenDELETE:
|
case Symbols.TokenDELETE:
|
||||||
|
|
|
@ -38,6 +38,7 @@ public interface Symbols {
|
||||||
int TokenARROW= 19;
|
int TokenARROW= 19;
|
||||||
int TokenDOUBLECOLON= 20;
|
int TokenDOUBLECOLON= 20;
|
||||||
int TokenSHIFTLEFT= 21;
|
int TokenSHIFTLEFT= 21;
|
||||||
|
int TokenPLUS= 22;
|
||||||
int TokenIF= 109;
|
int TokenIF= 109;
|
||||||
int TokenDO= 1010;
|
int TokenDO= 1010;
|
||||||
int TokenFOR= 1011;
|
int TokenFOR= 1011;
|
||||||
|
|
Loading…
Add table
Reference in a new issue