DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • My Experiences with Maven in IntelliJ IDEA and NetBeans IDE
  • Hack OpenJDK with NetBeans IDE
  • How To Do Unit Testing Using JUnit4 on Netbeans IDE
  • Build Quicker With Zipper: Building a Ping Pong Ranking App Using TypeScript Functions

Trending

  • What Is Good Database Design?
  • Revolutionizing Software Testing
  • DZone's Article Submission Guidelines
  • Designing Databases for Distributed Systems
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Student Project: Automatic Import Statement Organizer in NetBeans IDE

Student Project: Automatic Import Statement Organizer in NetBeans IDE

Jens Hofschröer user avatar by
Jens Hofschröer
·
Apr. 07, 10 · News
Like (0)
Save
Tweet
Share
17.07K Views

Join the DZone community and get the full member experience.

Join For Free

I work in the Research Group Gear Design and Manufacturing Simulation at RWTH Aachen University in Germany. I was in Göttingen last year at the NetBeans Platform Certified Training during the Source Talk Tage. It was a great help to understand the basic concepts of the NetBeans Platform. We tried to learn some things by ourselves but fell into many traps. After the training we had to rewrite a bunch of code in our application (and are still doing so).

And today I published my first NetBeans plugin in the NetBeans Plugin Portal:

http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=27296

Install it in NetBeans IDE 6.7.1 or 6.8 and you can reorganize import statements. Let's say that the import statements in my class look like this:
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import org.openide.cookies.EditorCookie;
import java.util.Collections;
import java.util.List;
import javax.swing.Action;
import javax.swing.JEditorPane;
import javax.swing.text.EditorKit;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.EditorRegistry;
import org.openide.windows.IOProvider;
import org.openide.windows.InputOutput;
import org.openide.windows.OutputWriter;

When I click Ctrl-Alt-i, the list above now is automatically as follows:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.Action;
import javax.swing.JEditorPane;
import javax.swing.text.EditorKit;
import javax.swing.text.JTextComponent;

import org.netbeans.api.editor.EditorRegistry;
import org.openide.cookies.EditorCookie;
import org.openide.windows.IOProvider;
import org.openide.windows.InputOutput;
import org.openide.windows.OutputWriter;

The plugin provides an Options window tab for configuring the import statement organizer:

Why did I make this? It's easy: I missed this feature. My first "real" Java IDE was Eclipse which has this feature "from beginning" as part of the "fix imports" feature. A great way to keep an overview of big import lists in big Java files. If you order the imports by yourself and later add some new import statements via the "fix imports" feature, you have to resort the imports every time. It's time consuming and you stop doing this every time you fix your imports.

When starting with NetBeans IDE, I missed this feature from the beginning. With every new release I wished someone else had done this because I had no time to do this at work or in my spare time. Working on another "big" Java file with many import statements, I no longer wanted to wait. So I started to search for a NetBeans module to manipulate my source files. It took about a month or so to get it working beside the actual work I needed to do.

Most work was done by searching the NetBeans site (I created a browser search plugin, which was a great advantage), reading the JavaDocs, and source code. The time I found out how to deal with the CodeGenerator classes, the rest was not that difficult. The only thing I did not find was an API to access some kind of code formatter to add the empty lines between the "import groups" so I has to "edit" the BaseDocument of the Java editor directly.

Hope the plugin will be useful!

Integrated development environment NetBeans

Opinions expressed by DZone contributors are their own.

Related

  • My Experiences with Maven in IntelliJ IDEA and NetBeans IDE
  • Hack OpenJDK with NetBeans IDE
  • How To Do Unit Testing Using JUnit4 on Netbeans IDE
  • Build Quicker With Zipper: Building a Ping Pong Ranking App Using TypeScript Functions

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: