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 236447 - [Inline] Inline looses all formatting and comments
Summary: [Inline] Inline looses all formatting and comments
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.4
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-27 08:38 UTC by tomzi
Modified: 2014-05-23 02:45 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Shows the issue (118.00 KB, image/png)
2014-02-13 15:33 UTC, markiewb
Details
Proposed patch (1.02 KB, patch)
2014-04-28 21:13 UTC, markiewb
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description tomzi 2013-09-27 08:38:49 UTC
Consider this code:

    private void test() {
        inline();
    }

    private void inline() {

        System.out.println("Test1");

        //Hmmm What now?
        System.out.println("Here");
    }

Now do an inline refactoring on the inline() method:
This is what is the result:

     private void test() {
        System.out.println("Test1");
        System.out.println("Here");
    }

This is even worse for larger method, the completely loose all the formatting and comments, which is an unusable refactoring for larger methods.

Expected: Keep all exsiting formatting and comments



Product Version = NetBeans IDE 7.4 RC1 (Build 201309162201)
Operating System = Linux version 3.8.0-30-generic running on amd64
Java; VM; Vendor = 1.7.0_40
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.0-b56
Comment 1 markiewb 2014-02-13 15:33:40 UTC
Created attachment 145154 [details]
Shows the issue

Another example:

* Take the following code

package com;

public class Main
{
    private void bar()
    {
        //TODO barbar
        foo();
        //TODO barbar
    }
    
    private void foo(){
        //TODO blabla
        System.out.println("this = " + this);
        //TODO blabla
    }
}

* Inline foo()

ACTUAL: (comments are lost)
package com;

public class Main
{
    private void bar()
    {
        System.out.println("this = " + this);
        //TODO barbar
    }
}
EXPECTED: (comments are retained)
package com;

public class Main
{
    private void bar()
    {
        //TODO barbar
        //TODO blabla
        System.out.println("this = " + this);
        //TODO blabla
        //TODO barbar
    }
}

When will this be fixed? It is very annoying to review the generated code after many of those simple refactorings.
Comment 2 markiewb 2014-04-28 21:13:56 UTC
Created attachment 146991 [details]
Proposed patch

Using the following patch

package com;

public class Main
{
    private void bar()
    {
        //TODO barbar
        foo();
        //TODO barbar
    }
    
    private void foo(){
        //TODO blabla
        System.out.println("this = " + this);
        //TODO blabla
    }
}
can be transformed (at least) into

package com;

public class Main
{
    private void bar()
    {
        //TODO blabla
        System.out.println("this = " + this);
        //TODO blabla
    }
    
}

but I could not figure out how to preserve the original "barbar" comments. 
BTW: In org.netbeans.modules.refactoring.java.plugins.InlineMethodTransformer there are also two other locations where the tree is rewritten.

@Ralph: Please review!
Comment 3 Ralph Ruijs 2014-05-20 14:08:26 UTC
changeset   : e0a6cabca94c
author      : Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
date        : Tue May 20 16:00:05 CEST 2014
summary     : #236447 - [Inline] Inline looses all formatting and comments


The fix is a bit more complicated than the proposed patch. Comments are ignored if the tree is not new or changed.
Comment 4 Quality Engineering 2014-05-23 02:45:27 UTC
Integrated into 'main-silver', will be available in build *201405230001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/e0a6cabca94c
User: Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
Log: #236447 - [Inline] Inline looses all formatting and comments