1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Follow-up fix for 192412: [Indenter] Improve indenter heuristics

Fix for 194586: [Indenter] Indentation issue in class member funtion
This commit is contained in:
Anton Leherbauer 2007-06-29 09:43:57 +00:00
parent 771a1f3876
commit 8bc05fc9c1
4 changed files with 205 additions and 8 deletions

View file

@ -68,7 +68,25 @@ public class CIndenterTest extends BaseUITestCase {
//foo(arg,
// "string");
public void testIndentationOfStringLiteralAsLastArgument_Bug192412() throws Exception {
public void testIndentationOfStringLiteralAsLastArgument1_Bug192412() throws Exception {
assertIndenterResult();
}
//a::foo(arg,
//"string");
//a::foo(arg,
// "string");
public void testIndentationOfStringLiteralAsLastArgument2_Bug192412() throws Exception {
assertIndenterResult();
}
//a::foo(arg,
// "string");
//a::foo(arg,
// "string");
public void testIndentationOfStringLiteralAsLastArgument3_Bug192412() throws Exception {
assertIndenterResult();
}
@ -105,6 +123,19 @@ public class CIndenterTest extends BaseUITestCase {
assertIndenterResult();
}
//std::ostream& operator<<(std::ostream& stream,
//const BinFileParser::Exception& exp)
//{
//}
//std::ostream& operator<<(std::ostream& stream,
// const BinFileParser::Exception& exp)
//{
//}
public void testIndentationOfOperatorMethodBody_Bug192412() throws Exception {
assertIndenterResult();
}
//struct x {
// int f1 : 1;
// int f2 : 1;
@ -120,4 +151,58 @@ public class CIndenterTest extends BaseUITestCase {
assertIndenterResult();
}
//class A {
//A(int a,
//int b)
//{
//}
//};
//class A {
// A(int a,
// int b)
// {
// }
//};
public void testIndentationOfConstructorBody_Bug194586() throws Exception {
assertIndenterResult();
}
//class A {
//A(int a,
//int b)
//throw()
//{
//}
//};
//class A {
// A(int a,
// int b)
// throw()
// {
// }
//};
public void testIndentationOfConstructorBodyWithThrow_Bug194586() throws Exception {
assertIndenterResult();
}
//class A {
//A(int a,
//int b)
//:f(0)
//{
//}
//};
//class A {
// A(int a,
// int b)
// :f(0)
// {
// }
//};
public void testIndentationOfConstructorBodyWithInitializer_Bug194586() throws Exception {
assertIndenterResult();
}
}

View file

@ -301,17 +301,20 @@ public final class CHeuristicScanner implements Symbols {
* @return a constant from {@link Symbols} describing the next token
*/
public int nextToken(int start, int bound) {
int pos= scanForward(start, bound, fNonWS);
if (pos == NOT_FOUND)
return TokenEOF;
try {
// check for string or char literal
char ch = fDocument.getChar(start);
char ch = fDocument.getChar(pos);
if (ch == '"' || ch == '\'') {
fChar= ch;
fPos= fNonWSDefaultPart.nextPosition(start, true);
fPos= fNonWSDefaultPart.nextPosition(pos, true);
return TokenOTHER;
}
} catch (BadLocationException exc) {
}
int pos= scanForward(start, bound, fNonWSDefaultPart);
pos= scanForward(pos, bound, fNonWSDefaultPart);
if (pos == NOT_FOUND)
return TokenEOF;
@ -346,6 +349,14 @@ public final class CHeuristicScanner implements Symbols {
case EQUAL:
return TokenEQUAL;
case LANGLE:
switch (peekNextChar()) {
case LANGLE:
++fPos;
return TokenSHIFTLEFT;
case EQUAL:
++fPos;
return TokenOTHER;
}
return TokenLESSTHAN;
case RANGLE:
switch (peekNextChar()) {
@ -442,13 +453,17 @@ public final class CHeuristicScanner implements Symbols {
case EQUAL:
switch (peekPreviousChar()) {
case RANGLE:
--fPos;
case LANGLE:
--fPos;
return TokenOTHER;
}
return TokenEQUAL;
case LANGLE:
switch (peekPreviousChar()) {
case LANGLE:
--fPos;
return TokenSHIFTLEFT;
}
return TokenLESSTHAN;
case RANGLE:
switch (peekPreviousChar()) {
@ -566,6 +581,10 @@ public final class CHeuristicScanner implements Symbols {
return TokenWHILE;
if ("union".equals(s)) //$NON-NLS-1$
return TokenUNION;
if ("throw".equals(s)) //$NON-NLS-1$
return TokenTHROW;
if ("const".equals(s)) //$NON-NLS-1$
return TokenCONST;
break;
case 6:
if ("delete".equals(s)) //$NON-NLS-1$
@ -589,6 +608,10 @@ public final class CHeuristicScanner implements Symbols {
if ("virtual".equals(s)) //$NON-NLS-1$
return TokenVIRTUAL;
break;
case 8:
if ("operator".equals(s)) //$NON-NLS-1$
return TokenOPERATOR;
break;
case 9:
if ("namespace".equals(s)) //$NON-NLS-1$
return TokenNAMESPACE;

View file

@ -1653,6 +1653,25 @@ public final class CIndenter {
return false;
}
/**
* Skips pointer operators if the current token is a pointer operator.
*
* @return <code>true</code> if a <code>*</code> or <code>&amp;</code> could be scanned, the
* current token is left at the operator.
*/
private boolean skipPointerOperators() {
if (fToken == Symbols.TokenOTHER) {
CharSequence token= getTokenContent();
if (token.length() == 1 && token.charAt(0) == '*' || token.charAt(0) == '&') {
return true;
}
} else if (fToken == Symbols.TokenCONST) {
return true;
}
return false;
}
/**
* Skips brackets if the current token is a RBRACKET. There can be nothing
* but whitespace in between, this is only to be used for <code>[]</code> elements.
@ -1724,7 +1743,9 @@ public final class CIndenter {
*/
private boolean looksLikeMethodDecl() {
nextToken();
if (fToken == Symbols.TokenIDENT) { // method name
switch (fToken) {
case Symbols.TokenIDENT: // method name
int pos= fPosition;
nextToken();
// check destructor tilde
if (fToken == Symbols.TokenTILDE) {
@ -1737,8 +1758,72 @@ public final class CIndenter {
while (skipBrackets()) {
nextToken();
}
return fToken == Symbols.TokenIDENT;
while (skipPointerOperators()) {
nextToken();
}
switch (fToken) {
case Symbols.TokenIDENT:
return true;
case Symbols.TokenSEMICOLON:
case Symbols.TokenRBRACE:
fPosition= pos;
return true;
case Symbols.TokenLBRACE:
if (fScanner.looksLikeCompositeTypeDefinitionBackward(fPosition, CHeuristicScanner.UNBOUND)) {
fPosition= pos;
return true;
}
break;
case Symbols.TokenGREATERTHAN:
return skipScope();
case Symbols.TokenCOLON:
nextToken();
switch (fToken) {
case Symbols.TokenPUBLIC:
case Symbols.TokenPROTECTED:
case Symbols.TokenPRIVATE:
fPosition= pos;
return true;
case Symbols.TokenRPAREN:
// constructor initializer
if (skipScope()) {
nextToken();
// optional throw
if (fToken == Symbols.TokenTHROW) {
nextToken();
if (fToken != Symbols.TokenRPAREN || !skipScope()) {
return false;
}
}
return looksLikeMethodDecl();
}
break;
}
}
break;
case Symbols.TokenARROW:
case Symbols.TokenCOMMA:
case Symbols.TokenEQUAL:
case Symbols.TokenGREATERTHAN:
case Symbols.TokenLESSTHAN:
case Symbols.TokenMINUS:
case Symbols.TokenSHIFTRIGHT:
case Symbols.TokenSHIFTLEFT:
case Symbols.TokenDELETE:
case Symbols.TokenNEW:
nextToken();
return fToken == Symbols.TokenOPERATOR;
case Symbols.TokenOTHER:
if (getTokenContent().length() == 1) {
nextToken();
if (fToken == Symbols.TokenOPERATOR)
return true;
}
if (getTokenContent().length() == 1) {
nextToken();
if (fToken == Symbols.TokenOPERATOR)
return true;
}
}
return false;
}

View file

@ -37,6 +37,7 @@ public interface Symbols {
int TokenSHIFTRIGHT= 18;
int TokenARROW= 19;
int TokenDOUBLECOLON= 20;
int TokenSHIFTLEFT= 21;
int TokenIF= 109;
int TokenDO= 1010;
int TokenFOR= 1011;
@ -62,5 +63,8 @@ public interface Symbols {
int TokenENUM= 1031;
int TokenVIRTUAL= 1032;
int TokenNAMESPACE= 1033;
int TokenOPERATOR= 1034;
int TokenTHROW= 1035;
int TokenCONST= 1036;
int TokenIDENT= 2000;
}