Lines 85-90
Link Here
|
85 |
// suite.addTest(new IfTest("testModifyingIf")); |
85 |
// suite.addTest(new IfTest("testModifyingIf")); |
86 |
// suite.addTest(new IfTest("test158463a")); |
86 |
// suite.addTest(new IfTest("test158463a")); |
87 |
// suite.addTest(new IfTest("test158463b")); |
87 |
// suite.addTest(new IfTest("test158463b")); |
|
|
88 |
// suite.addTest(new IfTest("test158154OneIf")); |
89 |
// suite.addTest(new IfTest("test158154TwoIfs")); |
88 |
return suite; |
90 |
return suite; |
89 |
} |
91 |
} |
90 |
|
92 |
|
Lines 433-438
Link Here
|
433 |
assertEquals(golden, res); |
435 |
assertEquals(golden, res); |
434 |
} |
436 |
} |
435 |
|
437 |
|
|
|
438 |
public void test158154OneIf() throws Exception { |
439 |
String source = "class Test {\n" |
440 |
+ " void m1(boolean b) {\n" |
441 |
+ " if (b) ; else System.out.println(\"hi\");\n" |
442 |
+ " }\n" |
443 |
+ "}"; |
444 |
String golden = "class Test {\n" |
445 |
+ " void m1(boolean b) {\n" |
446 |
+ " if (!(b)) System.out.println(\"hi\");\n" |
447 |
+ " }\n" |
448 |
+ "}"; |
449 |
testFile = new File(getWorkDir(), "Test.java"); |
450 |
|
451 |
TestUtilities.copyStringToFile(testFile, source); |
452 |
JavaSource src = getJavaSource(testFile); |
453 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
454 |
public void run(WorkingCopy copy) throws Exception { |
455 |
if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { |
456 |
return; |
457 |
} |
458 |
|
459 |
TreeMaker make = copy.getTreeMaker(); |
460 |
ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0); |
461 |
MethodTree method = (MethodTree) clazz.getMembers().get(1); |
462 |
BlockTree block = method.getBody(); |
463 |
IfTree original = (IfTree) block.getStatements().get(0); |
464 |
|
465 |
IfTree modified = make.If( |
466 |
make.Parenthesized( |
467 |
make.Unary(Kind.LOGICAL_COMPLEMENT, original.getCondition())), |
468 |
original.getElseStatement(), null); |
469 |
copy.rewrite(original, modified); |
470 |
} |
471 |
}; |
472 |
|
473 |
src.runModificationTask(task).commit(); |
474 |
String res = TestUtilities.copyFileToString(testFile); |
475 |
System.out.println(res); |
476 |
assertEquals(golden, res); |
477 |
} |
478 |
|
479 |
public void test158154TwoIfs() throws Exception { |
480 |
String source = "class Test {\n" |
481 |
+ " void m1(boolean b) {\n" |
482 |
+ " if (b) ; else System.out.println(\"first hi\");\n" |
483 |
+ " if (b) ; else System.out.println(\"second hi\");\n" |
484 |
+ " }\n" |
485 |
+ "}"; |
486 |
String golden = "class Test {\n" |
487 |
+ " void m1(boolean b) {\n" |
488 |
+ " if (!(b)) System.out.println(\"first hi\");\n" |
489 |
+ " if (!(b)) System.out.println(\"second hi\");\n" |
490 |
+ " }\n" |
491 |
+ "}"; |
492 |
testFile = new File(getWorkDir(), "Test.java"); |
493 |
TestUtilities.copyStringToFile(testFile, source); |
494 |
JavaSource src = getJavaSource(testFile); |
495 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
496 |
public void run(WorkingCopy copy) throws Exception { |
497 |
if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { |
498 |
return; |
499 |
} |
500 |
|
501 |
TreeMaker make = copy.getTreeMaker(); |
502 |
ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0); |
503 |
MethodTree method = (MethodTree) clazz.getMembers().get(1); |
504 |
BlockTree block = method.getBody(); |
505 |
IfTree originalA = (IfTree) block.getStatements().get(0); |
506 |
IfTree originalB = (IfTree) block.getStatements().get(1); |
507 |
IfTree modifiedA = make.If( |
508 |
make.Parenthesized( |
509 |
make.Unary(Kind.LOGICAL_COMPLEMENT, originalA.getCondition())), |
510 |
originalA.getElseStatement(), null); |
511 |
copy.rewrite(originalA, modifiedA); |
512 |
IfTree modifiedB = make.If( |
513 |
make.Parenthesized( |
514 |
make.Unary(Kind.LOGICAL_COMPLEMENT, originalB.getCondition())), |
515 |
originalB.getElseStatement(), null); |
516 |
copy.rewrite(originalB, modifiedB); |
517 |
} |
518 |
}; |
519 |
src.runModificationTask(task).commit(); |
520 |
String res = TestUtilities.copyFileToString(testFile); |
521 |
System.out.println(res); |
522 |
assertEquals(golden, res); |
523 |
} |
524 |
|
436 |
String getGoldenPckg() { |
525 |
String getGoldenPckg() { |
437 |
return ""; |
526 |
return ""; |
438 |
} |
527 |
} |