mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix auto-insert of closing brace with semicolon for anonymous declarations
This commit is contained in:
parent
6d4221b57f
commit
82b9f0cd2f
2 changed files with 24 additions and 8 deletions
|
@ -426,7 +426,7 @@ public class CAutoIndentTest extends TestCase {
|
||||||
public void testBracketWithSemiColonInsertion() throws BadLocationException {
|
public void testBracketWithSemiColonInsertion() throws BadLocationException {
|
||||||
AutoEditTester tester = createAutoEditTester();
|
AutoEditTester tester = createAutoEditTester();
|
||||||
String[] kw= new String[] {"class", "union", "struct", "enum"};
|
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++) {
|
for(int i=0; i<kw.length; i++) {
|
||||||
tester.reset();
|
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$
|
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$
|
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
|
* Tests that brackets are inserted (without semi-colons) in appropriate
|
||||||
|
|
|
@ -963,7 +963,12 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
*/
|
*/
|
||||||
public boolean looksLikeCompositeTypeDefinitionBackward(int start, int bound) {
|
public boolean looksLikeCompositeTypeDefinitionBackward(int start, int bound) {
|
||||||
int token= previousToken(start - 1, 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);
|
token= previousToken(getPosition(), bound);
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case Symbols.TokenCLASS:
|
case Symbols.TokenCLASS:
|
||||||
|
@ -974,8 +979,12 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
default:
|
default:
|
||||||
// backtrack
|
// backtrack
|
||||||
token= previousToken(start - 1, bound);
|
token= previousToken(start - 1, bound);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// backtrack
|
||||||
|
token= previousToken(start - 1, bound);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// match base-clause
|
// match base-clause
|
||||||
if (token == Symbols.TokenGREATERTHAN) {
|
if (token == Symbols.TokenGREATERTHAN) {
|
||||||
|
@ -986,13 +995,13 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
}
|
}
|
||||||
token= previousToken(getPosition(), bound);
|
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);
|
token= previousToken(getPosition(), bound);
|
||||||
// match nested-name-specifier
|
// match nested-name-specifier
|
||||||
while (token == Symbols.TokenCOLON) { // colon of qualification
|
while (token == Symbols.TokenCOLON) { // colon of qualification
|
||||||
token= previousToken(getPosition(), bound);
|
token= previousToken(getPosition(), bound);
|
||||||
if (token != Symbols.TokenCOLON) { // second colon of qualification
|
if (token != Symbols.TokenCOLON) { // second colon of qualification
|
||||||
break outer;
|
break outerWhile;
|
||||||
}
|
}
|
||||||
token= previousToken(getPosition(), bound);
|
token= previousToken(getPosition(), bound);
|
||||||
if (token != Symbols.TokenIDENT) // qualification name?
|
if (token != Symbols.TokenIDENT) // qualification name?
|
||||||
|
@ -1027,7 +1036,7 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case Symbols.TokenCOLON:
|
case Symbols.TokenCOLON:
|
||||||
token= previousToken(getPosition(), bound);
|
token= previousToken(getPosition(), bound);
|
||||||
break outer;
|
break outerWhile;
|
||||||
case Symbols.TokenCOMMA:
|
case Symbols.TokenCOMMA:
|
||||||
token= previousToken(getPosition(), bound);
|
token= previousToken(getPosition(), bound);
|
||||||
if (token == Symbols.TokenGREATERTHAN) {
|
if (token == Symbols.TokenGREATERTHAN) {
|
||||||
|
@ -1040,7 +1049,7 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
}
|
}
|
||||||
continue; // another base type
|
continue; // another base type
|
||||||
case Symbols.TokenIDENT:
|
case Symbols.TokenIDENT:
|
||||||
break outer;
|
break outerWhile;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue