diff -r b55daa2abcb0 java.source/test/unit/src/org/netbeans/api/java/source/gen/OperatorsTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/OperatorsTest.java Mon May 11 13:04:02 2009 +0200 +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/OperatorsTest.java Thu May 14 22:21:33 2009 +0100 @@ -286,6 +286,66 @@ return make.Unary(Kind.LOGICAL_COMPLEMENT, make.Parenthesized(input)); } } + + public void testChangeUnary2() throws Exception { + String test = "public class Test { void m(int x) { int y = x+|+; } }"; + String golden = "public class Test { void m(int x) { int y = --x; } }"; + testFile = new File(getWorkDir(), "Test.java"); + final int index = test.indexOf("|"); + assertTrue(index != -1); + TestUtilities.copyStringToFile(testFile, test.replace("|", "")); + 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; + } + Tree node = copy.getTreeUtilities().pathFor(index).getLeaf(); + assertEquals(Kind.POSTFIX_INCREMENT, node.getKind()); + UnaryTree node2 = (UnaryTree) node; + IdentifierTree original = (IdentifierTree) node2.getExpression(); + System.out.println("node: " + node); + TreeMaker make = copy.getTreeMaker(); + UnaryTree modified = make.Unary(Kind.PREFIX_DECREMENT, original); + System.out.println("modified: " + modified); + copy.rewrite(node, modified); + } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + assertEquals(golden, res); + } + + public void testUnary158150() throws Exception { + String test = "public class Test { void m(int x) { int y = -| - x; } }"; + String golden = "public class Test { void m(int x) { int y = + x; } }"; + testFile = new File(getWorkDir(), "Test.java"); + final int index = test.indexOf("|"); + assertTrue(index != -1); + TestUtilities.copyStringToFile(testFile, test.replace("|", "")); + 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; + } + Tree node = copy.getTreeUtilities().pathFor(index).getLeaf(); + assertEquals(Kind.UNARY_MINUS, node.getKind()); + UnaryTree node2 = (UnaryTree) node; + UnaryTree original = (UnaryTree) node2.getExpression(); + System.out.println("node: " + node); + TreeMaker make = copy.getTreeMaker(); + UnaryTree modified = make.Unary(Kind.UNARY_PLUS, original.getExpression()); + System.out.println("modified: " + modified); + copy.rewrite(node, modified); + } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + assertEquals(golden, res); + } String getGoldenPckg() { return "";