Over a million developers have joined DZone.

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

· Java Zone

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.

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




...with two clicks of a button!

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


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 JetBrains.  Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}