Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!

Bug 176212

Summary: Extracting a method does not detect other similar code fragments
Product: java Reporter: chandru_in <chandru_in>
Component: HintsAssignee: Jan Lahoda <jlahoda>
Status: RESOLVED FIXED QA Contact: issues <issues.netbeans.org>
Priority: P3    
Version: 6.x   
Target Milestone: 6.x   
Hardware: All   
OS: All   
Whiteboard:
Issue Type: DEFECT Exception Report:

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