diff -r b36f797e7177 java.source/src/org/netbeans/modules/java/source/builder/TreeFactory.java --- a/java.source/src/org/netbeans/modules/java/source/builder/TreeFactory.java Thu May 07 12:43:45 2009 +0200 +++ b/java.source/src/org/netbeans/modules/java/source/builder/TreeFactory.java Sun May 10 19:59:27 2009 +0100 @@ -165,7 +165,7 @@ } public BreakTree Break(CharSequence label) { - Name n = label != null ? names.fromString(label.toString()) : null; + Name n = label != null ? names.fromString(label.toString()) : names.empty; return make.Break(n); } @@ -279,7 +279,7 @@ } public ContinueTree Continue(CharSequence label) { - Name n = label != null ? names.fromString(label.toString()) : null; + Name n = label != null ? names.fromString(label.toString()) : names.empty; return make.Continue(n); } diff -r b36f797e7177 java.source/test/unit/src/org/netbeans/api/java/source/gen/BreakContinueTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/BreakContinueTest.java Sun May 10 19:59:27 2009 +0100 @@ -0,0 +1,115 @@ +/* + * 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.BreakTree; +import com.sun.source.tree.ContinueTree; +import com.sun.source.tree.Tree; +import com.sun.source.tree.Tree.Kind; +import com.sun.source.util.TreePath; +import java.io.File; +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 BreakContinueTest extends GeneratorTest { + + public BreakContinueTest(String name) { + super(name); + } + + private interface Delegate { + + public void run(WorkingCopy copy, Tree tree); + } + + private void testHelper(String test, String golden, final Kind kind, final Delegate delegate) throws Exception { + testFile = new File(getWorkDir(), "Test.java"); + 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 Exception { + if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { + return; + } + TreePath node = copy.getTreeUtilities().pathFor(index); + assertTrue(node.getLeaf().getKind() == kind); + delegate.run(copy, node.getLeaf()); + } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + assertEquals(golden, res); + } + + public void testBreak158130() throws Exception { + String test = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { b|reak loop; } } } }"; + String golden = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { break; } } } }"; + testHelper(test, golden, Kind.BREAK, new Delegate() { + + public void run(WorkingCopy copy, Tree tree) { + BreakTree original = (BreakTree) tree; + TreeMaker make = copy.getTreeMaker(); + BreakTree modified = make.Break(null); + copy.rewrite(original, modified); + } + }); + } + + public void testContinue158130() throws Exception { + String test = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { con|tinue loop; } } } }"; + String golden = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { continue; } } } }"; + testHelper(test, golden, Kind.CONTINUE, new Delegate() { + + public void run(WorkingCopy copy, Tree tree) { + ContinueTree original = (ContinueTree) tree; + TreeMaker make = copy.getTreeMaker(); + ContinueTree modified = make.Continue(null); + copy.rewrite(original, modified); + } + }); + } + + // XXX I don't understand what these are used for + @Override + String getSourcePckg() { + return ""; + } + + @Override + String getGoldenPckg() { + return ""; + } +}