### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v retrieving revision 1.230 diff -u -r1.230 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 2 Mar 2010 18:28:49 -0000 1.230 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 20 Apr 2010 10:22:02 -0000 @@ -1505,7 +1505,7 @@ isChunkStart = memberAlignment.checkChunkStart(TYPE, i, this.scribe.scanner.currentPosition); format((TypeDeclaration)member, null, isChunkStart, i == 0); } - if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) { + while (isNextToken(TerminalTokens.TokenNameSEMICOLON)) { this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); } @@ -2021,7 +2021,7 @@ isChunkStart = memberAlignment.checkChunkStart(Alignment.CHUNK_TYPE, i, this.scribe.scanner.currentPosition); format((TypeDeclaration)member, typeDeclaration.scope, isChunkStart, i == 0); } - if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) { + while (isNextToken(TerminalTokens.TokenNameSEMICOLON)) { this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java,v retrieving revision 1.25 diff -u -r1.25 FormatterBugsTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 3 Mar 2010 16:32:13 -0000 1.25 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 20 Apr 2010 10:22:06 -0000 @@ -5373,4 +5373,59 @@ ); } +/** + * @bug 309706: [formatter] doesn´t work when code has three semicolons side by side + * @test Verify that formatter does get puzzled by three consecutive semicolons + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=309706" + */ +public void testBug309706() { + String source = + "public class Test {\n" + + "\n" + + " private int id;;;\n" + + "\n" + + " private void dummy() {\n" + + "\n" + + " if (true) {\n" + + " System.out.println(\"bla\");\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "public class Test {\n" + + "\n" + + " private int id;;;\n" + + "\n" + + " private void dummy() {\n" + + "\n" + + " if (true) {\n" + + " System.out.println(\"bla\");\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug309706b() { + String source = + " private int id;;;\n" + + "\n" + + " private void dummy() {\n" + + "\n" + + " if (true) {\n" + + " System.out.println(\"bla\");\n" + + " }\n" + + " }\n"; + formatSource(source, + "private int id;;;\n" + + "\n" + + "private void dummy() {\n" + + "\n" + + " if (true) {\n" + + " System.out.println(\"bla\");\n" + + " }\n" + + "}", + CodeFormatter.K_CLASS_BODY_DECLARATIONS + ); +} + }