Watching the Eclipse:

Eclipse is an open source platform for building development tools and even entire applications. Put on your sunglasses -- with wide industry support, Eclipse's future is very bright.

In November 2001, IBM donated $40 million worth of its Websphere Studio Workbench source code to Open Source. Dubbed “Eclipse” and managed by its own consortium, IBM’s grand experiment in Open Source has quickly become one of the most influential and disruptive Open Source projects so far, perhaps second or third only to Linux and JBoss. With more than three million downloads, 175 industry supporters (including Oracle, Rational, SAP, and Parasoft), and 100 Eclipse-compatible tools released so far, Eclipse is a juggernaut.

Some say that juggernaut is aimed squarely at Microsoft. Eclipse, they say, finally challenges Microsoft’s dominant .NET platform, offering a viable alternative to all things Redmond. Others say that Eclipse is aimed squarely at Sun: some say, Eclipse, is but the first spark in a chain reaction that eventually explodes Sun’s proprietary solutions. Some say Eclipse is destined to become the Emacs for the new millennium.

Politics and Emacs aside, Eclipse is undeniably becoming a platform technology. Written completely in Java and designed to be platform-neutral (Eclipse is currently available for Linux, Solaris, several flavors of Unix, Mac OS X, and Windows), extensible, and language-neutral, Eclipse can be used to build new programming tools or even entire applications. Eclipse is also a world-class Java IDE.

In this article, let’s give Eclipse a quick once-over, take it for a test drive, and along the way, see what it has to offer the developer and the developer community at large. Why, Eclipse’s future is so bright, it needs sunglasses.

Getting Started

To get started, head over to http://www.eclipse.org/downloads and choose a version of Eclipse to install. There are three types of builds available: releases, stable, and integration. Releases, marked by the prefix “R“, are the most stable, but often don’t contain the latest and greatest features. Stable builds are integration builds that contain the latest and greatest features, and have been used for a couple of days by the core Eclipse development team without any major problems. Stable builds are marked with an “M“. Integration builds are typically planned builds that happen every few days, when each team has new work to include. Integration builds are prefixed with “I“.

In general, stick to stable builds. Occasionally, an integration build will contain a feature that is compelling enough to warrant an upgrade. By the way, none of the builds include a Java runtime environment, so you’ll need to download JDK 1.3 or JRE 1.3 (or later) to use Eclipse.

If you’re running Eclipse on Linux, you have to decide if you want to run the GTK 2 version or the Motif version. The Motif version is more stable but uglier, while the GTK version is less stable, but much easier on the eyes. Decide which is important to you.

Great Ideas in the IDE

Some developers say, “IDEs get in the way and slow me down. They tie me to some proprietary (read: expensive) technology that’s opaque and adverse to change.” Yes, an IDE can get in the way, but a good one can also make you exceedingly more productive.

For example, Eclipse already has an enormous set of features for developing and debugging Java code. Here’s a small list of power-features that Eclipse offers:

Figure One: A Java perspective in Eclipse

Figure Two: Coding quickly with content assist

Figure Three: Using quick fix to do top-down coding

Figure Four: Keeping track of coding todos is automatic

Figure Five: Eclipse’s Task View

Figure Six: Useless code is flagged by Eclipse

Figure Seven: Choosing a live template

Figure Eight: Filling in a template

Hands-on with Eclipse

  • You can refactor code, including renaming your Java packages or classes; replacing all direct references to an instance variable with a getter/setter; and renaming a method/field and updating all references (without errors).

  • You can “hot-swap” code in the debugger, so you can debug, edit code, and restart the VM from the changed method.

  • You can save typing time with a sophisticated code completion system that offers suggestions for lexically correct completions.

  • You can leverage Live-Templates to create common Java idioms quickly. For example, Eclipse offers templates for iterating over a collection or array and surrounding a block of code with a try/catch block. Live-Edit shows syntax errors in your code as you edit it, alerting you to errors before you save your code.

  • You can use cleaner-code to highlight redundant import statements and show unused variables, hidden catch blocks, unused parameters, and assignments that have no effect (among others).

  • Eclipse has great CVS integration that, among other things, visually shows when a managed resource is out of sync.

  • Eclipse plays well with other tools, especially command-line tools like Ant and make.

Many of these features, especially those directly related to coding, are accessible directly from the keyboard, making them that much more convenient.

Let’s suit up and take a look at Eclipse.

Figure One shows one of the ways you can organize your views and editors to conveniently browse and write Java code. If you don’t like how the views are organized, you can always change them.

Notice how some of the icons (like cbg.train) have small images superimposed to the side. These small images are called overlays. The cbg.train package icon has a red “X” overlay because one of the classes in the package has an error. Likewise, glancing at the “Types” view, the Train class has an error. Notice that the Train class also has an “A” overlay, indicating that Train is an abstract class. In the “Members” view, notice that constructors are overlaid with a “C” and that the getMass() method is re-implementing a superclass’ method, as shown by the hollow up-triangle overlay.

Another time-saving feature of Eclipse is content-assist with Javadoc descriptions. Figure Two shows an example of content assist. Here the word Array was typed, followed by Ctrl-Space to activate the assist window. Once the assist window is up, you have a few choices: you can continue typing, in which case the list of completions will be pared down as you type; you can press Down Arrow to select a choice from the list and press Enter; you can reach for the mouse and select a choice; or you can press Esc and dismiss the suggestions.

Figure Three shows quick fix, one of Eclipse’s nicest features. Notice the light bulb in the left gutter. This lightbulb alerts you to an error in your code and offers suggestions on how to fix it. In this example, the method you’re trying to call doesn’t exist, so the “quick fix” is to create the method. The tip even provides a stub, updateMass(int), of the method that will be created for you. This kind of quick fix is invaluable because it allows you to write code in a top-down fashion.

There are many different types of quick fixes, including surround a block of code with a try/catch block; add a throws clause to the method declaration; cast an object to the appropriate type as you retrieve it from a collection class; offer spelling suggestions, and many more. Like content assist, quick fix can be completely driven from the keyboard or mouse.

Also notice the red squiggly underline in Figure Three. The squiggle, like those used by word processors, highlights errors in your code. This is another time-saving feature.

Let’s say you took the quick fix suggestion to create the updateMass() method. Notice in Figure Four that quick fix inserted a comment into the body of the method. The // todo comment is noticed by Eclipse’s compiler, which automatically adds a new task into the Tasks View, shown in Figure Five. When you select one of the tasks in the Tasks View, you’re taken to the appropriate line of the resource containing that task. The Tasks View also shows warnings, errors, source code management notifications, bookmarks, and todos.

Eclipse also shows you when you have useless code. Figure Six shows an example of this nice compiler feature. The import is useless because the Set class is not used anywhere in this source file. The quick fix light bulb pops up to remove the useless import for you, or you can press Ctrl-Shift-O to organize your imports, which automatically removes superfluous imports.

The assignment statement is also flagged as redundant. int size is considered useless because the temporary variable size is never read in the body of the method. Notice the small yellow boxes in the right gutter — they indicate errors. The right gutter is like a zoomed (out) view of the source and allows you to quickly jump right to a problem. You can also use the keyboard to jump to the next problem.

Figure Nine: Eclipse can generate method stubs for you

Figure Ten: Using the integrated CVS tools

Figure Eleven: JUnit is well-integrated into Eclipse

Coding Is a Pleasure

Live templates are shown in Figure Seven. It’s difficult to convey the power of live templates in words, so keep in mind that part of their usefulness comes from the fact that you can use them without taking your hands off the keyboard. Live templates are like lightweight forms: you Tab and Shift-Tab between the various fields.

In Figure Seven, you can see that fo was typed, and content assist was activated by pressing Ctrl-Space. In addition to showing valid completions, content assist also displays matching templates. Here, you’re about to choose the “iterate over a collection” template, which is previewed in the info window to the right of the content assist window.

Once you select the template, the code is inserted into the editor and the cursor is placed at the beginning of the first green underlined word, iter, shown in Figure Eight. If you start typing, you’ll replace the underlined word with your new value. Then press Tab to jump to the next underlined word. Notice that the underlined word type appears twice. The two occurrences are linked, so if you modify either of them, both will change. Eclipse comes with many preset live templates, and you’re free to add your own.

Figure Nine shows how you can quickly create method stubs for overridden or implemented methods. Select the methods you want and Eclipse creates stubs for them.

Tools to the Rescue

Figure Ten shows an example of a CVS compare on an entire Java project. In this case, ColoringPartitionScanner.java is being compared to the CVS HEAD version. Notice that the “Java Structure Compare” shows that the current version removed two methods, as indicated by the two minus signs. The editor view shows this in detail, and the gutter on the far right highlights all of the changes made to the file.

JUnit is also well-supported in Eclipse, as Figure Eleven shows. This figure shows TrainTestcase being run by the integrated JUnit runner. If (when) there is a testcase failure, the failure trace is shown in the bottom half of the view. When you select a line of the trace, the appropriate editor opens the file to the line in error.

Eclipse Plug-ins

Eclipse has an extremely extensible, modular design. At its core, Eclipse consists of plug-ins and a plug-in loader. Plug-ins both define their own code and optionally extend other plug-ins (via a mechanism called extensions). An Eclipse application (even the IDE) is simply the sum of all of its plug-ins.

Here’s an overview of what happens when Eclipse starts. First, the core is booted — this is a bootstrap to bring up the rest of Eclipse. Next, the plug-in machinery starts so all of the plug-ins can be loaded. From this point on in the lifecycle, everything else is just a plug-in. All of the concepts mentioned thus far (resources, workspaces, views, editors) are all implemented as plug-ins.

Installing new plug-ins is very easy. To install a new plug-in, simply download it (plug-ins are typically packaged as zip files), unzip the file into your Eclipse plugins directory, and restart Eclipse. Later versions of Eclipse (2.0 and greater) also include a built-in update manager that supports installing plug-ins from remote sites.

Out of the box, Eclipse includes an impressive array of plug-ins. The CVS plug-in does a nice job of adding CVS support to Eclipse. (Several developers on the newsgroup have said that it’s one of the most impressive CVS user interfaces available.) In addition to CVS, there are several third-party source code management plug-ins provided by companies and individuals, including ClearCase, Perforce, MKS, PVCS Stellation, and Visual Source Safe. There is also a Subclipse project on Sourceforge, working on adding Subversion support to Eclipse.

Eclipse also ships with integrated Ant support. The current Ant support is not as well integrated as developers want, so it is currently undergoing a major rework. JUnit support, on the other hand, is very tightly integrated, including wizards to help create test cases.

In addition to the built-in plugins, there are currently 230 plug-ins listed at the Eclipse plug-ins site. You can find XML editors, Java decompilers, UML modeling tools, and plug-ins to help develop servlets and JSPs.

In addition to Java projects, there are a number of plug-ins for other programming languages, including Ruby, C/C++, Cobol, Goo, C#, PHP, and Python.

The most useful plugins can be found at the community site at http://eclipse-plugins.2y.net/eclipse.

Eclipse As Application Framework

At first blush, Eclipse appears to be “Just Another Java IDE”, but Eclipse is really designed to be an application framework. Eclipse includes high-level concepts like workspaces, wizards, viewers, editors, resources, and, of course, plug-ins. These concepts can be used to create your own state-of-the-art IDE or your next business application.

What would a new Eclipse-based application look like? Suppose you want to build an email application. You’d begin by creating an Eclipse plug-in. Then you’d find and extend complementary plug-ins.

For example, your email plug-in can implement a Messages View (that displays a tree of all your messages organized into various folders) by extending org.eclipse .ui.views. You could also create a preferences page by extending org.eclipse.ui.preferencesPage to allow the user to customize the messages view. Finally, you can implement an editor to allow users to compose messages. by extending org.eclipse.ui.editors.

Eclipse as a framework provides a tremendous amount of code that you don’t have to write. Take Eclipse’s definition of a view as an example. Views can be opened, closed, turned into fast views, reordered by the user, stacked, extended by other plug-in writers, and more. You don’t need to write code to make your views perform any of these actions; you simply get it for free by extending the org.eclipse.ui.views.

Put On Your Shades

Eclipse is still a young project. Version 2.0 of Eclipse was released on June 27, 2002. Major bugs are being fixed in the 2.0.1 stream while work on the next major release (2.1) is ongoing. The tentative plans are to release 2.1 in March of 2003. There are a lot of exciting new features coming in 2.1 and you’re encouraged to try them out as they show up in the milestone and integration releases.

If you want to know more about the Eclipse IDE, download the Workbench User Guide. This will introduce you to most of the important Eclipse concepts, such as views, editors and perspectives. If you’re interested in writing plugins for Eclipse, make sure you read the articles found on the web site and make ample usage of the web site’s search feature. The search is useful because it searches the newsgroup as well as the web site. And since Eclipse itself is written as a set of plugins, the source code that comes with Eclipse is an invaluable resource.

SWT: Eclipse’s Secret Weapon

Probably the most controversial aspect of the Eclipse project is the SWT user interface (UI) toolkit. SWT has caused a stir because the core Eclipse development team chose to create their own cross-platform UI toolkit, instead of building on AWT or Swing.

What is SWT? Think of SWT as AWT “done right.” SWT widgets — like buttons, lists, tables, trees, and notebooks — have small memory footprints and try to leverage as much of the underlying platform as possible. In general, the Java code for SWT widgets talks directly to the native operating system. So, if you look at the source code for the GTK SWT button, you’ll see code that’s familiar to you if you’ve ever programmed a GTK button in C.

This design was intentional — it leverages existing native toolkits and provides tighter integration. When an SWT button is created in Windows, it creates a native Windows button; on the Mac, it creates a native Mac button using Carbon. When Microsoft released Windows XP with skinning support, SWT got that behavior for free just like all of the other native Windows applications. Things like drag and drop or embedding in other applications tend to be much more straightforward with native toolkits.

Yes, SWT is less feature-rich than Swing, and SWT is not nearly as flexible. However, you still have a great deal of power, evidenced by the fact that Eclipse itself is built atop SWT. Indeed, if initial response is any indication, developers agree.

Chris Grindstaff is a senior member of Applied Reasoning. He’s been using Eclipse ever since IBM released it to the public and has written several Eclipse plugins. Chris can be reached at chris@gstaff.org.

Comments are closed.