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 158129
Collapse All | Expand All

(-)a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java (-2 / +3 lines)
Lines 905-911 Link Here
905
        localPointer = diffTree(oldT.selector, newT.selector, selectorBounds);
905
        localPointer = diffTree(oldT.selector, newT.selector, selectorBounds);
906
906
907
        tokenSequence.move(selectorBounds[1]);
907
        tokenSequence.move(selectorBounds[1]);
908
        while (tokenSequence.moveNext() && JavaTokenId.LBRACE != tokenSequence.token().id()) ;
908
        do { } while (tokenSequence.moveNext() && JavaTokenId.LBRACE != tokenSequence.token().id());
909
        tokenSequence.moveNext();
909
        tokenSequence.moveNext();
910
        copyTo(localPointer, localPointer = tokenSequence.offset());
910
        copyTo(localPointer, localPointer = tokenSequence.offset());
911
        PositionEstimator est = EstimatorFactory.cases(oldT.getCases(), newT.getCases(), workingCopy);
911
        PositionEstimator est = EstimatorFactory.cases(oldT.getCases(), newT.getCases(), workingCopy);
Lines 922-928 Link Here
922
            copyTo(localPointer, patBounds[0]);
922
            copyTo(localPointer, patBounds[0]);
923
            localPointer = diffTree(oldT.pat, newT.pat, patBounds);
923
            localPointer = diffTree(oldT.pat, newT.pat, patBounds);
924
            tokenSequence.move(patBounds[1]);
924
            tokenSequence.move(patBounds[1]);
925
            while (tokenSequence.moveNext() && JavaTokenId.COLON != tokenSequence.token().id()) ;
925
            do { } while (tokenSequence.moveNext() && JavaTokenId.COLON != tokenSequence.token().id());
926
            tokenSequence.moveNext();
926
            copyTo(localPointer, localPointer = tokenSequence.offset());
927
            copyTo(localPointer, localPointer = tokenSequence.offset());
927
        }
928
        }
928
        // todo (#pf): hot-fix of #113313, think about correct matching later
929
        // todo (#pf): hot-fix of #113313, think about correct matching later
(-)aede0d1c40d7 (+96 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.CaseTree;
27
import com.sun.source.tree.StatementTree;
28
import com.sun.source.tree.Tree.Kind;
29
import com.sun.source.util.TreePath;
30
import java.io.File;
31
import java.io.IOException;
32
import java.util.ArrayList;
33
import java.util.List;
34
import org.netbeans.api.java.source.JavaSource;
35
import org.netbeans.api.java.source.JavaSource.Phase;
36
import org.netbeans.api.java.source.Task;
37
import org.netbeans.api.java.source.TestUtilities;
38
import org.netbeans.api.java.source.TreeMaker;
39
import org.netbeans.api.java.source.WorkingCopy;
40
41
/**
42
 * The following shell script was used to generate the code snippets
43
 * <code>cat test/unit/data/test/Test.java | tr '\n' ' ' | tr '\t' ' ' | sed -E 's| +| |g' | sed 's|"|\\"|g'</code>
44
 * @author Samuel Halliday
45
 */
46
public class SwitchTest extends GeneratorTest {
47
48
    public SwitchTest(String name) {
49
        super(name);
50
    }
51
52
    public void test158129() throws Exception {
53
        testFile = new File(getWorkDir(), "Test.java");
54
        String test = "public class Test { void m(int p) { switch (p) { ca|se 0: } } }";
55
        // XXX whitespace "public class Test { void m(int p) { switch (p) { case 0: break; } } }"
56
        String golden = "public class Test { void m(int p) { switch (p) { case 0:break;\n } } }";
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 IOException {
64
                if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
65
                    return;
66
                }
67
                TreeMaker make = copy.getTreeMaker();
68
                TreePath node = copy.getTreeUtilities().pathFor(index);
69
                assertTrue(node.getLeaf().getKind() == Kind.CASE);
70
                CaseTree original = (CaseTree) node.getLeaf();
71
                System.err.println("ORIGINAL " + original);
72
                List<StatementTree> st = new ArrayList<StatementTree>();
73
                st.addAll(original.getStatements());
74
                st.add(make.Break(null));
75
                CaseTree modified = make.Case(original.getExpression(), st);
76
                System.err.println("MODIFIED " + modified);
77
                copy.rewrite(original, modified);
78
            }
79
        };
80
        src.runModificationTask(task).commit();
81
        String res = TestUtilities.copyFileToString(testFile);
82
        System.err.println(res);
83
        assertEquals(golden, res);
84
    }
85
86
    // XXX I don't understand what these are used for
87
    @Override
88
    String getSourcePckg() {
89
        return "";
90
    }
91
92
    @Override
93
    String getGoldenPckg() {
94
        return "";
95
    }
96
}

Return to bug 158129