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 119-124
Link Here
|
119 |
public static NbTestSuite suite() { |
119 |
public static NbTestSuite suite() { |
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("testInsertMethodBeforeVariablesBug177824")); |
122 |
suite.addTest(new GuardedBlockTest("testAddMethodAfterVariables")); |
123 |
suite.addTest(new GuardedBlockTest("testAddMethodAfterVariables")); |
123 |
suite.addTest(new GuardedBlockTest("test119048")); |
124 |
suite.addTest(new GuardedBlockTest("test119048")); |
124 |
suite.addTest(new GuardedBlockTest("test119962")); |
125 |
suite.addTest(new GuardedBlockTest("test119962")); |
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 test;\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 fooActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fooActionPerformed\n" + |
175 |
" }//GEN-LAST:event_fooActionPerformed\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 test;\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 fooActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fooActionPerformed\n" + |
196 |
" }//GEN-LAST:event_fooActionPerformed\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 |
assertEquals(golden, res); |
232 |
} |
233 |
|
160 |
/** |
234 |
/** |
161 |
* #90424: Guarded Exception |
235 |
* #90424: Guarded Exception |
162 |
*/ |
236 |
*/ |
163 |
public void testAddMethodAfterVariables() throws Exception { |
237 |
public void testAddMethodAfterVariables() throws Exception { |
164 |
testFile = new File(getWorkDir(), "Test.java"); |
238 |
testFile = new File(getWorkDir(), "Test.java"); |
165 |
TestUtilities.copyStringToFile(testFile, |
239 |
TestUtilities.copyStringToFile(testFile, |
166 |
"package javaapplication5;\n" + |
240 |
"package javaapplication5;\n" + |
167 |
"\n" + |
241 |
"\n" + |
168 |
"import java.awt.event.ActionEvent;\n" + |
242 |
"import java.awt.event.ActionEvent;\n" + |
Lines 181-187
Link Here
|
181 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
255 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
182 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
256 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
183 |
Document doc = editorCookie.openDocument(); |
257 |
Document doc = editorCookie.openDocument(); |
184 |
String golden = |
258 |
String golden = |
185 |
"package javaapplication5;\n" + |
259 |
"package javaapplication5;\n" + |
186 |
"\n" + |
260 |
"\n" + |
187 |
"import java.awt.event.ActionEvent;\n" + |
261 |
"import java.awt.event.ActionEvent;\n" + |
Lines 199-205
Link Here
|
199 |
" public void actionPerformed(ActionEvent e) {\n" + |
273 |
" public void actionPerformed(ActionEvent e) {\n" + |
200 |
" }\n" + |
274 |
" }\n" + |
201 |
"}\n"; |
275 |
"}\n"; |
202 |
|
276 |
|
203 |
JavaSource src = getJavaSource(testFile); |
277 |
JavaSource src = getJavaSource(testFile); |
204 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
278 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
205 |
|
279 |
|
Lines 216-229
Link Here
|
216 |
Collections.<VariableTree>singletonList( |
290 |
Collections.<VariableTree>singletonList( |
217 |
make.Variable( |
291 |
make.Variable( |
218 |
make.Modifiers(Collections.<Modifier>emptySet()), |
292 |
make.Modifiers(Collections.<Modifier>emptySet()), |
219 |
"e", |
293 |
"e", |
220 |
make.Identifier("ActionEvent"), |
294 |
make.Identifier("ActionEvent"), |
221 |
null) |
295 |
null) |
222 |
), |
296 |
), |
223 |
Collections.<ExpressionTree>emptyList(), |
297 |
Collections.<ExpressionTree>emptyList(), |
224 |
make.Block(Collections.<StatementTree>emptyList(), false), |
298 |
make.Block(Collections.<StatementTree>emptyList(), false), |
225 |
null // default value - not applicable |
299 |
null // default value - not applicable |
226 |
); |
300 |
); |
227 |
ClassTree copy = make.addClassMember(clazz, newMethod); |
301 |
ClassTree copy = make.addClassMember(clazz, newMethod); |
228 |
workingCopy.rewrite(clazz, copy); |
302 |
workingCopy.rewrite(clazz, copy); |
229 |
} |
303 |
} |
Lines 240-246
Link Here
|
240 |
*/ |
314 |
*/ |
241 |
public void test119048() throws Exception { |
315 |
public void test119048() throws Exception { |
242 |
testFile = new File(getWorkDir(), "Test.java"); |
316 |
testFile = new File(getWorkDir(), "Test.java"); |
243 |
TestUtilities.copyStringToFile(testFile, |
317 |
TestUtilities.copyStringToFile(testFile, |
244 |
"package javaapplication5;\n" + |
318 |
"package javaapplication5;\n" + |
245 |
"\n" + |
319 |
"\n" + |
246 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
320 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
Lines 255-261
Link Here
|
255 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
329 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
256 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
330 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
257 |
Document doc = editorCookie.openDocument(); |
331 |
Document doc = editorCookie.openDocument(); |
258 |
String golden = |
332 |
String golden = |
259 |
"package javaapplication5;\n" + |
333 |
"package javaapplication5;\n" + |
260 |
"\n" + |
334 |
"\n" + |
261 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
335 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
Lines 267-273
Link Here
|
267 |
" }//GEN-LAST:event_jButton1ActionPerformed\n" + |
341 |
" }//GEN-LAST:event_jButton1ActionPerformed\n" + |
268 |
"\n" + |
342 |
"\n" + |
269 |
"}"; |
343 |
"}"; |
270 |
|
344 |
|
271 |
JavaSource src = getJavaSource(testFile); |
345 |
JavaSource src = getJavaSource(testFile); |
272 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
346 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
273 |
|
347 |
|
Lines 293-305
Link Here
|
293 |
System.err.println(res); |
367 |
System.err.println(res); |
294 |
assertEquals(golden, res); |
368 |
assertEquals(golden, res); |
295 |
} |
369 |
} |
296 |
|
370 |
|
297 |
/** |
371 |
/** |
298 |
* #119962: Guarded Exception |
372 |
* #119962: Guarded Exception |
299 |
*/ |
373 |
*/ |
300 |
public void test119962() throws Exception { |
374 |
public void test119962() throws Exception { |
301 |
testFile = new File(getWorkDir(), "Test.java"); |
375 |
testFile = new File(getWorkDir(), "Test.java"); |
302 |
TestUtilities.copyStringToFile(testFile, |
376 |
TestUtilities.copyStringToFile(testFile, |
303 |
"package test;\n" + |
377 |
"package test;\n" + |
304 |
"\n" + |
378 |
"\n" + |
305 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
379 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
Lines 330-336
Link Here
|
330 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
404 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
331 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
405 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
332 |
Document doc = editorCookie.openDocument(); |
406 |
Document doc = editorCookie.openDocument(); |
333 |
String golden = |
407 |
String golden = |
334 |
"package test;\n" + |
408 |
"package test;\n" + |
335 |
"\n" + |
409 |
"\n" + |
336 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
410 |
"public class NewJFrame extends javax.swing.JFrame {\n" + |
Lines 360-366
Link Here
|
360 |
" public void actionPerformed(ActionEvent e) {\n" + |
434 |
" public void actionPerformed(ActionEvent e) {\n" + |
361 |
" }\n" + |
435 |
" }\n" + |
362 |
"}"; |
436 |
"}"; |
363 |
|
437 |
|
364 |
JavaSource src = getJavaSource(testFile); |
438 |
JavaSource src = getJavaSource(testFile); |
365 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
439 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
366 |
|
440 |
|
Lines 377-390
Link Here
|
377 |
Collections.<VariableTree>singletonList( |
451 |
Collections.<VariableTree>singletonList( |
378 |
make.Variable( |
452 |
make.Variable( |
379 |
make.Modifiers(Collections.<Modifier>emptySet()), |
453 |
make.Modifiers(Collections.<Modifier>emptySet()), |
380 |
"e", |
454 |
"e", |
381 |
make.Identifier("ActionEvent"), |
455 |
make.Identifier("ActionEvent"), |
382 |
null) |
456 |
null) |
383 |
), |
457 |
), |
384 |
Collections.<ExpressionTree>emptyList(), |
458 |
Collections.<ExpressionTree>emptyList(), |
385 |
make.Block(Collections.<StatementTree>emptyList(), false), |
459 |
make.Block(Collections.<StatementTree>emptyList(), false), |
386 |
null // default value - not applicable |
460 |
null // default value - not applicable |
387 |
); |
461 |
); |
388 |
workingCopy.rewrite(clazz, make.addClassMember(clazz, newMethod)); |
462 |
workingCopy.rewrite(clazz, make.addClassMember(clazz, newMethod)); |
389 |
} |
463 |
} |
390 |
}; |
464 |
}; |
Lines 394-400
Link Here
|
394 |
System.err.println(res); |
468 |
System.err.println(res); |
395 |
assertEquals(golden, res); |
469 |
assertEquals(golden, res); |
396 |
} |
470 |
} |
397 |
|
471 |
|
398 |
/** |
472 |
/** |
399 |
* #119345: Duplicated initComponents() when trying to rename in |
473 |
* #119345: Duplicated initComponents() when trying to rename in |
400 |
* the guarded. |
474 |
* the guarded. |
Lines 539-545
Link Here
|
539 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
613 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
540 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
614 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
541 |
Document doc = editorCookie.openDocument(); |
615 |
Document doc = editorCookie.openDocument(); |
542 |
String golden = |
616 |
String golden = |
543 |
"package crystalball;\n" + |
617 |
"package crystalball;\n" + |
544 |
"\n" + |
618 |
"\n" + |
545 |
"import org.jdesktop.application.Action;\n" + |
619 |
"import org.jdesktop.application.Action;\n" + |
Lines 673-679
Link Here
|
673 |
" // End of variables declaration//GEN-END:variables\n" + |
747 |
" // End of variables declaration//GEN-END:variables\n" + |
674 |
" \n" + |
748 |
" \n" + |
675 |
"}\n"; |
749 |
"}\n"; |
676 |
|
750 |
|
677 |
JavaSource src = getJavaSource(testFile); |
751 |
JavaSource src = getJavaSource(testFile); |
678 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
752 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
679 |
|
753 |
|
Lines 694-700
Link Here
|
694 |
mst = (MemberSelectTree) invocation.getArguments().get(0); |
768 |
mst = (MemberSelectTree) invocation.getArguments().get(0); |
695 |
mst = (MemberSelectTree) mst.getExpression(); |
769 |
mst = (MemberSelectTree) mst.getExpression(); |
696 |
workingCopy.rewrite(mst.getExpression(), make.Identifier("crystalball")); |
770 |
workingCopy.rewrite(mst.getExpression(), make.Identifier("crystalball")); |
697 |
|
771 |
|
698 |
var = (VariableTree) stmts.get(16); |
772 |
var = (VariableTree) stmts.get(16); |
699 |
invocation = (MethodInvocationTree) var.getInitializer(); |
773 |
invocation = (MethodInvocationTree) var.getInitializer(); |
700 |
mst = (MemberSelectTree) invocation.getArguments().get(0); |
774 |
mst = (MemberSelectTree) invocation.getArguments().get(0); |
Lines 713-722
Link Here
|
713 |
System.err.println(res); |
787 |
System.err.println(res); |
714 |
assertEquals(golden, res); |
788 |
assertEquals(golden, res); |
715 |
} |
789 |
} |
716 |
|
790 |
|
717 |
public void testRenameTypeParameter125385() throws Exception { |
791 |
public void testRenameTypeParameter125385() throws Exception { |
718 |
testFile = new File(getWorkDir(), "Test.java"); |
792 |
testFile = new File(getWorkDir(), "Test.java"); |
719 |
TestUtilities.copyStringToFile(testFile, |
793 |
TestUtilities.copyStringToFile(testFile, |
720 |
"package hierbas.del.litoral;\n" + |
794 |
"package hierbas.del.litoral;\n" + |
721 |
"\n" + |
795 |
"\n" + |
722 |
"public class MyList {\n" + |
796 |
"public class MyList {\n" + |
Lines 733-744
Link Here
|
733 |
" return null;\n" + |
807 |
" return null;\n" + |
734 |
" }\n" + |
808 |
" }\n" + |
735 |
"}\n"; |
809 |
"}\n"; |
736 |
|
810 |
|
737 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
811 |
DataObject dataObject = DataObject.find(FileUtil.toFileObject(testFile)); |
738 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
812 |
EditorCookie editorCookie = ((GuardedDataObject) dataObject).getCookie(EditorCookie.class); |
739 |
Document doc = editorCookie.openDocument(); |
813 |
Document doc = editorCookie.openDocument(); |
740 |
JavaSource src = getJavaSource(testFile); |
814 |
JavaSource src = getJavaSource(testFile); |
741 |
|
815 |
|
742 |
Task task = new Task<WorkingCopy>() { |
816 |
Task task = new Task<WorkingCopy>() { |
743 |
|
817 |
|
744 |
public void run(final WorkingCopy workingCopy) throws IOException { |
818 |
public void run(final WorkingCopy workingCopy) throws IOException { |
Lines 1008-1014
Link Here
|
1008 |
((Environment) this.env).removeSaveCookie(); |
1082 |
((Environment) this.env).removeSaveCookie(); |
1009 |
} |
1083 |
} |
1010 |
|
1084 |
|
1011 |
@Override |
1085 |
@Override |
1012 |
protected CloneableEditor createCloneableEditor() { |
1086 |
protected CloneableEditor createCloneableEditor() { |
1013 |
return new CloneableEditor(this); |
1087 |
return new CloneableEditor(this); |
1014 |
} |
1088 |
} |