diff -r aede0d1c40d7 java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java --- a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java Thu May 07 23:29:20 2009 +0200 +++ b/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java Fri May 08 19:59:40 2009 +0100 @@ -905,7 +905,7 @@ localPointer = diffTree(oldT.selector, newT.selector, selectorBounds); tokenSequence.move(selectorBounds[1]); - while (tokenSequence.moveNext() && JavaTokenId.LBRACE != tokenSequence.token().id()) ; + do { } while (tokenSequence.moveNext() && JavaTokenId.LBRACE != tokenSequence.token().id()); tokenSequence.moveNext(); copyTo(localPointer, localPointer = tokenSequence.offset()); PositionEstimator est = EstimatorFactory.cases(oldT.getCases(), newT.getCases(), workingCopy); @@ -922,7 +922,8 @@ copyTo(localPointer, patBounds[0]); localPointer = diffTree(oldT.pat, newT.pat, patBounds); tokenSequence.move(patBounds[1]); - while (tokenSequence.moveNext() && JavaTokenId.COLON != tokenSequence.token().id()) ; + do { } while (tokenSequence.moveNext() && JavaTokenId.COLON != tokenSequence.token().id()); + tokenSequence.moveNext(); copyTo(localPointer, localPointer = tokenSequence.offset()); } // todo (#pf): hot-fix of #113313, think about correct matching later diff -r aede0d1c40d7 java.source/test/unit/src/org/netbeans/api/java/source/gen/SwitchTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/SwitchTest.java Fri May 08 19:59:40 2009 +0100 @@ -0,0 +1,96 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + */ +package org.netbeans.api.java.source.gen; + +import com.sun.source.tree.CaseTree; +import com.sun.source.tree.StatementTree; +import com.sun.source.tree.Tree.Kind; +import com.sun.source.util.TreePath; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.java.source.JavaSource.Phase; +import org.netbeans.api.java.source.Task; +import org.netbeans.api.java.source.TestUtilities; +import org.netbeans.api.java.source.TreeMaker; +import org.netbeans.api.java.source.WorkingCopy; + +/** + * The following shell script was used to generate the code snippets + * cat test/unit/data/test/Test.java | tr '\n' ' ' | tr '\t' ' ' | sed -E 's| +| |g' | sed 's|"|\\"|g' + * @author Samuel Halliday + */ +public class SwitchTest extends GeneratorTest { + + public SwitchTest(String name) { + super(name); + } + + public void test158129() throws Exception { + testFile = new File(getWorkDir(), "Test.java"); + String test = "public class Test { void m(int p) { switch (p) { ca|se 0: } } }"; + // XXX whitespace "public class Test { void m(int p) { switch (p) { case 0: break; } } }" + String golden = "public class Test { void m(int p) { switch (p) { case 0:break;\n } } }"; + final int index = test.indexOf("|"); + assertTrue(index != -1); + TestUtilities.copyStringToFile(testFile, test.replace("|", "")); + JavaSource src = getJavaSource(testFile); + Task task = new Task() { + + public void run(WorkingCopy copy) throws IOException { + if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { + return; + } + TreeMaker make = copy.getTreeMaker(); + TreePath node = copy.getTreeUtilities().pathFor(index); + assertTrue(node.getLeaf().getKind() == Kind.CASE); + CaseTree original = (CaseTree) node.getLeaf(); + System.err.println("ORIGINAL " + original); + List st = new ArrayList(); + st.addAll(original.getStatements()); + st.add(make.Break(null)); + CaseTree modified = make.Case(original.getExpression(), st); + System.err.println("MODIFIED " + modified); + copy.rewrite(original, modified); + } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + System.err.println(res); + assertEquals(golden, res); + } + + // XXX I don't understand what these are used for + @Override + String getSourcePckg() { + return ""; + } + + @Override + String getGoldenPckg() { + return ""; + } +}