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.

Bug 201382 - Refactor "introduce method" gets confused in designer-generated callback
Summary: Refactor "introduce method" gets confused in designer-generated callback
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.0.1
Hardware: PC Linux
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-27 23:28 UTC by chunkyks
Modified: 2014-02-20 03:04 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Code that exhibits the problem (4.56 KB, application/zip)
2011-08-27 23:28 UTC, chunkyks
Details

Note You need to log in before you can comment on or make changes to this bug.
Description chunkyks 2011-08-27 23:28:54 UTC
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
Comment 1 Jan Stola 2011-08-30 09:44:38 UTC
GUI Builder's code doesn't affect the outcome of this test-case in any way => reassigning to Java/Refactoring for evaluation.
Comment 2 Jan Becicka 2011-09-15 12:44:53 UTC
source generator issue
Comment 3 Svata Dedic 2013-12-13 14:54:24 UTC
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.
Comment 4 Svata Dedic 2014-02-17 13:35:09 UTC
Will be fixed in jet-main#aad5fd7d4c8e
Comment 5 Quality Engineering 2014-02-20 03:04:14 UTC
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