This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 158130
Collapse All | Expand All

(-)a/java.source/src/org/netbeans/modules/java/source/builder/TreeFactory.java (-2 / +2 lines)
Lines 165-171 Link Here
165
    }
165
    }
166
    
166
    
167
    public BreakTree Break(CharSequence label) {
167
    public BreakTree Break(CharSequence label) {
168
        Name n = label != null ? names.fromString(label.toString()) : null;
168
    Name n = label != null ? names.fromString(label.toString()) : names.empty;
169
        return make.Break(n);
169
        return make.Break(n);
170
    }
170
    }
171
    
171
    
Lines 279-285 Link Here
279
    }
279
    }
280
    
280
    
281
    public ContinueTree Continue(CharSequence label) {
281
    public ContinueTree Continue(CharSequence label) {
282
        Name n = label != null ? names.fromString(label.toString()) : null;
282
        Name n = label != null ? names.fromString(label.toString()) : names.empty;
283
        return make.Continue(n);
283
        return make.Continue(n);
284
    }
284
    }
285
    
285
    
(-)b36f797e7177 (+115 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 */
24
package org.netbeans.api.java.source.gen;
25
26
import com.sun.source.tree.BreakTree;
27
import com.sun.source.tree.ContinueTree;
28
import com.sun.source.tree.Tree;
29
import com.sun.source.tree.Tree.Kind;
30
import com.sun.source.util.TreePath;
31
import java.io.File;
32
import org.netbeans.api.java.source.JavaSource;
33
import org.netbeans.api.java.source.JavaSource.Phase;
34
import org.netbeans.api.java.source.Task;
35
import org.netbeans.api.java.source.TestUtilities;
36
import org.netbeans.api.java.source.TreeMaker;
37
import org.netbeans.api.java.source.WorkingCopy;
38
39
/**
40
 * The following shell script was used to generate the code snippets
41
 * <code>cat test/unit/data/test/Test.java | tr '\n' ' ' | tr '\t' ' ' | sed -E 's| +| |g' | sed 's|"|\\"|g'</code>
42
 * @author Samuel Halliday
43
 */
44
public class BreakContinueTest extends GeneratorTest {
45
46
    public BreakContinueTest(String name) {
47
        super(name);
48
    }
49
50
    private interface Delegate {
51
52
        public void run(WorkingCopy copy, Tree tree);
53
    }
54
55
    private void testHelper(String test, String golden, final Kind kind, final Delegate delegate) throws Exception {
56
        testFile = new File(getWorkDir(), "Test.java");
57
        final int index = test.indexOf("|");
58
        assertTrue(index != -1);
59
        TestUtilities.copyStringToFile(testFile, test.replace("|", ""));
60
        JavaSource src = getJavaSource(testFile);
61
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
62
63
            public void run(WorkingCopy copy) throws Exception {
64
                if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
65
                    return;
66
                }
67
                TreePath node = copy.getTreeUtilities().pathFor(index);
68
                assertTrue(node.getLeaf().getKind() == kind);
69
                delegate.run(copy, node.getLeaf());
70
            }
71
        };
72
        src.runModificationTask(task).commit();
73
        String res = TestUtilities.copyFileToString(testFile);
74
        assertEquals(golden, res);
75
    }
76
77
    public void testBreak158130() throws Exception {
78
        String test = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { b|reak loop; } } } }";
79
        String golden = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { break ; } } } }";
80
        testHelper(test, golden, Kind.BREAK, new Delegate() {
81
82
            public void run(WorkingCopy copy, Tree tree) {
83
                BreakTree original = (BreakTree) tree;
84
                TreeMaker make = copy.getTreeMaker();
85
                BreakTree modified = make.Break(null);
86
                copy.rewrite(original, modified);
87
            }
88
        });
89
    }
90
91
    public void testContinue158130() throws Exception {
92
        String test = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { con|tinue loop; } } } }";
93
        String golden = "public class Test { void m(int p) { loop: while (true) { if (p == 0) { continue ; } } } }";
94
        testHelper(test, golden, Kind.CONTINUE, new Delegate() {
95
96
            public void run(WorkingCopy copy, Tree tree) {
97
                ContinueTree original = (ContinueTree) tree;
98
                TreeMaker make = copy.getTreeMaker();
99
                ContinueTree modified = make.Continue(null);
100
                copy.rewrite(original, modified);
101
            }
102
        });
103
    }
104
105
    // XXX I don't understand what these are used for
106
    @Override
107
    String getSourcePckg() {
108
        return "";
109
    }
110
111
    @Override
112
    String getGoldenPckg() {
113
        return "";
114
    }
115
}

Return to bug 158130