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 176212 - Extracting a method does not detect other similar code fragments
Summary: Extracting a method does not detect other similar code fragments
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-09 05:32 UTC by chandru_in
Modified: 2010-05-10 15:30 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description chandru_in 2009-11-09 05:32:40 UTC
Extracting a method does not detect other similar code fragments and replace them with invocation to new method.  Extracting a method should have an effect as shown below.  But currently it replaces only at the location from which the refactoring was initiated.

Before Refactoring:

public class Sample { 
    public void method1(String str) { 
        String newStr = str + "_abc"; 
        // Do something on newStr. 
    } 
    public void method2(String anotherStr) { 
        String anotherNewStr = anotherStr + "_abc"; 
        // Do something else on anotherNewStr. 
    } 
}

After Refactoring: 

public class Sample { 
    public void method1(String str) { 
        String newStr = addSuffix(str); 
        // Do something on newStr. 
    } 

    public void method2(String anotherStr) { 
        String anotherNewStr = addSuffix(anotherStr); 
        // Do something else on anotherNewStr. 
    } 

    private String addSuffix(String anotherStr) { 
        return anotherStr + "_abc"; 
    } 
}
Comment 1 Jan Pokorsky 2009-11-10 09:47:14 UTC
It is org-netbeans-modules-java-hints-introduce-IntroduceMethodAction. Please do not change the component.
Comment 2 Jan Lahoda 2010-04-29 12:28:30 UTC
6.9 has the ability to find duplicates code for introduce method. This does not work for introduce method from expression, which is rather a bug. Fixed by local changeset 8ac9e0d326c5.
Comment 3 Jan Lahoda 2010-05-10 15:30:09 UTC
Should be fixed by the above changeset.