ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

What's New in Eclipse 3.2 Java Development Tools
Pages: 1, 2, 3


The most basic feature of any development environment is the editor. You'll spend most of your time there, so the editor has to be comfortable and unobtrusive, yet powerful. Just about every editor since Emacs has been imbued with at least a rudimentary knowledge of common source languages so that it can provide syntax highlighting. JDT uses its Java model to go way beyond this; for example, it knows the difference between class and instance variables, so it can color them differently. It can even peek inside the source code comments to tell if a method you're calling is obsolete (deprecated) and draw a line through the method call to emphasize that this is a section of code that needs attention.

One of the more useful commands in the Java editor is Ctrl-Space (content assist). Can't remember what the methods of an object are, or how to spell a class name? Press Ctrl-Space and Eclipse will offer a list of possibilities that are valid at any given point. Eclipse 3.2 continues to improve this feature. For example, do you find yourself typing long identifiers like "LongJavaName?" Now you can enter "LJN" and press Ctrl-Space, and Eclipse will know what you mean. This is called CamelCase completion. It works when searching for types, too (Ctrl-Shift-T).

Do you get tired of typing idioms like "StringBuffer buffer = new StringBuffer();"? Don't repeat yourself. In 3.2 you can type this instead: "SB," Ctrl-Space, Space, Ctrl-Space, " = new ", Ctrl-Space, "();". That's 16 keystrokes instead of 47. Want a different prefix on that variable name? No problem--just start typing it before that second Ctrl-Space. For example, in 3.2, "Element root" + Ctrl-Space is completed to "Element rootElement" (see Figure 1).

Content assist (<code>Ctrl</code>-<code>Space</code>) is continues to get smarter in 3.2
Figure 1. Content assist (Ctrl-Space) continues to get smarter in 3.2 with its support for CamelCase and keeping already-typed characters

Here's another time saver. In 3.2, Ctrl-Space will dynamically rearrange its suggestions based on your usage patterns. So, for example, if you always assign ArrayList instances to List variables, the ArrayList proposal will be ranked first so you can pick it more quickly. Code completion even works in Javadocs now, so you can create @links or regular references without having to remember those long names.

Do you ever find yourself asking, "If the IDE is smart enough to figure out there is a problem on this line, why can't it correct it?" Well, Eclipse has a feature called Quick Fix that does that and more. Put your cursor on a line with a problem and press Ctrl-1, and Eclipse will offer suggestions to fix it.

Each new release of Eclipse adds new quick fixes; for example, in 3.2, if you're getting a warning about using raw types, put the cursor on that line, press Ctrl-1, and select a fix like "Add type parameters." Also in 3.2, Quick Fix can take care of many common problems in the same file, or even in multiple files, instead of dealing with each problem individually.

One more feature that I wanted to mention is "rename type." If you're like me, you'll often name your variables and methods similarly to your types. For example if you have a Bar type, you might have a variable called fBar and a method called createBar (see Figure 2). The problem is, if you want to rename Bar to something else, you've got a bunch of other places that have to be changed, too. Well, 3.2 makes this easier by offering to change variables and methods that have similar names to the type you are changing. This magic renaming is one of my favorite features in 3.2.

When you rename a type in Eclipse 3.2, it offers to rename variables and methods that have similar name
Figure 2. When you rename a type in Eclipse 3.2, it offers to rename variables and methods that have similar names

Pages: 1, 2, 3

Next Pagearrow