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 257689 - Extract method: Try to detect duplicate code by variable type and apply them as parameters
Summary: Extract method: Try to detect duplicate code by variable type and apply them ...
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 8.2
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-23 13:02 UTC by markiewb
Modified: 2016-01-23 13:02 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description markiewb 2016-01-23 13:02:39 UTC
See this code

public class NewClass {
    private UserStore store;

    class User {
        String name;int age;
        public User(String name, int age) {
            this.name = name; this.age = age;
        }
    }
    class UserStore {
        public void append(User user) {}
    }

    private void method() {
        //<select from
        User user1 = new User("peter", 19);
        store.append(user1);//<select to

        User user2 = new User("paul", 27);
        store.append(user2);

        User user3 = new User("mary", 38);
        store.append(user3);
    }

}

Now extract a method based on the selection marked by <select from..<select to

ACTUAL: a method like
    public void extracted() {
        //<select from
        User user1 = new User("peter", 19);
        store.append(user1);//<select to
    }
is extracted

EXPECTED: take in account, that there is duplicated code. Detect variables and provide them as arguments. That means this should be the result

    private void method() {
        extracted("peter", 19);
        extracted("paul", 27);
        extracted("mary", 38);
    }
    public void extracted(String name, int age) {
        User user1 = new User(name, age);
        store.append(user1);
    }

I saw that feature in Idea14/15 and it seems to be useful. 
See 
* https://pbs.twimg.com/tweet_video/CUFVK-HWoAAAH_V.mp4
* http://blog.jetbrains.com/idea/2015/02/extract-method-refactoring-improved-in-intellij-idea-14-1/