diff --git a/java.hints/test/unit/src/org/netbeans/modules/java/hints/introduce/IntroduceHintTest.java b/java.hints/test/unit/src/org/netbeans/modules/java/hints/introduce/IntroduceHintTest.java --- a/java.hints/test/unit/src/org/netbeans/modules/java/hints/introduce/IntroduceHintTest.java +++ b/java.hints/test/unit/src/org/netbeans/modules/java/hints/introduce/IntroduceHintTest.java @@ -91,7 +91,7 @@ } private static Preferences codeStylePrefs;//XXX: does not allow parallel test execution - + @Override protected void setUp() throws Exception { SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]); @@ -374,7 +374,7 @@ new DialogDisplayerImpl("name", true, false, true), 4, 0); } - + // public void testFix121420() throws Exception { // performFixTest("package test; public class Test {public void test1() {|System.getProperty(\"\")|;} }", // "package test; public class Test {public void test1() { String name = System.getProperty(\"\");} }", @@ -820,7 +820,7 @@ public void testIntroduceMethodFix8() throws Exception { performFixTest("package test; import java.io.IOException; public class Test {public void test(int y) {while (true) {if (--y <= 0) break;}}}", 125 - 25, 145 - 25, - "package test; import java.io.IOException; public class Test {public void test(int y) {while (true) {if ( name(y)) break;}} private boolean name(int y) { if (--y <= 0) { return true; } return false; } }", + "package test; import java.io.IOException; public class Test {public void test(int y) {while (true) {if (name(y)) { break; } }} private boolean name(int y) { if (--y <= 0) { return true; } return false; } }", new DialogDisplayerImpl3("name", null, true)); } @@ -961,7 +961,7 @@ public void testIntroduceMethod109663f() throws Exception { performFixTest("package test; public class Test {public static void test(int y) {for (int u = y ; ; ) {if (y == 0) break; else y++;}}}", 112 - 25, 140 - 25, - "package test; public class Test {public static void test(int y) {for (int u = y ; ; ) {if ( name(y)) break;}} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }", + "package test; public class Test {public static void test(int y) {for (int u = y ; ; ) {if (name(y)) { break; } }} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }", new DialogDisplayerImpl3("name", EnumSet .of(Modifier.PRIVATE), true)); } @@ -969,7 +969,7 @@ public void testIntroduceMethod109663g() throws Exception { performFixTest("package test; public class Test {public static void test(int y) {for (Integer i : java.util.Arrays.asList(y)) {if (y == 0) break; else y++;}}}", 136 - 25, 164 - 25, - "package test; public class Test {public static void test(int y) {for (Integer i : java.util.Arrays.asList(y)) {if ( name(y)) break;}} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }", + "package test; public class Test {public static void test(int y) {for (Integer i : java.util.Arrays.asList(y)) {if (name(y)) { break; } }} private static boolean name(int y) { if (y == 0) { return true; } else { y++; } return false; } }", new DialogDisplayerImpl3("name", EnumSet .of(Modifier.PRIVATE), true)); } @@ -1399,7 +1399,7 @@ new DialogDisplayerImpl3("name", EnumSet.of(Modifier.PRIVATE), true, true), 1, 0); } - + public void testIntroduceMethodFromSingleStatement153399a() throws Exception { performFixTest("package test;\n" + "public class Test {\n" + @@ -1962,7 +1962,7 @@ new DialogDisplayerImpl2(null, IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PRIVATE), false, true), 5, 2); } - + public void testConstantFix208072a() throws Exception { Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences(); prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY"); @@ -1982,7 +1982,7 @@ new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)), 1, 0); } - + public void testConstantFix208072b() throws Exception { Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences(); prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD"); @@ -2009,7 +2009,7 @@ new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)), 5, 1); } - + public void testConstantFix208072c() throws Exception { Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences(); prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD"); @@ -2036,7 +2036,7 @@ new DialogDisplayerImpl("ZZ", true, true, true, EnumSet.of(Modifier.PRIVATE)), 5, 1); } - + public void testConstantFix219771a() throws Exception { performFixTest("package test;\n" + "public class Test {\n" + @@ -2056,7 +2056,7 @@ new DialogDisplayerImpl("C0", true, true, true, EnumSet.of(Modifier.PUBLIC)), 5, 1); } - + public void testConstantFix219771b() throws Exception { performFixTest("package test;\n" + "public class Test {\n" + @@ -2076,7 +2076,7 @@ new DialogDisplayerImpl2("C0", IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PUBLIC), true, true), 4, 1); } - + public void testConstantFix219771c() throws Exception { Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences(); prefs.put("classMembersOrder", "STATIC_INIT;FIELD;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD"); @@ -2099,7 +2099,7 @@ new DialogDisplayerImpl2("C0", IntroduceFieldPanel.INIT_FIELD, true, EnumSet.of(Modifier.PUBLIC), true, true), 5, 2); } - + public void testFieldFix208072d() throws Exception { Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences(); prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD"); @@ -2130,7 +2130,7 @@ public void testWhitespace216402() throws Exception { performSimpleSelectionVerificationTest("package test; public class Test {public void test() {int y = 3; y =| 2 |; }}", true); } - + protected void prepareTest(String code) throws Exception { clearWorkDir(); @@ -2548,7 +2548,7 @@ throw new UnsupportedOperationException("Not supported yet."); } } - + @ServiceProvider(service=Provider.class) public static final class PreferencesProvider implements Provider { @Override public Preferences forFile(FileObject file, String mimeType) { diff --git a/java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/InvertIfTest.java b/java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/InvertIfTest.java --- a/java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/InvertIfTest.java +++ b/java.hints/test/unit/src/org/netbeans/modules/java/hints/suggestions/InvertIfTest.java @@ -80,26 +80,18 @@ "public class Test {\n" + " public static void main(String[] args) {\n" + " if\n" + - " // A\n" + " (!args[0].isEmpty())\n" + - " // B\n" + - " {//4\n" + - " //5\n" + + " {\n" + " System.err.println(\"2\");\n" + - " //6\n" + " } \n" + - " // C\n" + " else\n" + - " // D\n" + - " { //1\n" + - " //2\n" + + " { \n" + " System.err.println(\"1\");\n" + - " //3\n" + - " } //E\n" + + " } \n" + " }\n" + "}\n"); } - + @Test public void testCaretPosition() throws Exception { HintTest.create() @@ -117,7 +109,7 @@ .run(InvertIf.class) .assertWarnings(); } - + @Test public void testOptimizeNeg() throws Exception { HintTest.create() @@ -147,7 +139,7 @@ " }\n" + "}\n"); } - + @Test public void testOptimizeNegParenthesized() throws Exception { HintTest.create() @@ -177,7 +169,7 @@ " }\n" + "}\n"); } - + @Test public void testOptimizeEquals() throws Exception { HintTest.create() @@ -207,7 +199,7 @@ " }\n" + "}\n"); } - + @Test public void testOptimizeNotEquals() throws Exception { HintTest.create() @@ -237,7 +229,7 @@ " }\n" + "}\n"); } - + @Test public void testTrue() throws Exception { HintTest.create() diff --git a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java b/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java --- a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java +++ b/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java @@ -170,7 +170,7 @@ //was: // int ln = td.oldTopLevel.lineMap.getLineNumber(start); // int lineStart = td.oldTopLevel.lineMap.getStartPosition(ln); - + td.printer.setInitialOffset(lineStart); Tree current = oldTree; @@ -288,7 +288,7 @@ localPointer = diffList(oldT.getTypeDecls(), newT.getTypeDecls(), localPointer, est, Measure.MEMBER, printer); printer.print(origText.substring(localPointer)); } - + private static int getOldIndent(DiffContext diffContext, Tree t) { if (diffContext.doc != null) { try { @@ -534,7 +534,7 @@ } return bounds[1]; } - + private boolean isEnum(Tree tree) { if (tree instanceof FieldGroupTree) return ((FieldGroupTree) tree).isEnum(); if (tree instanceof VariableTree) return (((JCVariableDecl) tree).getModifiers().flags & Flags.ENUM) != 0; @@ -622,7 +622,7 @@ } if (oldT.params.isEmpty()) { // compute the position. Find the parameters closing ')', its - // start position is important for us. This is used when + // start position is important for us. This is used when // there was not any parameter in original tree. int startOffset = oldT.pos; @@ -876,8 +876,8 @@ JCTree tree = oldstats.get(oldstats.size() - 1); localPointer = adjustLocalPointer(localPointer, comments.getComments(oldT), CommentSet.RelativePosition.INNER); CommentSet cs = comments.getComments(tree); - localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.INLINE); - localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.TRAILING); + localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.INLINE); + localPointer = adjustLocalPointer(localPointer, cs, CommentSet.RelativePosition.TRAILING); */ copyTo(localPointer, localPointer = endPos(oldT)); } @@ -906,7 +906,7 @@ return false; } } - + protected int diffDoLoop(JCDoWhileLoop oldT, JCDoWhileLoop newT, int[] bounds) { int localPointer = bounds[0]; @@ -1135,7 +1135,7 @@ for (Tree t = l.head; t!= null; l = l.tail, t = l.head) { printer.oldTrees.remove(t); } - } + } localPointer = diffParameterList(oldT.resources, newT.resources, parens ? new JavaTokenId[] { JavaTokenId.LPAREN, JavaTokenId.RPAREN } : null, @@ -1152,7 +1152,7 @@ } } } - + copyTo(localPointer, bodyPos[0]); localPointer = diffTree(oldT.body, newT.body, bodyPos); copyTo(localPointer, localPointer = bodyPos[1]); @@ -1503,7 +1503,7 @@ } } //#174552 end - + // rhs copyTo(localPointer, rhsBounds[0]); localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds); @@ -1858,7 +1858,7 @@ localPointer = tokenSequence.offset(); } } - + localPointer = diffAnnotationsLists(oldT.getAnnotations(), newT.getAnnotations(), startPos, localPointer); if ((oldT.flags & Flags.ANNOTATION) != 0) { @@ -1904,7 +1904,7 @@ private int diffAnnotationsLists(com.sun.tools.javac.util.List oldAnnotations, com.sun.tools.javac.util.List newAnnotations, int startPos, int localPointer) { int annotationsEnd = oldAnnotations.nonEmpty() ? endPos(oldAnnotations) : localPointer; - + if (listsMatch(oldAnnotations, newAnnotations)) { copyTo(localPointer, localPointer = (annotationsEnd != localPointer ? annotationsEnd : startPos)); } else { @@ -2344,7 +2344,7 @@ { return diffParameterList(oldList, newList, null, makeAround, pos, measure, spaceBefore, spaceAfter, isEnum, separator); } - + private int diffParameterList( List oldList, List newList, @@ -2583,7 +2583,7 @@ } case INSERT: { JCVariableDecl decl = (JCVariableDecl) item.element; - + if (oldIndex == 0) { int oldPrec = printer.setPrec(TreeInfo.noPrec); printer.visitVarDef(decl); @@ -2877,21 +2877,25 @@ } } } - if(wasInFieldGroup || treesMatch(item.element, lastdel, false)) { - VeryPretty oldPrinter = this.printer; - int old = oldPrinter.indent(); - this.printer = new VeryPretty(diffContext, diffContext.style, tree2Tag, tag2Span, origText, oldPrinter.toString().length() + oldPrinter.getInitialOffset());//XXX - this.printer.reset(old); - this.printer.oldTrees = oldTrees; - int index = oldList.indexOf(lastdel); - int[] poss = estimator.getPositions(index); - //TODO: should the original text between the return position of the following method and poss[1] be copied into the new text? - localPointer = diffTree(lastdel, item.element, poss); - printer.print(this.printer.toString()); - this.printer = oldPrinter; - this.printer.undent(old); - lastdel = null; - break; + if (wasInFieldGroup || treesMatch(item.element, lastdel, false)) { + if (item.element instanceof JCIf) { + lastdel = null; + } else { + VeryPretty oldPrinter = this.printer; + int old = oldPrinter.indent(); + this.printer = new VeryPretty(diffContext, diffContext.style, tree2Tag, tag2Span, origText, oldPrinter.toString().length() + oldPrinter.getInitialOffset());//XXX + this.printer.reset(old); + this.printer.oldTrees = oldTrees; + int index = oldList.indexOf(lastdel); + int[] poss = estimator.getPositions(index); + //TODO: should the original text between the return position of the following method and poss[1] be copied into the new text? + localPointer = diffTree(lastdel, item.element, poss); + printer.print(this.printer.toString()); + this.printer = oldPrinter; + this.printer.undent(old); + lastdel = null; + break; + } } } if (LineInsertionType.BEFORE == estimator.lineInsertType()) printer.newline(); @@ -2938,7 +2942,7 @@ protected int diffPrecedingComments(JCTree oldT, JCTree newT, int localPointer) { return diffPrecedingComments(oldT, newT, getOldPos(oldT), localPointer); } - + protected int diffPrecedingComments(JCTree oldT, JCTree newT, int oldTreeStartPos, int localPointer) { CommentSet cs = comments.getComments(newT); CommentSet old = comments.getComments(oldT); @@ -2964,7 +2968,7 @@ while (printer.out.isWhitespaceLine()) printer.eatChars(1); } - + localPointer = diffCommentLists(getOldPos(oldT), oldInlineComments, newInlineComments, false, false, localPointer); boolean containedEmbeddedNewLine = false; @@ -2973,7 +2977,7 @@ for (Comment oldComment : oldInlineComments) { if (oldComment.style() == Style.LINE) containedEmbeddedNewLine = true; } - + for (Comment nueComment : newInlineComments) { if (nueComment.style() == Style.LINE) containsEmbeddedNewLine = true; } @@ -2990,7 +2994,7 @@ Iterator newIter = newList.iterator(); Comment oldC = safeNext(oldIter); Comment newC = safeNext(newIter); - + while (oldC != null && newC != null) { if (!commentsMatch(oldC, newC)) return false; oldC = safeNext(oldIter); @@ -2999,7 +3003,7 @@ return !((oldC == null) ^ (newC == null)); } - + // refactor it! make it better private int diffCommentLists(int oldTreeStartPos, ListoldList, ListnewList, boolean trailing, boolean preceding, int localPointer) { @@ -3058,7 +3062,7 @@ } while (newC != null) { if (Style.WHITESPACE != newC.style()) { -// printer.print(newC.getText()); +// printer.print(newC.getText()); if (!firstNewCommentPrinted && preceding) { copyTo(localPointer, localPointer = oldTreeStartPos); } @@ -3204,7 +3208,7 @@ return oldBounds[1]; } } - + int commentsStart = Math.min(commentStart(comments.getComments(oldT), CommentSet.RelativePosition.INLINE), commentStart(comments.getComments(oldT), CommentSet.RelativePosition.TRAILING)); if (commentsStart < elementBounds[1]) { int lastIndex; diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/gen/BodyStatementTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/gen/BodyStatementTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/BodyStatementTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/BodyStatementTest.java @@ -64,16 +64,16 @@ /** * Test class add couple of body statements. It test statements creation and * addition to body. - * + * * @author Pavel Flaska */ public class BodyStatementTest extends GeneratorTestMDRCompat { - + /** Creates a new instance of BodyStatementTest */ public BodyStatementTest(String name) { super(name); } - + public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); suite.addTestSuite(BodyStatementTest.class); @@ -132,11 +132,11 @@ } /** - * Adds 'System.err.println(null);' statement to the method body. + * Adds 'System.err.println(null);' statement to the method body. */ public void testNullLiteral() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package hierbas.del.litoral;\n\n" + "import java.io.*;\n\n" + "public class Test {\n" + @@ -145,13 +145,13 @@ " }\n" + "}\n" ); - String golden = + String golden = "package hierbas.del.litoral;\n\n" + "import java.io.*;\n\n" + "public class Test {\n" + " public void taragui() {\n" + " ;\n" + - " System.err.println(null);\n" + + " System.err.println(null);\n" + " }\n" + "}\n"; JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); @@ -160,7 +160,7 @@ public void run(WorkingCopy workingCopy) throws java.io.IOException { workingCopy.toPhase(Phase.RESOLVED); TreeMaker make = workingCopy.getTreeMaker(); - + // finally, find the correct body and rewrite it. ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(1); @@ -182,20 +182,20 @@ BlockTree copy = make.addBlockStatement(method.getBody(), statement); workingCopy.rewrite(method.getBody(), copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** - * Adds 'System.err.println(true);' statement to the method body. + * Adds 'System.err.println(true);' statement to the method body. */ public void testBooleanLiteral() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package hierbas.del.litoral;\n\n" + "import java.io.*;\n\n" + "public class Test {\n" + @@ -204,13 +204,13 @@ " }\n" + "}\n" ); - String golden = + String golden = "package hierbas.del.litoral;\n\n" + "import java.io.*;\n\n" + "public class Test {\n" + " public void taragui() {\n" + " ;\n" + - " System.err.println(true);\n" + + " System.err.println(true);\n" + " }\n" + "}\n"; JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); @@ -219,7 +219,7 @@ public void run(WorkingCopy workingCopy) throws java.io.IOException { workingCopy.toPhase(Phase.RESOLVED); TreeMaker make = workingCopy.getTreeMaker(); - + // finally, find the correct body and rewrite it. ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(1); @@ -241,20 +241,20 @@ BlockTree copy = make.addBlockStatement(method.getBody(), statement); workingCopy.rewrite(method.getBody(), copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Renames el to element in method parameter and if statement */ public void testRenameInIfStatement() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -266,7 +266,7 @@ " }\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -302,20 +302,20 @@ IdentifierTree copy = make.setLabel(identToRename, "element"); workingCopy.rewrite(identToRename, copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Renames el to element in method parameter and if statement */ public void testRenameInLocalDecl() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -325,7 +325,7 @@ " String name = el.getName();\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -355,20 +355,20 @@ IdentifierTree copy = make.setLabel(identToRename, "element"); workingCopy.rewrite(identToRename, copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Renames el to element in method parameter and if statement */ public void testRenameInInvocationPars() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -379,7 +379,7 @@ " Collections.singleton(el);\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -410,7 +410,7 @@ IdentifierTree copy = make.setLabel(identToRename, "element"); workingCopy.rewrite(identToRename, copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); @@ -423,7 +423,7 @@ */ public void testAddMethodToAnnInTry() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -441,7 +441,7 @@ "}\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -487,20 +487,20 @@ ClassTree copy = make.addClassMember(anonClassTree, methodToAdd); workingCopy.rewrite(anonClassTree, copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Check return statement is not doubled. (#90806) */ public void testReturnNotDoubled() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -518,7 +518,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -565,20 +565,20 @@ ClassTree copy = make.addClassMember(anonClassTree, methodToAdd); workingCopy.rewrite(anonClassTree, copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Check 'for' body is not regenerated. (#91061) */ public void testForNotRegen() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -595,7 +595,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "import javax.swing.text.Element;\n" + @@ -623,17 +623,17 @@ // rewrite in initializer VariableTree initalizer = (VariableTree) forLoop.getInitializer().get(0); workingCopy.rewrite(initalizer, make.setLabel(initalizer, "newVar")); - + // rewrite in condition BinaryTree condition = (BinaryTree) forLoop.getCondition(); IdentifierTree ident = (IdentifierTree) condition.getLeftOperand(); workingCopy.rewrite(ident, make.setLabel(ident, "newVar")); - + ExpressionStatementTree update = (ExpressionStatementTree) forLoop.getUpdate().get(0); UnaryTree unary = (UnaryTree) update.getExpression(); ident = (IdentifierTree) unary.getExpression(); workingCopy.rewrite(ident, make.setLabel(ident, "newVar")); - + // and finally in the body BlockTree block = (BlockTree) forLoop.getStatement(); ExpressionStatementTree systemOut = (ExpressionStatementTree) block.getStatements().get(0); @@ -641,20 +641,20 @@ ident = (IdentifierTree) mit.getArguments().get(0); workingCopy.rewrite(ident, make.setLabel(ident, "newVar")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test for left right side of assignment */ public void testAssignLeft() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -663,7 +663,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -684,20 +684,20 @@ MemberSelectTree mstCopy = make.setLabel((MemberSelectTree) assignment.getVariable(), "key2"); workingCopy.rewrite(assignment.getVariable(), mstCopy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test for right side of assignment */ public void testAssignRight() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -706,7 +706,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -727,20 +727,20 @@ IdentifierTree copy = make.setLabel((IdentifierTree) assignment.getExpression(), "key2"); workingCopy.rewrite(assignment.getExpression(), copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test for right side of assignment */ public void testAssignBoth() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -749,7 +749,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -772,20 +772,20 @@ IdentifierTree copy = make.setLabel((IdentifierTree) assignment.getExpression(), "key2"); workingCopy.rewrite(assignment.getExpression(), copy); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test for return rename */ public void testReturn() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -794,7 +794,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -813,20 +813,20 @@ ReturnTree rejturn = (ReturnTree) method.getBody().getStatements().get(0); workingCopy.rewrite(rejturn.getExpression(), make.Identifier("nullanen2")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test in PLUS rename */ public void testPlusBinary() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -835,7 +835,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -859,20 +859,20 @@ IdentifierTree ident = (IdentifierTree) in.getRightOperand(); workingCopy.rewrite(ident, make.Identifier("key2")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Rename in while */ public void testRenameInWhile() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -884,7 +884,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -905,13 +905,13 @@ MethodTree method = (MethodTree) clazz.getMembers().get(1); VariableTree var = (VariableTree) method.getBody().getStatements().get(0); workingCopy.rewrite(var, make.setLabel(var, "counter")); - + WhileLoopTree whileLoop = (WhileLoopTree) method.getBody().getStatements().get(1); ParenthesizedTree paren = (ParenthesizedTree) whileLoop.getCondition(); BinaryTree lessThan = (BinaryTree) paren.getExpression(); IdentifierTree left = (IdentifierTree) lessThan.getLeftOperand(); workingCopy.rewrite(left, make.setLabel(left, "counter")); - + ExpressionStatementTree expr = (ExpressionStatementTree) ((BlockTree) whileLoop.getStatement()).getStatements().get(0); AssignmentTree assign = (AssignmentTree) expr.getExpression(); left = (IdentifierTree) assign.getVariable(); @@ -920,20 +920,20 @@ left = (IdentifierTree) right.getLeftOperand(); workingCopy.rewrite(left, make.setLabel(left, "counter")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Rename in do while */ public void testRenameInDoWhile() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -945,7 +945,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -966,31 +966,31 @@ MethodTree method = (MethodTree) clazz.getMembers().get(1); VariableTree var = (VariableTree) method.getBody().getStatements().get(0); workingCopy.rewrite(var, make.setLabel(var, "counter")); - + DoWhileLoopTree doWhileLoop = (DoWhileLoopTree) method.getBody().getStatements().get(1); ParenthesizedTree paren = (ParenthesizedTree) doWhileLoop.getCondition(); BinaryTree lessThan = (BinaryTree) paren.getExpression(); IdentifierTree left = (IdentifierTree) lessThan.getLeftOperand(); workingCopy.rewrite(left, make.setLabel(left, "counter")); - + ExpressionStatementTree expr = (ExpressionStatementTree) ((BlockTree) doWhileLoop.getStatement()).getStatements().get(0); UnaryTree unary = (UnaryTree) expr.getExpression(); workingCopy.rewrite(unary.getExpression(), make.setLabel(unary.getExpression(), "counter")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Rename in for each */ public void testRenameInForEach() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1002,7 +1002,7 @@ " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1013,7 +1013,7 @@ " }\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1024,7 +1024,7 @@ MethodTree method = (MethodTree) clazz.getMembers().get(1); VariableTree var = (VariableTree) method.getBody().getStatements().get(0); workingCopy.rewrite(var, make.setLabel(var, "list")); - + EnhancedForLoopTree forEach = (EnhancedForLoopTree) method.getBody().getStatements().get(1); var = forEach.getVariable(); workingCopy.rewrite(var, make.setLabel(var, "object")); @@ -1034,10 +1034,10 @@ ExpressionStatementTree est = (ExpressionStatementTree) body.getStatements().get(0); MethodInvocationTree mit = (MethodInvocationTree) est.getExpression(); MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect(); - + workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "object")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); @@ -1050,7 +1050,7 @@ */ public void testRenameInSyncro() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1063,8 +1063,8 @@ " }\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1077,7 +1077,7 @@ " }\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1088,7 +1088,7 @@ MethodTree method = (MethodTree) clazz.getMembers().get(1); VariableTree var = (VariableTree) method.getBody().getStatements().get(0); workingCopy.rewrite(var, make.setLabel(var, "zamek")); - + SynchronizedTree syncro = (SynchronizedTree) method.getBody().getStatements().get(1); ParenthesizedTree petecko = (ParenthesizedTree) syncro.getExpression(); IdentifierTree ident = (IdentifierTree) petecko.getExpression(); @@ -1097,23 +1097,23 @@ ExpressionStatementTree est = (ExpressionStatementTree) body.getStatements().get(1); MethodInvocationTree mit = (MethodInvocationTree) est.getExpression(); MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect(); - + workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "zamek")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in catch */ public void testRenameInCatch() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1126,8 +1126,8 @@ " }\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1140,7 +1140,7 @@ " }\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1160,21 +1160,21 @@ MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect(); workingCopy.rewrite(mst.getExpression(), make.setLabel(mst.getExpression(), "vyjimka")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in assign op. bit or * todo (#pf): extend test to replace right side and operator too! */ public void testRenameInAssignOp() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1183,8 +1183,8 @@ " bits2 |= 0x12;\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1193,7 +1193,7 @@ " bits |= 0x12;\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1210,14 +1210,14 @@ IdentifierTree ident = (IdentifierTree) cat.getVariable(); workingCopy.rewrite(ident, make.setLabel(ident, "bits")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in assign op. bit or * both, var and index are renamed in this test. @@ -1225,7 +1225,7 @@ */ public void testRenameInArrayIndex() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1235,8 +1235,8 @@ " System.err.println(i[pos-1]);\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1246,7 +1246,7 @@ " System.err.println(icko[position-1]);\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1269,20 +1269,20 @@ ident = (IdentifierTree) binary.getLeftOperand(); workingCopy.rewrite(ident, make.setLabel(ident, "position")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in type cast */ public void testRenameInTypeCast() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1292,8 +1292,8 @@ " Item item = (Item) o;\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1303,7 +1303,7 @@ " It it = (It) object;\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1330,20 +1330,20 @@ ident = (IdentifierTree) tct.getExpression(); workingCopy.rewrite(ident, make.setLabel(ident, "object")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in assert */ public void testRenameInAssert() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1351,8 +1351,8 @@ " assert a == 12 : a;\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1360,7 +1360,7 @@ " assert ada == 12 : ada;\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1379,20 +1379,20 @@ ident = (IdentifierTree) ass.getDetail(); workingCopy.rewrite(ident, make.setLabel(ident, "ada")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in throw statement */ public void testRenameInThrowSt() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1400,8 +1400,8 @@ " throw new NullPointerException();\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1409,7 +1409,7 @@ " throw new EnpeEcko();\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1424,20 +1424,20 @@ IdentifierTree ident = (IdentifierTree) nct.getIdentifier(); workingCopy.rewrite(ident, make.setLabel(ident, "EnpeEcko")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in conditional */ public void testRenameInConditional() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1445,8 +1445,8 @@ " int result = ada == 10 ? ada++ : --ada;\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1454,7 +1454,7 @@ " int result = alda == 10 ? alda++ : --alda;\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1478,7 +1478,7 @@ ident = (IdentifierTree) falsePart.getExpression(); workingCopy.rewrite(ident, make.setLabel(ident, "alda")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); @@ -1495,7 +1495,7 @@ 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"; JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { - + public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); TreeMaker make = workingCopy.getTreeMaker(); @@ -1505,15 +1505,15 @@ LabeledStatementTree lst = (LabeledStatementTree)block.getStatements().get(0); workingCopy.rewrite(lst, make.setLabel(lst, "zacatek_smycky")); } - - + + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #92187: Test rename in continue */ @@ -1524,7 +1524,7 @@ 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"; JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { - + public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); TreeMaker make = workingCopy.getTreeMaker(); @@ -1538,7 +1538,7 @@ ContinueTree ct = (ContinueTree)forTree.getStatements().get(0); workingCopy.rewrite(ct, make.setLabel(ct, "zacatek_smycky")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); @@ -1555,7 +1555,7 @@ 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"; JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { - + public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); @@ -1570,21 +1570,21 @@ BreakTree bt = (BreakTree)forTree.getStatements().get(0); workingCopy.rewrite(bt, make.setLabel(bt, "zacatek_smycky")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #88073: Test rename in loc. var type param. */ public void testRenameLocVarTypePar() throws Exception { testFile = new File(getWorkDir(), "Test.java"); testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n\n" + "import java.util.*;\n" + "\n" + @@ -1594,8 +1594,8 @@ " Map map2 = new TreeMap();\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n\n" + "import java.util.*;\n" + "\n" + @@ -1605,10 +1605,10 @@ " Map map2 = new TreeMap();\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { - + public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); @@ -1616,17 +1616,17 @@ ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(1); BlockTree block = method.getBody(); - + VariableTree vt = (VariableTree) block.getStatements().get(0); ParameterizedTypeTree ptt = (ParameterizedTypeTree) vt.getType(); IdentifierTree it = (IdentifierTree) ptt.getTypeArguments().get(1); workingCopy.rewrite(it, make.setLabel(it, "DataRen")); - + NewClassTree nct = (NewClassTree) vt.getInitializer(); ptt = (ParameterizedTypeTree) nct.getIdentifier(); it = (IdentifierTree) ptt.getTypeArguments().get(1); workingCopy.rewrite(it, make.setLabel(it, "DataRen")); - + vt = (VariableTree) block.getStatements().get(1); ptt = (ParameterizedTypeTree) vt.getType(); it = (IdentifierTree) ptt.getTypeArguments().get(0); @@ -1636,20 +1636,20 @@ it = (IdentifierTree) ptt.getTypeArguments().get(0); workingCopy.rewrite(it, make.setLabel(it, "DataRen")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Test rename in switch */ public void testRenameInSwitch() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1664,8 +1664,8 @@ " }\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1680,7 +1680,7 @@ " }\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1699,21 +1699,21 @@ IdentifierTree ident = (IdentifierTree) pTree.getExpression(); workingCopy.rewrite(ident, make.setLabel(ident, "renamed")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * diffNewArray * diffTypeArray */ public void testRenameInTypeNewArr() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1723,8 +1723,8 @@ " Test[][] obj = new Test[dim1][dim2];\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class RenamedTest {\n" + @@ -1734,7 +1734,7 @@ " RenamedTest[][] obj = new RenamedTest[dim1][dim2];\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1754,20 +1754,20 @@ NewArrayTree nat = (NewArrayTree) vt.getInitializer(); workingCopy.rewrite(nat.getType(), make.Identifier("RenamedTest")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * diffTypeTest */ public void testRenameInTypeTest() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1776,8 +1776,8 @@ " }\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -1786,7 +1786,7 @@ " }\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1806,20 +1806,20 @@ IdentifierTree ident = (IdentifierTree) iot.getExpression(); workingCopy.rewrite(ident, make.Identifier("obj")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * diffTypeTestII */ public void testRenameInTypeTestII() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1828,8 +1828,8 @@ " }\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class RenamedTest {\n" + @@ -1838,7 +1838,7 @@ " }\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1856,20 +1856,20 @@ IdentifierTree ident = (IdentifierTree) iot.getType(); workingCopy.rewrite(ident, make.Identifier("RenamedTest")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Changing literal test - #95614 */ public void testChangeLiteral() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1877,8 +1877,8 @@ " System.err.println(\"Karel\");\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class RenamedTest {\n" + @@ -1886,7 +1886,7 @@ " System.err.println(\"Hrebejk\");\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -1903,20 +1903,20 @@ LiteralTree literal = (LiteralTree) invocation.getArguments().get(0); workingCopy.rewrite(literal, make.Literal("Hrebejk")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Changing names in array init - #92610 */ public void testRenameInArrInit() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1925,11 +1925,11 @@ " Inner[] inArr = new Inner[] { inInst, new Inner() };\n" + " }\n" + " private static class Inner {\n" + - " public Inner() {\n" + + " public Inner() {\n" + " }\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class RenamedTest {\n" + @@ -1938,7 +1938,7 @@ " Inner[] inArr = new Inner[] { inInst, new Inner() };\n" + " }\n" + " private static class Inner {\n" + - " public Inner() {\n" + + " public Inner() {\n" + " }\n" + " }\n" + "}\n"; @@ -1954,22 +1954,22 @@ // body rename BlockTree block = method.getBody(); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Rename clazz... Test.class -> RenamedTest.class is not correctly generated * in method parameter (#92610) - * + * */ public void testRenameClazz() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -1977,7 +1977,7 @@ " method(Test.class);\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class RenamedTest {\n" + @@ -2001,7 +2001,7 @@ MemberSelectTree mst = (MemberSelectTree) mit.getArguments().get(0); workingCopy.rewrite(mst.getExpression(), make.Identifier("RenamedTest")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); @@ -2014,7 +2014,7 @@ */ public void testRenameInCase() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2032,8 +2032,8 @@ " }\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -2079,21 +2079,21 @@ CompoundAssignmentTree cat = (CompoundAssignmentTree) est.getExpression(); workingCopy.rewrite(cat.getVariable(), make.setLabel(cat.getVariable(), "ycko")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * Rename in new in parameter. (Test that issue #98438 is not caused by * generator.) */ public void testRenameClazzInNewParameter() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2101,7 +2101,7 @@ " method(new Test());\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class RenamedTest {\n" + @@ -2125,20 +2125,20 @@ NewClassTree nct = (NewClassTree) mit.getArguments().get(0); workingCopy.rewrite(nct.getIdentifier(), make.Identifier("RenamedTest")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + /** * #99445: Not well formatted statements when adding statement to body. */ public void test99445() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2146,7 +2146,7 @@ " method(new Test());\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -2181,7 +2181,7 @@ ); workingCopy.rewrite(block, make.addBlockStatement(block, est)); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); @@ -2194,7 +2194,7 @@ */ public void test101717() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2202,7 +2202,7 @@ " method(abcd, -1);\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -2222,7 +2222,7 @@ MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) block.getStatements().get(0)).getExpression(); workingCopy.rewrite(mit.getArguments().get(0), make.Identifier("abcde")); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); @@ -2232,7 +2232,7 @@ public void testModifyingIf() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2242,14 +2242,15 @@ " return y == 8;\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + " public boolean method(int i) {\n" + " int y = 0;\n" + - " if (method(null)) {return true;\n" + - "}\n" + + " if (method(null)) {\n" + + " return true;\n" + + " }\n" + " return y == 8;\n" + " }\n" + "}\n"; @@ -2266,17 +2267,17 @@ IfTree nue = make.If( make.Parenthesized( make.MethodInvocation( - Collections.emptyList(), - make.Identifier("method"), + Collections.emptyList(), + make.Identifier("method"), Arrays.asList(make.Literal(null)) ) - ), + ), make.Block(Collections.singletonList(make.Return(make.Literal(true))), false), null ); workingCopy.rewrite(mit, nue); } - + public void cancel() { } }; @@ -2285,10 +2286,10 @@ System.err.println(res); assertEquals(golden, res); } - + public void testRenameInParens() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package javaapplication1;\n" + "\n" + "import java.io.File;\n" + @@ -2304,7 +2305,7 @@ " new FileInputStream((f));\n" + " }\n" + "}\n"); - String golden = + String golden = "package javaapplication1;\n" + "\n" + "import java.io.File;\n" + @@ -2334,7 +2335,7 @@ ParenthesizedTree pareni = (ParenthesizedTree) nct.getArguments().get(0); workingCopy.rewrite(pareni.getExpression(), make.Identifier("file")); } - + public void cancel() { } }; @@ -2346,7 +2347,7 @@ public void test111983() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2358,7 +2359,7 @@ " NewClass.method();\n" + " }\n" + "}\n"); - String golden = + String golden = "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2379,7 +2380,7 @@ ClassTree clazz = (ClassTree)workingCopy.getCompilationUnit().getTypeDecls().get(0); MethodTree method = (MethodTree)clazz.getMembers().get(1); workingCopy.rewrite(method, make.setLabel(method, "metoda")); - + method = (MethodTree)clazz.getMembers().get(2); BlockTree block = method.getBody(); ExpressionStatementTree est = (ExpressionStatementTree) block.getStatements().get(0); @@ -2387,7 +2388,7 @@ MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect(); workingCopy.rewrite(mst, make.setLabel(mst, "metoda")); } - + public void cancel() { } }; @@ -2396,11 +2397,11 @@ System.err.println(res); assertEquals(golden, res); } - + // test 112290 public void test112290_1() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2409,7 +2410,7 @@ " int[][][] array = new int[size][size][size];\n" + " }\n" + "}\n"); - String golden = + String golden = "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2435,7 +2436,7 @@ workingCopy.rewrite(t, make.Identifier("velikost")); } } - + public void cancel() { } }; @@ -2444,11 +2445,11 @@ System.err.println(res); assertEquals(golden, res); } - + // test 112290 public void test112290_2() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2457,7 +2458,7 @@ " int[][][] array = new int[size][size][size];\n" + " }\n" + "}\n"); - String golden = + String golden = "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2481,7 +2482,7 @@ NewArrayTree newArr = (NewArrayTree) var.getInitializer(); workingCopy.rewrite(newArr.getDimensions().get(2), make.Identifier("velikost")); } - + public void cancel() { } }; @@ -2490,11 +2491,11 @@ System.err.println(res); assertEquals(golden, res); } - + // test 112290 public void test112290_3() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2503,7 +2504,7 @@ " int[][][] array = new int[size][size][size];\n" + " }\n" + "}\n"); - String golden = + String golden = "package javaapplication1;\n" + "\n" + "public class NewClass {\n" + @@ -2527,7 +2528,7 @@ NewArrayTree newArr = (NewArrayTree) var.getInitializer(); workingCopy.rewrite(newArr.getDimensions().get(0), make.Identifier("velikost")); } - + public void cancel() { } }; @@ -2536,10 +2537,10 @@ System.err.println(res); assertEquals(golden, res); } - + public void test126460a() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2548,8 +2549,8 @@ " assert l.get(0) == 12;\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -2559,7 +2560,7 @@ " assert name == 12;\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -2576,17 +2577,17 @@ BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit)); workingCopy.rewrite(block, nueBlock); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + public void test126460b() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2595,8 +2596,8 @@ " assert l.get(0) == 12;\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -2606,7 +2607,7 @@ " assert name == 12 : ada;\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -2624,17 +2625,17 @@ BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit)); workingCopy.rewrite(block, nueBlock); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + public void test126460c() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -2643,8 +2644,8 @@ " assert l.get(0) == 12 : ada;\n" + " }\n" + "}\n"); - - String golden = + + String golden = "package personal;\n" + "\n" + "public class Test {\n" + @@ -2654,7 +2655,7 @@ " assert name == 12;\n" + " }\n" + "}\n"; - + JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile)); Task task = new Task() { @@ -2672,14 +2673,14 @@ BlockTree nueBlock = make.insertBlockStatement(block, 1, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "name", make.Identifier("String"), mit)); workingCopy.rewrite(block, nueBlock); } - + }; testSource.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); } - + public void test159671a() throws Exception { testFile = new File(getWorkDir(), "Test.java"); TestUtilities.copyStringToFile(testFile, @@ -2801,9 +2802,9 @@ String getGoldenPckg() { return ""; } - + String getSourcePckg() { return ""; } - + } diff --git a/java.source/test/unit/src/org/netbeans/api/java/source/gen/IfTest.java b/java.source/test/unit/src/org/netbeans/api/java/source/gen/IfTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/IfTest.java +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/IfTest.java @@ -75,7 +75,7 @@ public IfTest(String name) { super(name); } - + public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); suite.addTestSuite(IfTest.class); @@ -85,6 +85,9 @@ // suite.addTest(new IfTest("testModifyingIf")); // suite.addTest(new IfTest("test158463a")); // suite.addTest(new IfTest("test158463b")); +// suite.addTest(new IfTest("test158154OneIf")); +// suite.addTest(new IfTest("test158154TwoIfs")); +// suite.addTest(new IfTest("test158154SeveralIfs")); return suite; } @@ -92,8 +95,8 @@ * Test replacing then statement with empty block. */ public void testEmptyThenBlock() throws Exception { - testFile = new File(getWorkDir(), "IfTest.java"); - TestUtilities.copyStringToFile(testFile, + testFile = new File(getWorkDir(), "IfTest.java"); + TestUtilities.copyStringToFile(testFile, "package foo.bar;\n" + "\n" + "public class IfTest {\n" + @@ -108,12 +111,12 @@ "\n" + "public class IfTest {\n" + " public void test(boolean b) {\n" + - " if( b ) {\n" + + " if (b) {\n" + " }\n" + " }\n" + "}\n"; JavaSource src = getJavaSource(testFile); - + Task task = new Task() { public void run(WorkingCopy workingCopy) throws IOException { @@ -136,10 +139,10 @@ System.err.println(res); assertEquals(golden, res); } - + public void testEmptyElseBlock() throws Exception { - testFile = new File(getWorkDir(), "IfTest.java"); - TestUtilities.copyStringToFile(testFile, + testFile = new File(getWorkDir(), "IfTest.java"); + TestUtilities.copyStringToFile(testFile, "package foo.bar;\n" + "\n" + "public class IfTest {\n" + @@ -161,7 +164,7 @@ " }\n" + "}\n"; JavaSource src = getJavaSource(testFile); - + Task task = new Task() { public void run(WorkingCopy workingCopy) throws IOException { @@ -184,10 +187,10 @@ System.err.println(res); assertEquals(golden, res); } - + public void testReplaceCondition() throws Exception { - testFile = new File(getWorkDir(), "IfTest.java"); - TestUtilities.copyStringToFile(testFile, + testFile = new File(getWorkDir(), "IfTest.java"); + TestUtilities.copyStringToFile(testFile, "package foo.bar;\n" + "\n" + "public class IfTest {\n" + @@ -207,7 +210,7 @@ " }\n" + "}\n"; JavaSource src = getJavaSource(testFile); - + Task task = new Task() { public void run(WorkingCopy workingCopy) throws IOException { @@ -233,7 +236,7 @@ public void testModifyingIf() throws Exception { testFile = new File(getWorkDir(), "Test.java"); - TestUtilities.copyStringToFile(testFile, + TestUtilities.copyStringToFile(testFile, "package personal;\n" + "\n" + "public class Test {\n" + @@ -245,13 +248,13 @@ " return y == 8;\n" + " }\n" + "}\n"); - String golden = + String golden = "package personal;\n" + "\n" + "public class Test {\n" + " public boolean method(int i) {\n" + " int y = 0;\n" + - " if (method(null)) {\n" + + " if (method(null)) {\n" + " return true;\n" + " }\n" + " return y == 8;\n" + @@ -281,7 +284,7 @@ ); workingCopy.rewrite(mit, nue); } - + public void cancel() { } }; @@ -362,9 +365,9 @@ "\n" + "public class Test {\n" + " void m1(int p, int q) {\n" + - " if ((p > 0) && (q > 0))\n" + + " if ((p > 0) && (q > 0)) {\n" + " p++;\n" + - " else {\n" + //TODO: brackets (#158154) + " } else {\n" + " p--;\n" + " }\n" + " }\n" + @@ -398,7 +401,7 @@ System.err.println(res); assertEquals(golden, res); } - + public void test159940() throws Exception { String test = "class Test {\n" + @@ -433,6 +436,162 @@ assertEquals(golden, res); } + public void test158154OneIf() throws Exception { + String source = "class Test {\n" + + " void m1(boolean b) {\n" + + " if (b) ; else System.out.println(\"hi\");\n" + + " }\n" + + "}"; + String golden = "class Test {\n" + + " void m1(boolean b) {\n" + + " if (!(b)) {\n" + + " System.out.println(\"hi\");\n" + + " }\n" + + " }\n" + + "}"; + testFile = new File(getWorkDir(), "Test.java"); + + TestUtilities.copyStringToFile(testFile, source); + JavaSource src = getJavaSource(testFile); + Task task = new Task() { + public void run(WorkingCopy copy) throws Exception { + if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { + return; + } + + TreeMaker make = copy.getTreeMaker(); + ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0); + MethodTree method = (MethodTree) clazz.getMembers().get(1); + BlockTree block = method.getBody(); + IfTree original = (IfTree) block.getStatements().get(0); + + IfTree modified = make.If( + make.Parenthesized( + make.Unary(Kind.LOGICAL_COMPLEMENT, original.getCondition())), + original.getElseStatement(), null); + copy.rewrite(original, modified); + } + }; + + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + System.out.println(res); + assertEquals(golden, res); + } + + public void test158154TwoIfs() throws Exception { + String source = "class Test {\n" + + " void m1(boolean b) {\n" + + " if (b) ; else System.out.println(\"first hi\");\n" + + " if (b) ; else System.out.println(\"second hi\");\n" + + " }\n" + + "}"; + String golden = "class Test {\n" + + " void m1(boolean b) {\n" + + " if (!(b)) {\n" + + " System.out.println(\"first hi\");\n" + + " }\n" + + " if (!(b)) {\n" + + " System.out.println(\"second hi\");\n" + + " }\n" + + " }\n" + + "}"; + testFile = new File(getWorkDir(), "Test.java"); + TestUtilities.copyStringToFile(testFile, source); + JavaSource src = getJavaSource(testFile); + Task task = new Task() { + public void run(WorkingCopy copy) throws Exception { + if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { + return; + } + + TreeMaker make = copy.getTreeMaker(); + ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0); + MethodTree method = (MethodTree) clazz.getMembers().get(1); + BlockTree block = method.getBody(); + IfTree originalA = (IfTree) block.getStatements().get(0); + IfTree originalB = (IfTree) block.getStatements().get(1); + IfTree modifiedA = make.If( + make.Parenthesized( + make.Unary(Kind.LOGICAL_COMPLEMENT, originalA.getCondition())), + originalA.getElseStatement(), null); + copy.rewrite(originalA, modifiedA); + IfTree modifiedB = make.If( + make.Parenthesized( + make.Unary(Kind.LOGICAL_COMPLEMENT, originalB.getCondition())), + originalB.getElseStatement(), null); + copy.rewrite(originalB, modifiedB); + } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + System.out.println(res); + assertEquals(golden, res); + } + + public void test158154SeveralIfs() throws Exception { + String source = "class Test {\n" + + " void m1(boolean b) {\n" + + " if (b) ; else System.out.println(\"first hi\");\n" + + " if (b) ; else System.out.println(\"second hi\");\n" + + " if (b) ; else System.out.println(\"third hi\");\n" + + " if (b) ; else System.out.println(\"fourth hi\");\n" + + " }\n" + + "}"; + String golden = "class Test {\n" + + " void m1(boolean b) {\n" + + " if (!(b)) {\n" + + " System.out.println(\"first hi\");\n" + + " }\n" + + " if (!(b)) {\n" + + " System.out.println(\"second hi\");\n" + + " }\n" + + " if (!(b)) {\n" + + " System.out.println(\"third hi\");\n" + + " }\n" + + " if (!(b)) {\n" + + " System.out.println(\"fourth hi\");\n" + + " }\n" + + " }\n" + + "}"; + testFile = new File(getWorkDir(), "Test.java"); + TestUtilities.copyStringToFile(testFile, source); + JavaSource src = getJavaSource(testFile); + Task task = new Task() { + public void run(WorkingCopy copy) throws Exception { + if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { + return; + } + + TreeMaker make = copy.getTreeMaker(); + ClassTree clazz = (ClassTree) copy.getCompilationUnit().getTypeDecls().get(0); + MethodTree method = (MethodTree) clazz.getMembers().get(1); + BlockTree block = method.getBody(); + + IfTree [] ifStatements = new IfTree[block.getStatements().size()]; + for (int i = 0; i < block.getStatements().size(); i++) { + ifStatements[i] = (IfTree) block.getStatements().get(i); + } + + IfTree [] modifiedIfs = new IfTree[block.getStatements().size()]; + for (int i = 0; i < block.getStatements().size(); i++) { + modifiedIfs[i] = make.If( + make.Parenthesized( + make.Unary(Kind.LOGICAL_COMPLEMENT, ifStatements[i].getCondition())), + ifStatements[i].getElseStatement(), null); + } + + for (int i = 0; i < block.getStatements().size(); i++) { + copy.rewrite(ifStatements[i], modifiedIfs[i]); + } + } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + System.out.println(res); + assertEquals(golden, res); + } + String getGoldenPckg() { return ""; } # HG changeset patch # User ffjre@netbeans.org # Date 1351978120 0 # Node ID a43924360613d008021e5b3d7e16eda69259030f # Parent a0be6062c996304d2c62af1e7e7d583a362b8688 # Parent 2976562fcd1781b130a8fe0176b6fff09072c05b Merge of http://hg.netbeans.org/web-main/ diff --git a/j2ee.persistence/nbproject/project.xml b/j2ee.persistence/nbproject/project.xml --- a/j2ee.persistence/nbproject/project.xml +++ b/j2ee.persistence/nbproject/project.xml @@ -50,6 +50,15 @@ org.netbeans.modules.j2ee.persistence + org.netbeans.api.annotations.common + + + + 1 + 1.17 + + + org.netbeans.api.java diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_1_0/package-info.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_1_0/package-info.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_1_0/package-info.java +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_1_0/package-info.java @@ -52,6 +52,7 @@ removeUnreferencedNodes=true, java5=true ) +@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes" package org.netbeans.modules.j2ee.persistence.dd.orm.model_1_0; import org.netbeans.modules.schema2beans.Schema2Beans; diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_2_0/package-info.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_2_0/package-info.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_2_0/package-info.java +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/orm/model_2_0/package-info.java @@ -52,6 +52,7 @@ removeUnreferencedNodes=true, java5=true ) +@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes" package org.netbeans.modules.j2ee.persistence.dd.orm.model_2_0; import org.netbeans.modules.schema2beans.Schema2Beans; diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_1_0/package-info.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_1_0/package-info.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_1_0/package-info.java +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_1_0/package-info.java @@ -51,6 +51,7 @@ removeUnreferencedNodes=true, java5=true ) +@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes" package org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0; import org.netbeans.modules.schema2beans.Schema2Beans; diff --git a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_2_0/package-info.java b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_2_0/package-info.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_2_0/package-info.java +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/dd/persistence/model_2_0/package-info.java @@ -51,6 +51,7 @@ removeUnreferencedNodes=true, java5=true ) +@org.netbeans.api.annotations.common.SuppressWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") // justification="Generated implementation classes" package org.netbeans.modules.j2ee.persistence.dd.persistence.model_2_0; import org.netbeans.modules.schema2beans.Schema2Beans;