Over a million developers have joined DZone.

NetBeans IDE's Cool New "Inspect & Transform" Feature

· Java Zone

Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems, brought to you in partnership with AppDynamics.

I've been using NetBeas IDE for 10+ years now and I know I've spent a lot more time griping about product bugs and lack of features than I've spent giving thanks. And it's definitely not because there isn't plenty to be thankful for!

For instance, I just discovered a feature that was added in NetBeans IDE 7.1: "Inspect and Transform". Wow! NetBeans IDE has always had a good number of refactorings and plenty of editor hints, but it hadn't previously brought the two together to let one fix/refactor many/all of the hinted shortcomings en masse.

We have a fairly large source base (about 4000 Java files) that's accumulated cruft & inefficiencies over the past 10 years and getting it back in good shape is a challenge. We're using the PMD plugin to avoid future source commits from containing these shortcomings, but it doesn't help much with fixing existing code.

With "Inspect and Transform", I just replaced 1,500 instances of

someVar.equals("") 

with

someVar.isEmpty()

...with two clicks of a button!

I also just replaced 15 inefficient loop-based List fills with

List.addAll(Arrays.asList(someArray)); 

Then I replaced 7812 instances where our code mixed String concatenation with StringBuffer/Builder.append(), such as:

stringBuilder.append("hello ").append(var1 + " " + var2)

instead of

stringBuilder.append("hello").append(var1).append(' ').append(var2))…

And there are a couple dozen more transforms I have yet to try… amazingly easy. Great job, NetBeans Team!

Developing isn't just about writing cool new features. It's also a lot of refactoring and rejigging to adapt software over time.

Thanks to NetBeans for making that job a bit easier!

The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}