From b9d5827fc80eec2a37d40ef6ad6e14a80e332fcf Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 18 Apr 2007 14:41:34 +0000 Subject: [PATCH] Auto-insert semicolon after array or struct initializer --- .../ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java | 4 ++++ .../eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java | 5 +++-- .../src/org/eclipse/cdt/internal/ui/text/CIndenter.java | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java index a090f207c61..699acd61546 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java @@ -503,6 +503,10 @@ public class CAutoIndentTest extends TestCase { tester.reset(); tester.type("for (;;) /*class*/ {\n"); //$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 { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java index ade36165f43..296ce56f388 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java @@ -260,7 +260,7 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy { int p = (c.offset == docLength ? c.offset - 1 : c.offset); CIndenter indenter = new CIndenter(d, scanner, fProject); - StringBuffer indent = indenter.computeIndentation(p); + StringBuffer indent = indenter.computeIndentation(c.offset); if (indent == null) indent = new StringBuffer(); 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 bracePos = scanner.findOpeningPeer(c.offset - 1, bound, '{', '}'); if (bracePos != CHeuristicScanner.NOT_FOUND) { - if (scanner.looksLikeCompositeTypeDefinitionBackward(bracePos, bound)) { + if (scanner.looksLikeCompositeTypeDefinitionBackward(bracePos, bound) || + scanner.previousToken(bracePos - 1, bound) == Symbols.TokenEQUAL) { buf.append(';'); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java index 214498edc62..5ae9d9d5900 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java @@ -908,7 +908,7 @@ public final class CIndenter { case Symbols.TokenLPAREN: case Symbols.TokenLBRACE: case Symbols.TokenLBRACKET: - return handleScopeIntroduction(offset + 1); + return handleScopeIntroduction(Math.min(offset + 1, fDocument.getLength())); case Symbols.TokenEOF: // trap when hitting start of document