Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 158154 | Differences between
and this patch

Collapse All | Expand All

(-)a/java.hints/test/unit/src/org/netbeans/modules/java/hints/introduce/IntroduceHintTest.java (-15 / +15 lines)
 Lines 91-97    Link Here 
91
    }
91
    }
92
92
93
    private static Preferences codeStylePrefs;//XXX: does not allow parallel test execution
93
    private static Preferences codeStylePrefs;//XXX: does not allow parallel test execution
94
    
94
95
    @Override
95
    @Override
96
    protected void setUp() throws Exception {
96
    protected void setUp() throws Exception {
97
        SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
97
        SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
 Lines 374-380    Link Here 
374
                       new DialogDisplayerImpl("name", true, false, true),
374
                       new DialogDisplayerImpl("name", true, false, true),
375
                       4, 0);
375
                       4, 0);
376
    }
376
    }
377
    
377
378
//    public void testFix121420() throws Exception {
378
//    public void testFix121420() throws Exception {
379
//        performFixTest("package test; public class Test {public void test1() {|System.getProperty(\"\")|;} }",
379
//        performFixTest("package test; public class Test {public void test1() {|System.getProperty(\"\")|;} }",
380
//                       "package test; public class Test {public void test1() { String name = System.getProperty(\"\");} }",
380
//                       "package test; public class Test {public void test1() { String name = System.getProperty(\"\");} }",
 Lines 820-826    Link Here 
820
    public void testIntroduceMethodFix8() throws Exception {
820
    public void testIntroduceMethodFix8() throws Exception {
821
        performFixTest("package test; import java.io.IOException; public class Test {public void test(int y) {while (true) {if (--y <= 0) break;}}}",
821
        performFixTest("package test; import java.io.IOException; public class Test {public void test(int y) {while (true) {if (--y <= 0) break;}}}",
822
                       125 - 25, 145 - 25,
822
                       125 - 25, 145 - 25,
823
                       "package test; import java.io.IOException; public class Test {public void test(int y) {while (true) {if ( name(y)) break;}} private boolean name(int y) { if (--y <= 0) { return true; } return false; } }",
823
                       "package test; import java.io.IOException; public class Test {public void test(int y) {while (true) {if (name(y)) { break; } }} private boolean name(int y) { if (--y <= 0) { return true; } return false; } }",
824
                       new DialogDisplayerImpl3("name", null, true));
824
                       new DialogDisplayerImpl3("name", null, true));
825
    }
825
    }
826
826
 Lines 961-967    Link Here 
961
    public void testIntroduceMethod109663f() throws Exception {
961
    public void testIntroduceMethod109663f() throws Exception {
962
        performFixTest("package test; public class Test {public static void test(int y) {for (int u = y ; ; ) {if (y == 0) break; else y++;}}}",
962
        performFixTest("package test; public class Test {public static void test(int y) {for (int u = y ; ; ) {if (y == 0) break; else y++;}}}",
963
                       112 - 25, 140 - 25,
963
                       112 - 25, 140 - 25,
964
                       "package test; public class Test {public static void test(int y) {for (int u = y ; ; ) {if ( name(y)) break;}} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }",
964
                       "package test; public class Test {public static void test(int y) {for (int u = y ; ; ) {if (name(y)) { break; } }} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }",
965
                       new DialogDisplayerImpl3("name", EnumSet
965
                       new DialogDisplayerImpl3("name", EnumSet
966
                .of(Modifier.PRIVATE), true));
966
                .of(Modifier.PRIVATE), true));
967
    }
967
    }
 Lines 969-975    Link Here 
969
    public void testIntroduceMethod109663g() throws Exception {
969
    public void testIntroduceMethod109663g() throws Exception {
970
        performFixTest("package test; public class Test {public static void test(int y) {for (Integer i : java.util.Arrays.asList(y)) {if (y == 0) break; else y++;}}}",
970
        performFixTest("package test; public class Test {public static void test(int y) {for (Integer i : java.util.Arrays.asList(y)) {if (y == 0) break; else y++;}}}",
971
                       136 - 25, 164 - 25,
971
                       136 - 25, 164 - 25,
972
                       "package test; public class Test {public static void test(int y) {for (Integer i : java.util.Arrays.asList(y)) {if ( name(y)) break;}} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }",
972
                       "package test; public class Test {public static void test(int y) {for (Integer i : java.util.Arrays.asList(y)) {if (name(y)) { break; } }} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }",
973
                       new DialogDisplayerImpl3("name", EnumSet
973
                       new DialogDisplayerImpl3("name", EnumSet
974
                .of(Modifier.PRIVATE), true));
974
                .of(Modifier.PRIVATE), true));
975
    }
975
    }
 Lines 1399-1405    Link Here 
1399
                       new DialogDisplayerImpl3("name", EnumSet.of(Modifier.PRIVATE), true, true),
1399
                       new DialogDisplayerImpl3("name", EnumSet.of(Modifier.PRIVATE), true, true),
1400
                       1, 0);
1400
                       1, 0);
1401
    }
1401
    }
1402
    
1402
1403
    public void testIntroduceMethodFromSingleStatement153399a() throws Exception {
1403
    public void testIntroduceMethodFromSingleStatement153399a() throws Exception {
1404
        performFixTest("package test;\n" +
1404
        performFixTest("package test;\n" +
1405
                       "public class Test {\n" +
1405
                       "public class Test {\n" +
 Lines 1962-1968    Link Here 
1962
                       new DialogDisplayerImpl2(null, IntroduceFieldPanel.INIT_FIELD, true, EnumSet.<Modifier>of(Modifier.PRIVATE), false, true),
1962
                       new DialogDisplayerImpl2(null, IntroduceFieldPanel.INIT_FIELD, true, EnumSet.<Modifier>of(Modifier.PRIVATE), false, true),
1963
                       5, 2);
1963
                       5, 2);
1964
    }
1964
    }
1965
    
1965
1966
    public void testConstantFix208072a() throws Exception {
1966
    public void testConstantFix208072a() throws Exception {
1967
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
1967
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
1968
        prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
1968
        prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
 Lines 1982-1988    Link Here 
1982
                       new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
1982
                       new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
1983
                       1, 0);
1983
                       1, 0);
1984
    }
1984
    }
1985
    
1985
1986
    public void testConstantFix208072b() throws Exception {
1986
    public void testConstantFix208072b() throws Exception {
1987
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
1987
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
1988
        prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
1988
        prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
 Lines 2009-2015    Link Here 
2009
                       new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
2009
                       new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
2010
                       5, 1);
2010
                       5, 1);
2011
    }
2011
    }
2012
    
2012
2013
    public void testConstantFix208072c() throws Exception {
2013
    public void testConstantFix208072c() throws Exception {
2014
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
2014
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
2015
        prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
2015
        prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
 Lines 2036-2042    Link Here 
2036
                       new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
2036
                       new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)),
2037
                       5, 1);
2037
                       5, 1);
2038
    }
2038
    }
2039
    
2039
2040
    public void testConstantFix219771a() throws Exception {
2040
    public void testConstantFix219771a() throws Exception {
2041
        performFixTest("package test;\n" +
2041
        performFixTest("package test;\n" +
2042
                       "public class Test {\n" +
2042
                       "public class Test {\n" +
 Lines 2056-2062    Link Here 
2056
                       new DialogDisplayerImpl("C0", true, true, true, EnumSet.of(Modifier.PUBLIC)),
2056
                       new DialogDisplayerImpl("C0", true, true, true, EnumSet.of(Modifier.PUBLIC)),
2057
                       5, 1);
2057
                       5, 1);
2058
    }
2058
    }
2059
    
2059
2060
    public void testConstantFix219771b() throws Exception {
2060
    public void testConstantFix219771b() throws Exception {
2061
        performFixTest("package test;\n" +
2061
        performFixTest("package test;\n" +
2062
                       "public class Test {\n" +
2062
                       "public class Test {\n" +
 Lines 2076-2082    Link Here 
2076
                       new DialogDisplayerImpl2("C0", IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PUBLIC), true, true),
2076
                       new DialogDisplayerImpl2("C0", IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PUBLIC), true, true),
2077
                       4, 1);
2077
                       4, 1);
2078
    }
2078
    }
2079
    
2079
2080
    public void testConstantFix219771c() throws Exception {
2080
    public void testConstantFix219771c() throws Exception {
2081
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
2081
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
2082
        prefs.put("classMembersOrder", "STATIC_INIT;FIELD;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD");
2082
        prefs.put("classMembersOrder", "STATIC_INIT;FIELD;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD");
 Lines 2099-2105    Link Here 
2099
                       new DialogDisplayerImpl2("C0", IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PUBLIC), true, true),
2099
                       new DialogDisplayerImpl2("C0", IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PUBLIC), true, true),
2100
                       5, 2);
2100
                       5, 2);
2101
    }
2101
    }
2102
    
2102
2103
    public void testFieldFix208072d() throws Exception {
2103
    public void testFieldFix208072d() throws Exception {
2104
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
2104
        Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
2105
        prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
2105
        prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
 Lines 2130-2136    Link Here 
2130
    public void testWhitespace216402() throws Exception {
2130
    public void testWhitespace216402() throws Exception {
2131
        performSimpleSelectionVerificationTest("package test; public class Test {public void test() {int y = 3; y =|  2   |; }}", true);
2131
        performSimpleSelectionVerificationTest("package test; public class Test {public void test() {int y = 3; y =|  2   |; }}", true);
2132
    }
2132
    }
2133
    
2133
2134
    protected void prepareTest(String code) throws Exception {
2134
    protected void prepareTest(String code) throws Exception {
2135
        clearWorkDir();
2135
        clearWorkDir();
2136
2136
 Lines 2548-2554    Link Here 
2548
            throw new UnsupportedOperationException("Not supported yet.");
2548
            throw new UnsupportedOperationException("Not supported yet.");
2549
        }
2549
        }
2550
    }
2550
    }
2551
    
2551
2552
    @ServiceProvider(service=Provider.class)
2552
    @ServiceProvider(service=Provider.class)
2553
    public static final class PreferencesProvider implements Provider {
2553
    public static final class PreferencesProvider implements Provider {
2554
        @Override public Preferences forFile(FileObject file, String mimeType) {
2554
        @Override public Preferences forFile(FileObject file, String mimeType) {
(-)a/java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/InvertIfTest.java (-17 / +9 lines)
 Lines 80-105    Link Here 
80
                              "public class Test {\n" +
80
                              "public class Test {\n" +
81
                              "    public static void main(String[] args) {\n" +
81
                              "    public static void main(String[] args) {\n" +
82
                              "        if\n" +
82
                              "        if\n" +
83
                              "        // A\n" +
84
                              "        (!args[0].isEmpty())\n" +
83
                              "        (!args[0].isEmpty())\n" +
85
                              "        // B\n" +
84
                              "        {\n" +
86
                              "        {//4\n" +
87
                              "            //5\n" +
88
                              "            System.err.println(\"2\");\n" +
85
                              "            System.err.println(\"2\");\n" +
89
                              "            //6\n" +
90
                              "        } \n" +
86
                              "        } \n" +
91
                              "        // C\n" +
92
                              "        else\n" +
87
                              "        else\n" +
93
                              "        // D\n" +
88
                              "        { \n" +
94
                              "        { //1\n" +
95
                              "            //2\n" +
96
                              "            System.err.println(\"1\");\n" +
89
                              "            System.err.println(\"1\");\n" +
97
                              "            //3\n" +
90
                              "        } \n" +
98
                              "        } //E\n" +
99
                              "    }\n" +
91
                              "    }\n" +
100
                              "}\n");
92
                              "}\n");
101
    }
93
    }
102
    
94
103
    @Test
95
    @Test
104
    public void testCaretPosition() throws Exception {
96
    public void testCaretPosition() throws Exception {
105
        HintTest.create()
97
        HintTest.create()
 Lines 117-123    Link Here 
117
                .run(InvertIf.class)
109
                .run(InvertIf.class)
118
                .assertWarnings();
110
                .assertWarnings();
119
    }
111
    }
120
    
112
121
    @Test
113
    @Test
122
    public void testOptimizeNeg() throws Exception {
114
    public void testOptimizeNeg() throws Exception {
123
        HintTest.create()
115
        HintTest.create()
 Lines 147-153    Link Here 
147
                              "    }\n" +
139
                              "    }\n" +
148
                              "}\n");
140
                              "}\n");
149
    }
141
    }
150
    
142
151
    @Test
143
    @Test
152
    public void testOptimizeNegParenthesized() throws Exception {
144
    public void testOptimizeNegParenthesized() throws Exception {
153
        HintTest.create()
145
        HintTest.create()
 Lines 177-183    Link Here 
177
                              "    }\n" +
169
                              "    }\n" +
178
                              "}\n");
170
                              "}\n");
179
    }
171
    }
180
    
172
181
    @Test
173
    @Test
182
    public void testOptimizeEquals() throws Exception {
174
    public void testOptimizeEquals() throws Exception {
183
        HintTest.create()
175
        HintTest.create()
 Lines 207-213    Link Here 
207
                              "    }\n" +
199
                              "    }\n" +
208
                              "}\n");
200
                              "}\n");
209
    }
201
    }
210
    
202
211
    @Test
203
    @Test
212
    public void testOptimizeNotEquals() throws Exception {
204
    public void testOptimizeNotEquals() throws Exception {
213
        HintTest.create()
205
        HintTest.create()
 Lines 237-243    Link Here 
237
                              "    }\n" +
229
                              "    }\n" +
238
                              "}\n");
230
                              "}\n");
239
    }
231
    }
240
    
232
241
    @Test
233
    @Test
242
    public void testTrue() throws Exception {
234
    public void testTrue() throws Exception {
243
        HintTest.create()
235
        HintTest.create()
(-)a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java (-36 / +40 lines)
 Lines 170-176    Link Here 
170
        //was:
170
        //was:
171
//        int ln = td.oldTopLevel.lineMap.getLineNumber(start);
171
//        int ln = td.oldTopLevel.lineMap.getLineNumber(start);
172
//        int lineStart = td.oldTopLevel.lineMap.getStartPosition(ln);
172
//        int lineStart = td.oldTopLevel.lineMap.getStartPosition(ln);
173
        
173
174
        td.printer.setInitialOffset(lineStart);
174
        td.printer.setInitialOffset(lineStart);
175
175
176
        Tree current = oldTree;
176
        Tree current = oldTree;
 Lines 288-294    Link Here 
288
        localPointer = diffList(oldT.getTypeDecls(), newT.getTypeDecls(), localPointer, est, Measure.MEMBER, printer);
288
        localPointer = diffList(oldT.getTypeDecls(), newT.getTypeDecls(), localPointer, est, Measure.MEMBER, printer);
289
        printer.print(origText.substring(localPointer));
289
        printer.print(origText.substring(localPointer));
290
    }
290
    }
291
    
291
292
    private static int getOldIndent(DiffContext diffContext, Tree t) {
292
    private static int getOldIndent(DiffContext diffContext, Tree t) {
293
        if (diffContext.doc != null) {
293
        if (diffContext.doc != null) {
294
            try {
294
            try {
 Lines 534-540    Link Here 
534
        }
534
        }
535
        return bounds[1];
535
        return bounds[1];
536
    }
536
    }
537
        
537
538
    private boolean isEnum(Tree tree) {
538
    private boolean isEnum(Tree tree) {
539
        if (tree instanceof FieldGroupTree) return ((FieldGroupTree) tree).isEnum();
539
        if (tree instanceof FieldGroupTree) return ((FieldGroupTree) tree).isEnum();
540
        if (tree instanceof VariableTree) return (((JCVariableDecl) tree).getModifiers().flags & Flags.ENUM) != 0;
540
        if (tree instanceof VariableTree) return (((JCVariableDecl) tree).getModifiers().flags & Flags.ENUM) != 0;
 Lines 622-628    Link Here 
622
        }
622
        }
623
        if (oldT.params.isEmpty()) {
623
        if (oldT.params.isEmpty()) {
624
            // compute the position. Find the parameters closing ')', its
624
            // compute the position. Find the parameters closing ')', its
625
            // start position is important for us. This is used when 
625
            // start position is important for us. This is used when
626
            // there was not any parameter in original tree.
626
            // there was not any parameter in original tree.
627
            int startOffset = oldT.pos;
627
            int startOffset = oldT.pos;
628
628
 Lines 876-883    Link Here 
876
            JCTree tree = oldstats.get(oldstats.size() - 1);
876
            JCTree tree = oldstats.get(oldstats.size() - 1);
877
            localPointer = adjustLocalPointer(localPointer, comments.getComments(oldT), CommentSet.RelativePosition.INNER);
877
            localPointer = adjustLocalPointer(localPointer, comments.getComments(oldT), CommentSet.RelativePosition.INNER);
878
            CommentSet cs = comments.getComments(tree);
878
            CommentSet cs = comments.getComments(tree);
879
            localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.INLINE);            
879
            localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.INLINE);
880
            localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.TRAILING);            
880
            localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.TRAILING);
881
*/
881
*/
882
            copyTo(localPointer, localPointer = endPos(oldT));
882
            copyTo(localPointer, localPointer = endPos(oldT));
883
        }
883
        }
 Lines 906-912    Link Here 
906
                return false;
906
                return false;
907
        }
907
        }
908
    }
908
    }
909
    
909
910
910
911
    protected int diffDoLoop(JCDoWhileLoop oldT, JCDoWhileLoop newT, int[] bounds) {
911
    protected int diffDoLoop(JCDoWhileLoop oldT, JCDoWhileLoop newT, int[] bounds) {
912
        int localPointer = bounds[0];
912
        int localPointer = bounds[0];
 Lines 1135-1141    Link Here 
1135
                    for (Tree t = l.head; t!= null; l = l.tail, t = l.head) {
1135
                    for (Tree t = l.head; t!= null; l = l.tail, t = l.head) {
1136
                        printer.oldTrees.remove(t);
1136
                        printer.oldTrees.remove(t);
1137
                    }
1137
                    }
1138
                }  
1138
                }
1139
                localPointer = diffParameterList(oldT.resources,
1139
                localPointer = diffParameterList(oldT.resources,
1140
                        newT.resources,
1140
                        newT.resources,
1141
                        parens ? new JavaTokenId[] { JavaTokenId.LPAREN, JavaTokenId.RPAREN } : null,
1141
                        parens ? new JavaTokenId[] { JavaTokenId.LPAREN, JavaTokenId.RPAREN } : null,
 Lines 1152-1158    Link Here 
1152
                }
1152
                }
1153
            }
1153
            }
1154
        }
1154
        }
1155
        
1155
1156
        copyTo(localPointer, bodyPos[0]);
1156
        copyTo(localPointer, bodyPos[0]);
1157
        localPointer = diffTree(oldT.body, newT.body, bodyPos);
1157
        localPointer = diffTree(oldT.body, newT.body, bodyPos);
1158
        copyTo(localPointer, localPointer = bodyPos[1]);
1158
        copyTo(localPointer, localPointer = bodyPos[1]);
 Lines 1503-1509    Link Here 
1503
            }
1503
            }
1504
        }
1504
        }
1505
        //#174552 end
1505
        //#174552 end
1506
        
1506
1507
        // rhs
1507
        // rhs
1508
        copyTo(localPointer, rhsBounds[0]);
1508
        copyTo(localPointer, rhsBounds[0]);
1509
        localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds);
1509
        localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds);
 Lines 1858-1864    Link Here 
1858
                localPointer = tokenSequence.offset();
1858
                localPointer = tokenSequence.offset();
1859
            }
1859
            }
1860
        }
1860
        }
1861
        
1861
1862
        localPointer = diffAnnotationsLists(oldT.getAnnotations(), newT.getAnnotations(), startPos, localPointer);
1862
        localPointer = diffAnnotationsLists(oldT.getAnnotations(), newT.getAnnotations(), startPos, localPointer);
1863
1863
1864
        if ((oldT.flags & Flags.ANNOTATION) != 0) {
1864
        if ((oldT.flags & Flags.ANNOTATION) != 0) {
 Lines 1904-1910    Link Here 
1904
1904
1905
    private int diffAnnotationsLists(com.sun.tools.javac.util.List<JCAnnotation> oldAnnotations, com.sun.tools.javac.util.List<JCAnnotation> newAnnotations, int startPos, int localPointer) {
1905
    private int diffAnnotationsLists(com.sun.tools.javac.util.List<JCAnnotation> oldAnnotations, com.sun.tools.javac.util.List<JCAnnotation> newAnnotations, int startPos, int localPointer) {
1906
        int annotationsEnd = oldAnnotations.nonEmpty() ? endPos(oldAnnotations) : localPointer;
1906
        int annotationsEnd = oldAnnotations.nonEmpty() ? endPos(oldAnnotations) : localPointer;
1907
        
1907
1908
        if (listsMatch(oldAnnotations, newAnnotations)) {
1908
        if (listsMatch(oldAnnotations, newAnnotations)) {
1909
            copyTo(localPointer, localPointer = (annotationsEnd != localPointer ? annotationsEnd : startPos));
1909
            copyTo(localPointer, localPointer = (annotationsEnd != localPointer ? annotationsEnd : startPos));
1910
        } else {
1910
        } else {
 Lines 2344-2350    Link Here 
2344
    {
2344
    {
2345
        return diffParameterList(oldList, newList, null, makeAround, pos, measure, spaceBefore, spaceAfter, isEnum, separator);
2345
        return diffParameterList(oldList, newList, null, makeAround, pos, measure, spaceBefore, spaceAfter, isEnum, separator);
2346
    }
2346
    }
2347
    
2347
2348
    private int diffParameterList(
2348
    private int diffParameterList(
2349
            List<? extends JCTree> oldList,
2349
            List<? extends JCTree> oldList,
2350
            List<? extends JCTree> newList,
2350
            List<? extends JCTree> newList,
 Lines 2583-2589    Link Here 
2583
                }
2583
                }
2584
                case INSERT: {
2584
                case INSERT: {
2585
                    JCVariableDecl decl = (JCVariableDecl) item.element;
2585
                    JCVariableDecl decl = (JCVariableDecl) item.element;
2586
                    
2586
2587
                    if (oldIndex == 0) {
2587
                    if (oldIndex == 0) {
2588
                        int oldPrec = printer.setPrec(TreeInfo.noPrec);
2588
                        int oldPrec = printer.setPrec(TreeInfo.noPrec);
2589
                        printer.visitVarDef(decl);
2589
                        printer.visitVarDef(decl);
 Lines 2877-2897    Link Here 
2877
                                    }
2877
                                    }
2878
                                }
2878
                                }
2879
                            }
2879
                            }
2880
                            if(wasInFieldGroup || treesMatch(item.element, lastdel, false)) {
2880
                            if (wasInFieldGroup || treesMatch(item.element, lastdel, false)) {
2881
                                VeryPretty oldPrinter = this.printer;
2881
                                if (item.element instanceof JCIf) {
2882
                                int old = oldPrinter.indent();
2882
                                    lastdel = null;
2883
                                this.printer = new VeryPretty(diffContext, diffContext.style, tree2Tag, tag2Span, origText, oldPrinter.toString().length() + oldPrinter.getInitialOffset());//XXX
2883
                                } else {
2884
                                this.printer.reset(old);
2884
                                    VeryPretty oldPrinter = this.printer;
2885
                                this.printer.oldTrees = oldTrees;
2885
                                    int old = oldPrinter.indent();
2886
                                int index = oldList.indexOf(lastdel);
2886
                                    this.printer = new VeryPretty(diffContext, diffContext.style, tree2Tag, tag2Span, origText, oldPrinter.toString().length() + oldPrinter.getInitialOffset());//XXX
2887
                                int[] poss = estimator.getPositions(index);
2887
                                    this.printer.reset(old);
2888
                                //TODO: should the original text between the return position of the following method and poss[1] be copied into the new text?
2888
                                    this.printer.oldTrees = oldTrees;
2889
                                localPointer = diffTree(lastdel, item.element, poss);
2889
                                    int index = oldList.indexOf(lastdel);
2890
                                printer.print(this.printer.toString());
2890
                                    int[] poss = estimator.getPositions(index);
2891
                                this.printer = oldPrinter;
2891
                                    //TODO: should the original text between the return position of the following method and poss[1] be copied into the new text?
2892
                                this.printer.undent(old);
2892
                                    localPointer = diffTree(lastdel, item.element, poss);
2893
                                lastdel = null;
2893
                                    printer.print(this.printer.toString());
2894
                                break;
2894
                                    this.printer = oldPrinter;
2895
                                    this.printer.undent(old);
2896
                                    lastdel = null;
2897
                                    break;
2898
                                }
2895
                            }
2899
                            }
2896
                        }
2900
                        }
2897
                        if (LineInsertionType.BEFORE == estimator.lineInsertType()) printer.newline();
2901
                        if (LineInsertionType.BEFORE == estimator.lineInsertType()) printer.newline();
 Lines 2938-2944    Link Here 
2938
    protected int diffPrecedingComments(JCTree oldT, JCTree newT, int localPointer) {
2942
    protected int diffPrecedingComments(JCTree oldT, JCTree newT, int localPointer) {
2939
        return diffPrecedingComments(oldT, newT, getOldPos(oldT), localPointer);
2943
        return diffPrecedingComments(oldT, newT, getOldPos(oldT), localPointer);
2940
    }
2944
    }
2941
    
2945
2942
    protected int diffPrecedingComments(JCTree oldT, JCTree newT, int oldTreeStartPos, int localPointer) {
2946
    protected int diffPrecedingComments(JCTree oldT, JCTree newT, int oldTreeStartPos, int localPointer) {
2943
        CommentSet cs = comments.getComments(newT);
2947
        CommentSet cs = comments.getComments(newT);
2944
        CommentSet old = comments.getComments(oldT);
2948
        CommentSet old = comments.getComments(oldT);
 Lines 2964-2970    Link Here 
2964
            while (printer.out.isWhitespaceLine())
2968
            while (printer.out.isWhitespaceLine())
2965
                printer.eatChars(1);
2969
                printer.eatChars(1);
2966
        }
2970
        }
2967
        
2971
2968
        localPointer = diffCommentLists(getOldPos(oldT), oldInlineComments, newInlineComments, false, false, localPointer);
2972
        localPointer = diffCommentLists(getOldPos(oldT), oldInlineComments, newInlineComments, false, false, localPointer);
2969
2973
2970
        boolean containedEmbeddedNewLine = false;
2974
        boolean containedEmbeddedNewLine = false;
 Lines 2973-2979    Link Here 
2973
        for (Comment oldComment : oldInlineComments) {
2977
        for (Comment oldComment : oldInlineComments) {
2974
            if (oldComment.style() == Style.LINE) containedEmbeddedNewLine = true;
2978
            if (oldComment.style() == Style.LINE) containedEmbeddedNewLine = true;
2975
        }
2979
        }
2976
        
2980
2977
        for (Comment nueComment : newInlineComments) {
2981
        for (Comment nueComment : newInlineComments) {
2978
            if (nueComment.style() == Style.LINE) containsEmbeddedNewLine = true;
2982
            if (nueComment.style() == Style.LINE) containsEmbeddedNewLine = true;
2979
        }
2983
        }
 Lines 2990-2996    Link Here 
2990
        Iterator<Comment> newIter = newList.iterator();
2994
        Iterator<Comment> newIter = newList.iterator();
2991
        Comment oldC = safeNext(oldIter);
2995
        Comment oldC = safeNext(oldIter);
2992
        Comment newC = safeNext(newIter);
2996
        Comment newC = safeNext(newIter);
2993
        
2997
2994
        while (oldC != null && newC != null) {
2998
        while (oldC != null && newC != null) {
2995
            if (!commentsMatch(oldC, newC)) return false;
2999
            if (!commentsMatch(oldC, newC)) return false;
2996
            oldC = safeNext(oldIter);
3000
            oldC = safeNext(oldIter);
 Lines 2999-3005    Link Here 
2999
3003
3000
        return !((oldC == null) ^ (newC == null));
3004
        return !((oldC == null) ^ (newC == null));
3001
    }
3005
    }
3002
    
3006
3003
    // refactor it! make it better
3007
    // refactor it! make it better
3004
    private int diffCommentLists(int oldTreeStartPos, List<Comment>oldList,
3008
    private int diffCommentLists(int oldTreeStartPos, List<Comment>oldList,
3005
                                  List<Comment>newList, boolean trailing, boolean preceding, int localPointer) {
3009
                                  List<Comment>newList, boolean trailing, boolean preceding, int localPointer) {
 Lines 3058-3064    Link Here 
3058
        }
3062
        }
3059
        while (newC != null) {
3063
        while (newC != null) {
3060
            if (Style.WHITESPACE != newC.style()) {
3064
            if (Style.WHITESPACE != newC.style()) {
3061
//                printer.print(newC.getText());                
3065
//                printer.print(newC.getText());
3062
                if (!firstNewCommentPrinted && preceding) {
3066
                if (!firstNewCommentPrinted && preceding) {
3063
                    copyTo(localPointer, localPointer = oldTreeStartPos);
3067
                    copyTo(localPointer, localPointer = oldTreeStartPos);
3064
                }
3068
                }
 Lines 3204-3210    Link Here 
3204
                return oldBounds[1];
3208
                return oldBounds[1];
3205
            }
3209
            }
3206
        }
3210
        }
3207
        
3211
3208
        int commentsStart = Math.min(commentStart(comments.getComments(oldT), CommentSet.RelativePosition.INLINE), commentStart(comments.getComments(oldT), CommentSet.RelativePosition.TRAILING));
3212
        int commentsStart = Math.min(commentStart(comments.getComments(oldT), CommentSet.RelativePosition.INLINE), commentStart(comments.getComments(oldT), CommentSet.RelativePosition.TRAILING));
3209
        if (commentsStart < elementBounds[1]) {
3213
        if (commentsStart < elementBounds[1]) {
3210
            int lastIndex;
3214
            int lastIndex;
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/gen/BodyStatementTest.java (-253 / +254 lines)
 Lines 64-79    Link Here 
64
/**
64
/**
65
 * Test class add couple of body statements. It test statements creation and
65
 * Test class add couple of body statements. It test statements creation and
66
 * addition to body.
66
 * addition to body.
67
 * 
67
 *
68
 * @author Pavel Flaska
68
 * @author Pavel Flaska
69
 */
69
 */
70
public class BodyStatementTest extends GeneratorTestMDRCompat {
70
public class BodyStatementTest extends GeneratorTestMDRCompat {
71
    
71
72
    /** Creates a new instance of BodyStatementTest */
72
    /** Creates a new instance of BodyStatementTest */
73
    public BodyStatementTest(String name) {
73
    public BodyStatementTest(String name) {
74
        super(name);
74
        super(name);
75
    }
75
    }
76
    
76
77
    public static NbTestSuite suite() {
77
    public static NbTestSuite suite() {
78
        NbTestSuite suite = new NbTestSuite();
78
        NbTestSuite suite = new NbTestSuite();
79
        suite.addTestSuite(BodyStatementTest.class);
79
        suite.addTestSuite(BodyStatementTest.class);
 Lines 132-142    Link Here 
132
    }
132
    }
133
133
134
    /**
134
    /**
135
     * Adds 'System.err.println(null);' statement to the method body. 
135
     * Adds 'System.err.println(null);' statement to the method body.
136
     */
136
     */
137
    public void testNullLiteral() throws Exception {
137
    public void testNullLiteral() throws Exception {
138
        testFile = new File(getWorkDir(), "Test.java");
138
        testFile = new File(getWorkDir(), "Test.java");
139
        TestUtilities.copyStringToFile(testFile, 
139
        TestUtilities.copyStringToFile(testFile,
140
            "package hierbas.del.litoral;\n\n" +
140
            "package hierbas.del.litoral;\n\n" +
141
            "import java.io.*;\n\n" +
141
            "import java.io.*;\n\n" +
142
            "public class Test {\n" +
142
            "public class Test {\n" +
 Lines 145-157    Link Here 
145
            "    }\n" +
145
            "    }\n" +
146
            "}\n"
146
            "}\n"
147
            );
147
            );
148
        String golden = 
148
        String golden =
149
            "package hierbas.del.litoral;\n\n" +
149
            "package hierbas.del.litoral;\n\n" +
150
            "import java.io.*;\n\n" +
150
            "import java.io.*;\n\n" +
151
            "public class Test {\n" +
151
            "public class Test {\n" +
152
            "    public void taragui() {\n" +
152
            "    public void taragui() {\n" +
153
            "        ;\n" +
153
            "        ;\n" +
154
            "        System.err.println(null);\n" + 
154
            "        System.err.println(null);\n" +
155
            "    }\n" +
155
            "    }\n" +
156
            "}\n";
156
            "}\n";
157
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
157
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
 Lines 160-166    Link Here 
160
            public void run(WorkingCopy workingCopy) throws java.io.IOException {
160
            public void run(WorkingCopy workingCopy) throws java.io.IOException {
161
                workingCopy.toPhase(Phase.RESOLVED);
161
                workingCopy.toPhase(Phase.RESOLVED);
162
                TreeMaker make = workingCopy.getTreeMaker();
162
                TreeMaker make = workingCopy.getTreeMaker();
163
                
163
164
                // finally, find the correct body and rewrite it.
164
                // finally, find the correct body and rewrite it.
165
                ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
165
                ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
166
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
166
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
 Lines 182-201    Link Here 
182
                BlockTree copy = make.addBlockStatement(method.getBody(), statement);
182
                BlockTree copy = make.addBlockStatement(method.getBody(), statement);
183
                workingCopy.rewrite(method.getBody(), copy);
183
                workingCopy.rewrite(method.getBody(), copy);
184
            }
184
            }
185
            
185
186
        };
186
        };
187
        testSource.runModificationTask(task).commit();
187
        testSource.runModificationTask(task).commit();
188
        String res = TestUtilities.copyFileToString(testFile);
188
        String res = TestUtilities.copyFileToString(testFile);
189
        System.err.println(res);
189
        System.err.println(res);
190
        assertEquals(golden, res);
190
        assertEquals(golden, res);
191
    }
191
    }
192
    
192
193
    /**
193
    /**
194
     * Adds 'System.err.println(true);' statement to the method body. 
194
     * Adds 'System.err.println(true);' statement to the method body.
195
     */
195
     */
196
    public void testBooleanLiteral() throws Exception {
196
    public void testBooleanLiteral() throws Exception {
197
        testFile = new File(getWorkDir(), "Test.java");
197
        testFile = new File(getWorkDir(), "Test.java");
198
        TestUtilities.copyStringToFile(testFile, 
198
        TestUtilities.copyStringToFile(testFile,
199
            "package hierbas.del.litoral;\n\n" +
199
            "package hierbas.del.litoral;\n\n" +
200
            "import java.io.*;\n\n" +
200
            "import java.io.*;\n\n" +
201
            "public class Test {\n" +
201
            "public class Test {\n" +
 Lines 204-216    Link Here 
204
            "    }\n" +
204
            "    }\n" +
205
            "}\n"
205
            "}\n"
206
            );
206
            );
207
        String golden = 
207
        String golden =
208
            "package hierbas.del.litoral;\n\n" +
208
            "package hierbas.del.litoral;\n\n" +
209
            "import java.io.*;\n\n" +
209
            "import java.io.*;\n\n" +
210
            "public class Test {\n" +
210
            "public class Test {\n" +
211
            "    public void taragui() {\n" +
211
            "    public void taragui() {\n" +
212
            "        ;\n" +
212
            "        ;\n" +
213
            "        System.err.println(true);\n" + 
213
            "        System.err.println(true);\n" +
214
            "    }\n" +
214
            "    }\n" +
215
            "}\n";
215
            "}\n";
216
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
216
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
 Lines 219-225    Link Here 
219
            public void run(WorkingCopy workingCopy) throws java.io.IOException {
219
            public void run(WorkingCopy workingCopy) throws java.io.IOException {
220
                workingCopy.toPhase(Phase.RESOLVED);
220
                workingCopy.toPhase(Phase.RESOLVED);
221
                TreeMaker make = workingCopy.getTreeMaker();
221
                TreeMaker make = workingCopy.getTreeMaker();
222
                
222
223
                // finally, find the correct body and rewrite it.
223
                // finally, find the correct body and rewrite it.
224
                ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
224
                ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
225
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
225
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
 Lines 241-260    Link Here 
241
                BlockTree copy = make.addBlockStatement(method.getBody(), statement);
241
                BlockTree copy = make.addBlockStatement(method.getBody(), statement);
242
                workingCopy.rewrite(method.getBody(), copy);
242
                workingCopy.rewrite(method.getBody(), copy);
243
            }
243
            }
244
            
244
245
        };
245
        };
246
        testSource.runModificationTask(task).commit();
246
        testSource.runModificationTask(task).commit();
247
        String res = TestUtilities.copyFileToString(testFile);
247
        String res = TestUtilities.copyFileToString(testFile);
248
        System.err.println(res);
248
        System.err.println(res);
249
        assertEquals(golden, res);
249
        assertEquals(golden, res);
250
    }
250
    }
251
    
251
252
    /**
252
    /**
253
     * Renames el to element in method parameter and if statement
253
     * Renames el to element in method parameter and if statement
254
     */
254
     */
255
    public void testRenameInIfStatement() throws Exception {
255
    public void testRenameInIfStatement() throws Exception {
256
        testFile = new File(getWorkDir(), "Test.java");
256
        testFile = new File(getWorkDir(), "Test.java");
257
        TestUtilities.copyStringToFile(testFile, 
257
        TestUtilities.copyStringToFile(testFile,
258
            "package personal;\n" +
258
            "package personal;\n" +
259
            "\n" +
259
            "\n" +
260
            "import javax.swing.text.Element;\n" +
260
            "import javax.swing.text.Element;\n" +
 Lines 266-272    Link Here 
266
            "        }\n" +
266
            "        }\n" +
267
            "    }\n" +
267
            "    }\n" +
268
            "}\n");
268
            "}\n");
269
        String golden = 
269
        String golden =
270
            "package personal;\n" +
270
            "package personal;\n" +
271
            "\n" +
271
            "\n" +
272
            "import javax.swing.text.Element;\n" +
272
            "import javax.swing.text.Element;\n" +
 Lines 302-321    Link Here 
302
                IdentifierTree copy = make.setLabel(identToRename, "element");
302
                IdentifierTree copy = make.setLabel(identToRename, "element");
303
                workingCopy.rewrite(identToRename, copy);
303
                workingCopy.rewrite(identToRename, copy);
304
            }
304
            }
305
            
305
306
        };
306
        };
307
        testSource.runModificationTask(task).commit();
307
        testSource.runModificationTask(task).commit();
308
        String res = TestUtilities.copyFileToString(testFile);
308
        String res = TestUtilities.copyFileToString(testFile);
309
        System.err.println(res);
309
        System.err.println(res);
310
        assertEquals(golden, res);
310
        assertEquals(golden, res);
311
    }
311
    }
312
    
312
313
    /**
313
    /**
314
     * Renames el to element in method parameter and if statement
314
     * Renames el to element in method parameter and if statement
315
     */
315
     */
316
    public void testRenameInLocalDecl() throws Exception {
316
    public void testRenameInLocalDecl() throws Exception {
317
        testFile = new File(getWorkDir(), "Test.java");
317
        testFile = new File(getWorkDir(), "Test.java");
318
        TestUtilities.copyStringToFile(testFile, 
318
        TestUtilities.copyStringToFile(testFile,
319
            "package personal;\n" +
319
            "package personal;\n" +
320
            "\n" +
320
            "\n" +
321
            "import javax.swing.text.Element;\n" +
321
            "import javax.swing.text.Element;\n" +
 Lines 325-331    Link Here 
325
            "        String name = el.getName();\n" +
325
            "        String name = el.getName();\n" +
326
            "    }\n" +
326
            "    }\n" +
327
            "}\n");
327
            "}\n");
328
        String golden = 
328
        String golden =
329
            "package personal;\n" +
329
            "package personal;\n" +
330
            "\n" +
330
            "\n" +
331
            "import javax.swing.text.Element;\n" +
331
            "import javax.swing.text.Element;\n" +
 Lines 355-374    Link Here 
355
                IdentifierTree copy = make.setLabel(identToRename, "element");
355
                IdentifierTree copy = make.setLabel(identToRename, "element");
356
                workingCopy.rewrite(identToRename, copy);
356
                workingCopy.rewrite(identToRename, copy);
357
            }
357
            }
358
            
358
359
        };
359
        };
360
        testSource.runModificationTask(task).commit();
360
        testSource.runModificationTask(task).commit();
361
        String res = TestUtilities.copyFileToString(testFile);
361
        String res = TestUtilities.copyFileToString(testFile);
362
        System.err.println(res);
362
        System.err.println(res);
363
        assertEquals(golden, res);
363
        assertEquals(golden, res);
364
    }
364
    }
365
    
365
366
    /**
366
    /**
367
     * Renames el to element in method parameter and if statement
367
     * Renames el to element in method parameter and if statement
368
     */
368
     */
369
    public void testRenameInInvocationPars() throws Exception {
369
    public void testRenameInInvocationPars() throws Exception {
370
        testFile = new File(getWorkDir(), "Test.java");
370
        testFile = new File(getWorkDir(), "Test.java");
371
        TestUtilities.copyStringToFile(testFile, 
371
        TestUtilities.copyStringToFile(testFile,
372
            "package personal;\n" +
372
            "package personal;\n" +
373
            "\n" +
373
            "\n" +
374
            "import javax.swing.text.Element;\n" +
374
            "import javax.swing.text.Element;\n" +
 Lines 379-385    Link Here 
379
            "        Collections.singleton(el);\n" +
379
            "        Collections.singleton(el);\n" +
380
            "    }\n" +
380
            "    }\n" +
381
            "}\n");
381
            "}\n");
382
        String golden = 
382
        String golden =
383
            "package personal;\n" +
383
            "package personal;\n" +
384
            "\n" +
384
            "\n" +
385
            "import javax.swing.text.Element;\n" +
385
            "import javax.swing.text.Element;\n" +
 Lines 410-416    Link Here 
410
                IdentifierTree copy = make.setLabel(identToRename, "element");
410
                IdentifierTree copy = make.setLabel(identToRename, "element");
411
                workingCopy.rewrite(identToRename, copy);
411
                workingCopy.rewrite(identToRename, copy);
412
            }
412
            }
413
            
413
414
        };
414
        };
415
        testSource.runModificationTask(task).commit();
415
        testSource.runModificationTask(task).commit();
416
        String res = TestUtilities.copyFileToString(testFile);
416
        String res = TestUtilities.copyFileToString(testFile);
 Lines 423-429    Link Here 
423
     */
423
     */
424
    public void testAddMethodToAnnInTry() throws Exception {
424
    public void testAddMethodToAnnInTry() throws Exception {
425
        testFile = new File(getWorkDir(), "Test.java");
425
        testFile = new File(getWorkDir(), "Test.java");
426
        TestUtilities.copyStringToFile(testFile, 
426
        TestUtilities.copyStringToFile(testFile,
427
            "package personal;\n" +
427
            "package personal;\n" +
428
            "\n" +
428
            "\n" +
429
            "import javax.swing.text.Element;\n" +
429
            "import javax.swing.text.Element;\n" +
 Lines 441-447    Link Here 
441
            "}\n" +
441
            "}\n" +
442
            "}\n");
442
            "}\n");
443
443
444
         String golden = 
444
         String golden =
445
            "package personal;\n" +
445
            "package personal;\n" +
446
            "\n" +
446
            "\n" +
447
            "import javax.swing.text.Element;\n" +
447
            "import javax.swing.text.Element;\n" +
 Lines 487-506    Link Here 
487
                ClassTree copy = make.addClassMember(anonClassTree, methodToAdd);
487
                ClassTree copy = make.addClassMember(anonClassTree, methodToAdd);
488
                workingCopy.rewrite(anonClassTree, copy);
488
                workingCopy.rewrite(anonClassTree, copy);
489
            }
489
            }
490
            
490
491
        };
491
        };
492
        testSource.runModificationTask(task).commit();
492
        testSource.runModificationTask(task).commit();
493
        String res = TestUtilities.copyFileToString(testFile);
493
        String res = TestUtilities.copyFileToString(testFile);
494
        System.err.println(res);
494
        System.err.println(res);
495
        assertEquals(golden, res);
495
        assertEquals(golden, res);
496
    }
496
    }
497
    
497
498
    /**
498
    /**
499
     * Check return statement is not doubled. (#90806)
499
     * Check return statement is not doubled. (#90806)
500
     */
500
     */
501
    public void testReturnNotDoubled() throws Exception {
501
    public void testReturnNotDoubled() throws Exception {
502
        testFile = new File(getWorkDir(), "Test.java");
502
        testFile = new File(getWorkDir(), "Test.java");
503
        TestUtilities.copyStringToFile(testFile, 
503
        TestUtilities.copyStringToFile(testFile,
504
            "package personal;\n" +
504
            "package personal;\n" +
505
            "\n" +
505
            "\n" +
506
            "import javax.swing.text.Element;\n" +
506
            "import javax.swing.text.Element;\n" +
 Lines 518-524    Link Here 
518
            "    }\n" +
518
            "    }\n" +
519
            "}\n");
519
            "}\n");
520
520
521
         String golden = 
521
         String golden =
522
            "package personal;\n" +
522
            "package personal;\n" +
523
            "\n" +
523
            "\n" +
524
            "import javax.swing.text.Element;\n" +
524
            "import javax.swing.text.Element;\n" +
 Lines 565-584    Link Here 
565
                ClassTree copy = make.addClassMember(anonClassTree, methodToAdd);
565
                ClassTree copy = make.addClassMember(anonClassTree, methodToAdd);
566
                workingCopy.rewrite(anonClassTree, copy);
566
                workingCopy.rewrite(anonClassTree, copy);
567
            }
567
            }
568
            
568
569
        };
569
        };
570
        testSource.runModificationTask(task).commit();
570
        testSource.runModificationTask(task).commit();
571
        String res = TestUtilities.copyFileToString(testFile);
571
        String res = TestUtilities.copyFileToString(testFile);
572
        System.err.println(res);
572
        System.err.println(res);
573
        assertEquals(golden, res);
573
        assertEquals(golden, res);
574
    }
574
    }
575
    
575
576
    /**
576
    /**
577
     * Check 'for' body is not regenerated. (#91061)
577
     * Check 'for' body is not regenerated. (#91061)
578
     */
578
     */
579
    public void testForNotRegen() throws Exception {
579
    public void testForNotRegen() throws Exception {
580
        testFile = new File(getWorkDir(), "Test.java");
580
        testFile = new File(getWorkDir(), "Test.java");
581
        TestUtilities.copyStringToFile(testFile, 
581
        TestUtilities.copyStringToFile(testFile,
582
            "package personal;\n" +
582
            "package personal;\n" +
583
            "\n" +
583
            "\n" +
584
            "import javax.swing.text.Element;\n" +
584
            "import javax.swing.text.Element;\n" +
 Lines 595-601    Link Here 
595
            "    }\n" +
595
            "    }\n" +
596
            "}\n");
596
            "}\n");
597
597
598
         String golden = 
598
         String golden =
599
            "package personal;\n" +
599
            "package personal;\n" +
600
            "\n" +
600
            "\n" +
601
            "import javax.swing.text.Element;\n" +
601
            "import javax.swing.text.Element;\n" +
 Lines 623-639    Link Here 
623
                // rewrite in initializer
623
                // rewrite in initializer
624
                VariableTree initalizer = (VariableTree) forLoop.getInitializer().get(0);
624
                VariableTree initalizer = (VariableTree) forLoop.getInitializer().get(0);
625
                workingCopy.rewrite(initalizer, make.setLabel(initalizer, "newVar"));
625
                workingCopy.rewrite(initalizer, make.setLabel(initalizer, "newVar"));
626
                
626
627
                // rewrite in condition
627
                // rewrite in condition
628
                BinaryTree condition = (BinaryTree) forLoop.getCondition();
628
                BinaryTree condition = (BinaryTree) forLoop.getCondition();
629
                IdentifierTree ident = (IdentifierTree) condition.getLeftOperand();
629
                IdentifierTree ident = (IdentifierTree) condition.getLeftOperand();
630
                workingCopy.rewrite(ident, make.setLabel(ident, "newVar"));
630
                workingCopy.rewrite(ident, make.setLabel(ident, "newVar"));
631
                
631
632
                ExpressionStatementTree update = (ExpressionStatementTree) forLoop.getUpdate().get(0);
632
                ExpressionStatementTree update = (ExpressionStatementTree) forLoop.getUpdate().get(0);
633
                UnaryTree unary = (UnaryTree) update.getExpression();
633
                UnaryTree unary = (UnaryTree) update.getExpression();
634
                ident = (IdentifierTree) unary.getExpression();
634
                ident = (IdentifierTree) unary.getExpression();
635
                workingCopy.rewrite(ident, make.setLabel(ident, "newVar"));
635
                workingCopy.rewrite(ident, make.setLabel(ident, "newVar"));
636
                
636
637
                // and finally in the body
637
                // and finally in the body
638
                BlockTree block = (BlockTree) forLoop.getStatement();
638
                BlockTree block = (BlockTree) forLoop.getStatement();
639
                ExpressionStatementTree systemOut = (ExpressionStatementTree) block.getStatements().get(0);
639
                ExpressionStatementTree systemOut = (ExpressionStatementTree) block.getStatements().get(0);
 Lines 641-660    Link Here 
641
                ident = (IdentifierTree) mit.getArguments().get(0);
641
                ident = (IdentifierTree) mit.getArguments().get(0);
642
                workingCopy.rewrite(ident, make.setLabel(ident, "newVar"));
642
                workingCopy.rewrite(ident, make.setLabel(ident, "newVar"));
643
            }
643
            }
644
            
644
645
        };
645
        };
646
        testSource.runModificationTask(task).commit();
646
        testSource.runModificationTask(task).commit();
647
        String res = TestUtilities.copyFileToString(testFile);
647
        String res = TestUtilities.copyFileToString(testFile);
648
        System.err.println(res);
648
        System.err.println(res);
649
        assertEquals(golden, res);
649
        assertEquals(golden, res);
650
    }
650
    }
651
    
651
652
    /**
652
    /**
653
     * #92187: Test for left right side of assignment
653
     * #92187: Test for left right side of assignment
654
     */
654
     */
655
    public void testAssignLeft() throws Exception {
655
    public void testAssignLeft() throws Exception {
656
        testFile = new File(getWorkDir(), "Test.java");
656
        testFile = new File(getWorkDir(), "Test.java");
657
        TestUtilities.copyStringToFile(testFile, 
657
        TestUtilities.copyStringToFile(testFile,
658
            "package personal;\n" +
658
            "package personal;\n" +
659
            "\n" +
659
            "\n" +
660
            "public class Test {\n" +
660
            "public class Test {\n" +
 Lines 663-669    Link Here 
663
            "    }\n" +
663
            "    }\n" +
664
            "}\n");
664
            "}\n");
665
665
666
         String golden = 
666
         String golden =
667
            "package personal;\n" +
667
            "package personal;\n" +
668
            "\n" +
668
            "\n" +
669
            "public class Test {\n" +
669
            "public class Test {\n" +
 Lines 684-703    Link Here 
684
                MemberSelectTree mstCopy = make.setLabel((MemberSelectTree) assignment.getVariable(), "key2");
684
                MemberSelectTree mstCopy = make.setLabel((MemberSelectTree) assignment.getVariable(), "key2");
685
                workingCopy.rewrite(assignment.getVariable(), mstCopy);
685
                workingCopy.rewrite(assignment.getVariable(), mstCopy);
686
            }
686
            }
687
            
687
688
        };
688
        };
689
        testSource.runModificationTask(task).commit();
689
        testSource.runModificationTask(task).commit();
690
        String res = TestUtilities.copyFileToString(testFile);
690
        String res = TestUtilities.copyFileToString(testFile);
691
        System.err.println(res);
691
        System.err.println(res);
692
        assertEquals(golden, res);
692
        assertEquals(golden, res);
693
    }
693
    }
694
    
694
695
    /**
695
    /**
696
     * #92187: Test for right side of assignment
696
     * #92187: Test for right side of assignment
697
     */
697
     */
698
    public void testAssignRight() throws Exception {
698
    public void testAssignRight() throws Exception {
699
        testFile = new File(getWorkDir(), "Test.java");
699
        testFile = new File(getWorkDir(), "Test.java");
700
        TestUtilities.copyStringToFile(testFile, 
700
        TestUtilities.copyStringToFile(testFile,
701
            "package personal;\n" +
701
            "package personal;\n" +
702
            "\n" +
702
            "\n" +
703
            "public class Test {\n" +
703
            "public class Test {\n" +
 Lines 706-712    Link Here 
706
            "    }\n" +
706
            "    }\n" +
707
            "}\n");
707
            "}\n");
708
708
709
         String golden = 
709
         String golden =
710
            "package personal;\n" +
710
            "package personal;\n" +
711
            "\n" +
711
            "\n" +
712
            "public class Test {\n" +
712
            "public class Test {\n" +
 Lines 727-746    Link Here 
727
                IdentifierTree copy = make.setLabel((IdentifierTree) assignment.getExpression(), "key2");
727
                IdentifierTree copy = make.setLabel((IdentifierTree) assignment.getExpression(), "key2");
728
                workingCopy.rewrite(assignment.getExpression(), copy);
728
                workingCopy.rewrite(assignment.getExpression(), copy);
729
            }
729
            }
730
            
730
731
        };
731
        };
732
        testSource.runModificationTask(task).commit();
732
        testSource.runModificationTask(task).commit();
733
        String res = TestUtilities.copyFileToString(testFile);
733
        String res = TestUtilities.copyFileToString(testFile);
734
        System.err.println(res);
734
        System.err.println(res);
735
        assertEquals(golden, res);
735
        assertEquals(golden, res);
736
    }
736
    }
737
    
737
738
    /**
738
    /**
739
     * #92187: Test for right side of assignment
739
     * #92187: Test for right side of assignment
740
     */
740
     */
741
    public void testAssignBoth() throws Exception {
741
    public void testAssignBoth() throws Exception {
742
        testFile = new File(getWorkDir(), "Test.java");
742
        testFile = new File(getWorkDir(), "Test.java");
743
        TestUtilities.copyStringToFile(testFile, 
743
        TestUtilities.copyStringToFile(testFile,
744
            "package personal;\n" +
744
            "package personal;\n" +
745
            "\n" +
745
            "\n" +
746
            "public class Test {\n" +
746
            "public class Test {\n" +
 Lines 749-755    Link Here 
749
            "    }\n" +
749
            "    }\n" +
750
            "}\n");
750
            "}\n");
751
751
752
         String golden = 
752
         String golden =
753
            "package personal;\n" +
753
            "package personal;\n" +
754
            "\n" +
754
            "\n" +
755
            "public class Test {\n" +
755
            "public class Test {\n" +
 Lines 772-791    Link Here 
772
                IdentifierTree copy = make.setLabel((IdentifierTree) assignment.getExpression(), "key2");
772
                IdentifierTree copy = make.setLabel((IdentifierTree) assignment.getExpression(), "key2");
773
                workingCopy.rewrite(assignment.getExpression(), copy);
773
                workingCopy.rewrite(assignment.getExpression(), copy);
774
            }
774
            }
775
            
775
776
        };
776
        };
777
        testSource.runModificationTask(task).commit();
777
        testSource.runModificationTask(task).commit();
778
        String res = TestUtilities.copyFileToString(testFile);
778
        String res = TestUtilities.copyFileToString(testFile);
779
        System.err.println(res);
779
        System.err.println(res);
780
        assertEquals(golden, res);
780
        assertEquals(golden, res);
781
    }
781
    }
782
    
782
783
    /**
783
    /**
784
     * #92187: Test for return rename
784
     * #92187: Test for return rename
785
     */
785
     */
786
    public void testReturn() throws Exception {
786
    public void testReturn() throws Exception {
787
        testFile = new File(getWorkDir(), "Test.java");
787
        testFile = new File(getWorkDir(), "Test.java");
788
        TestUtilities.copyStringToFile(testFile, 
788
        TestUtilities.copyStringToFile(testFile,
789
            "package personal;\n" +
789
            "package personal;\n" +
790
            "\n" +
790
            "\n" +
791
            "public class Test {\n" +
791
            "public class Test {\n" +
 Lines 794-800    Link Here 
794
            "    }\n" +
794
            "    }\n" +
795
            "}\n");
795
            "}\n");
796
796
797
         String golden = 
797
         String golden =
798
            "package personal;\n" +
798
            "package personal;\n" +
799
            "\n" +
799
            "\n" +
800
            "public class Test {\n" +
800
            "public class Test {\n" +
 Lines 813-832    Link Here 
813
                ReturnTree rejturn = (ReturnTree) method.getBody().getStatements().get(0);
813
                ReturnTree rejturn = (ReturnTree) method.getBody().getStatements().get(0);
814
                workingCopy.rewrite(rejturn.getExpression(), make.Identifier("nullanen2"));
814
                workingCopy.rewrite(rejturn.getExpression(), make.Identifier("nullanen2"));
815
            }
815
            }
816
            
816
817
        };
817
        };
818
        testSource.runModificationTask(task).commit();
818
        testSource.runModificationTask(task).commit();
819
        String res = TestUtilities.copyFileToString(testFile);
819
        String res = TestUtilities.copyFileToString(testFile);
820
        System.err.println(res);
820
        System.err.println(res);
821
        assertEquals(golden, res);
821
        assertEquals(golden, res);
822
    }
822
    }
823
    
823
824
    /**
824
    /**
825
     * #92187: Test in PLUS rename
825
     * #92187: Test in PLUS rename
826
     */
826
     */
827
    public void testPlusBinary() throws Exception {
827
    public void testPlusBinary() throws Exception {
828
        testFile = new File(getWorkDir(), "Test.java");
828
        testFile = new File(getWorkDir(), "Test.java");
829
        TestUtilities.copyStringToFile(testFile, 
829
        TestUtilities.copyStringToFile(testFile,
830
            "package personal;\n" +
830
            "package personal;\n" +
831
            "\n" +
831
            "\n" +
832
            "public class Test {\n" +
832
            "public class Test {\n" +
 Lines 835-841    Link Here 
835
            "    }\n" +
835
            "    }\n" +
836
            "}\n");
836
            "}\n");
837
837
838
         String golden = 
838
         String golden =
839
            "package personal;\n" +
839
            "package personal;\n" +
840
            "\n" +
840
            "\n" +
841
            "public class Test {\n" +
841
            "public class Test {\n" +
 Lines 859-878    Link Here 
859
                IdentifierTree ident = (IdentifierTree) in.getRightOperand();
859
                IdentifierTree ident = (IdentifierTree) in.getRightOperand();
860
                workingCopy.rewrite(ident, make.Identifier("key2"));
860
                workingCopy.rewrite(ident, make.Identifier("key2"));
861
            }
861
            }
862
            
862
863
        };
863
        };
864
        testSource.runModificationTask(task).commit();
864
        testSource.runModificationTask(task).commit();
865
        String res = TestUtilities.copyFileToString(testFile);
865
        String res = TestUtilities.copyFileToString(testFile);
866
        System.err.println(res);
866
        System.err.println(res);
867
        assertEquals(golden, res);
867
        assertEquals(golden, res);
868
    }
868
    }
869
    
869
870
    /**
870
    /**
871
     * #92187: Rename in while
871
     * #92187: Rename in while
872
     */
872
     */
873
    public void testRenameInWhile() throws Exception {
873
    public void testRenameInWhile() throws Exception {
874
        testFile = new File(getWorkDir(), "Test.java");
874
        testFile = new File(getWorkDir(), "Test.java");
875
        TestUtilities.copyStringToFile(testFile, 
875
        TestUtilities.copyStringToFile(testFile,
876
            "package personal;\n" +
876
            "package personal;\n" +
877
            "\n" +
877
            "\n" +
878
            "public class Test {\n" +
878
            "public class Test {\n" +
 Lines 884-890    Link Here 
884
            "    }\n" +
884
            "    }\n" +
885
            "}\n");
885
            "}\n");
886
886
887
         String golden = 
887
         String golden =
888
            "package personal;\n" +
888
            "package personal;\n" +
889
            "\n" +
889
            "\n" +
890
            "public class Test {\n" +
890
            "public class Test {\n" +
 Lines 905-917    Link Here 
905
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
905
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
906
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
906
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
907
                workingCopy.rewrite(var, make.setLabel(var, "counter"));
907
                workingCopy.rewrite(var, make.setLabel(var, "counter"));
908
                
908
909
                WhileLoopTree whileLoop = (WhileLoopTree) method.getBody().getStatements().get(1);
909
                WhileLoopTree whileLoop = (WhileLoopTree) method.getBody().getStatements().get(1);
910
                ParenthesizedTree paren = (ParenthesizedTree) whileLoop.getCondition();
910
                ParenthesizedTree paren = (ParenthesizedTree) whileLoop.getCondition();
911
                BinaryTree lessThan = (BinaryTree) paren.getExpression();
911
                BinaryTree lessThan = (BinaryTree) paren.getExpression();
912
                IdentifierTree left = (IdentifierTree) lessThan.getLeftOperand();
912
                IdentifierTree left = (IdentifierTree) lessThan.getLeftOperand();
913
                workingCopy.rewrite(left, make.setLabel(left, "counter"));
913
                workingCopy.rewrite(left, make.setLabel(left, "counter"));
914
                
914
915
                ExpressionStatementTree expr = (ExpressionStatementTree) ((BlockTree) whileLoop.getStatement()).getStatements().get(0);
915
                ExpressionStatementTree expr = (ExpressionStatementTree) ((BlockTree) whileLoop.getStatement()).getStatements().get(0);
916
                AssignmentTree assign = (AssignmentTree) expr.getExpression();
916
                AssignmentTree assign = (AssignmentTree) expr.getExpression();
917
                left = (IdentifierTree) assign.getVariable();
917
                left = (IdentifierTree) assign.getVariable();
 Lines 920-939    Link Here 
920
                left = (IdentifierTree) right.getLeftOperand();
920
                left = (IdentifierTree) right.getLeftOperand();
921
                workingCopy.rewrite(left, make.setLabel(left, "counter"));
921
                workingCopy.rewrite(left, make.setLabel(left, "counter"));
922
            }
922
            }
923
            
923
924
        };
924
        };
925
        testSource.runModificationTask(task).commit();
925
        testSource.runModificationTask(task).commit();
926
        String res = TestUtilities.copyFileToString(testFile);
926
        String res = TestUtilities.copyFileToString(testFile);
927
        System.err.println(res);
927
        System.err.println(res);
928
        assertEquals(golden, res);
928
        assertEquals(golden, res);
929
    }
929
    }
930
    
930
931
    /**
931
    /**
932
     * #92187: Rename in do while
932
     * #92187: Rename in do while
933
     */
933
     */
934
    public void testRenameInDoWhile() throws Exception {
934
    public void testRenameInDoWhile() throws Exception {
935
        testFile = new File(getWorkDir(), "Test.java");
935
        testFile = new File(getWorkDir(), "Test.java");
936
        TestUtilities.copyStringToFile(testFile, 
936
        TestUtilities.copyStringToFile(testFile,
937
            "package personal;\n" +
937
            "package personal;\n" +
938
            "\n" +
938
            "\n" +
939
            "public class Test {\n" +
939
            "public class Test {\n" +
 Lines 945-951    Link Here 
945
            "    }\n" +
945
            "    }\n" +
946
            "}\n");
946
            "}\n");
947
947
948
         String golden = 
948
         String golden =
949
            "package personal;\n" +
949
            "package personal;\n" +
950
            "\n" +
950
            "\n" +
951
            "public class Test {\n" +
951
            "public class Test {\n" +
 Lines 966-996    Link Here 
966
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
966
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
967
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
967
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
968
                workingCopy.rewrite(var, make.setLabel(var, "counter"));
968
                workingCopy.rewrite(var, make.setLabel(var, "counter"));
969
                
969
970
                DoWhileLoopTree doWhileLoop = (DoWhileLoopTree) method.getBody().getStatements().get(1);
970
                DoWhileLoopTree doWhileLoop = (DoWhileLoopTree) method.getBody().getStatements().get(1);
971
                ParenthesizedTree paren = (ParenthesizedTree) doWhileLoop.getCondition();
971
                ParenthesizedTree paren = (ParenthesizedTree) doWhileLoop.getCondition();
972
                BinaryTree lessThan = (BinaryTree) paren.getExpression();
972
                BinaryTree lessThan = (BinaryTree) paren.getExpression();
973
                IdentifierTree left = (IdentifierTree) lessThan.getLeftOperand();
973
                IdentifierTree left = (IdentifierTree) lessThan.getLeftOperand();
974
                workingCopy.rewrite(left, make.setLabel(left, "counter"));
974
                workingCopy.rewrite(left, make.setLabel(left, "counter"));
975
                
975
976
                ExpressionStatementTree expr = (ExpressionStatementTree) ((BlockTree) doWhileLoop.getStatement()).getStatements().get(0);
976
                ExpressionStatementTree expr = (ExpressionStatementTree) ((BlockTree) doWhileLoop.getStatement()).getStatements().get(0);
977
                UnaryTree unary = (UnaryTree) expr.getExpression();
977
                UnaryTree unary = (UnaryTree) expr.getExpression();
978
                workingCopy.rewrite(unary.getExpression(), make.setLabel(unary.getExpression(), "counter"));
978
                workingCopy.rewrite(unary.getExpression(), make.setLabel(unary.getExpression(), "counter"));
979
            }
979
            }
980
            
980
981
        };
981
        };
982
        testSource.runModificationTask(task).commit();
982
        testSource.runModificationTask(task).commit();
983
        String res = TestUtilities.copyFileToString(testFile);
983
        String res = TestUtilities.copyFileToString(testFile);
984
        System.err.println(res);
984
        System.err.println(res);
985
        assertEquals(golden, res);
985
        assertEquals(golden, res);
986
    }
986
    }
987
    
987
988
    /**
988
    /**
989
     * #92187: Rename in for each
989
     * #92187: Rename in for each
990
     */
990
     */
991
    public void testRenameInForEach() throws Exception {
991
    public void testRenameInForEach() throws Exception {
992
        testFile = new File(getWorkDir(), "Test.java");
992
        testFile = new File(getWorkDir(), "Test.java");
993
        TestUtilities.copyStringToFile(testFile, 
993
        TestUtilities.copyStringToFile(testFile,
994
            "package personal;\n" +
994
            "package personal;\n" +
995
            "\n" +
995
            "\n" +
996
            "public class Test {\n" +
996
            "public class Test {\n" +
 Lines 1002-1008    Link Here 
1002
            "    }\n" +
1002
            "    }\n" +
1003
            "}\n");
1003
            "}\n");
1004
1004
1005
         String golden = 
1005
         String golden =
1006
            "package personal;\n" +
1006
            "package personal;\n" +
1007
            "\n" +
1007
            "\n" +
1008
            "public class Test {\n" +
1008
            "public class Test {\n" +
 Lines 1013-1019    Link Here 
1013
            "        }\n" +
1013
            "        }\n" +
1014
            "    }\n" +
1014
            "    }\n" +
1015
            "}\n";
1015
            "}\n";
1016
                 
1016
1017
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1017
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1018
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1018
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1019
1019
 Lines 1024-1030    Link Here 
1024
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
1024
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
1025
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
1025
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
1026
                workingCopy.rewrite(var, make.setLabel(var, "list"));
1026
                workingCopy.rewrite(var, make.setLabel(var, "list"));
1027
                
1027
1028
                EnhancedForLoopTree forEach = (EnhancedForLoopTree) method.getBody().getStatements().get(1);
1028
                EnhancedForLoopTree forEach = (EnhancedForLoopTree) method.getBody().getStatements().get(1);
1029
                var = forEach.getVariable();
1029
                var = forEach.getVariable();
1030
                workingCopy.rewrite(var, make.setLabel(var, "object"));
1030
                workingCopy.rewrite(var, make.setLabel(var, "object"));
 Lines 1034-1043    Link Here 
1034
                ExpressionStatementTree est = (ExpressionStatementTree) body.getStatements().get(0);
1034
                ExpressionStatementTree est = (ExpressionStatementTree) body.getStatements().get(0);
1035
                MethodInvocationTree mit = (MethodInvocationTree) est.getExpression();
1035
                MethodInvocationTree mit = (MethodInvocationTree) est.getExpression();
1036
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
1036
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
1037
                
1037
1038
                workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "object"));
1038
                workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "object"));
1039
            }
1039
            }
1040
            
1040
1041
        };
1041
        };
1042
        testSource.runModificationTask(task).commit();
1042
        testSource.runModificationTask(task).commit();
1043
        String res = TestUtilities.copyFileToString(testFile);
1043
        String res = TestUtilities.copyFileToString(testFile);
 Lines 1050-1056    Link Here 
1050
     */
1050
     */
1051
    public void testRenameInSyncro() throws Exception {
1051
    public void testRenameInSyncro() throws Exception {
1052
        testFile = new File(getWorkDir(), "Test.java");
1052
        testFile = new File(getWorkDir(), "Test.java");
1053
        TestUtilities.copyStringToFile(testFile, 
1053
        TestUtilities.copyStringToFile(testFile,
1054
            "package personal;\n" +
1054
            "package personal;\n" +
1055
            "\n" +
1055
            "\n" +
1056
            "public class Test {\n" +
1056
            "public class Test {\n" +
 Lines 1063-1070    Link Here 
1063
            "        }\n" +
1063
            "        }\n" +
1064
            "    }\n" +
1064
            "    }\n" +
1065
            "}\n");
1065
            "}\n");
1066
        
1066
1067
         String golden = 
1067
         String golden =
1068
            "package personal;\n" +
1068
            "package personal;\n" +
1069
            "\n" +
1069
            "\n" +
1070
            "public class Test {\n" +
1070
            "public class Test {\n" +
 Lines 1077-1083    Link Here 
1077
            "        }\n" +
1077
            "        }\n" +
1078
            "    }\n" +
1078
            "    }\n" +
1079
            "}\n";
1079
            "}\n";
1080
                 
1080
1081
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1081
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1082
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1082
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1083
1083
 Lines 1088-1094    Link Here 
1088
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
1088
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
1089
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
1089
                VariableTree var = (VariableTree) method.getBody().getStatements().get(0);
1090
                workingCopy.rewrite(var, make.setLabel(var, "zamek"));
1090
                workingCopy.rewrite(var, make.setLabel(var, "zamek"));
1091
                
1091
1092
                SynchronizedTree syncro = (SynchronizedTree) method.getBody().getStatements().get(1);
1092
                SynchronizedTree syncro = (SynchronizedTree) method.getBody().getStatements().get(1);
1093
                ParenthesizedTree petecko = (ParenthesizedTree) syncro.getExpression();
1093
                ParenthesizedTree petecko = (ParenthesizedTree) syncro.getExpression();
1094
                IdentifierTree ident = (IdentifierTree) petecko.getExpression();
1094
                IdentifierTree ident = (IdentifierTree) petecko.getExpression();
 Lines 1097-1119    Link Here 
1097
                ExpressionStatementTree est = (ExpressionStatementTree) body.getStatements().get(1);
1097
                ExpressionStatementTree est = (ExpressionStatementTree) body.getStatements().get(1);
1098
                MethodInvocationTree mit = (MethodInvocationTree) est.getExpression();
1098
                MethodInvocationTree mit = (MethodInvocationTree) est.getExpression();
1099
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
1099
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
1100
                
1100
1101
                workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "zamek"));
1101
                workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "zamek"));
1102
            }
1102
            }
1103
            
1103
1104
        };
1104
        };
1105
        testSource.runModificationTask(task).commit();
1105
        testSource.runModificationTask(task).commit();
1106
        String res = TestUtilities.copyFileToString(testFile);
1106
        String res = TestUtilities.copyFileToString(testFile);
1107
        System.err.println(res);
1107
        System.err.println(res);
1108
        assertEquals(golden, res);
1108
        assertEquals(golden, res);
1109
    }
1109
    }
1110
    
1110
1111
    /**
1111
    /**
1112
     * #92187: Test rename in catch
1112
     * #92187: Test rename in catch
1113
     */
1113
     */
1114
    public void testRenameInCatch() throws Exception {
1114
    public void testRenameInCatch() throws Exception {
1115
        testFile = new File(getWorkDir(), "Test.java");
1115
        testFile = new File(getWorkDir(), "Test.java");
1116
        TestUtilities.copyStringToFile(testFile, 
1116
        TestUtilities.copyStringToFile(testFile,
1117
            "package personal;\n" +
1117
            "package personal;\n" +
1118
            "\n" +
1118
            "\n" +
1119
            "public class Test {\n" +
1119
            "public class Test {\n" +
 Lines 1126-1133    Link Here 
1126
            "        }\n" +
1126
            "        }\n" +
1127
            "    }\n" +
1127
            "    }\n" +
1128
            "}\n");
1128
            "}\n");
1129
        
1129
1130
         String golden = 
1130
         String golden =
1131
            "package personal;\n" +
1131
            "package personal;\n" +
1132
            "\n" +
1132
            "\n" +
1133
            "public class Test {\n" +
1133
            "public class Test {\n" +
 Lines 1140-1146    Link Here 
1140
            "        }\n" +
1140
            "        }\n" +
1141
            "    }\n" +
1141
            "    }\n" +
1142
            "}\n";
1142
            "}\n";
1143
                 
1143
1144
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1144
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1145
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1145
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1146
1146
 Lines 1160-1180    Link Here 
1160
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
1160
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
1161
                workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "vyjimka"));
1161
                workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "vyjimka"));
1162
            }
1162
            }
1163
            
1163
1164
        };
1164
        };
1165
        testSource.runModificationTask(task).commit();
1165
        testSource.runModificationTask(task).commit();
1166
        String res = TestUtilities.copyFileToString(testFile);
1166
        String res = TestUtilities.copyFileToString(testFile);
1167
        System.err.println(res);
1167
        System.err.println(res);
1168
        assertEquals(golden, res);
1168
        assertEquals(golden, res);
1169
    }
1169
    }
1170
    
1170
1171
    /**
1171
    /**
1172
     * #92187: Test rename in assign op. bit or
1172
     * #92187: Test rename in assign op. bit or
1173
     * todo (#pf): extend test to replace right side and operator too!
1173
     * todo (#pf): extend test to replace right side and operator too!
1174
     */
1174
     */
1175
    public void testRenameInAssignOp() throws Exception {
1175
    public void testRenameInAssignOp() throws Exception {
1176
        testFile = new File(getWorkDir(), "Test.java");
1176
        testFile = new File(getWorkDir(), "Test.java");
1177
        TestUtilities.copyStringToFile(testFile, 
1177
        TestUtilities.copyStringToFile(testFile,
1178
            "package personal;\n" +
1178
            "package personal;\n" +
1179
            "\n" +
1179
            "\n" +
1180
            "public class Test {\n" +
1180
            "public class Test {\n" +
 Lines 1183-1190    Link Here 
1183
            "        bits2 |= 0x12;\n" +
1183
            "        bits2 |= 0x12;\n" +
1184
            "    }\n" +
1184
            "    }\n" +
1185
            "}\n");
1185
            "}\n");
1186
        
1186
1187
         String golden = 
1187
         String golden =
1188
            "package personal;\n" +
1188
            "package personal;\n" +
1189
            "\n" +
1189
            "\n" +
1190
            "public class Test {\n" +
1190
            "public class Test {\n" +
 Lines 1193-1199    Link Here 
1193
            "        bits |= 0x12;\n" +
1193
            "        bits |= 0x12;\n" +
1194
            "    }\n" +
1194
            "    }\n" +
1195
            "}\n";
1195
            "}\n";
1196
                 
1196
1197
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1197
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1198
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1198
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1199
1199
 Lines 1210-1223    Link Here 
1210
                IdentifierTree ident = (IdentifierTree) cat.getVariable();
1210
                IdentifierTree ident = (IdentifierTree) cat.getVariable();
1211
                workingCopy.rewrite(ident, make.setLabel(ident, "bits"));
1211
                workingCopy.rewrite(ident, make.setLabel(ident, "bits"));
1212
            }
1212
            }
1213
            
1213
1214
        };
1214
        };
1215
        testSource.runModificationTask(task).commit();
1215
        testSource.runModificationTask(task).commit();
1216
        String res = TestUtilities.copyFileToString(testFile);
1216
        String res = TestUtilities.copyFileToString(testFile);
1217
        System.err.println(res);
1217
        System.err.println(res);
1218
        assertEquals(golden, res);
1218
        assertEquals(golden, res);
1219
    }
1219
    }
1220
    
1220
1221
    /**
1221
    /**
1222
     * #92187: Test rename in assign op. bit or
1222
     * #92187: Test rename in assign op. bit or
1223
     * both, var and index are renamed in this test.
1223
     * both, var and index are renamed in this test.
 Lines 1225-1231    Link Here 
1225
     */
1225
     */
1226
    public void testRenameInArrayIndex() throws Exception {
1226
    public void testRenameInArrayIndex() throws Exception {
1227
        testFile = new File(getWorkDir(), "Test.java");
1227
        testFile = new File(getWorkDir(), "Test.java");
1228
        TestUtilities.copyStringToFile(testFile, 
1228
        TestUtilities.copyStringToFile(testFile,
1229
            "package personal;\n" +
1229
            "package personal;\n" +
1230
            "\n" +
1230
            "\n" +
1231
            "public class Test {\n" +
1231
            "public class Test {\n" +
 Lines 1235-1242    Link Here 
1235
            "        System.err.println(i[pos-1]);\n" +
1235
            "        System.err.println(i[pos-1]);\n" +
1236
            "    }\n" +
1236
            "    }\n" +
1237
            "}\n");
1237
            "}\n");
1238
        
1238
1239
         String golden = 
1239
         String golden =
1240
            "package personal;\n" +
1240
            "package personal;\n" +
1241
            "\n" +
1241
            "\n" +
1242
            "public class Test {\n" +
1242
            "public class Test {\n" +
 Lines 1246-1252    Link Here 
1246
            "        System.err.println(icko[position-1]);\n" +
1246
            "        System.err.println(icko[position-1]);\n" +
1247
            "    }\n" +
1247
            "    }\n" +
1248
            "}\n";
1248
            "}\n";
1249
                 
1249
1250
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1250
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1251
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1251
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1252
1252
 Lines 1269-1288    Link Here 
1269
                ident = (IdentifierTree) binary.getLeftOperand();
1269
                ident = (IdentifierTree) binary.getLeftOperand();
1270
                workingCopy.rewrite(ident, make.setLabel(ident, "position"));
1270
                workingCopy.rewrite(ident, make.setLabel(ident, "position"));
1271
            }
1271
            }
1272
            
1272
1273
        };
1273
        };
1274
        testSource.runModificationTask(task).commit();
1274
        testSource.runModificationTask(task).commit();
1275
        String res = TestUtilities.copyFileToString(testFile);
1275
        String res = TestUtilities.copyFileToString(testFile);
1276
        System.err.println(res);
1276
        System.err.println(res);
1277
        assertEquals(golden, res);
1277
        assertEquals(golden, res);
1278
    }
1278
    }
1279
    
1279
1280
    /**
1280
    /**
1281
     * #92187: Test rename in type cast
1281
     * #92187: Test rename in type cast
1282
     */
1282
     */
1283
    public void testRenameInTypeCast() throws Exception {
1283
    public void testRenameInTypeCast() throws Exception {
1284
        testFile = new File(getWorkDir(), "Test.java");
1284
        testFile = new File(getWorkDir(), "Test.java");
1285
        TestUtilities.copyStringToFile(testFile, 
1285
        TestUtilities.copyStringToFile(testFile,
1286
            "package personal;\n" +
1286
            "package personal;\n" +
1287
            "\n" +
1287
            "\n" +
1288
            "public class Test {\n" +
1288
            "public class Test {\n" +
 Lines 1292-1299    Link Here 
1292
            "        Item item = (Item) o;\n" +
1292
            "        Item item = (Item) o;\n" +
1293
            "    }\n" +
1293
            "    }\n" +
1294
            "}\n");
1294
            "}\n");
1295
        
1295
1296
         String golden = 
1296
         String golden =
1297
            "package personal;\n" +
1297
            "package personal;\n" +
1298
            "\n" +
1298
            "\n" +
1299
            "public class Test {\n" +
1299
            "public class Test {\n" +
 Lines 1303-1309    Link Here 
1303
            "        It it = (It) object;\n" +
1303
            "        It it = (It) object;\n" +
1304
            "    }\n" +
1304
            "    }\n" +
1305
            "}\n";
1305
            "}\n";
1306
                 
1306
1307
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1307
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1308
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1308
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1309
1309
 Lines 1330-1349    Link Here 
1330
                ident = (IdentifierTree) tct.getExpression();
1330
                ident = (IdentifierTree) tct.getExpression();
1331
                workingCopy.rewrite(ident, make.setLabel(ident, "object"));
1331
                workingCopy.rewrite(ident, make.setLabel(ident, "object"));
1332
            }
1332
            }
1333
            
1333
1334
        };
1334
        };
1335
        testSource.runModificationTask(task).commit();
1335
        testSource.runModificationTask(task).commit();
1336
        String res = TestUtilities.copyFileToString(testFile);
1336
        String res = TestUtilities.copyFileToString(testFile);
1337
        System.err.println(res);
1337
        System.err.println(res);
1338
        assertEquals(golden, res);
1338
        assertEquals(golden, res);
1339
    }
1339
    }
1340
    
1340
1341
    /**
1341
    /**
1342
     * #92187: Test rename in assert
1342
     * #92187: Test rename in assert
1343
     */
1343
     */
1344
    public void testRenameInAssert() throws Exception {
1344
    public void testRenameInAssert() throws Exception {
1345
        testFile = new File(getWorkDir(), "Test.java");
1345
        testFile = new File(getWorkDir(), "Test.java");
1346
        TestUtilities.copyStringToFile(testFile, 
1346
        TestUtilities.copyStringToFile(testFile,
1347
            "package personal;\n" +
1347
            "package personal;\n" +
1348
            "\n" +
1348
            "\n" +
1349
            "public class Test {\n" +
1349
            "public class Test {\n" +
 Lines 1351-1358    Link Here 
1351
            "        assert a == 12 : a;\n" +
1351
            "        assert a == 12 : a;\n" +
1352
            "    }\n" +
1352
            "    }\n" +
1353
            "}\n");
1353
            "}\n");
1354
        
1354
1355
         String golden = 
1355
         String golden =
1356
            "package personal;\n" +
1356
            "package personal;\n" +
1357
            "\n" +
1357
            "\n" +
1358
            "public class Test {\n" +
1358
            "public class Test {\n" +
 Lines 1360-1366    Link Here 
1360
            "        assert ada == 12 : ada;\n" +
1360
            "        assert ada == 12 : ada;\n" +
1361
            "    }\n" +
1361
            "    }\n" +
1362
            "}\n";
1362
            "}\n";
1363
                 
1363
1364
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1364
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1365
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1365
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1366
1366
 Lines 1379-1398    Link Here 
1379
                ident = (IdentifierTree) ass.getDetail();
1379
                ident = (IdentifierTree) ass.getDetail();
1380
                workingCopy.rewrite(ident, make.setLabel(ident, "ada"));
1380
                workingCopy.rewrite(ident, make.setLabel(ident, "ada"));
1381
            }
1381
            }
1382
            
1382
1383
        };
1383
        };
1384
        testSource.runModificationTask(task).commit();
1384
        testSource.runModificationTask(task).commit();
1385
        String res = TestUtilities.copyFileToString(testFile);
1385
        String res = TestUtilities.copyFileToString(testFile);
1386
        System.err.println(res);
1386
        System.err.println(res);
1387
        assertEquals(golden, res);
1387
        assertEquals(golden, res);
1388
    }
1388
    }
1389
    
1389
1390
    /**
1390
    /**
1391
     * #92187: Test rename in throw statement
1391
     * #92187: Test rename in throw statement
1392
     */
1392
     */
1393
    public void testRenameInThrowSt() throws Exception {
1393
    public void testRenameInThrowSt() throws Exception {
1394
        testFile = new File(getWorkDir(), "Test.java");
1394
        testFile = new File(getWorkDir(), "Test.java");
1395
        TestUtilities.copyStringToFile(testFile, 
1395
        TestUtilities.copyStringToFile(testFile,
1396
            "package personal;\n" +
1396
            "package personal;\n" +
1397
            "\n" +
1397
            "\n" +
1398
            "public class Test {\n" +
1398
            "public class Test {\n" +
 Lines 1400-1407    Link Here 
1400
            "        throw new NullPointerException();\n" +
1400
            "        throw new NullPointerException();\n" +
1401
            "    }\n" +
1401
            "    }\n" +
1402
            "}\n");
1402
            "}\n");
1403
        
1403
1404
         String golden = 
1404
         String golden =
1405
            "package personal;\n" +
1405
            "package personal;\n" +
1406
            "\n" +
1406
            "\n" +
1407
            "public class Test {\n" +
1407
            "public class Test {\n" +
 Lines 1409-1415    Link Here 
1409
            "        throw new EnpeEcko();\n" +
1409
            "        throw new EnpeEcko();\n" +
1410
            "    }\n" +
1410
            "    }\n" +
1411
            "}\n";
1411
            "}\n";
1412
                 
1412
1413
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1413
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1414
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1414
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1415
1415
 Lines 1424-1443    Link Here 
1424
                IdentifierTree ident = (IdentifierTree) nct.getIdentifier();
1424
                IdentifierTree ident = (IdentifierTree) nct.getIdentifier();
1425
                workingCopy.rewrite(ident, make.setLabel(ident, "EnpeEcko"));
1425
                workingCopy.rewrite(ident, make.setLabel(ident, "EnpeEcko"));
1426
            }
1426
            }
1427
            
1427
1428
        };
1428
        };
1429
        testSource.runModificationTask(task).commit();
1429
        testSource.runModificationTask(task).commit();
1430
        String res = TestUtilities.copyFileToString(testFile);
1430
        String res = TestUtilities.copyFileToString(testFile);
1431
        System.err.println(res);
1431
        System.err.println(res);
1432
        assertEquals(golden, res);
1432
        assertEquals(golden, res);
1433
    }
1433
    }
1434
    
1434
1435
    /**
1435
    /**
1436
     * #92187: Test rename in conditional
1436
     * #92187: Test rename in conditional
1437
     */
1437
     */
1438
    public void testRenameInConditional() throws Exception {
1438
    public void testRenameInConditional() throws Exception {
1439
        testFile = new File(getWorkDir(), "Test.java");
1439
        testFile = new File(getWorkDir(), "Test.java");
1440
        TestUtilities.copyStringToFile(testFile, 
1440
        TestUtilities.copyStringToFile(testFile,
1441
            "package personal;\n" +
1441
            "package personal;\n" +
1442
            "\n" +
1442
            "\n" +
1443
            "public class Test {\n" +
1443
            "public class Test {\n" +
 Lines 1445-1452    Link Here 
1445
            "        int result = ada == 10 ? ada++ : --ada;\n" +
1445
            "        int result = ada == 10 ? ada++ : --ada;\n" +
1446
            "    }\n" +
1446
            "    }\n" +
1447
            "}\n");
1447
            "}\n");
1448
        
1448
1449
         String golden = 
1449
         String golden =
1450
            "package personal;\n" +
1450
            "package personal;\n" +
1451
            "\n" +
1451
            "\n" +
1452
            "public class Test {\n" +
1452
            "public class Test {\n" +
 Lines 1454-1460    Link Here 
1454
            "        int result = alda == 10 ? alda++ : --alda;\n" +
1454
            "        int result = alda == 10 ? alda++ : --alda;\n" +
1455
            "    }\n" +
1455
            "    }\n" +
1456
            "}\n";
1456
            "}\n";
1457
                 
1457
1458
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1458
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1459
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1459
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1460
1460
 Lines 1478-1484    Link Here 
1478
                ident = (IdentifierTree) falsePart.getExpression();
1478
                ident = (IdentifierTree) falsePart.getExpression();
1479
                workingCopy.rewrite(ident, make.setLabel(ident, "alda"));
1479
                workingCopy.rewrite(ident, make.setLabel(ident, "alda"));
1480
            }
1480
            }
1481
            
1481
1482
        };
1482
        };
1483
        testSource.runModificationTask(task).commit();
1483
        testSource.runModificationTask(task).commit();
1484
        String res = TestUtilities.copyFileToString(testFile);
1484
        String res = TestUtilities.copyFileToString(testFile);
 Lines 1495-1501    Link Here 
1495
        String golden = "package personal;\n\npublic class Test {\n    public Object method() {\n        zacatek_smycky: for (int i = 0; i < 10; i++) {\n        }\n    }\n}\n";
1495
        String golden = "package personal;\n\npublic class Test {\n    public Object method() {\n        zacatek_smycky: for (int i = 0; i < 10; i++) {\n        }\n    }\n}\n";
1496
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1496
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1497
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1497
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1498
            
1498
1499
            public void run(WorkingCopy workingCopy) throws IOException {
1499
            public void run(WorkingCopy workingCopy) throws IOException {
1500
                workingCopy.toPhase(Phase.RESOLVED);
1500
                workingCopy.toPhase(Phase.RESOLVED);
1501
                TreeMaker make = workingCopy.getTreeMaker();
1501
                TreeMaker make = workingCopy.getTreeMaker();
 Lines 1505-1519    Link Here 
1505
                LabeledStatementTree lst = (LabeledStatementTree)block.getStatements().get(0);
1505
                LabeledStatementTree lst = (LabeledStatementTree)block.getStatements().get(0);
1506
                workingCopy.rewrite(lst, make.setLabel(lst, "zacatek_smycky"));
1506
                workingCopy.rewrite(lst, make.setLabel(lst, "zacatek_smycky"));
1507
            }
1507
            }
1508
            
1508
1509
            
1509
1510
        };
1510
        };
1511
        testSource.runModificationTask(task).commit();
1511
        testSource.runModificationTask(task).commit();
1512
        String res = TestUtilities.copyFileToString(testFile);
1512
        String res = TestUtilities.copyFileToString(testFile);
1513
        System.err.println(res);
1513
        System.err.println(res);
1514
        assertEquals(golden, res);
1514
        assertEquals(golden, res);
1515
    }
1515
    }
1516
    
1516
1517
    /**
1517
    /**
1518
     * #92187: Test rename in continue
1518
     * #92187: Test rename in continue
1519
     */
1519
     */
 Lines 1524-1530    Link Here 
1524
        String golden = "package personal;\n\npublic class Test {\n    public Object method() {\n        zacatek_smycky: for (int i = 0; i < 10; i++) {\n            continue zacatek_smycky;\n        }\n    }\n}\n";
1524
        String golden = "package personal;\n\npublic class Test {\n    public Object method() {\n        zacatek_smycky: for (int i = 0; i < 10; i++) {\n            continue zacatek_smycky;\n        }\n    }\n}\n";
1525
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1525
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1526
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1526
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1527
            
1527
1528
            public void run(WorkingCopy workingCopy) throws IOException {
1528
            public void run(WorkingCopy workingCopy) throws IOException {
1529
                workingCopy.toPhase(Phase.RESOLVED);
1529
                workingCopy.toPhase(Phase.RESOLVED);
1530
                TreeMaker make = workingCopy.getTreeMaker();
1530
                TreeMaker make = workingCopy.getTreeMaker();
 Lines 1538-1544    Link Here 
1538
                ContinueTree ct = (ContinueTree)forTree.getStatements().get(0);
1538
                ContinueTree ct = (ContinueTree)forTree.getStatements().get(0);
1539
                workingCopy.rewrite(ct, make.setLabel(ct, "zacatek_smycky"));
1539
                workingCopy.rewrite(ct, make.setLabel(ct, "zacatek_smycky"));
1540
            }
1540
            }
1541
            
1541
1542
        };
1542
        };
1543
        testSource.runModificationTask(task).commit();
1543
        testSource.runModificationTask(task).commit();
1544
        String res = TestUtilities.copyFileToString(testFile);
1544
        String res = TestUtilities.copyFileToString(testFile);
 Lines 1555-1561    Link Here 
1555
        String golden = "package personal;\n\npublic class Test {\n    public Object method() {\n        zacatek_smycky: for (int i = 0; i < 10; i++) {\n            break zacatek_smycky;\n        }\n    }\n}\n";
1555
        String golden = "package personal;\n\npublic class Test {\n    public Object method() {\n        zacatek_smycky: for (int i = 0; i < 10; i++) {\n            break zacatek_smycky;\n        }\n    }\n}\n";
1556
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1556
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1557
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1557
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1558
            
1558
1559
            public void run(WorkingCopy workingCopy)
1559
            public void run(WorkingCopy workingCopy)
1560
                    throws IOException {
1560
                    throws IOException {
1561
                workingCopy.toPhase(Phase.RESOLVED);
1561
                workingCopy.toPhase(Phase.RESOLVED);
 Lines 1570-1590    Link Here 
1570
                BreakTree bt = (BreakTree)forTree.getStatements().get(0);
1570
                BreakTree bt = (BreakTree)forTree.getStatements().get(0);
1571
                workingCopy.rewrite(bt, make.setLabel(bt, "zacatek_smycky"));
1571
                workingCopy.rewrite(bt, make.setLabel(bt, "zacatek_smycky"));
1572
            }
1572
            }
1573
            
1573
1574
        };
1574
        };
1575
        testSource.runModificationTask(task).commit();
1575
        testSource.runModificationTask(task).commit();
1576
        String res = TestUtilities.copyFileToString(testFile);
1576
        String res = TestUtilities.copyFileToString(testFile);
1577
        System.err.println(res);
1577
        System.err.println(res);
1578
        assertEquals(golden, res);
1578
        assertEquals(golden, res);
1579
    }
1579
    }
1580
    
1580
1581
    /**
1581
    /**
1582
     * #88073: Test rename in loc. var type param.
1582
     * #88073: Test rename in loc. var type param.
1583
     */
1583
     */
1584
    public void testRenameLocVarTypePar() throws Exception {
1584
    public void testRenameLocVarTypePar() throws Exception {
1585
        testFile = new File(getWorkDir(), "Test.java");
1585
        testFile = new File(getWorkDir(), "Test.java");
1586
        testFile = new File(getWorkDir(), "Test.java");
1586
        testFile = new File(getWorkDir(), "Test.java");
1587
        TestUtilities.copyStringToFile(testFile, 
1587
        TestUtilities.copyStringToFile(testFile,
1588
            "package personal;\n\n" +
1588
            "package personal;\n\n" +
1589
            "import java.util.*;\n" +
1589
            "import java.util.*;\n" +
1590
            "\n" +
1590
            "\n" +
 Lines 1594-1601    Link Here 
1594
            "        Map<Data,String> map2 = new TreeMap<Data, String>();\n" +
1594
            "        Map<Data,String> map2 = new TreeMap<Data, String>();\n" +
1595
            "    }\n" +
1595
            "    }\n" +
1596
            "}\n");
1596
            "}\n");
1597
        
1597
1598
         String golden = 
1598
         String golden =
1599
            "package personal;\n\n" +
1599
            "package personal;\n\n" +
1600
            "import java.util.*;\n" +
1600
            "import java.util.*;\n" +
1601
            "\n" +
1601
            "\n" +
 Lines 1605-1614    Link Here 
1605
            "        Map<DataRen,String> map2 = new TreeMap<DataRen, String>();\n" +
1605
            "        Map<DataRen,String> map2 = new TreeMap<DataRen, String>();\n" +
1606
            "    }\n" +
1606
            "    }\n" +
1607
            "}\n";
1607
            "}\n";
1608
         
1608
1609
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1609
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1610
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1610
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1611
            
1611
1612
            public void run(WorkingCopy workingCopy)
1612
            public void run(WorkingCopy workingCopy)
1613
                    throws IOException {
1613
                    throws IOException {
1614
                workingCopy.toPhase(Phase.RESOLVED);
1614
                workingCopy.toPhase(Phase.RESOLVED);
 Lines 1616-1632    Link Here 
1616
                ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
1616
                ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
1617
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
1617
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
1618
                BlockTree block = method.getBody();
1618
                BlockTree block = method.getBody();
1619
                
1619
1620
                VariableTree vt = (VariableTree) block.getStatements().get(0);
1620
                VariableTree vt = (VariableTree) block.getStatements().get(0);
1621
                ParameterizedTypeTree ptt = (ParameterizedTypeTree) vt.getType();
1621
                ParameterizedTypeTree ptt = (ParameterizedTypeTree) vt.getType();
1622
                IdentifierTree it = (IdentifierTree) ptt.getTypeArguments().get(1);
1622
                IdentifierTree it = (IdentifierTree) ptt.getTypeArguments().get(1);
1623
                workingCopy.rewrite(it, make.setLabel(it, "DataRen"));
1623
                workingCopy.rewrite(it, make.setLabel(it, "DataRen"));
1624
                
1624
1625
                NewClassTree nct = (NewClassTree) vt.getInitializer();
1625
                NewClassTree nct = (NewClassTree) vt.getInitializer();
1626
                ptt = (ParameterizedTypeTree) nct.getIdentifier();
1626
                ptt = (ParameterizedTypeTree) nct.getIdentifier();
1627
                it = (IdentifierTree) ptt.getTypeArguments().get(1);
1627
                it = (IdentifierTree) ptt.getTypeArguments().get(1);
1628
                workingCopy.rewrite(it, make.setLabel(it, "DataRen"));
1628
                workingCopy.rewrite(it, make.setLabel(it, "DataRen"));
1629
                
1629
1630
                vt = (VariableTree) block.getStatements().get(1);
1630
                vt = (VariableTree) block.getStatements().get(1);
1631
                ptt = (ParameterizedTypeTree) vt.getType();
1631
                ptt = (ParameterizedTypeTree) vt.getType();
1632
                it = (IdentifierTree) ptt.getTypeArguments().get(0);
1632
                it = (IdentifierTree) ptt.getTypeArguments().get(0);
 Lines 1636-1655    Link Here 
1636
                it = (IdentifierTree) ptt.getTypeArguments().get(0);
1636
                it = (IdentifierTree) ptt.getTypeArguments().get(0);
1637
                workingCopy.rewrite(it, make.setLabel(it, "DataRen"));
1637
                workingCopy.rewrite(it, make.setLabel(it, "DataRen"));
1638
            }
1638
            }
1639
            
1639
1640
        };
1640
        };
1641
        testSource.runModificationTask(task).commit();
1641
        testSource.runModificationTask(task).commit();
1642
        String res = TestUtilities.copyFileToString(testFile);
1642
        String res = TestUtilities.copyFileToString(testFile);
1643
        System.err.println(res);
1643
        System.err.println(res);
1644
        assertEquals(golden, res);
1644
        assertEquals(golden, res);
1645
    }
1645
    }
1646
    
1646
1647
    /**
1647
    /**
1648
     * Test rename in switch
1648
     * Test rename in switch
1649
     */
1649
     */
1650
    public void testRenameInSwitch() throws Exception {
1650
    public void testRenameInSwitch() throws Exception {
1651
        testFile = new File(getWorkDir(), "Test.java");
1651
        testFile = new File(getWorkDir(), "Test.java");
1652
        TestUtilities.copyStringToFile(testFile, 
1652
        TestUtilities.copyStringToFile(testFile,
1653
            "package personal;\n" +
1653
            "package personal;\n" +
1654
            "\n" +
1654
            "\n" +
1655
            "public class Test {\n" +
1655
            "public class Test {\n" +
 Lines 1664-1671    Link Here 
1664
            "        }\n" +
1664
            "        }\n" +
1665
            "    }\n" +
1665
            "    }\n" +
1666
            "}\n");
1666
            "}\n");
1667
        
1667
1668
         String golden = 
1668
         String golden =
1669
            "package personal;\n" +
1669
            "package personal;\n" +
1670
            "\n" +
1670
            "\n" +
1671
            "public class Test {\n" +
1671
            "public class Test {\n" +
 Lines 1680-1686    Link Here 
1680
            "        }\n" +
1680
            "        }\n" +
1681
            "    }\n" +
1681
            "    }\n" +
1682
            "}\n";
1682
            "}\n";
1683
                 
1683
1684
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1684
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1685
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1685
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1686
1686
 Lines 1699-1719    Link Here 
1699
                IdentifierTree ident = (IdentifierTree) pTree.getExpression();
1699
                IdentifierTree ident = (IdentifierTree) pTree.getExpression();
1700
                workingCopy.rewrite(ident, make.setLabel(ident, "renamed"));
1700
                workingCopy.rewrite(ident, make.setLabel(ident, "renamed"));
1701
            }
1701
            }
1702
            
1702
1703
        };
1703
        };
1704
        testSource.runModificationTask(task).commit();
1704
        testSource.runModificationTask(task).commit();
1705
        String res = TestUtilities.copyFileToString(testFile);
1705
        String res = TestUtilities.copyFileToString(testFile);
1706
        System.err.println(res);
1706
        System.err.println(res);
1707
        assertEquals(golden, res);
1707
        assertEquals(golden, res);
1708
    }
1708
    }
1709
    
1709
1710
    /**
1710
    /**
1711
     * diffNewArray
1711
     * diffNewArray
1712
     * diffTypeArray
1712
     * diffTypeArray
1713
     */
1713
     */
1714
    public void testRenameInTypeNewArr() throws Exception {
1714
    public void testRenameInTypeNewArr() throws Exception {
1715
        testFile = new File(getWorkDir(), "Test.java");
1715
        testFile = new File(getWorkDir(), "Test.java");
1716
        TestUtilities.copyStringToFile(testFile, 
1716
        TestUtilities.copyStringToFile(testFile,
1717
            "package personal;\n" +
1717
            "package personal;\n" +
1718
            "\n" +
1718
            "\n" +
1719
            "public class Test {\n" +
1719
            "public class Test {\n" +
 Lines 1723-1730    Link Here 
1723
            "        Test[][] obj = new Test[dim1][dim2];\n" +
1723
            "        Test[][] obj = new Test[dim1][dim2];\n" +
1724
            "    }\n" +
1724
            "    }\n" +
1725
            "}\n");
1725
            "}\n");
1726
        
1726
1727
         String golden = 
1727
         String golden =
1728
            "package personal;\n" +
1728
            "package personal;\n" +
1729
            "\n" +
1729
            "\n" +
1730
            "public class RenamedTest {\n" +
1730
            "public class RenamedTest {\n" +
 Lines 1734-1740    Link Here 
1734
            "        RenamedTest[][] obj = new RenamedTest[dim1][dim2];\n" +
1734
            "        RenamedTest[][] obj = new RenamedTest[dim1][dim2];\n" +
1735
            "    }\n" +
1735
            "    }\n" +
1736
            "}\n";
1736
            "}\n";
1737
                 
1737
1738
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1738
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1739
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1739
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1740
1740
 Lines 1754-1773    Link Here 
1754
                NewArrayTree nat = (NewArrayTree) vt.getInitializer();
1754
                NewArrayTree nat = (NewArrayTree) vt.getInitializer();
1755
                workingCopy.rewrite(nat.getType(), make.Identifier("RenamedTest"));
1755
                workingCopy.rewrite(nat.getType(), make.Identifier("RenamedTest"));
1756
            }
1756
            }
1757
            
1757
1758
        };
1758
        };
1759
        testSource.runModificationTask(task).commit();
1759
        testSource.runModificationTask(task).commit();
1760
        String res = TestUtilities.copyFileToString(testFile);
1760
        String res = TestUtilities.copyFileToString(testFile);
1761
        System.err.println(res);
1761
        System.err.println(res);
1762
        assertEquals(golden, res);
1762
        assertEquals(golden, res);
1763
    }
1763
    }
1764
    
1764
1765
    /**
1765
    /**
1766
     * diffTypeTest
1766
     * diffTypeTest
1767
     */
1767
     */
1768
    public void testRenameInTypeTest() throws Exception {
1768
    public void testRenameInTypeTest() throws Exception {
1769
        testFile = new File(getWorkDir(), "Test.java");
1769
        testFile = new File(getWorkDir(), "Test.java");
1770
        TestUtilities.copyStringToFile(testFile, 
1770
        TestUtilities.copyStringToFile(testFile,
1771
            "package personal;\n" +
1771
            "package personal;\n" +
1772
            "\n" +
1772
            "\n" +
1773
            "public class Test {\n" +
1773
            "public class Test {\n" +
 Lines 1776-1783    Link Here 
1776
            "        }\n" +
1776
            "        }\n" +
1777
            "    }\n" +
1777
            "    }\n" +
1778
            "}\n");
1778
            "}\n");
1779
        
1779
1780
         String golden = 
1780
         String golden =
1781
            "package personal;\n" +
1781
            "package personal;\n" +
1782
            "\n" +
1782
            "\n" +
1783
            "public class Test {\n" +
1783
            "public class Test {\n" +
 Lines 1786-1792    Link Here 
1786
            "        }\n" +
1786
            "        }\n" +
1787
            "    }\n" +
1787
            "    }\n" +
1788
            "}\n";
1788
            "}\n";
1789
                 
1789
1790
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1790
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1791
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1791
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1792
1792
 Lines 1806-1825    Link Here 
1806
                IdentifierTree ident = (IdentifierTree) iot.getExpression();
1806
                IdentifierTree ident = (IdentifierTree) iot.getExpression();
1807
                workingCopy.rewrite(ident, make.Identifier("obj"));
1807
                workingCopy.rewrite(ident, make.Identifier("obj"));
1808
            }
1808
            }
1809
            
1809
1810
        };
1810
        };
1811
        testSource.runModificationTask(task).commit();
1811
        testSource.runModificationTask(task).commit();
1812
        String res = TestUtilities.copyFileToString(testFile);
1812
        String res = TestUtilities.copyFileToString(testFile);
1813
        System.err.println(res);
1813
        System.err.println(res);
1814
        assertEquals(golden, res);
1814
        assertEquals(golden, res);
1815
    }
1815
    }
1816
    
1816
1817
    /**
1817
    /**
1818
     * diffTypeTestII
1818
     * diffTypeTestII
1819
     */
1819
     */
1820
    public void testRenameInTypeTestII() throws Exception {
1820
    public void testRenameInTypeTestII() throws Exception {
1821
        testFile = new File(getWorkDir(), "Test.java");
1821
        testFile = new File(getWorkDir(), "Test.java");
1822
        TestUtilities.copyStringToFile(testFile, 
1822
        TestUtilities.copyStringToFile(testFile,
1823
            "package personal;\n" +
1823
            "package personal;\n" +
1824
            "\n" +
1824
            "\n" +
1825
            "public class Test {\n" +
1825
            "public class Test {\n" +
 Lines 1828-1835    Link Here 
1828
            "        }\n" +
1828
            "        }\n" +
1829
            "    }\n" +
1829
            "    }\n" +
1830
            "}\n");
1830
            "}\n");
1831
        
1831
1832
         String golden = 
1832
         String golden =
1833
            "package personal;\n" +
1833
            "package personal;\n" +
1834
            "\n" +
1834
            "\n" +
1835
            "public class RenamedTest {\n" +
1835
            "public class RenamedTest {\n" +
 Lines 1838-1844    Link Here 
1838
            "        }\n" +
1838
            "        }\n" +
1839
            "    }\n" +
1839
            "    }\n" +
1840
            "}\n";
1840
            "}\n";
1841
                 
1841
1842
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1842
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1843
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1843
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1844
1844
 Lines 1856-1875    Link Here 
1856
                IdentifierTree ident = (IdentifierTree) iot.getType();
1856
                IdentifierTree ident = (IdentifierTree) iot.getType();
1857
                workingCopy.rewrite(ident, make.Identifier("RenamedTest"));
1857
                workingCopy.rewrite(ident, make.Identifier("RenamedTest"));
1858
            }
1858
            }
1859
            
1859
1860
        };
1860
        };
1861
        testSource.runModificationTask(task).commit();
1861
        testSource.runModificationTask(task).commit();
1862
        String res = TestUtilities.copyFileToString(testFile);
1862
        String res = TestUtilities.copyFileToString(testFile);
1863
        System.err.println(res);
1863
        System.err.println(res);
1864
        assertEquals(golden, res);
1864
        assertEquals(golden, res);
1865
    }
1865
    }
1866
    
1866
1867
    /**
1867
    /**
1868
     * Changing literal test - #95614
1868
     * Changing literal test - #95614
1869
     */
1869
     */
1870
    public void testChangeLiteral() throws Exception {
1870
    public void testChangeLiteral() throws Exception {
1871
        testFile = new File(getWorkDir(), "Test.java");
1871
        testFile = new File(getWorkDir(), "Test.java");
1872
        TestUtilities.copyStringToFile(testFile, 
1872
        TestUtilities.copyStringToFile(testFile,
1873
            "package personal;\n" +
1873
            "package personal;\n" +
1874
            "\n" +
1874
            "\n" +
1875
            "public class Test {\n" +
1875
            "public class Test {\n" +
 Lines 1877-1884    Link Here 
1877
            "        System.err.println(\"Karel\");\n" +
1877
            "        System.err.println(\"Karel\");\n" +
1878
            "    }\n" +
1878
            "    }\n" +
1879
            "}\n");
1879
            "}\n");
1880
        
1880
1881
         String golden = 
1881
         String golden =
1882
            "package personal;\n" +
1882
            "package personal;\n" +
1883
            "\n" +
1883
            "\n" +
1884
            "public class RenamedTest {\n" +
1884
            "public class RenamedTest {\n" +
 Lines 1886-1892    Link Here 
1886
            "        System.err.println(\"Hrebejk\");\n" +
1886
            "        System.err.println(\"Hrebejk\");\n" +
1887
            "    }\n" +
1887
            "    }\n" +
1888
            "}\n";
1888
            "}\n";
1889
                 
1889
1890
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1890
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
1891
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1891
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
1892
1892
 Lines 1903-1922    Link Here 
1903
                LiteralTree literal = (LiteralTree) invocation.getArguments().get(0);
1903
                LiteralTree literal = (LiteralTree) invocation.getArguments().get(0);
1904
                workingCopy.rewrite(literal, make.Literal("Hrebejk"));
1904
                workingCopy.rewrite(literal, make.Literal("Hrebejk"));
1905
            }
1905
            }
1906
            
1906
1907
        };
1907
        };
1908
        testSource.runModificationTask(task).commit();
1908
        testSource.runModificationTask(task).commit();
1909
        String res = TestUtilities.copyFileToString(testFile);
1909
        String res = TestUtilities.copyFileToString(testFile);
1910
        System.err.println(res);
1910
        System.err.println(res);
1911
        assertEquals(golden, res);
1911
        assertEquals(golden, res);
1912
    }
1912
    }
1913
    
1913
1914
    /**
1914
    /**
1915
     * Changing names in array init - #92610
1915
     * Changing names in array init - #92610
1916
     */
1916
     */
1917
    public void testRenameInArrInit() throws Exception {
1917
    public void testRenameInArrInit() throws Exception {
1918
        testFile = new File(getWorkDir(), "Test.java");
1918
        testFile = new File(getWorkDir(), "Test.java");
1919
        TestUtilities.copyStringToFile(testFile, 
1919
        TestUtilities.copyStringToFile(testFile,
1920
            "package personal;\n" +
1920
            "package personal;\n" +
1921
            "\n" +
1921
            "\n" +
1922
            "public class Test {\n" +
1922
            "public class Test {\n" +
 Lines 1925-1935    Link Here 
1925
            "        Inner[] inArr = new Inner[] { inInst, new Inner() };\n" +
1925
            "        Inner[] inArr = new Inner[] { inInst, new Inner() };\n" +
1926
            "    }\n" +
1926
            "    }\n" +
1927
            "    private static class Inner {\n" +
1927
            "    private static class Inner {\n" +
1928
            "        public Inner() {\n" + 
1928
            "        public Inner() {\n" +
1929
            "        }\n" +
1929
            "        }\n" +
1930
            "    }\n" +
1930
            "    }\n" +
1931
            "}\n");
1931
            "}\n");
1932
         String golden = 
1932
         String golden =
1933
            "package personal;\n" +
1933
            "package personal;\n" +
1934
            "\n" +
1934
            "\n" +
1935
            "public class RenamedTest {\n" +
1935
            "public class RenamedTest {\n" +
 Lines 1938-1944    Link Here 
1938
            "        Inner[] inArr = new Inner[] { inInst, new Inner() };\n" +
1938
            "        Inner[] inArr = new Inner[] { inInst, new Inner() };\n" +
1939
            "    }\n" +
1939
            "    }\n" +
1940
            "    private static class Inner {\n" +
1940
            "    private static class Inner {\n" +
1941
            "        public Inner() {\n" + 
1941
            "        public Inner() {\n" +
1942
            "        }\n" +
1942
            "        }\n" +
1943
            "    }\n" +
1943
            "    }\n" +
1944
            "}\n";
1944
            "}\n";
 Lines 1954-1975    Link Here 
1954
                // body rename
1954
                // body rename
1955
                BlockTree block = method.getBody();
1955
                BlockTree block = method.getBody();
1956
            }
1956
            }
1957
            
1957
1958
        };
1958
        };
1959
        testSource.runModificationTask(task).commit();
1959
        testSource.runModificationTask(task).commit();
1960
        String res = TestUtilities.copyFileToString(testFile);
1960
        String res = TestUtilities.copyFileToString(testFile);
1961
        System.err.println(res);
1961
        System.err.println(res);
1962
        assertEquals(golden, res);
1962
        assertEquals(golden, res);
1963
    }
1963
    }
1964
    
1964
1965
    /**
1965
    /**
1966
     * Rename clazz... Test.class -> RenamedTest.class is not correctly generated
1966
     * Rename clazz... Test.class -> RenamedTest.class is not correctly generated
1967
     * in method parameter (#92610)
1967
     * in method parameter (#92610)
1968
     * 
1968
     *
1969
     */
1969
     */
1970
    public void testRenameClazz() throws Exception {
1970
    public void testRenameClazz() throws Exception {
1971
        testFile = new File(getWorkDir(), "Test.java");
1971
        testFile = new File(getWorkDir(), "Test.java");
1972
        TestUtilities.copyStringToFile(testFile, 
1972
        TestUtilities.copyStringToFile(testFile,
1973
            "package personal;\n" +
1973
            "package personal;\n" +
1974
            "\n" +
1974
            "\n" +
1975
            "public class Test {\n" +
1975
            "public class Test {\n" +
 Lines 1977-1983    Link Here 
1977
            "        method(Test.class);\n" +
1977
            "        method(Test.class);\n" +
1978
            "    }\n" +
1978
            "    }\n" +
1979
            "}\n");
1979
            "}\n");
1980
         String golden = 
1980
         String golden =
1981
            "package personal;\n" +
1981
            "package personal;\n" +
1982
            "\n" +
1982
            "\n" +
1983
            "public class RenamedTest {\n" +
1983
            "public class RenamedTest {\n" +
 Lines 2001-2007    Link Here 
2001
                MemberSelectTree mst = (MemberSelectTree) mit.getArguments().get(0);
2001
                MemberSelectTree mst = (MemberSelectTree) mit.getArguments().get(0);
2002
                workingCopy.rewrite(mst.getExpression(), make.Identifier("RenamedTest"));
2002
                workingCopy.rewrite(mst.getExpression(), make.Identifier("RenamedTest"));
2003
            }
2003
            }
2004
            
2004
2005
        };
2005
        };
2006
        testSource.runModificationTask(task).commit();
2006
        testSource.runModificationTask(task).commit();
2007
        String res = TestUtilities.copyFileToString(testFile);
2007
        String res = TestUtilities.copyFileToString(testFile);
 Lines 2014-2020    Link Here 
2014
     */
2014
     */
2015
    public void testRenameInCase() throws Exception {
2015
    public void testRenameInCase() throws Exception {
2016
        testFile = new File(getWorkDir(), "Test.java");
2016
        testFile = new File(getWorkDir(), "Test.java");
2017
        TestUtilities.copyStringToFile(testFile, 
2017
        TestUtilities.copyStringToFile(testFile,
2018
            "package personal;\n" +
2018
            "package personal;\n" +
2019
            "\n" +
2019
            "\n" +
2020
            "public class Test {\n" +
2020
            "public class Test {\n" +
 Lines 2032-2039    Link Here 
2032
            "        }\n" +
2032
            "        }\n" +
2033
            "    }\n" +
2033
            "    }\n" +
2034
            "}\n");
2034
            "}\n");
2035
        
2035
2036
         String golden = 
2036
         String golden =
2037
            "package personal;\n" +
2037
            "package personal;\n" +
2038
            "\n" +
2038
            "\n" +
2039
            "public class Test {\n" +
2039
            "public class Test {\n" +
 Lines 2079-2099    Link Here 
2079
                CompoundAssignmentTree cat = (CompoundAssignmentTree) est.getExpression();
2079
                CompoundAssignmentTree cat = (CompoundAssignmentTree) est.getExpression();
2080
                workingCopy.rewrite(cat.getVariable(), make.setLabel(cat.getVariable(), "ycko"));
2080
                workingCopy.rewrite(cat.getVariable(), make.setLabel(cat.getVariable(), "ycko"));
2081
            }
2081
            }
2082
            
2082
2083
        };
2083
        };
2084
        testSource.runModificationTask(task).commit();
2084
        testSource.runModificationTask(task).commit();
2085
        String res = TestUtilities.copyFileToString(testFile);
2085
        String res = TestUtilities.copyFileToString(testFile);
2086
        System.err.println(res);
2086
        System.err.println(res);
2087
        assertEquals(golden, res);
2087
        assertEquals(golden, res);
2088
    }
2088
    }
2089
    
2089
2090
    /**
2090
    /**
2091
     * Rename in new in parameter. (Test that issue #98438 is not caused by
2091
     * Rename in new in parameter. (Test that issue #98438 is not caused by
2092
     * generator.)
2092
     * generator.)
2093
     */
2093
     */
2094
    public void testRenameClazzInNewParameter() throws Exception {
2094
    public void testRenameClazzInNewParameter() throws Exception {
2095
        testFile = new File(getWorkDir(), "Test.java");
2095
        testFile = new File(getWorkDir(), "Test.java");
2096
        TestUtilities.copyStringToFile(testFile, 
2096
        TestUtilities.copyStringToFile(testFile,
2097
            "package personal;\n" +
2097
            "package personal;\n" +
2098
            "\n" +
2098
            "\n" +
2099
            "public class Test {\n" +
2099
            "public class Test {\n" +
 Lines 2101-2107    Link Here 
2101
            "        method(new Test());\n" +
2101
            "        method(new Test());\n" +
2102
            "    }\n" +
2102
            "    }\n" +
2103
            "}\n");
2103
            "}\n");
2104
         String golden = 
2104
         String golden =
2105
            "package personal;\n" +
2105
            "package personal;\n" +
2106
            "\n" +
2106
            "\n" +
2107
            "public class RenamedTest {\n" +
2107
            "public class RenamedTest {\n" +
 Lines 2125-2144    Link Here 
2125
                NewClassTree nct = (NewClassTree) mit.getArguments().get(0);
2125
                NewClassTree nct = (NewClassTree) mit.getArguments().get(0);
2126
                workingCopy.rewrite(nct.getIdentifier(), make.Identifier("RenamedTest"));
2126
                workingCopy.rewrite(nct.getIdentifier(), make.Identifier("RenamedTest"));
2127
            }
2127
            }
2128
            
2128
2129
        };
2129
        };
2130
        testSource.runModificationTask(task).commit();
2130
        testSource.runModificationTask(task).commit();
2131
        String res = TestUtilities.copyFileToString(testFile);
2131
        String res = TestUtilities.copyFileToString(testFile);
2132
        System.err.println(res);
2132
        System.err.println(res);
2133
        assertEquals(golden, res);
2133
        assertEquals(golden, res);
2134
    }
2134
    }
2135
    
2135
2136
    /**
2136
    /**
2137
     * #99445: Not well formatted statements when adding statement to body.
2137
     * #99445: Not well formatted statements when adding statement to body.
2138
     */
2138
     */
2139
    public void test99445() throws Exception {
2139
    public void test99445() throws Exception {
2140
        testFile = new File(getWorkDir(), "Test.java");
2140
        testFile = new File(getWorkDir(), "Test.java");
2141
        TestUtilities.copyStringToFile(testFile, 
2141
        TestUtilities.copyStringToFile(testFile,
2142
            "package personal;\n" +
2142
            "package personal;\n" +
2143
            "\n" +
2143
            "\n" +
2144
            "public class Test {\n" +
2144
            "public class Test {\n" +
 Lines 2146-2152    Link Here 
2146
            "        method(new Test());\n" +
2146
            "        method(new Test());\n" +
2147
            "    }\n" +
2147
            "    }\n" +
2148
            "}\n");
2148
            "}\n");
2149
         String golden = 
2149
         String golden =
2150
            "package personal;\n" +
2150
            "package personal;\n" +
2151
            "\n" +
2151
            "\n" +
2152
            "public class Test {\n" +
2152
            "public class Test {\n" +
 Lines 2181-2187    Link Here 
2181
                );
2181
                );
2182
                workingCopy.rewrite(block, make.addBlockStatement(block, est));
2182
                workingCopy.rewrite(block, make.addBlockStatement(block, est));
2183
            }
2183
            }
2184
            
2184
2185
        };
2185
        };
2186
        testSource.runModificationTask(task).commit();
2186
        testSource.runModificationTask(task).commit();
2187
        String res = TestUtilities.copyFileToString(testFile);
2187
        String res = TestUtilities.copyFileToString(testFile);
 Lines 2194-2200    Link Here 
2194
     */
2194
     */
2195
    public void test101717() throws Exception {
2195
    public void test101717() throws Exception {
2196
        testFile = new File(getWorkDir(), "Test.java");
2196
        testFile = new File(getWorkDir(), "Test.java");
2197
        TestUtilities.copyStringToFile(testFile, 
2197
        TestUtilities.copyStringToFile(testFile,
2198
            "package personal;\n" +
2198
            "package personal;\n" +
2199
            "\n" +
2199
            "\n" +
2200
            "public class Test {\n" +
2200
            "public class Test {\n" +
 Lines 2202-2208    Link Here 
2202
            "        method(abcd, -1);\n" +
2202
            "        method(abcd, -1);\n" +
2203
            "    }\n" +
2203
            "    }\n" +
2204
            "}\n");
2204
            "}\n");
2205
         String golden = 
2205
         String golden =
2206
            "package personal;\n" +
2206
            "package personal;\n" +
2207
            "\n" +
2207
            "\n" +
2208
            "public class Test {\n" +
2208
            "public class Test {\n" +
 Lines 2222-2228    Link Here 
2222
                MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) block.getStatements().get(0)).getExpression();
2222
                MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) block.getStatements().get(0)).getExpression();
2223
                workingCopy.rewrite(mit.getArguments().get(0), make.Identifier("abcde"));
2223
                workingCopy.rewrite(mit.getArguments().get(0), make.Identifier("abcde"));
2224
            }
2224
            }
2225
            
2225
2226
        };
2226
        };
2227
        testSource.runModificationTask(task).commit();
2227
        testSource.runModificationTask(task).commit();
2228
        String res = TestUtilities.copyFileToString(testFile);
2228
        String res = TestUtilities.copyFileToString(testFile);
 Lines 2232-2238    Link Here 
2232
2232
2233
    public void testModifyingIf() throws Exception {
2233
    public void testModifyingIf() throws Exception {
2234
        testFile = new File(getWorkDir(), "Test.java");
2234
        testFile = new File(getWorkDir(), "Test.java");
2235
        TestUtilities.copyStringToFile(testFile, 
2235
        TestUtilities.copyStringToFile(testFile,
2236
            "package personal;\n" +
2236
            "package personal;\n" +
2237
            "\n" +
2237
            "\n" +
2238
            "public class Test {\n" +
2238
            "public class Test {\n" +
 Lines 2242-2255    Link Here 
2242
            "        return y == 8;\n" +
2242
            "        return y == 8;\n" +
2243
            "    }\n" +
2243
            "    }\n" +
2244
            "}\n");
2244
            "}\n");
2245
         String golden = 
2245
         String golden =
2246
            "package personal;\n" +
2246
            "package personal;\n" +
2247
            "\n" +
2247
            "\n" +
2248
            "public class Test {\n" +
2248
            "public class Test {\n" +
2249
            "    public boolean method(int i) {\n" +
2249
            "    public boolean method(int i) {\n" +
2250
            "        int y = 0;\n" +
2250
            "        int y = 0;\n" +
2251
            "        if (method(null)) {return true;\n" + 
2251
            "        if (method(null)) {\n" +
2252
            "}\n" +
2252
            "            return true;\n" +
2253
            "        }\n" +
2253
            "        return y == 8;\n" +
2254
            "        return y == 8;\n" +
2254
            "    }\n" +
2255
            "    }\n" +
2255
            "}\n";
2256
            "}\n";
 Lines 2266-2282    Link Here 
2266
                IfTree nue = make.If(
2267
                IfTree nue = make.If(
2267
                    make.Parenthesized(
2268
                    make.Parenthesized(
2268
                        make.MethodInvocation(
2269
                        make.MethodInvocation(
2269
                            Collections.<ExpressionTree>emptyList(), 
2270
                            Collections.<ExpressionTree>emptyList(),
2270
                            make.Identifier("method"), 
2271
                            make.Identifier("method"),
2271
                            Arrays.asList(make.Literal(null))
2272
                            Arrays.asList(make.Literal(null))
2272
                        )
2273
                        )
2273
                    ), 
2274
                    ),
2274
                    make.Block(Collections.<StatementTree>singletonList(make.Return(make.Literal(true))), false),
2275
                    make.Block(Collections.<StatementTree>singletonList(make.Return(make.Literal(true))), false),
2275
                    null
2276
                    null
2276
                );
2277
                );
2277
                workingCopy.rewrite(mit, nue);
2278
                workingCopy.rewrite(mit, nue);
2278
            }
2279
            }
2279
            
2280
2280
            public void cancel() {
2281
            public void cancel() {
2281
            }
2282
            }
2282
        };
2283
        };
 Lines 2285-2294    Link Here 
2285
        System.err.println(res);
2286
        System.err.println(res);
2286
        assertEquals(golden, res);
2287
        assertEquals(golden, res);
2287
    }
2288
    }
2288
    
2289
2289
    public void testRenameInParens() throws Exception {
2290
    public void testRenameInParens() throws Exception {
2290
        testFile = new File(getWorkDir(), "Test.java");
2291
        testFile = new File(getWorkDir(), "Test.java");
2291
        TestUtilities.copyStringToFile(testFile, 
2292
        TestUtilities.copyStringToFile(testFile,
2292
            "package javaapplication1;\n" +
2293
            "package javaapplication1;\n" +
2293
            "\n" +
2294
            "\n" +
2294
            "import java.io.File;\n" +
2295
            "import java.io.File;\n" +
 Lines 2304-2310    Link Here 
2304
            "        new FileInputStream((f));\n" +
2305
            "        new FileInputStream((f));\n" +
2305
            "    }\n" +
2306
            "    }\n" +
2306
            "}\n");
2307
            "}\n");
2307
         String golden = 
2308
         String golden =
2308
            "package javaapplication1;\n" +
2309
            "package javaapplication1;\n" +
2309
            "\n" +
2310
            "\n" +
2310
            "import java.io.File;\n" +
2311
            "import java.io.File;\n" +
 Lines 2334-2340    Link Here 
2334
                ParenthesizedTree pareni = (ParenthesizedTree) nct.getArguments().get(0);
2335
                ParenthesizedTree pareni = (ParenthesizedTree) nct.getArguments().get(0);
2335
                workingCopy.rewrite(pareni.getExpression(), make.Identifier("file"));
2336
                workingCopy.rewrite(pareni.getExpression(), make.Identifier("file"));
2336
            }
2337
            }
2337
            
2338
2338
            public void cancel() {
2339
            public void cancel() {
2339
            }
2340
            }
2340
        };
2341
        };
 Lines 2346-2352    Link Here 
2346
2347
2347
    public void test111983() throws Exception {
2348
    public void test111983() throws Exception {
2348
        testFile = new File(getWorkDir(), "Test.java");
2349
        testFile = new File(getWorkDir(), "Test.java");
2349
        TestUtilities.copyStringToFile(testFile, 
2350
        TestUtilities.copyStringToFile(testFile,
2350
            "package javaapplication1;\n" +
2351
            "package javaapplication1;\n" +
2351
            "\n" +
2352
            "\n" +
2352
            "public class NewClass {\n" +
2353
            "public class NewClass {\n" +
 Lines 2358-2364    Link Here 
2358
            "        NewClass.<Class>method();\n" +
2359
            "        NewClass.<Class>method();\n" +
2359
            "    }\n" +
2360
            "    }\n" +
2360
            "}\n");
2361
            "}\n");
2361
        String golden = 
2362
        String golden =
2362
            "package javaapplication1;\n" +
2363
            "package javaapplication1;\n" +
2363
            "\n" +
2364
            "\n" +
2364
            "public class NewClass {\n" +
2365
            "public class NewClass {\n" +
 Lines 2379-2385    Link Here 
2379
                ClassTree clazz = (ClassTree)workingCopy.getCompilationUnit().getTypeDecls().get(0);
2380
                ClassTree clazz = (ClassTree)workingCopy.getCompilationUnit().getTypeDecls().get(0);
2380
                MethodTree method = (MethodTree)clazz.getMembers().get(1);
2381
                MethodTree method = (MethodTree)clazz.getMembers().get(1);
2381
                workingCopy.rewrite(method, make.setLabel(method, "metoda"));
2382
                workingCopy.rewrite(method, make.setLabel(method, "metoda"));
2382
                
2383
2383
                method = (MethodTree)clazz.getMembers().get(2);
2384
                method = (MethodTree)clazz.getMembers().get(2);
2384
                BlockTree block = method.getBody();
2385
                BlockTree block = method.getBody();
2385
                ExpressionStatementTree est = (ExpressionStatementTree) block.getStatements().get(0);
2386
                ExpressionStatementTree est = (ExpressionStatementTree) block.getStatements().get(0);
 Lines 2387-2393    Link Here 
2387
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
2388
                MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect();
2388
                workingCopy.rewrite(mst, make.setLabel(mst, "metoda"));
2389
                workingCopy.rewrite(mst, make.setLabel(mst, "metoda"));
2389
            }
2390
            }
2390
            
2391
2391
            public void cancel() {
2392
            public void cancel() {
2392
            }
2393
            }
2393
        };
2394
        };
 Lines 2396-2406    Link Here 
2396
        System.err.println(res);
2397
        System.err.println(res);
2397
        assertEquals(golden, res);
2398
        assertEquals(golden, res);
2398
    }
2399
    }
2399
    
2400
2400
    // test 112290
2401
    // test 112290
2401
    public void test112290_1() throws Exception {
2402
    public void test112290_1() throws Exception {
2402
        testFile = new File(getWorkDir(), "Test.java");
2403
        testFile = new File(getWorkDir(), "Test.java");
2403
        TestUtilities.copyStringToFile(testFile, 
2404
        TestUtilities.copyStringToFile(testFile,
2404
            "package javaapplication1;\n" +
2405
            "package javaapplication1;\n" +
2405
            "\n" +
2406
            "\n" +
2406
            "public class NewClass {\n" +
2407
            "public class NewClass {\n" +
 Lines 2409-2415    Link Here 
2409
            "        int[][][] array = new int[size][size][size];\n" +
2410
            "        int[][][] array = new int[size][size][size];\n" +
2410
            "    }\n" +
2411
            "    }\n" +
2411
            "}\n");
2412
            "}\n");
2412
        String golden = 
2413
        String golden =
2413
            "package javaapplication1;\n" +
2414
            "package javaapplication1;\n" +
2414
            "\n" +
2415
            "\n" +
2415
            "public class NewClass {\n" +
2416
            "public class NewClass {\n" +
 Lines 2435-2441    Link Here 
2435
                    workingCopy.rewrite(t, make.Identifier("velikost"));
2436
                    workingCopy.rewrite(t, make.Identifier("velikost"));
2436
                }
2437
                }
2437
            }
2438
            }
2438
            
2439
2439
            public void cancel() {
2440
            public void cancel() {
2440
            }
2441
            }
2441
        };
2442
        };
 Lines 2444-2454    Link Here 
2444
        System.err.println(res);
2445
        System.err.println(res);
2445
        assertEquals(golden, res);
2446
        assertEquals(golden, res);
2446
    }
2447
    }
2447
    
2448
2448
    // test 112290
2449
    // test 112290
2449
    public void test112290_2() throws Exception {
2450
    public void test112290_2() throws Exception {
2450
        testFile = new File(getWorkDir(), "Test.java");
2451
        testFile = new File(getWorkDir(), "Test.java");
2451
        TestUtilities.copyStringToFile(testFile, 
2452
        TestUtilities.copyStringToFile(testFile,
2452
            "package javaapplication1;\n" +
2453
            "package javaapplication1;\n" +
2453
            "\n" +
2454
            "\n" +
2454
            "public class NewClass {\n" +
2455
            "public class NewClass {\n" +
 Lines 2457-2463    Link Here 
2457
            "        int[][][] array = new int[size][size][size];\n" +
2458
            "        int[][][] array = new int[size][size][size];\n" +
2458
            "    }\n" +
2459
            "    }\n" +
2459
            "}\n");
2460
            "}\n");
2460
        String golden = 
2461
        String golden =
2461
            "package javaapplication1;\n" +
2462
            "package javaapplication1;\n" +
2462
            "\n" +
2463
            "\n" +
2463
            "public class NewClass {\n" +
2464
            "public class NewClass {\n" +
 Lines 2481-2487    Link Here 
2481
                NewArrayTree newArr = (NewArrayTree) var.getInitializer();
2482
                NewArrayTree newArr = (NewArrayTree) var.getInitializer();
2482
                workingCopy.rewrite(newArr.getDimensions().get(2), make.Identifier("velikost"));
2483
                workingCopy.rewrite(newArr.getDimensions().get(2), make.Identifier("velikost"));
2483
            }
2484
            }
2484
            
2485
2485
            public void cancel() {
2486
            public void cancel() {
2486
            }
2487
            }
2487
        };
2488
        };
 Lines 2490-2500    Link Here 
2490
        System.err.println(res);
2491
        System.err.println(res);
2491
        assertEquals(golden, res);
2492
        assertEquals(golden, res);
2492
    }
2493
    }
2493
    
2494
2494
    // test 112290
2495
    // test 112290
2495
    public void test112290_3() throws Exception {
2496
    public void test112290_3() throws Exception {
2496
        testFile = new File(getWorkDir(), "Test.java");
2497
        testFile = new File(getWorkDir(), "Test.java");
2497
        TestUtilities.copyStringToFile(testFile, 
2498
        TestUtilities.copyStringToFile(testFile,
2498
            "package javaapplication1;\n" +
2499
            "package javaapplication1;\n" +
2499
            "\n" +
2500
            "\n" +
2500
            "public class NewClass {\n" +
2501
            "public class NewClass {\n" +
 Lines 2503-2509    Link Here 
2503
            "        int[][][] array = new int[size][size][size];\n" +
2504
            "        int[][][] array = new int[size][size][size];\n" +
2504
            "    }\n" +
2505
            "    }\n" +
2505
            "}\n");
2506
            "}\n");
2506
        String golden = 
2507
        String golden =
2507
            "package javaapplication1;\n" +
2508
            "package javaapplication1;\n" +
2508
            "\n" +
2509
            "\n" +
2509
            "public class NewClass {\n" +
2510
            "public class NewClass {\n" +
 Lines 2527-2533    Link Here 
2527
                NewArrayTree newArr = (NewArrayTree) var.getInitializer();
2528
                NewArrayTree newArr = (NewArrayTree) var.getInitializer();
2528
                workingCopy.rewrite(newArr.getDimensions().get(0), make.Identifier("velikost"));
2529
                workingCopy.rewrite(newArr.getDimensions().get(0), make.Identifier("velikost"));
2529
            }
2530
            }
2530
            
2531
2531
            public void cancel() {
2532
            public void cancel() {
2532
            }
2533
            }
2533
        };
2534
        };
 Lines 2536-2545    Link Here 
2536
        System.err.println(res);
2537
        System.err.println(res);
2537
        assertEquals(golden, res);
2538
        assertEquals(golden, res);
2538
    }
2539
    }
2539
    
2540
2540
    public void test126460a() throws Exception {
2541
    public void test126460a() throws Exception {
2541
        testFile = new File(getWorkDir(), "Test.java");
2542
        testFile = new File(getWorkDir(), "Test.java");
2542
        TestUtilities.copyStringToFile(testFile, 
2543
        TestUtilities.copyStringToFile(testFile,
2543
            "package personal;\n" +
2544
            "package personal;\n" +
2544
            "\n" +
2545
            "\n" +
2545
            "public class Test {\n" +
2546
            "public class Test {\n" +
 Lines 2548-2555    Link Here 
2548
            "        assert l.get(0) == 12;\n" +
2549
            "        assert l.get(0) == 12;\n" +
2549
            "    }\n" +
2550
            "    }\n" +
2550
            "}\n");
2551
            "}\n");
2551
        
2552
2552
         String golden = 
2553
         String golden =
2553
            "package personal;\n" +
2554
            "package personal;\n" +
2554
            "\n" +
2555
            "\n" +
2555
            "public class Test {\n" +
2556
            "public class Test {\n" +
 Lines 2559-2565    Link Here 
2559
            "        assert name == 12;\n" +
2560
            "        assert name == 12;\n" +
2560
            "    }\n" +
2561
            "    }\n" +
2561
            "}\n";
2562
            "}\n";
2562
                 
2563
2563
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
2564
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
2564
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
2565
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
2565
2566
 Lines 2576-2592    Link Here 
2576
                BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit));
2577
                BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit));
2577
                workingCopy.rewrite(block, nueBlock);
2578
                workingCopy.rewrite(block, nueBlock);
2578
            }
2579
            }
2579
            
2580
2580
        };
2581
        };
2581
        testSource.runModificationTask(task).commit();
2582
        testSource.runModificationTask(task).commit();
2582
        String res = TestUtilities.copyFileToString(testFile);
2583
        String res = TestUtilities.copyFileToString(testFile);
2583
        System.err.println(res);
2584
        System.err.println(res);
2584
        assertEquals(golden, res);
2585
        assertEquals(golden, res);
2585
    }
2586
    }
2586
    
2587
2587
    public void test126460b() throws Exception {
2588
    public void test126460b() throws Exception {
2588
        testFile = new File(getWorkDir(), "Test.java");
2589
        testFile = new File(getWorkDir(), "Test.java");
2589
        TestUtilities.copyStringToFile(testFile, 
2590
        TestUtilities.copyStringToFile(testFile,
2590
            "package personal;\n" +
2591
            "package personal;\n" +
2591
            "\n" +
2592
            "\n" +
2592
            "public class Test {\n" +
2593
            "public class Test {\n" +
 Lines 2595-2602    Link Here 
2595
            "        assert l.get(0) == 12;\n" +
2596
            "        assert l.get(0) == 12;\n" +
2596
            "    }\n" +
2597
            "    }\n" +
2597
            "}\n");
2598
            "}\n");
2598
        
2599
2599
         String golden = 
2600
         String golden =
2600
            "package personal;\n" +
2601
            "package personal;\n" +
2601
            "\n" +
2602
            "\n" +
2602
            "public class Test {\n" +
2603
            "public class Test {\n" +
 Lines 2606-2612    Link Here 
2606
            "        assert name == 12 : ada;\n" +
2607
            "        assert name == 12 : ada;\n" +
2607
            "    }\n" +
2608
            "    }\n" +
2608
            "}\n";
2609
            "}\n";
2609
                 
2610
2610
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
2611
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
2611
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
2612
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
2612
2613
 Lines 2624-2640    Link Here 
2624
                BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit));
2625
                BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit));
2625
                workingCopy.rewrite(block, nueBlock);
2626
                workingCopy.rewrite(block, nueBlock);
2626
            }
2627
            }
2627
            
2628
2628
        };
2629
        };
2629
        testSource.runModificationTask(task).commit();
2630
        testSource.runModificationTask(task).commit();
2630
        String res = TestUtilities.copyFileToString(testFile);
2631
        String res = TestUtilities.copyFileToString(testFile);
2631
        System.err.println(res);
2632
        System.err.println(res);
2632
        assertEquals(golden, res);
2633
        assertEquals(golden, res);
2633
    }
2634
    }
2634
    
2635
2635
    public void test126460c() throws Exception {
2636
    public void test126460c() throws Exception {
2636
        testFile = new File(getWorkDir(), "Test.java");
2637
        testFile = new File(getWorkDir(), "Test.java");
2637
        TestUtilities.copyStringToFile(testFile, 
2638
        TestUtilities.copyStringToFile(testFile,
2638
            "package personal;\n" +
2639
            "package personal;\n" +
2639
            "\n" +
2640
            "\n" +
2640
            "public class Test {\n" +
2641
            "public class Test {\n" +
 Lines 2643-2650    Link Here 
2643
            "        assert l.get(0) == 12 : ada;\n" +
2644
            "        assert l.get(0) == 12 : ada;\n" +
2644
            "    }\n" +
2645
            "    }\n" +
2645
            "}\n");
2646
            "}\n");
2646
        
2647
2647
         String golden = 
2648
         String golden =
2648
            "package personal;\n" +
2649
            "package personal;\n" +
2649
            "\n" +
2650
            "\n" +
2650
            "public class Test {\n" +
2651
            "public class Test {\n" +
 Lines 2654-2660    Link Here 
2654
            "        assert name == 12;\n" +
2655
            "        assert name == 12;\n" +
2655
            "    }\n" +
2656
            "    }\n" +
2656
            "}\n";
2657
            "}\n";
2657
                 
2658
2658
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
2659
        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
2659
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
2660
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
2660
2661
 Lines 2672-2685    Link Here 
2672
                BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit));
2673
                BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit));
2673
                workingCopy.rewrite(block, nueBlock);
2674
                workingCopy.rewrite(block, nueBlock);
2674
            }
2675
            }
2675
            
2676
2676
        };
2677
        };
2677
        testSource.runModificationTask(task).commit();
2678
        testSource.runModificationTask(task).commit();
2678
        String res = TestUtilities.copyFileToString(testFile);
2679
        String res = TestUtilities.copyFileToString(testFile);
2679
        System.err.println(res);
2680
        System.err.println(res);
2680
        assertEquals(golden, res);
2681
        assertEquals(golden, res);
2681
    }
2682
    }
2682
    
2683
2683
    public void test159671a() throws Exception {
2684
    public void test159671a() throws Exception {
2684
        testFile = new File(getWorkDir(), "Test.java");
2685
        testFile = new File(getWorkDir(), "Test.java");
2685
        TestUtilities.copyStringToFile(testFile,
2686
        TestUtilities.copyStringToFile(testFile,
 Lines 2801-2809    Link Here 
2801
    String getGoldenPckg() {
2802
    String getGoldenPckg() {
2802
        return "";
2803
        return "";
2803
    }
2804
    }
2804
    
2805
2805
    String getSourcePckg() {
2806
    String getSourcePckg() {
2806
        return "";
2807
        return "";
2807
    }
2808
    }
2808
    
2809
2809
}
2810
}
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/gen/IfTest.java (-20 / +179 lines)
 Lines 75-81    Link Here 
75
    public IfTest(String name) {
75
    public IfTest(String name) {
76
        super(name);
76
        super(name);
77
    }
77
    }
78
    
78
79
    public static NbTestSuite suite() {
79
    public static NbTestSuite suite() {
80
        NbTestSuite suite = new NbTestSuite();
80
        NbTestSuite suite = new NbTestSuite();
81
        suite.addTestSuite(IfTest.class);
81
        suite.addTestSuite(IfTest.class);
 Lines 85-90    Link Here 
85
//        suite.addTest(new IfTest("testModifyingIf"));
85
//        suite.addTest(new IfTest("testModifyingIf"));
86
//        suite.addTest(new IfTest("test158463a"));
86
//        suite.addTest(new IfTest("test158463a"));
87
//        suite.addTest(new IfTest("test158463b"));
87
//        suite.addTest(new IfTest("test158463b"));
88
//        suite.addTest(new IfTest("test158154OneIf"));
89
//        suite.addTest(new IfTest("test158154TwoIfs"));
90
//        suite.addTest(new IfTest("test158154SeveralIfs"));
88
        return suite;
91
        return suite;
89
    }
92
    }
90
93
 Lines 92-99    Link Here 
92
     * Test replacing then statement with empty block.
95
     * Test replacing then statement with empty block.
93
     */
96
     */
94
    public void testEmptyThenBlock() throws Exception {
97
    public void testEmptyThenBlock() throws Exception {
95
        testFile = new File(getWorkDir(), "IfTest.java");        
98
        testFile = new File(getWorkDir(), "IfTest.java");
96
        TestUtilities.copyStringToFile(testFile, 
99
        TestUtilities.copyStringToFile(testFile,
97
            "package foo.bar;\n" +
100
            "package foo.bar;\n" +
98
            "\n" +
101
            "\n" +
99
            "public class IfTest {\n" +
102
            "public class IfTest {\n" +
 Lines 108-119    Link Here 
108
            "\n" +
111
            "\n" +
109
            "public class IfTest {\n" +
112
            "public class IfTest {\n" +
110
            "    public void test(boolean b) {\n" +
113
            "    public void test(boolean b) {\n" +
111
            "        if( b ) {\n" +
114
            "        if (b) {\n" +
112
            "        }\n" +
115
            "        }\n" +
113
            "    }\n" +
116
            "    }\n" +
114
            "}\n";
117
            "}\n";
115
        JavaSource src = getJavaSource(testFile);
118
        JavaSource src = getJavaSource(testFile);
116
        
119
117
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
120
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
118
121
119
            public void run(WorkingCopy workingCopy) throws IOException {
122
            public void run(WorkingCopy workingCopy) throws IOException {
 Lines 136-145    Link Here 
136
        System.err.println(res);
139
        System.err.println(res);
137
        assertEquals(golden, res);
140
        assertEquals(golden, res);
138
    }
141
    }
139
    
142
140
    public void testEmptyElseBlock() throws Exception {
143
    public void testEmptyElseBlock() throws Exception {
141
        testFile = new File(getWorkDir(), "IfTest.java");        
144
        testFile = new File(getWorkDir(), "IfTest.java");
142
        TestUtilities.copyStringToFile(testFile, 
145
        TestUtilities.copyStringToFile(testFile,
143
            "package foo.bar;\n" +
146
            "package foo.bar;\n" +
144
            "\n" +
147
            "\n" +
145
            "public class IfTest {\n" +
148
            "public class IfTest {\n" +
 Lines 161-167    Link Here 
161
            "    }\n" +
164
            "    }\n" +
162
            "}\n";
165
            "}\n";
163
        JavaSource src = getJavaSource(testFile);
166
        JavaSource src = getJavaSource(testFile);
164
        
167
165
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
168
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
166
169
167
            public void run(WorkingCopy workingCopy) throws IOException {
170
            public void run(WorkingCopy workingCopy) throws IOException {
 Lines 184-193    Link Here 
184
        System.err.println(res);
187
        System.err.println(res);
185
        assertEquals(golden, res);
188
        assertEquals(golden, res);
186
    }
189
    }
187
    
190
188
    public void testReplaceCondition() throws Exception {
191
    public void testReplaceCondition() throws Exception {
189
        testFile = new File(getWorkDir(), "IfTest.java");        
192
        testFile = new File(getWorkDir(), "IfTest.java");
190
        TestUtilities.copyStringToFile(testFile, 
193
        TestUtilities.copyStringToFile(testFile,
191
            "package foo.bar;\n" +
194
            "package foo.bar;\n" +
192
            "\n" +
195
            "\n" +
193
            "public class IfTest {\n" +
196
            "public class IfTest {\n" +
 Lines 207-213    Link Here 
207
            "    }\n" +
210
            "    }\n" +
208
            "}\n";
211
            "}\n";
209
        JavaSource src = getJavaSource(testFile);
212
        JavaSource src = getJavaSource(testFile);
210
        
213
211
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
214
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
212
215
213
            public void run(WorkingCopy workingCopy) throws IOException {
216
            public void run(WorkingCopy workingCopy) throws IOException {
 Lines 233-239    Link Here 
233
236
234
    public void testModifyingIf() throws Exception {
237
    public void testModifyingIf() throws Exception {
235
        testFile = new File(getWorkDir(), "Test.java");
238
        testFile = new File(getWorkDir(), "Test.java");
236
        TestUtilities.copyStringToFile(testFile, 
239
        TestUtilities.copyStringToFile(testFile,
237
            "package personal;\n" +
240
            "package personal;\n" +
238
            "\n" +
241
            "\n" +
239
            "public class Test {\n" +
242
            "public class Test {\n" +
 Lines 245-257    Link Here 
245
            "        return y == 8;\n" +
248
            "        return y == 8;\n" +
246
            "    }\n" +
249
            "    }\n" +
247
            "}\n");
250
            "}\n");
248
         String golden = 
251
         String golden =
249
            "package personal;\n" +
252
            "package personal;\n" +
250
            "\n" +
253
            "\n" +
251
            "public class Test {\n" +
254
            "public class Test {\n" +
252
            "    public boolean method(int i) {\n" +
255
            "    public boolean method(int i) {\n" +
253
            "        int y = 0;\n" +
256
            "        int y = 0;\n" +
254
            "        if (method(null)) {\n" + 
257
            "        if (method(null)) {\n" +
255
            "            return true;\n" +
258
            "            return true;\n" +
256
            "        }\n" +
259
            "        }\n" +
257
            "        return y == 8;\n" +
260
            "        return y == 8;\n" +
 Lines 281-287    Link Here 
281
                );
284
                );
282
                workingCopy.rewrite(mit, nue);
285
                workingCopy.rewrite(mit, nue);
283
            }
286
            }
284
            
287
285
            public void cancel() {
288
            public void cancel() {
286
            }
289
            }
287
        };
290
        };
 Lines 362-370    Link Here 
362
            "\n" +
365
            "\n" +
363
            "public class Test {\n" +
366
            "public class Test {\n" +
364
            "    void m1(int p, int q) {\n" +
367
            "    void m1(int p, int q) {\n" +
365
            "        if ((p > 0) && (q > 0))\n" +
368
            "        if ((p > 0) && (q > 0)) {\n" +
366
            "            p++;\n" +
369
            "            p++;\n" +
367
            "        else {\n" + //TODO: brackets (#158154)
370
            "        } else {\n" +
368
            "            p--;\n" +
371
            "            p--;\n" +
369
            "        }\n" +
372
            "        }\n" +
370
            "    }\n" +
373
            "    }\n" +
 Lines 398-404    Link Here 
398
        System.err.println(res);
401
        System.err.println(res);
399
        assertEquals(golden, res);
402
        assertEquals(golden, res);
400
    }
403
    }
401
    
404
402
    public void test159940() throws Exception {
405
    public void test159940() throws Exception {
403
        String test =
406
        String test =
404
                "class Test {\n" +
407
                "class Test {\n" +
 Lines 433-438    Link Here 
433
        assertEquals(golden, res);
436
        assertEquals(golden, res);
434
    }
437
    }
435
438
439
    public void test158154OneIf() throws Exception {
440
        String source = "class Test {\n"
441
                + "    void m1(boolean b) {\n"
442
                + "        if (b) ; else System.out.println(\"hi\");\n"
443
                + "    }\n"
444
                + "}";
445
        String golden = "class Test {\n"
446
                + "    void m1(boolean b) {\n"
447
                + "        if (!(b)) {\n"
448
                + "            System.out.println(\"hi\");\n"
449
                + "        }\n"
450
                + "    }\n"
451
                + "}";
452
        testFile = new File(getWorkDir(), "Test.java");
453
454
        TestUtilities.copyStringToFile(testFile, source);
455
        JavaSource src = getJavaSource(testFile);
456
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
457
            public void run(WorkingCopy copy) throws Exception {
458
                if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
459
                    return;
460
                }
461
462
                TreeMaker make = copy.getTreeMaker();
463
                ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0);
464
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
465
                BlockTree block = method.getBody();
466
                IfTree original = (IfTree) block.getStatements().get(0);
467
468
                IfTree modified = make.If(
469
                        make.Parenthesized(
470
                        make.Unary(Kind.LOGICAL_COMPLEMENT, original.getCondition())),
471
                        original.getElseStatement(), null);
472
                copy.rewrite(original, modified);
473
            }
474
        };
475
476
        src.runModificationTask(task).commit();
477
        String res = TestUtilities.copyFileToString(testFile);
478
        System.out.println(res);
479
        assertEquals(golden, res);
480
    }
481
482
    public void test158154TwoIfs() throws Exception {
483
        String source = "class Test {\n"
484
                + "    void m1(boolean b) {\n"
485
                + "        if (b) ; else System.out.println(\"first hi\");\n"
486
                + "        if (b) ; else System.out.println(\"second hi\");\n"
487
                + "    }\n"
488
                + "}";
489
        String golden = "class Test {\n"
490
                + "    void m1(boolean b) {\n"
491
                + "        if (!(b)) {\n"
492
                + "            System.out.println(\"first hi\");\n"
493
                + "        }\n"
494
                + "        if (!(b)) {\n"
495
                + "            System.out.println(\"second hi\");\n"
496
                + "        }\n"
497
                + "    }\n"
498
                + "}";
499
        testFile = new File(getWorkDir(), "Test.java");
500
        TestUtilities.copyStringToFile(testFile, source);
501
        JavaSource src = getJavaSource(testFile);
502
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
503
            public void run(WorkingCopy copy) throws Exception {
504
                if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
505
                    return;
506
                }
507
508
                TreeMaker make = copy.getTreeMaker();
509
                ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0);
510
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
511
                BlockTree block = method.getBody();
512
                IfTree originalA = (IfTree) block.getStatements().get(0);
513
                IfTree originalB = (IfTree) block.getStatements().get(1);
514
                IfTree modifiedA = make.If(
515
                        make.Parenthesized(
516
                        make.Unary(Kind.LOGICAL_COMPLEMENT, originalA.getCondition())),
517
                        originalA.getElseStatement(), null);
518
                copy.rewrite(originalA, modifiedA);
519
                IfTree modifiedB = make.If(
520
                        make.Parenthesized(
521
                        make.Unary(Kind.LOGICAL_COMPLEMENT, originalB.getCondition())),
522
                        originalB.getElseStatement(), null);
523
                copy.rewrite(originalB, modifiedB);
524
            }
525
        };
526
        src.runModificationTask(task).commit();
527
        String res = TestUtilities.copyFileToString(testFile);
528
        System.out.println(res);
529
        assertEquals(golden, res);
530
    }
531
532
    public void test158154SeveralIfs() throws Exception {
533
        String source = "class Test {\n"
534
                + "    void m1(boolean b) {\n"
535
                + "        if (b) ; else System.out.println(\"first hi\");\n"
536
                + "        if (b) ; else System.out.println(\"second hi\");\n"
537
                + "        if (b) ; else System.out.println(\"third hi\");\n"
538
                + "        if (b) ; else System.out.println(\"fourth hi\");\n"
539
                + "    }\n"
540
                + "}";
541
        String golden = "class Test {\n"
542
                + "    void m1(boolean b) {\n"
543
                + "        if (!(b)) {\n"
544
                + "            System.out.println(\"first hi\");\n"
545
                + "        }\n"
546
                + "        if (!(b)) {\n"
547
                + "            System.out.println(\"second hi\");\n"
548
                + "        }\n"
549
                + "        if (!(b)) {\n"
550
                + "            System.out.println(\"third hi\");\n"
551
                + "        }\n"
552
                + "        if (!(b)) {\n"
553
                + "            System.out.println(\"fourth hi\");\n"
554
                + "        }\n"
555
                + "    }\n"
556
                + "}";
557
        testFile = new File(getWorkDir(), "Test.java");
558
        TestUtilities.copyStringToFile(testFile, source);
559
        JavaSource src = getJavaSource(testFile);
560
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
561
            public void run(WorkingCopy copy) throws Exception {
562
                if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
563
                    return;
564
                }
565
566
                TreeMaker make = copy.getTreeMaker();
567
                ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0);
568
                MethodTree method = (MethodTree) clazz.getMembers().get(1);
569
                BlockTree block = method.getBody();
570
571
                IfTree [] ifStatements = new IfTree[block.getStatements().size()];
572
                for (int i = 0; i < block.getStatements().size(); i++) {
573
                    ifStatements[i] = (IfTree) block.getStatements().get(i);
574
                }
575
576
                IfTree [] modifiedIfs = new IfTree[block.getStatements().size()];
577
                for (int i = 0; i < block.getStatements().size(); i++) {
578
                    modifiedIfs[i] = make.If(
579
                        make.Parenthesized(
580
                        make.Unary(Kind.LOGICAL_COMPLEMENT, ifStatements[i].getCondition())),
581
                        ifStatements[i].getElseStatement(), null);
582
                }
583
584
                for (int i = 0; i < block.getStatements().size(); i++) {
585
                    copy.rewrite(ifStatements[i], modifiedIfs[i]);
586
                }
587
            }
588
        };
589
        src.runModificationTask(task).commit();
590
        String res = TestUtilities.copyFileToString(testFile);
591
        System.out.println(res);
592
        assertEquals(golden, res);
593
    }
594
436
    String getGoldenPckg() {
595
    String getGoldenPckg() {
437
        return "";
596
        return "";
438
    }
597
    }
(-)a/j2ee.persistence/nbproject/project.xml (+9 lines)
 Lines 50-55    Link Here 
50
            <code-name-base>org.netbeans.modules.j2ee.persistence</code-name-base>
50
            <code-name-base>org.netbeans.modules.j2ee.persistence</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.17</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
53
                    <code-name-base>org.netbeans.api.java</code-name-base>
62
                    <code-name-base>org.netbeans.api.java</code-name-base>
54
                    <build-prerequisite/>
63
                    <build-prerequisite/>
55
                    <compile-dependency/>
64
                    <compile-dependency/>
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_1_0/package-info.java (+1 lines)
 Lines 52-57    Link Here 
52
    removeUnreferencedNodes=true,
52
    removeUnreferencedNodes=true,
53
    java5=true
53
    java5=true
54
)
54
)
55
@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes"
55
package org.netbeans.modules.j2ee.persistence.dd.orm.model_1_0;
56
package org.netbeans.modules.j2ee.persistence.dd.orm.model_1_0;
56
57
57
import org.netbeans.modules.schema2beans.Schema2Beans;
58
import org.netbeans.modules.schema2beans.Schema2Beans;
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_2_0/package-info.java (+1 lines)
 Lines 52-57    Link Here 
52
    removeUnreferencedNodes=true,
52
    removeUnreferencedNodes=true,
53
    java5=true
53
    java5=true
54
)
54
)
55
@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes"
55
package org.netbeans.modules.j2ee.persistence.dd.orm.model_2_0;
56
package org.netbeans.modules.j2ee.persistence.dd.orm.model_2_0;
56
57
57
import org.netbeans.modules.schema2beans.Schema2Beans;
58
import org.netbeans.modules.schema2beans.Schema2Beans;
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_1_0/package-info.java (+1 lines)
 Lines 51-56    Link Here 
51
    removeUnreferencedNodes=true,
51
    removeUnreferencedNodes=true,
52
    java5=true
52
    java5=true
53
)
53
)
54
@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes"
54
package org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0;
55
package org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0;
55
56
56
import org.netbeans.modules.schema2beans.Schema2Beans;
57
import org.netbeans.modules.schema2beans.Schema2Beans;
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_2_0/package-info.java (+1 lines)
 Lines 51-56    Link Here 
51
    removeUnreferencedNodes=true,
51
    removeUnreferencedNodes=true,
52
    java5=true
52
    java5=true
53
)
53
)
54
@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes"
54
package org.netbeans.modules.j2ee.persistence.dd.persistence.model_2_0;
55
package org.netbeans.modules.j2ee.persistence.dd.persistence.model_2_0;
55
56
56
import org.netbeans.modules.schema2beans.Schema2Beans;
57
import org.netbeans.modules.schema2beans.Schema2Beans;

Return to bug 158154
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo