diff -r b36f797e7177 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 Thu May 07 12:43:45 2009 +0200 +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/OperatorsTest.java Sun May 10 20:39:59 2009 +0100 @@ -41,6 +41,7 @@ package org.netbeans.api.java.source.gen; import com.sun.source.tree.*; +import com.sun.source.util.TreePath; import static com.sun.source.tree.Tree.*; import java.io.File; import org.netbeans.api.java.source.*; @@ -286,6 +287,35 @@ return make.Unary(Kind.LOGICAL_COMPLEMENT, make.Parenthesized(input)); } } + + 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; + } + TreePath node = copy.getTreeUtilities().pathFor(index); + assertEquals(Kind.UNARY_MINUS, node.getLeaf().getKind()); + UnaryTree original = (UnaryTree) node.getLeaf(); + System.out.println("original: " + original); + TreeMaker make = copy.getTreeMaker(); + UnaryTree modified = make.Unary(Kind.UNARY_PLUS, original.getExpression()); + System.out.println("modified: " + modified); + copy.rewrite(original, modified); + } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + assertEquals(golden, res); + } String getGoldenPckg() { return "";