Automatic Import in DrJava’s Interactions Pane

Today we had our weekly lab meeting again, and one of the topics was COMP 312, the class that develops DrJava. We decided we needed to start setting goals for the semester. I will probably work on a general tools interface that will allow my tools to interact with DrJava.

After that discussion, I was in the mood for doing a little DrJava work, and I decided to take a look at a feature that had come to my mind a while ago: One of the common problems in the Interactions Pane is a forgotten import statement. There have been several feature requests asking for this to be automated, and I thought my trusted old predictive input dialog was the right tool for this.

Whenever the “Error: Undefined class ‘Foo'” error appears after an interaction, DrJava now opens a dialog with all the standard Java API classes and lets the user select a class to import. If the user chooses one, then the import will be performed and the erroneous line re-executed. If it works, great. If there is another “undefined class” error, the dialog will appear again. The user can also press cancel to abort automatic import.

It’s not perfect, and not perfectly automatic, but it’s much better than what was there. That’s my mantra for DrJava. The predictive input dialog must be the paramount example of Extreme Programming: Written for a “Go To File” function, I’ve also used it for simple auto-completion, to display Javadoc pages, and now to import classes. About 1,500 lines of well-designed code that keep paying off…


About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in DrJava. Bookmark the permalink.

Leave a Reply