Over a million developers have joined DZone.

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

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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!

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}