Bug 176212 - Extracting a method does not detect other similar code fragments
Extracting a method does not detect other similar code fragments
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Hints
6.x
All All
: P3 with 1 vote (vote)
: 6.x
Assigned To: Jan Lahoda
issues@java
:
Depends on:
Blocks:
  Show dependency treegraph
 
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
:


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.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo