1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Fix auto-insert of closing brace with semicolon for anonymous declarations

This commit is contained in:
Anton Leherbauer 2007-04-06 11:54:18 +00:00
parent 6d4221b57f
commit 82b9f0cd2f
2 changed files with 24 additions and 8 deletions

View file

@ -426,7 +426,7 @@ public class CAutoIndentTest extends TestCase {
public void testBracketWithSemiColonInsertion() throws BadLocationException {
AutoEditTester tester = createAutoEditTester();
String[] kw= new String[] {"class", "union", "struct", "enum"};
String[] kw_inh= new String[] {"class", "union", "struct", "enum"};
String[] kw_anon= new String[] {"union", "struct", "enum"};
for(int i=0; i<kw.length; i++) {
tester.reset();
@ -476,7 +476,14 @@ public class CAutoIndentTest extends TestCase {
tester.type(kw[i]+" /* for(int i=0; i<100; i++) {} */\nA \n{\n"); //$NON-NLS-1$
assertEquals("\n// foo\n"+kw[i]+" /* for(int i=0; i<100; i++) {} */\nA \n{\n\t\n};\n\n//bar\n\n", tester.fDoc.get()); //$NON-NLS-1$
}
}
for(int i=0; i<kw_anon.length; i++) {
tester.reset();
tester.type("\n\n\n"+kw_anon[i]+" {\n"); //$NON-NLS-1$
assertEquals("\n\n\n"+kw_anon[i]+" {\n\t\n};", tester.fDoc.get()); //$NON-NLS-1$
}
}
/**
* Tests that brackets are inserted (without semi-colons) in appropriate

View file

@ -963,7 +963,12 @@ public final class CHeuristicScanner implements Symbols {
*/
public boolean looksLikeCompositeTypeDefinitionBackward(int start, int bound) {
int token= previousToken(start - 1, bound);
if (token == Symbols.TokenIDENT) {
switch (token) {
case Symbols.TokenSTRUCT:
case Symbols.TokenUNION:
case Symbols.TokenENUM:
return true; // anonymous
case Symbols.TokenIDENT:
token= previousToken(getPosition(), bound);
switch (token) {
case Symbols.TokenCLASS:
@ -974,8 +979,12 @@ public final class CHeuristicScanner implements Symbols {
default:
// backtrack
token= previousToken(start - 1, bound);
break;
}
break;
default:
// backtrack
token= previousToken(start - 1, bound);
break;
}
// match base-clause
if (token == Symbols.TokenGREATERTHAN) {
@ -986,13 +995,13 @@ public final class CHeuristicScanner implements Symbols {
}
token= previousToken(getPosition(), bound);
}
outer: while (token == Symbols.TokenIDENT) {// type name or base type
outerWhile: while (token == Symbols.TokenIDENT) {// type name or base type
token= previousToken(getPosition(), bound);
// match nested-name-specifier
while (token == Symbols.TokenCOLON) { // colon of qualification
token= previousToken(getPosition(), bound);
if (token != Symbols.TokenCOLON) { // second colon of qualification
break outer;
break outerWhile;
}
token= previousToken(getPosition(), bound);
if (token != Symbols.TokenIDENT) // qualification name?
@ -1027,7 +1036,7 @@ public final class CHeuristicScanner implements Symbols {
/* fallthrough */
case Symbols.TokenCOLON:
token= previousToken(getPosition(), bound);
break outer;
break outerWhile;
case Symbols.TokenCOMMA:
token= previousToken(getPosition(), bound);
if (token == Symbols.TokenGREATERTHAN) {
@ -1040,7 +1049,7 @@ public final class CHeuristicScanner implements Symbols {
}
continue; // another base type
case Symbols.TokenIDENT:
break outer;
break outerWhile;
default:
return false;
}