posted by Laurent Duperval on Fri 9th Apr 2004 07:44 UTC
IconEclipse is one powerful IDE. I've been using it for a few weeks and in this article, I will be reviewing a few of the features that make it such a wonderful tool.

I've been a Vim user for the longest time. Vim has always been a great development tool, but with the complexity of Java development nowadays, I've found that IDE's are no longer candy: they have become a necessity.

I've used a number of IDE's. My first love was Forte. Then, someone explained to me that Forte was based on Netbeans. So I tried Netbeans and I liked it. It was my main IDE for almost two years. But I was still using Vim periodically because some editing was easier in Vim than in Netbeans.

Then, one of my colleagues (Michel, it's all your fault!) introduced me to IntelliJ IDEA. I was hooked! IntelliJ remains my favourite IDE, even more than Eclipse. But I don't have the funds to pay for a license, so I looked for the next best thing.

I'd been hearing a lot about Eclipse so I decided to try it. My first use of Eclipse was during the 2.1 era. At that time, it had a bad bug which froze the interface when using cetain versions of GTK+. But late last year, the 3.0 releases began showing up and the bug was gone. I started looking closely at Eclipse and I liked what I saw. I adopted it and since then, I've been trying to locate all the little things that can speed development time.

This isn't an introduction to Eclipse, it doesn't cover every aspect but it covers enough nifty features to hopefully make you want to give it a spin.

Automate it!

The greatest element of modern IDE's, I find, is the automation of a lot of repetitive, boring and not very educational tasks. For example, creating new classes (screenshot). It's always the same: insert the package declaration, put some Javadoc, the class name and maybe a couple of other things.

Most IDE's have facilities to automate creation of classes. But what if the way it creates them is not the way you need them to be? For example, I have a client who likes his code to look like this:

/***********************
 * Class: ClassName
 *
 * © 2004, This company, All rights reserved
 **********************/

package com.foo.package;

/**
 * Class: ClassName
 * 
 * This class does something.
 *
 * Created by: My Name
 * On: Creation date
 */
public class ClassName {
    
    private c_iAnInteger;
    
    //////////////////////////
    // getAnInteger()
    /////////////////////////
    /**
     * Put some text here
     *
     * @return
     */
    public void getAnInteger() {
        return c_iAnInteger;
    }

    //////////////////////////
    // setAnInteger()
    /////////////////////////
    /**
     * Put some text here
     *
     * @javadoc
     */
    public void setAnInteger(int p_iAnInteger) {
        c_iAnInteger = p_iAnInteger;
    }

    //////////////////////////
    // aMethod()
    /////////////////////////
    /**
     * Put some text here
     *
     * @javadoc
     */
    public void aMethod() {
        ;
    }

}

As you can see, it's pretty far from the Java Coding Standards. After creating one or two classes like that, I quickly saw that I needed to automate this or I'd lose my mind! That's where Eclipse's templates come into play.

Templates for classes

Templates are pieces of code that you tell Eclipse to use when it is generating code for you. You can use special variables that are expanded to insert appropriate code in the generated code. So in the end, Eclipse does everything that doesn't require any thinking to accomplish, while you have fun writing real code.

This is what a template to generate the above class looks like:

/***********************
 * Class: ${type_name}
 *
 * © 2004, This company, All rights reserved
 **********************/

${package_declaration}

${typecomment}
${type_declaration} 
So what does all this mean? Chances are that just by looking at the above code, you have a pretty good idea what it does. Everything that is not a variable will be inserted as is. Variables look like this: ${string}. In the above snippet, these are the variables used:

${type_name}: This is the name of the class. In our example, it is expanded to ClassName.

${package_declaration}: The package declaration. Eclipse will generate the package declaration for you automatically, depending on where in your source tree the new file will be created.

${type_comment}: This inserts the comment for the class. Comments templates are defined separately, as we will see later.

${type_declaration}: This is the actual code for the class, with its name, the type modifiers (private, public, static, etc.) and any automatically generated methods.

Once the template for the class is to our liking, we can concentrate on the templates for the various pieces of code.

Table of contents
  1. "Templates with Eclipse, Page 1/2"
  2. "Templates with Eclipse, Page 2/2"
e p (0)    27 Comment(s)