diff -r 06ad65d6fab5 java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java --- a/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java Sat May 16 19:07:21 2009 +0200 +++ b/java.source/src/org/netbeans/modules/java/source/save/CasualDiff.java Mon May 18 22:49:58 2009 +0100 @@ -1989,6 +1989,7 @@ printer.print(makeAround[0].fixedText()); } int oldIndex = 0; + int deleted = 0; boolean wasComma = false; for (int j = 0; j < result.length; j++) { ResultItem item = result[j]; @@ -2021,6 +2022,7 @@ } case DELETE: oldIndex++; + deleted++; tokenSequence.move(getBounds(item.element)[1]); moveToSrcRelevant(tokenSequence, Direction.FORWARD); pos = tokenSequence.offset(); @@ -2030,7 +2032,7 @@ oldIndex++; int[] bounds = getBounds(item.element); tokenSequence.move(bounds[0]); - if (oldIndex != 1) { + if (oldIndex - deleted != 1) { moveToSrcRelevant(tokenSequence, Direction.BACKWARD); } tokenSequence.moveNext(); diff -r 06ad65d6fab5 java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodParameterChange.pass --- a/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodParameterChange.pass Sat May 16 19:07:21 2009 +0200 +++ b/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodParameterChange.pass Mon May 18 22:49:58 2009 +0100 @@ -64,7 +64,7 @@ * * @return value of something */ - public long thirdMethod( String c, int a) { + public long thirdMethod(String c, int a) { int e = a++; String d = c; diff -r 06ad65d6fab5 java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodParameters.pass --- a/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodParameters.pass Sat May 16 19:07:21 2009 +0200 +++ b/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodParameters.pass Mon May 18 22:49:58 2009 +0100 @@ -64,7 +64,7 @@ * * @return value of something */ - public long thirdMethod( String c, int a) { + public long thirdMethod(String c, int a) { int e = a++; String d = c; diff -r 06ad65d6fab5 java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodReturnType.pass --- a/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodReturnType.pass Sat May 16 19:07:21 2009 +0200 +++ b/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodReturnType.pass Mon May 18 22:49:58 2009 +0100 @@ -64,7 +64,7 @@ * * @return value of something */ - public long thirdMethod( String c, int a) { + public long thirdMethod(String c, int a) { int e = a++; String d = c; diff -r 06ad65d6fab5 java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodThrows.pass --- a/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodThrows.pass Sat May 16 19:07:21 2009 +0200 +++ b/java.source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/MethodTest1/MethodTest1/testMethodThrows.pass Mon May 18 22:49:58 2009 +0100 @@ -64,7 +64,7 @@ * * @return value of something */ - public long thirdMethod( String c, int a) { + public long thirdMethod(String c, int a) { int e = a++; String d = c; diff -r 06ad65d6fab5 java.source/test/unit/src/org/netbeans/api/java/source/gen/Method1Test.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/Method1Test.java Sat May 16 19:07:21 2009 +0200 +++ b/java.source/test/unit/src/org/netbeans/api/java/source/gen/Method1Test.java Mon May 18 22:49:58 2009 +0100 @@ -41,6 +41,8 @@ package org.netbeans.api.java.source.gen; import com.sun.source.tree.*; +import com.sun.source.tree.Tree.Kind; +import java.io.File; import java.util.*; import java.io.IOException; import javax.lang.model.element.Modifier; @@ -70,6 +72,7 @@ suite.addTest(new Method1Test("testMethodParameterChange")); suite.addTest(new Method1Test("testMethodThrows")); suite.addTest(new Method1Test("testMethodReturnType")); + suite.addTest(new Method1Test("test159944")); // suite.addTest(new Method1Test("testMethodBody")); // suite.addTest(new Method1Test("testParameterizedMethod")); // suite.addTest(new Method1Test("testAddRemoveInOneTrans")); @@ -242,6 +245,51 @@ assertFiles("testMethodReturnType.pass"); } + public void test159944() throws Exception { + String test = + "class Test {\n" + + " void m() {\n" + + " plus(|1, Math.abs(2));\n" + + " }\n" + + "}"; + String golden = + "class Test {\n" + + " void m() {\n" + + " plus(Math.abs(2), 1);\n" + + " }\n" + + "}"; + File file = new File(getWorkDir(), "Test.java"); + final int indexA = test.indexOf("|"); + assertTrue(indexA != -1); + TestUtilities.copyStringToFile(file, test.replace("|", "")); + JavaSource src = getJavaSource(file); + 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(indexA).getLeaf(); + assertEquals(Kind.METHOD_INVOCATION, node.getKind()); + TreeMaker make = copy.getTreeMaker(); + MethodInvocationTree original = (MethodInvocationTree) node; + List oldArgs = original.getArguments(); + List newArgs = new ArrayList(); + newArgs.add(oldArgs.get(1)); + newArgs.add(oldArgs.get(0)); + @SuppressWarnings("unchecked") + MethodInvocationTree modified = make.MethodInvocation( + (List) original.getTypeArguments(), + original.getMethodSelect(), newArgs); + System.out.println("original: " + node); + System.out.println("modified: " + modified); + copy.rewrite(node, modified); } + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(file); + assertEquals(golden, res); + } + /** * Tests method body. */