1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Auto-insert semicolon after array or struct initializer

This commit is contained in:
Anton Leherbauer 2007-04-18 14:41:34 +00:00
parent f6ab39e0ce
commit b9d5827fc8
3 changed files with 8 additions and 3 deletions

View file

@ -503,6 +503,10 @@ public class CAutoIndentTest extends TestCase {
tester.reset(); tester.reset();
tester.type("for (;;) /*class*/ {\n"); //$NON-NLS-1$ tester.type("for (;;) /*class*/ {\n"); //$NON-NLS-1$
assertEquals("for (;;) /*class*/ {\n\t\r\n}", tester.fDoc.get()); //$NON-NLS-1$ assertEquals("for (;;) /*class*/ {\n\t\r\n}", tester.fDoc.get()); //$NON-NLS-1$
tester.reset();
tester.type("int i[5]={\n"); //$NON-NLS-1$
assertEquals("int i[5]={\n\t\t\r\n};", tester.fDoc.get()); //$NON-NLS-1$
} }
public void testSmartPasteWhitesmiths_Bug180531() throws Exception { public void testSmartPasteWhitesmiths_Bug180531() throws Exception {

View file

@ -260,7 +260,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
int p = (c.offset == docLength ? c.offset - 1 : c.offset); int p = (c.offset == docLength ? c.offset - 1 : c.offset);
CIndenter indenter = new CIndenter(d, scanner, fProject); CIndenter indenter = new CIndenter(d, scanner, fProject);
StringBuffer indent = indenter.computeIndentation(p); StringBuffer indent = indenter.computeIndentation(c.offset);
if (indent == null) if (indent == null)
indent = new StringBuffer(); indent = new StringBuffer();
if (addIndent > 0 && indent.length() == 0) { if (addIndent > 0 && indent.length() == 0) {
@ -306,7 +306,8 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
int bound= c.offset > 200 ? c.offset - 200 : CHeuristicScanner.UNBOUND; int bound= c.offset > 200 ? c.offset - 200 : CHeuristicScanner.UNBOUND;
int bracePos = scanner.findOpeningPeer(c.offset - 1, bound, '{', '}'); int bracePos = scanner.findOpeningPeer(c.offset - 1, bound, '{', '}');
if (bracePos != CHeuristicScanner.NOT_FOUND) { if (bracePos != CHeuristicScanner.NOT_FOUND) {
if (scanner.looksLikeCompositeTypeDefinitionBackward(bracePos, bound)) { if (scanner.looksLikeCompositeTypeDefinitionBackward(bracePos, bound) ||
scanner.previousToken(bracePos - 1, bound) == Symbols.TokenEQUAL) {
buf.append(';'); buf.append(';');
} }
} }

View file

@ -908,7 +908,7 @@ public final class CIndenter {
case Symbols.TokenLPAREN: case Symbols.TokenLPAREN:
case Symbols.TokenLBRACE: case Symbols.TokenLBRACE:
case Symbols.TokenLBRACKET: case Symbols.TokenLBRACKET:
return handleScopeIntroduction(offset + 1); return handleScopeIntroduction(Math.min(offset + 1, fDocument.getLength()));
case Symbols.TokenEOF: case Symbols.TokenEOF:
// trap when hitting start of document // trap when hitting start of document