Refactoring plug-in for Netbeans

33 views
Skip to first unread message

Chandru

unread,
Nov 6, 2009, 5:01:09 AM11/6/09
to bo...@googlegroups.com
Hi,

I tend to prefer Netbeans' overall due to the quirkiness of Eclipse.  However, one place where Netbeans is really weak is with re-factoring Java code.

Does anyone know a good plug-in which targets this specific problem of Netbeans?

Angad Singh

unread,
Nov 6, 2009, 5:47:55 AM11/6/09
to bo...@googlegroups.com
Hi Chandru,

Netbeans refactoring is fairly well featured:

Is there any particular function you find missing?

-Angad

Chandru

unread,
Nov 6, 2009, 6:41:10 AM11/6/09
to bo...@googlegroups.com
There are quite a few things missing.  In fact I wanted to raise in Netbeans' bugzilla, but unfortunately the service is down for maintenance.  :(

It might be that some of them are available but not obvious to me, ignore them.  Some of them are minor inconveniences but do hurt productivity.
  1. If I have an expression within my method, which I'd like to parameterize, there is no direct option for it. (Refactor -> Introduce Parameter in Eclispe).
  2. When changing the method parameters, there is no code assist/intellisense available for the arguments' types.
  3. Introducing a variable needs selection of the exact expression even if it is the only expression in that line.
  4. When a new variable is introduced the actual type of the expression is used and there is not option to use a super type.  The type has to be changed manually.
  5. Extracting a method does not detect other similar code fragments and replace them with invocation to new method.  See below for what I mean.  This is a trivial example.  But I'm sure you'll get the idea where you want to remove code duplicated across multiple methods.
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";
    }
}

In Eclipse, both str + "_abc" fragments are replaced in a single "Extract Method" refactoring.  But Netbeans replaces only the location from which you initiated the refactoring leaving out the other.
Reply all
Reply to author
Forward
0 new messages