This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Created attachment 110258 [details] Code that exhibits the problem I've attached the code I'm working on that exhibits the problem. To manifest the issue: 1) Open the code, go to "Source" 2) Find the "solveButtonActionPerformed" method [it's the callback for the solve button] 3) Select all of the code inside the method 4) Refactor->Introduce method, call it "solve" The refactoring doesn't seem to work right; the end brace that was automatically created in the callback code is still there, but it appears to have put the new method *before* it, and introduced an extra closing brace after the call to the method it just created. It might be easier to show code: // Before private void solveButtonActionPerformed(java.awt.event.ActionEvent evt) { // This line is highlighted grey Boolean[][] soln = naiveSolution(); cheatedThisGame = true; if(squareSizeX == 5 && squareSizeY == 5) { soln = optimiseSolution5(soln); } dumpSolution(soln); for (int y = 0; y < squareSizeY; y++) { for (int x = 0; x < squareSizeX; x++) { Boolean thisPress = soln[y][x]; if (thisPress) { allButtonsSquare[y][x].setText("X"); } } } } // This line is highlighted grey // After private void solveButtonActionPerformed(java.awt.event.ActionEvent evt) { // This line is highlighted grey solve(); } // This end brace was introduced by the refactor private void solve() { Boolean[][] soln = naiveSolution(); cheatedThisGame = true; if(squareSizeX == 5 && squareSizeY == 5) { soln = optimiseSolution5(soln); } dumpSolution(soln); for (int y = 0; y < squareSizeY; y++) { for (int x = 0; x < squareSizeX; x++) { Boolean thisPress = soln[y][x]; if (thisPress) { allButtonsSquare[y][x].setText("X"); } } } } } // This line is highlighted grey
GUI Builder's code doesn't affect the outcome of this test-case in any way => reassigning to Java/Refactoring for evaluation.
source generator issue
Still present in dev version. The code generator is actually OK, but after that, a diff is computed between the old and new text version and then applied. However the diff does not take into account writable text areas, so as with usual diff, change/remove & insert after is confused to change across method boundary + insert a partial extracted method body. The diff ought to operate either in block scopes, or cease diffing at guarded area boundaries. This may potentially affect more refactorings; the key condition is that the newly generated text after or before guarded block is "similar enough" to the original.
Will be fixed in jet-main#aad5fd7d4c8e
Integrated into 'main-silver', will be available in build *201402200001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/aad5fd7d4c8e User: Svata Dedic <sdedic@netbeans.org> Log: #201382: CasualDiff stops at guarded block boundaries; improved whitespace preservation during code generation