Saturday, May 19, 2007

Here is a Quick Way to Eliminate Dead Code

If plug-ins were tools the Eclipse Core Tools plug-in would be a Swiss army knife. One of it's most useful tools is finding unused methods and fields in your code. I used it recently to remove obsolete code from my plug-ins.

To start removing unused code, follow these steps:

  1. Download version 1.4.0 (for Eclipse 3.2) of the Eclipse Core Tools from this update site:
    http://www.eclipse.org/eclipse/platform-core/updates/

  2. In a workspace that contains all related code, select the project / package / file you want to work on.

    (When I did this, I actually closed my unit-test projects because I didn't want to keep code around that is used nowhere but in tests. I refactored or removed the broken tests afterwards.)

  3. In the context menu select Find Unreferenced Members. The results will be shown in the Search view.



  4. Remove unreferenced code, but use your judgment!

    Some code may appear unreferenced, that in fact isn't. Common examples:
    • code that is contributed through extension-points
    • code that is invoked through reflection

    Some code may be unreferenced, but there might be good reasons for keeping it:
    • unreferenced code that is API
    • unreferenced fields in Serializable classes
    • private constructors (if you use them to enforce non-instantiability or the singleton property - Effective Java, Items 2 and 3)

  5. Repeat steps 2 - 4 as often as necessary.

What are your favorite tools for cleaning-up code?

Knife Image: (c) 2004, brokenarts/stock.xchng

Sunday, May 6, 2007

Quick Access (Ctrl+3) is bliss!

Are you one of those developers who try to get as much done as possible without lifting your fingers from the keyboard?

If you are, then you will love the new Quick Access (Ctrl+3) command introduced in Eclipse 3.3 M7. It allows you to access UI-elements - like Views, Perspectives, Commands, etc. - by just typing their name. And it supports Camel Case too.

Some usage examples:
  • Open the Navigator View? Ctrl+3, Navi, return
  • Debug Last Launched? Ctrl+3, DLL, return
  • Open the Debug Perspective? Ctrl+3, Perspectives D (Perspectives Debug), return
  • Return to the class WorkbenchAdvisor in an open editor? Ctrl+3, WorkbenchA, return (*)
The possibilities are endless...

Another subtle nicety is that Quick Access remembers the previously used choices, so the next time you press Ctrl+3 these are shown first.

(*) In the last example the file name is not matched when entering "WA". It seems that capital characters must be preceded by a whitespace in order to be picked up by the camel case matcher. E.g. "CC" would match Camel Case but not CamelCase.

UML Quick Reference

While working on some UML diagrams I realized that I could use an UML quick reference chart. A search pointed me to this UML Cheatsheet (pdf) originally posted in Lou Franco's blog. Thanks Lou, for making this available.

Since the fonts used in the cheatsheet are quite large, it is very readable even when printed out on a single page (4:1 reduction).

-- Update 04/11/2008 - I've updated the links so that they point Lou's new blog.

 

Content: © Copyright 2007 - 2009, Elias Volanakis. All rights reserved. Datenschutzhinweis / Privacy Policy