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 |
} |