1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +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, //foo(arg,
// "string"); // "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(); assertIndenterResult();
} }
@ -105,6 +123,19 @@ public class CIndenterTest extends BaseUITestCase {
assertIndenterResult(); 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 { //struct x {
// int f1 : 1; // int f1 : 1;
// int f2 : 1; // int f2 : 1;
@ -120,4 +151,58 @@ public class CIndenterTest extends BaseUITestCase {
assertIndenterResult(); 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 * @return a constant from {@link Symbols} describing the next token
*/ */
public int nextToken(int start, int bound) { public int nextToken(int start, int bound) {
int pos= scanForward(start, bound, fNonWS);
if (pos == NOT_FOUND)
return TokenEOF;
try { try {
// check for string or char literal // check for string or char literal
char ch = fDocument.getChar(start); char ch = fDocument.getChar(pos);
if (ch == '"' || ch == '\'') { if (ch == '"' || ch == '\'') {
fChar= ch; fChar= ch;
fPos= fNonWSDefaultPart.nextPosition(start, true); fPos= fNonWSDefaultPart.nextPosition(pos, true);
return TokenOTHER; return TokenOTHER;
} }
} catch (BadLocationException exc) { } catch (BadLocationException exc) {
} }
int pos= scanForward(start, bound, fNonWSDefaultPart); pos= scanForward(pos, bound, fNonWSDefaultPart);
if (pos == NOT_FOUND) if (pos == NOT_FOUND)
return TokenEOF; return TokenEOF;
@ -346,6 +349,14 @@ public final class CHeuristicScanner implements Symbols {
case EQUAL: case EQUAL:
return TokenEQUAL; return TokenEQUAL;
case LANGLE: case LANGLE:
switch (peekNextChar()) {
case LANGLE:
++fPos;
return TokenSHIFTLEFT;
case EQUAL:
++fPos;
return TokenOTHER;
}
return TokenLESSTHAN; return TokenLESSTHAN;
case RANGLE: case RANGLE:
switch (peekNextChar()) { switch (peekNextChar()) {
@ -442,13 +453,17 @@ public final class CHeuristicScanner implements Symbols {
case EQUAL: case EQUAL:
switch (peekPreviousChar()) { switch (peekPreviousChar()) {
case RANGLE: case RANGLE:
--fPos;
case LANGLE: case LANGLE:
--fPos; --fPos;
return TokenOTHER; return TokenOTHER;
} }
return TokenEQUAL; return TokenEQUAL;
case LANGLE: case LANGLE:
switch (peekPreviousChar()) {
case LANGLE:
--fPos;
return TokenSHIFTLEFT;
}
return TokenLESSTHAN; return TokenLESSTHAN;
case RANGLE: case RANGLE:
switch (peekPreviousChar()) { switch (peekPreviousChar()) {
@ -566,6 +581,10 @@ public final class CHeuristicScanner implements Symbols {
return TokenWHILE; return TokenWHILE;
if ("union".equals(s)) //$NON-NLS-1$ if ("union".equals(s)) //$NON-NLS-1$
return TokenUNION; return TokenUNION;
if ("throw".equals(s)) //$NON-NLS-1$
return TokenTHROW;
if ("const".equals(s)) //$NON-NLS-1$
return TokenCONST;
break; break;
case 6: case 6:
if ("delete".equals(s)) //$NON-NLS-1$ if ("delete".equals(s)) //$NON-NLS-1$
@ -589,6 +608,10 @@ public final class CHeuristicScanner implements Symbols {
if ("virtual".equals(s)) //$NON-NLS-1$ if ("virtual".equals(s)) //$NON-NLS-1$
return TokenVIRTUAL; return TokenVIRTUAL;
break; break;
case 8:
if ("operator".equals(s)) //$NON-NLS-1$
return TokenOPERATOR;
break;
case 9: case 9:
if ("namespace".equals(s)) //$NON-NLS-1$ if ("namespace".equals(s)) //$NON-NLS-1$
return TokenNAMESPACE; return TokenNAMESPACE;

View file

@ -1653,6 +1653,25 @@ public final class CIndenter {
return false; 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 * 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. * 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() { private boolean looksLikeMethodDecl() {
nextToken(); nextToken();
if (fToken == Symbols.TokenIDENT) { // method name switch (fToken) {
case Symbols.TokenIDENT: // method name
int pos= fPosition;
nextToken(); nextToken();
// check destructor tilde // check destructor tilde
if (fToken == Symbols.TokenTILDE) { if (fToken == Symbols.TokenTILDE) {
@ -1737,8 +1758,72 @@ public final class CIndenter {
while (skipBrackets()) { while (skipBrackets()) {
nextToken(); 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; return false;
} }

View file

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