Dec 14 2005

Eclipse Tool Tip #6: Quick Find

Most people know that in Windows base application you can hit the ctrl+f keys to search within a document. Of course supports Eclipse ctrl+f but if you want to do a quick search just highlight the word of interest (you can double click to highlight) and hit the ctrl+k to find the next instance of said word. This is so convenient because you do not interact with any find dialog box, again to do that you can use the ctrl+f hot keys.

I can’t say it enough time that if you are using Eclipse on a daily basis you should know the hot keys to build, run, and debug your code. I have written about Eclipse hot keys before in Eclipse Tool Tip #4: Key Assist and I will probably write about debug specific hot key in a future Eclipse Tool Tip.


Nov 23 2005

Eclipse Tool Tip #5: Templates

Continuing with the Eclipse Tool Tip Series try this out. Inside a method type ‘ins’ and then hit the ctrl+space keys. You should see the instanceof template in the code assist popup box. Select it and you get the following bit of code generated for you:

if (name instanceof type)  {
    type new_name = (type) name;
}

The sample code above does not do the Eclipse template functionality any service because I can’t show you how if you update the type in the if condition it will update it in the cast and declaration for you. You have to try it out yourself or take me word for it.

By default you will have templates for try/catch, for/in, private static method, several while loops, etc. And of course you can add your custom templates. For example, I created a try catch template that automatically has our applications exception already filled. So when I type ‘try’ and hit the ctrl+space keys my try/catch template generates code like this:

try {
    // TODO: Fill in exception block
}catch(MyApplicationException ex) {
    ex.printStackTrace();
    logger.error(ex.getMessage());
    NotificationService.error(ex.getMessage());
}

If you want to add your own code template you need to open up the preferences (Window > Preferences) and click on Java > Editor > Templates to add a new template. Yes, I know, some where there is some ol’ timer muttering under his breath “Emacs had templates back in ’72.” Hey, I wasn’t there then so I wouldn’t know but templates are a common functionality in NetBeans, IntelliJ, and since Microsoft ‘tailgates’ other technologies I am sure Visual Studio has it as well.


Nov 10 2005

Eclipse Tool Tip #4: Key Assist

Every once in a while you need an assist, well, Eclipse gives it to you. Go to Help > Key Assist to open a dialog containing a lot of short cuts to different Eclipse functionality such as Content Assist (ctrl+space) to Word Complete (alt+/). The hot key short cuts I use the most are ctrl+shift+r to open a resource, ctrl+shift+t to open a type, and ctrl+t to display the type hierarchy, ctrl+shift+f for code format and ctrl+space for content assists amonst others. But if you forget all other hot keys, just remember ctrl+shift+l to open the Key Assist.


Oct 29 2005

Eclipse Tool Tip #3: Code Perspective

Even though I have two monitors, I need to utilize every possible dpi of IDE real estate. Eclipse has provides for different perspectives such as Debug and Java but it does not matter what perspective I am using, I am most interested in the code. To focus on the code select the source file you are interested and hit ctrl+m. Ctrl+m will maximize the currently selected tab. To switch back to your perspective hit the ctrl+m again.


Oct 28 2005

Hard To Debug

Whenever I start debugging the struts based web application I am working on the server freezes. I am using JBoss/Tomcat with Struts 1.1 and Eclipse 3.1. Since I can’t fire up the debugger, mark breakpoints, and set expressions I fell back to the tried and tested ‘printf method of debugging’. I call it ‘printf’ because I learned to debug this way back in my C programming days in college. Since I couldn’t fire up the debugger and examine the strack trace I throw my own debugging exceptions and print out the last few lines method calls in the stack.

    try {
        // TODO: Remove/debug
        throw new Exception("DEBUG EXCEPTION");
    }catch (Exception ex) {
        Object[] stack = ex.getStackTrace();
        for(int i=0; i < 4; i++) {
            System.out.println(stack[i]);
        }
    }

I should probably look more deeply into why the server freezes when I start up the debugger. On the other hand, I have managed to come up with a work around to get the job done.


Oct 20 2005

Eclipse Tool Tip #2: Local History

Yet another reason to love Eclipse is its Local History feature. Yeah, you might have a version control system but what happens if your recent changes are accidentally wiped out before you commit them to CVS, Perforce, or whatever else you use? If you are using Eclipse, you compare your current source file against locally saved changes. To see this in action, from the Package Explorer right click on a source file you have recently modified. Click on Compare With > Local History to open the Compare with Local History tool. You can diff between your current source and a previously saved file from your local history file. This Eclipse feature has saved me many a time, hopefully you also find it useful.