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

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

(-)a/java.source/src/org/netbeans/api/java/source/ModificationResult.java (-39 / +45 lines)
Lines 98-104 Link Here
98
    private boolean committed;
98
    private boolean committed;
99
    Map<FileObject, List<Difference>> diffs = new HashMap<FileObject, List<Difference>>();
99
    Map<FileObject, List<Difference>> diffs = new HashMap<FileObject, List<Difference>>();
100
    Map<?, int[]> tag2Span = new IdentityHashMap<Object, int[]>();
100
    Map<?, int[]> tag2Span = new IdentityHashMap<Object, int[]>();
101
    
101
102
    /** Creates a new instance of ModificationResult */
102
    /** Creates a new instance of ModificationResult */
103
    ModificationResult(final JavaSource js) {
103
    ModificationResult(final JavaSource js) {
104
        this.sources = js != null ? JavaSourceAccessor.getINSTANCE().getSources(js) : null;
104
        this.sources = js != null ? JavaSourceAccessor.getINSTANCE().getSources(js) : null;
Lines 164-178 Link Here
164
        });
164
        });
165
        return result;
165
        return result;
166
    }
166
    }
167
    
167
168
    public @NonNull Set<? extends FileObject> getModifiedFileObjects() {
168
    public @NonNull Set<? extends FileObject> getModifiedFileObjects() {
169
        return diffs.keySet();
169
        return diffs.keySet();
170
    }
170
    }
171
    
171
172
    public List<? extends Difference> getDifferences(@NonNull FileObject fo) {
172
    public List<? extends Difference> getDifferences(@NonNull FileObject fo) {
173
        return diffs.get(fo);
173
        return diffs.get(fo);
174
    }
174
    }
175
    
175
176
    public @NonNull Set<File> getNewFiles() {
176
    public @NonNull Set<File> getNewFiles() {
177
        Set<File> newFiles = new HashSet<File>();
177
        Set<File> newFiles = new HashSet<File>();
178
        for (List<Difference> ds:diffs.values()) {
178
        for (List<Difference> ds:diffs.values()) {
Lines 184-190 Link Here
184
        }
184
        }
185
        return newFiles;
185
        return newFiles;
186
    }
186
    }
187
    
187
188
    /**
188
    /**
189
     * Once all of the changes have been collected, this method can be used
189
     * Once all of the changes have been collected, this method can be used
190
     * to commit the changes to the source files
190
     * to commit the changes to the source files
Lines 224-235 Link Here
224
            this.sources = null;
224
            this.sources = null;
225
        }
225
        }
226
    }
226
    }
227
    
227
228
    static void commit (final FileObject fo, final List<Difference> differences, final Writer out) throws IOException {
228
    static void commit (final FileObject fo, final List<Difference> differences, final Writer out) throws IOException {
229
        DataObject dObj = DataObject.find(fo);
229
        DataObject dObj = DataObject.find(fo);
230
        EditorCookie ec = dObj != null ? dObj.getCookie(org.openide.cookies.EditorCookie.class) : null;
230
        EditorCookie ec = dObj != null ? dObj.getCookie(org.openide.cookies.EditorCookie.class) : null;
231
        // if editor cookie was found and user does not provided his own
231
        // if editor cookie was found and user does not provided his own
232
        // writer where he wants to see changes, commit the changes to 
232
        // writer where he wants to see changes, commit the changes to
233
        // found document.
233
        // found document.
234
        if (ec != null && out == null) {
234
        if (ec != null && out == null) {
235
            final StyledDocument doc = ec.getDocument();
235
            final StyledDocument doc = ec.getDocument();
Lines 272-278 Link Here
272
                }
272
                }
273
                out2 = new FilteringWriter(out2, hasReturnChar);
273
                out2 = new FilteringWriter(out2, hasReturnChar);
274
            }
274
            }
275
            int offset = 0;                
275
            int offset = 0;
276
            for (Difference diff : differences) {
276
            for (Difference diff : differences) {
277
                if (diff.isExcluded())
277
                if (diff.isExcluded())
278
                    continue;
278
                    continue;
Lines 308-314 Link Here
308
                        out2.write(diff.getNewText());
308
                        out2.write(diff.getNewText());
309
                        break;
309
                        break;
310
                }
310
                }
311
            }                    
311
            }
312
            char[] buff = new char[1024];
312
            char[] buff = new char[1024];
313
            int n;
313
            int n;
314
            while ((n = in.read(buff)) > 0) {
314
            while ((n = in.read(buff)) > 0) {
Lines 319-325 Link Here
319
                in.close();
319
                in.close();
320
            if (out2 != null)
320
            if (out2 != null)
321
                out2.close();
321
                out2.close();
322
        }            
322
        }
323
    }
323
    }
324
324
325
    private static void commit2 (final StyledDocument doc, final List<Difference> differences, Writer out) throws IOException {
325
    private static void commit2 (final StyledDocument doc, final List<Difference> differences, Writer out) throws IOException {
Lines 338-344 Link Here
338
            }
338
            }
339
        }
339
        }
340
    }
340
    }
341
    
341
342
    private static void processDocument(final StyledDocument doc, final Difference diff) throws IOException {
342
    private static void processDocument(final StyledDocument doc, final Difference diff) throws IOException {
343
        final BadLocationException[] blex = new BadLocationException[1];
343
        final BadLocationException[] blex = new BadLocationException[1];
344
        Runnable task = new Runnable() {
344
        Runnable task = new Runnable() {
Lines 393-399 Link Here
393
            throw ioe;
393
            throw ioe;
394
        }
394
        }
395
    }
395
    }
396
    
396
397
    private static void processDocumentLocked(Document doc, Difference diff) throws BadLocationException {
397
    private static void processDocumentLocked(Document doc, Difference diff) throws BadLocationException {
398
        switch (diff.getKind()) {
398
        switch (diff.getKind()) {
399
            case INSERT:
399
            case INSERT:
Lines 403-410 Link Here
403
                doc.remove(diff.getStartPosition().getOffset(), diff.getEndPosition().getOffset() - diff.getStartPosition().getOffset());
403
                doc.remove(diff.getStartPosition().getOffset(), diff.getEndPosition().getOffset() - diff.getStartPosition().getOffset());
404
                break;
404
                break;
405
            case CHANGE:
405
            case CHANGE:
406
                doc.remove(diff.getStartPosition().getOffset(), diff.getEndPosition().getOffset() - diff.getStartPosition().getOffset());
406
                try {
407
                doc.insertString(diff.getStartPosition().getOffset(), diff.getNewText(), null);
407
                    doc.remove(diff.getStartPosition().getOffset(), diff.getEndPosition().getOffset() - diff.getStartPosition().getOffset());
408
                    doc.insertString(diff.getStartPosition().getOffset(), diff.getNewText(), null);
409
                } catch (BadLocationException e) {
410
                    // do nothing because it won't accomplish those two
411
                    // statements anyway. bug #177824
412
                    Logger.getLogger(WorkingCopy.class.getName()).log(Level.WARNING, e.getMessage());
413
                }
408
                break;
414
                break;
409
        }
415
        }
410
    }
416
    }
Lines 430-440 Link Here
430
            }
436
            }
431
        }
437
        }
432
    }
438
    }
433
    
439
434
    /**
440
    /**
435
     * Returned string represents preview of resulting source. No difference
441
     * Returned string represents preview of resulting source. No difference
436
     * really is applied. Respects {@code isExcluded()} flag of difference.
442
     * really is applied. Respects {@code isExcluded()} flag of difference.
437
     * 
443
     *
438
     * @param   there can be more resulting source, user has to specify
444
     * @param   there can be more resulting source, user has to specify
439
     *          which wants to preview.
445
     *          which wants to preview.
440
     * @return  if changes are applied source looks like return string
446
     * @return  if changes are applied source looks like return string
Lines 447-456 Link Here
447
        if (!getModifiedFileObjects().contains(fileObject)) {
453
        if (!getModifiedFileObjects().contains(fileObject)) {
448
            throw new IllegalArgumentException("File: " + FileUtil.getFileDisplayName(fileObject) + " is not modified in this ModificationResult");
454
            throw new IllegalArgumentException("File: " + FileUtil.getFileDisplayName(fileObject) + " is not modified in this ModificationResult");
449
        }
455
        }
450
        
456
451
        StringWriter writer = new StringWriter();
457
        StringWriter writer = new StringWriter();
452
        commit(fileObject, diffs.get(fileObject), writer);
458
        commit(fileObject, diffs.get(fileObject), writer);
453
        
459
454
        return writer.toString();
460
        return writer.toString();
455
    }
461
    }
456
462
Lines 463-469 Link Here
463
    public @NullUnknown int[] getSpan(@NonNull Object tag) {
469
    public @NullUnknown int[] getSpan(@NonNull Object tag) {
464
        return tag2Span.get(tag);
470
        return tag2Span.get(tag);
465
    }
471
    }
466
    
472
467
    public static class Difference {
473
    public static class Difference {
468
              Kind kind;
474
              Kind kind;
469
        final PositionRef startPos;
475
        final PositionRef startPos;
Lines 483-517 Link Here
483
            this.description = description;
489
            this.description = description;
484
            this.excluded = false;
490
            this.excluded = false;
485
        }
491
        }
486
        
492
487
        Difference(Kind kind, PositionRef startPos, PositionRef endPos, String oldText, String newText) {
493
        Difference(Kind kind, PositionRef startPos, PositionRef endPos, String oldText, String newText) {
488
            this(kind, startPos, endPos, oldText, newText, null);
494
            this(kind, startPos, endPos, oldText, newText, null);
489
        }
495
        }
490
        
496
491
        public @NonNull Kind getKind() {
497
        public @NonNull Kind getKind() {
492
            return kind;
498
            return kind;
493
        }
499
        }
494
        
500
495
        public @NonNull PositionRef getStartPosition() {
501
        public @NonNull PositionRef getStartPosition() {
496
            return startPos;
502
            return startPos;
497
        }
503
        }
498
        
504
499
        public @NonNull PositionRef getEndPosition() {
505
        public @NonNull PositionRef getEndPosition() {
500
            return endPos;
506
            return endPos;
501
        }
507
        }
502
        
508
503
        public @NonNull String getOldText() {
509
        public @NonNull String getOldText() {
504
            return oldText;
510
            return oldText;
505
        }
511
        }
506
        
512
507
        public @NonNull String getNewText() {
513
        public @NonNull String getNewText() {
508
            return newText;
514
            return newText;
509
        }
515
        }
510
        
516
511
        public boolean isExcluded() {
517
        public boolean isExcluded() {
512
            return excluded;
518
            return excluded;
513
        }
519
        }
514
        
520
515
        public void exclude(boolean b) {
521
        public void exclude(boolean b) {
516
            excluded = b;
522
            excluded = b;
517
        }
523
        }
Lines 526-532 Link Here
526
        public boolean isCommitToGuards() {
532
        public boolean isCommitToGuards() {
527
            return ignoreGuards;
533
            return ignoreGuards;
528
        }
534
        }
529
        
535
530
        /**
536
        /**
531
         * Sets flag if it is possible to write to guarded sections.
537
         * Sets flag if it is possible to write to guarded sections.
532
         * @param b flag if it is possible to write to guarded sections
538
         * @param b flag if it is possible to write to guarded sections
Lines 543-549 Link Here
543
        public String getDescription() {
549
        public String getDescription() {
544
            return description;
550
            return description;
545
        }
551
        }
546
        
552
547
        public static enum Kind {
553
        public static enum Kind {
548
            INSERT,
554
            INSERT,
549
            REMOVE,
555
            REMOVE,
Lines 551-560 Link Here
551
            CREATE;
557
            CREATE;
552
        }
558
        }
553
    }
559
    }
554
    
560
555
    static class CreateChange extends Difference {
561
    static class CreateChange extends Difference {
556
        JavaFileObject fileObject;
562
        JavaFileObject fileObject;
557
        
563
558
        CreateChange(JavaFileObject fileObject, String text) {
564
        CreateChange(JavaFileObject fileObject, String text) {
559
            super(Kind.CREATE, null, null, null, text, "Create file " + fileObject.getName());
565
            super(Kind.CREATE, null, null, null, text, "Create file " + fileObject.getName());
560
            this.fileObject = fileObject;
566
            this.fileObject = fileObject;
Lines 569-577 Link Here
569
            return kind + "Create File: " + fileObject.getName() + "; contents = \"\n" + newText + "\"";
575
            return kind + "Create File: " + fileObject.getName() + "; contents = \"\n" + newText + "\"";
570
        }
576
        }
571
    }
577
    }
572
    
578
573
    private static final class FilteringReader extends Reader {
579
    private static final class FilteringReader extends Reader {
574
        
580
575
        private final Reader delegate;
581
        private final Reader delegate;
576
        private final boolean[] hasReturnChar;
582
        private final boolean[] hasReturnChar;
577
        private boolean beforeFirstLine = true;
583
        private boolean beforeFirstLine = true;
Lines 585-591 Link Here
585
        public int read(char[] cbuf, int off, int len) throws IOException {
591
        public int read(char[] cbuf, int off, int len) throws IOException {
586
            int read;
592
            int read;
587
            int j;
593
            int j;
588
            
594
589
            do {
595
            do {
590
                read = delegate.read(cbuf, off, len);
596
                read = delegate.read(cbuf, off, len);
591
                j = 0;
597
                j = 0;
Lines 602-608 Link Here
602
                    }
608
                    }
603
                }
609
                }
604
            } while (j == 0 && read > 0);
610
            } while (j == 0 && read > 0);
605
            
611
606
            return j;
612
            return j;
607
        }
613
        }
608
614
Lines 611-617 Link Here
611
            delegate.close();
617
            delegate.close();
612
        }
618
        }
613
    }
619
    }
614
    
620
615
    private static final class FilteringWriter extends Writer {
621
    private static final class FilteringWriter extends Writer {
616
        private final boolean[] hasReturnChar;
622
        private final boolean[] hasReturnChar;
617
        private final Writer delegate;
623
        private final Writer delegate;
Lines 626-632 Link Here
626
            if (hasReturnChar[0]) {
632
            if (hasReturnChar[0]) {
627
                char[] buf = new char[len * 2];
633
                char[] buf = new char[len * 2];
628
                int j = 0;
634
                int j = 0;
629
                
635
630
                for (int i = off; i < off + len; i++) {
636
                for (int i = off; i < off + len; i++) {
631
                    if (cbuf[i] == '\n') {
637
                    if (cbuf[i] == '\n') {
632
                        buf[j++] = '\r';
638
                        buf[j++] = '\r';
Lines 635-641 Link Here
635
                        buf[j++] = cbuf[i];
641
                        buf[j++] = cbuf[i];
636
                    }
642
                    }
637
                }
643
                }
638
                
644
639
                delegate.write(buf, 0, j);
645
                delegate.write(buf, 0, j);
640
            } else {
646
            } else {
641
                delegate.write(cbuf, off, len);
647
                delegate.write(cbuf, off, len);
Lines 651-656 Link Here
651
        public void close() throws IOException {
657
        public void close() throws IOException {
652
            delegate.close();
658
            delegate.close();
653
        }
659
        }
654
        
660
655
    }
661
    }
656
}
662
}
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/gen/GuardedBlockTest.java (-28 / +103 lines)
Lines 107-113 Link Here
107
107
108
/**
108
/**
109
 * Regression tests for guarded exceptions.
109
 * Regression tests for guarded exceptions.
110
 * 
110
 *
111
 * @author Pavel Flaska
111
 * @author Pavel Flaska
112
 */
112
 */
113
public class GuardedBlockTest extends GeneratorTestMDRCompat {
113
public class GuardedBlockTest extends GeneratorTestMDRCompat {
Lines 120-125 Link Here
120
        NbTestSuite suite = new NbTestSuite();
120
        NbTestSuite suite = new NbTestSuite();
121
//        suite.addTestSuite(GuardedBlockTest.class);
121
//        suite.addTestSuite(GuardedBlockTest.class);
122
        suite.addTest(new GuardedBlockTest("testAddMethodAfterVariables"));
122
        suite.addTest(new GuardedBlockTest("testAddMethodAfterVariables"));
123
        suite.addTest(new GuardedBlockTest("testInsertMethodBeforeVariablesBug177824"));
123
        suite.addTest(new GuardedBlockTest("test119048"));
124
        suite.addTest(new GuardedBlockTest("test119048"));
124
        suite.addTest(new GuardedBlockTest("test119962"));
125
        suite.addTest(new GuardedBlockTest("test119962"));
125
        suite.addTest(new GuardedBlockTest("testRenameTypeParameter125385"));
126
        suite.addTest(new GuardedBlockTest("testRenameTypeParameter125385"));
Lines 127-133 Link Here
127
        suite.addTest(new GuardedBlockTest("testComplex186754"));
128
        suite.addTest(new GuardedBlockTest("testComplex186754"));
128
        return suite;
129
        return suite;
129
    }
130
    }
130
    
131
131
    /**
132
    /**
132
     * We need our own data loader to use guarded blocks.
133
     * We need our own data loader to use guarded blocks.
133
     */
134
     */
Lines 156-168 Link Here
156
        cacheFolder.mkdirs();
157
        cacheFolder.mkdirs();
157
        IndexUtil.setCacheFolder(cacheFolder);
158
        IndexUtil.setCacheFolder(cacheFolder);
158
    }
159
    }
159
    
160
161
    /**
162
     * #177824: Guarded Exception
163
     */
164
    public void testInsertMethodBeforeVariablesBug177824() throws Exception {
165
166
        String source =
167
            "package javaapplication5;\n" +
168
            "\n" +
169
            "import java.awt.event.ActionEvent;\n" +
170
            "import java.awt.event.ActionListener;\n" +
171
            "\n" +
172
            "public class Guarded1 implements ActionListener {\n" +
173
            "    \n" +
174
            "    private void rbInvoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbInvoiceActionPerformed\n" +
175
            "    }//GEN-LAST:event_rbInvoiceActionPerformed\n" +
176
            "\n" +
177
            "    // Variables declaration - do not modify//GEN-BEGIN:variables\n" +
178
            "    private javax.swing.JButton jButton1;\n" +
179
            "    // End of variables declaration//GEN-END:variables\n" +
180
            "}\n";
181
182
        testFile = new File(getWorkDir(), "Test.java");
183
        TestUtilities.copyStringToFile(testFile, source);
184
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
185
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
186
        Document doc = editorCookie.openDocument();
187
        String golden =
188
            "package javaapplication5;\n" +
189
            "\n" +
190
            "import java.awt.event.ActionEvent;\n" +
191
            "import java.awt.event.ActionListener;\n" +
192
            "\n" +
193
            "public class Guarded1 implements ActionListener {\n" +
194
            "    \n" +
195
            "    private void rbInvoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbInvoiceActionPerformed\n" +
196
            "    }//GEN-LAST:event_rbInvoiceActionPerformed\n" +
197
            "\n" +
198
            "    public String toString() {\n" +
199
            "    }\n" +
200
            "\n" +
201
            "    // Variables declaration - do not modify//GEN-BEGIN:variables\n" +
202
            "    private javax.swing.JButton jButton1;\n" +
203
            "    // End of variables declaration//GEN-END:variables\n" +
204
            "}\n";
205
206
        JavaSource src = getJavaSource(testFile);
207
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
208
209
            public void run(WorkingCopy workingCopy) throws IOException {
210
                workingCopy.toPhase(RESOLVED);
211
                CompilationUnitTree cut = workingCopy.getCompilationUnit();
212
                TreeMaker make = workingCopy.getTreeMaker();
213
                ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
214
                MethodTree newMethod = make.Method(
215
                        make.Modifiers(Collections.<Modifier>singleton(Modifier.PUBLIC)),
216
                        "toString",
217
                        make.Type("java.lang.String"),
218
                        Collections.<TypeParameterTree>emptyList(),
219
                        Collections.<VariableTree>emptyList(),
220
                        Collections.<ExpressionTree>emptyList(),
221
                        make.Block(Collections.<StatementTree>emptyList(), false),
222
                        null // default value - not applicable
223
                );
224
                ClassTree copy = make.insertClassMember(clazz, 2, newMethod);
225
                workingCopy.rewrite(clazz, copy);
226
            }
227
        };
228
        src.runModificationTask(task).commit();
229
        editorCookie.saveDocument();
230
        String res = TestUtilities.copyFileToString(testFile);
231
232
        assertEquals(golden, res);
233
    }
234
160
    /**
235
    /**
161
     * #90424: Guarded Exception
236
     * #90424: Guarded Exception
162
     */
237
     */
163
    public void testAddMethodAfterVariables() throws Exception {
238
    public void testAddMethodAfterVariables() throws Exception {
164
        testFile = new File(getWorkDir(), "Test.java");
239
        testFile = new File(getWorkDir(), "Test.java");
165
        TestUtilities.copyStringToFile(testFile, 
240
        TestUtilities.copyStringToFile(testFile,
166
            "package javaapplication5;\n" +
241
            "package javaapplication5;\n" +
167
            "\n" +
242
            "\n" +
168
            "import java.awt.event.ActionEvent;\n" +
243
            "import java.awt.event.ActionEvent;\n" +
Lines 181-187 Link Here
181
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
256
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
182
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
257
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
183
        Document doc = editorCookie.openDocument();
258
        Document doc = editorCookie.openDocument();
184
        String golden = 
259
        String golden =
185
            "package javaapplication5;\n" +
260
            "package javaapplication5;\n" +
186
            "\n" +
261
            "\n" +
187
            "import java.awt.event.ActionEvent;\n" +
262
            "import java.awt.event.ActionEvent;\n" +
Lines 199-205 Link Here
199
            "    public void actionPerformed(ActionEvent e) {\n" +
274
            "    public void actionPerformed(ActionEvent e) {\n" +
200
            "    }\n" +
275
            "    }\n" +
201
            "}\n";
276
            "}\n";
202
        
277
203
        JavaSource src = getJavaSource(testFile);
278
        JavaSource src = getJavaSource(testFile);
204
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
279
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
205
280
Lines 216-229 Link Here
216
                        Collections.<VariableTree>singletonList(
291
                        Collections.<VariableTree>singletonList(
217
                            make.Variable(
292
                            make.Variable(
218
                                make.Modifiers(Collections.<Modifier>emptySet()),
293
                                make.Modifiers(Collections.<Modifier>emptySet()),
219
                                "e", 
294
                                "e",
220
                                make.Identifier("ActionEvent"), 
295
                                make.Identifier("ActionEvent"),
221
                            null)
296
                            null)
222
                        ),
297
                        ),
223
                        Collections.<ExpressionTree>emptyList(),
298
                        Collections.<ExpressionTree>emptyList(),
224
                        make.Block(Collections.<StatementTree>emptyList(), false),
299
                        make.Block(Collections.<StatementTree>emptyList(), false),
225
                        null // default value - not applicable
300
                        null // default value - not applicable
226
                ); 
301
                );
227
                ClassTree copy = make.addClassMember(clazz, newMethod);
302
                ClassTree copy = make.addClassMember(clazz, newMethod);
228
                workingCopy.rewrite(clazz, copy);
303
                workingCopy.rewrite(clazz, copy);
229
            }
304
            }
Lines 240-246 Link Here
240
     */
315
     */
241
    public void test119048() throws Exception {
316
    public void test119048() throws Exception {
242
        testFile = new File(getWorkDir(), "Test.java");
317
        testFile = new File(getWorkDir(), "Test.java");
243
        TestUtilities.copyStringToFile(testFile, 
318
        TestUtilities.copyStringToFile(testFile,
244
            "package javaapplication5;\n" +
319
            "package javaapplication5;\n" +
245
            "\n" +
320
            "\n" +
246
            "public class NewJFrame extends javax.swing.JFrame {\n" +
321
            "public class NewJFrame extends javax.swing.JFrame {\n" +
Lines 255-261 Link Here
255
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
330
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
256
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
331
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
257
        Document doc = editorCookie.openDocument();
332
        Document doc = editorCookie.openDocument();
258
        String golden = 
333
        String golden =
259
            "package javaapplication5;\n" +
334
            "package javaapplication5;\n" +
260
            "\n" +
335
            "\n" +
261
            "public class NewJFrame extends javax.swing.JFrame {\n" +
336
            "public class NewJFrame extends javax.swing.JFrame {\n" +
Lines 267-273 Link Here
267
            "    }//GEN-LAST:event_jButton1ActionPerformed\n" +
342
            "    }//GEN-LAST:event_jButton1ActionPerformed\n" +
268
            "\n" +
343
            "\n" +
269
            "}";
344
            "}";
270
        
345
271
        JavaSource src = getJavaSource(testFile);
346
        JavaSource src = getJavaSource(testFile);
272
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
347
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
273
348
Lines 293-305 Link Here
293
        System.err.println(res);
368
        System.err.println(res);
294
        assertEquals(golden, res);
369
        assertEquals(golden, res);
295
    }
370
    }
296
    
371
297
    /**
372
    /**
298
     * #119962: Guarded Exception
373
     * #119962: Guarded Exception
299
     */
374
     */
300
    public void test119962() throws Exception {
375
    public void test119962() throws Exception {
301
        testFile = new File(getWorkDir(), "Test.java");
376
        testFile = new File(getWorkDir(), "Test.java");
302
        TestUtilities.copyStringToFile(testFile, 
377
        TestUtilities.copyStringToFile(testFile,
303
            "package test;\n" +
378
            "package test;\n" +
304
            "\n" +
379
            "\n" +
305
            "public class NewJFrame extends javax.swing.JFrame {\n" +
380
            "public class NewJFrame extends javax.swing.JFrame {\n" +
Lines 330-336 Link Here
330
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
405
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
331
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
406
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
332
        Document doc = editorCookie.openDocument();
407
        Document doc = editorCookie.openDocument();
333
        String golden = 
408
        String golden =
334
            "package test;\n" +
409
            "package test;\n" +
335
            "\n" +
410
            "\n" +
336
            "public class NewJFrame extends javax.swing.JFrame {\n" +
411
            "public class NewJFrame extends javax.swing.JFrame {\n" +
Lines 360-366 Link Here
360
            "    public void actionPerformed(ActionEvent e) {\n" +
435
            "    public void actionPerformed(ActionEvent e) {\n" +
361
            "    }\n" +
436
            "    }\n" +
362
            "}";
437
            "}";
363
        
438
364
        JavaSource src = getJavaSource(testFile);
439
        JavaSource src = getJavaSource(testFile);
365
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
440
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
366
441
Lines 377-390 Link Here
377
                        Collections.<VariableTree>singletonList(
452
                        Collections.<VariableTree>singletonList(
378
                            make.Variable(
453
                            make.Variable(
379
                                make.Modifiers(Collections.<Modifier>emptySet()),
454
                                make.Modifiers(Collections.<Modifier>emptySet()),
380
                                "e", 
455
                                "e",
381
                                make.Identifier("ActionEvent"), 
456
                                make.Identifier("ActionEvent"),
382
                            null)
457
                            null)
383
                        ),
458
                        ),
384
                        Collections.<ExpressionTree>emptyList(),
459
                        Collections.<ExpressionTree>emptyList(),
385
                        make.Block(Collections.<StatementTree>emptyList(), false),
460
                        make.Block(Collections.<StatementTree>emptyList(), false),
386
                        null // default value - not applicable
461
                        null // default value - not applicable
387
                ); 
462
                );
388
                workingCopy.rewrite(clazz, make.addClassMember(clazz, newMethod));
463
                workingCopy.rewrite(clazz, make.addClassMember(clazz, newMethod));
389
            }
464
            }
390
        };
465
        };
Lines 394-400 Link Here
394
        System.err.println(res);
469
        System.err.println(res);
395
        assertEquals(golden, res);
470
        assertEquals(golden, res);
396
    }
471
    }
397
    
472
398
    /**
473
    /**
399
     * #119345: Duplicated initComponents() when trying to rename in
474
     * #119345: Duplicated initComponents() when trying to rename in
400
     * the guarded.
475
     * the guarded.
Lines 539-545 Link Here
539
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
614
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
540
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
615
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
541
        Document doc = editorCookie.openDocument();
616
        Document doc = editorCookie.openDocument();
542
        String golden = 
617
        String golden =
543
                "package crystalball;\n" +
618
                "package crystalball;\n" +
544
                "\n" +
619
                "\n" +
545
                "import org.jdesktop.application.Action;\n" +
620
                "import org.jdesktop.application.Action;\n" +
Lines 673-679 Link Here
673
                "    // End of variables declaration//GEN-END:variables\n" +
748
                "    // End of variables declaration//GEN-END:variables\n" +
674
                "    \n" +
749
                "    \n" +
675
                "}\n";
750
                "}\n";
676
        
751
677
        JavaSource src = getJavaSource(testFile);
752
        JavaSource src = getJavaSource(testFile);
678
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
753
        Task<WorkingCopy> task = new Task<WorkingCopy>() {
679
754
Lines 694-700 Link Here
694
                mst = (MemberSelectTree) invocation.getArguments().get(0);
769
                mst = (MemberSelectTree) invocation.getArguments().get(0);
695
                mst = (MemberSelectTree) mst.getExpression();
770
                mst = (MemberSelectTree) mst.getExpression();
696
                workingCopy.rewrite(mst.getExpression(), make.Identifier("crystalball"));
771
                workingCopy.rewrite(mst.getExpression(), make.Identifier("crystalball"));
697
                
772
698
                var = (VariableTree) stmts.get(16);
773
                var = (VariableTree) stmts.get(16);
699
                invocation = (MethodInvocationTree) var.getInitializer();
774
                invocation = (MethodInvocationTree) var.getInitializer();
700
                mst = (MemberSelectTree) invocation.getArguments().get(0);
775
                mst = (MemberSelectTree) invocation.getArguments().get(0);
Lines 713-722 Link Here
713
        System.err.println(res);
788
        System.err.println(res);
714
        assertEquals(golden, res);
789
        assertEquals(golden, res);
715
    }
790
    }
716
    
791
717
    public void testRenameTypeParameter125385() throws Exception {
792
    public void testRenameTypeParameter125385() throws Exception {
718
        testFile = new File(getWorkDir(), "Test.java");
793
        testFile = new File(getWorkDir(), "Test.java");
719
        TestUtilities.copyStringToFile(testFile, 
794
        TestUtilities.copyStringToFile(testFile,
720
            "package hierbas.del.litoral;\n" +
795
            "package hierbas.del.litoral;\n" +
721
            "\n" +
796
            "\n" +
722
            "public class MyList {\n" +
797
            "public class MyList {\n" +
Lines 733-744 Link Here
733
            "        return null;\n" +
808
            "        return null;\n" +
734
            "    }\n" +
809
            "    }\n" +
735
            "}\n";
810
            "}\n";
736
        
811
737
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
812
        DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile));
738
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
813
        EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class);
739
        Document doc = editorCookie.openDocument();
814
        Document doc = editorCookie.openDocument();
740
        JavaSource src = getJavaSource(testFile);
815
        JavaSource src = getJavaSource(testFile);
741
        
816
742
        Task task = new Task<WorkingCopy>() {
817
        Task task = new Task<WorkingCopy>() {
743
818
744
            public void run(final WorkingCopy workingCopy) throws IOException {
819
            public void run(final WorkingCopy workingCopy) throws IOException {
Lines 1008-1014 Link Here
1008
                ((Environment) this.env).removeSaveCookie();
1083
                ((Environment) this.env).removeSaveCookie();
1009
            }
1084
            }
1010
1085
1011
            @Override 
1086
            @Override
1012
            protected CloneableEditor createCloneableEditor() {
1087
            protected CloneableEditor createCloneableEditor() {
1013
                return new CloneableEditor(this);
1088
                return new CloneableEditor(this);
1014
            }
1089
            }

Return to bug 177824