Sunday, August 31, 2008

Eclipse template variables ${selection} and ${clipboard}

I just filed two enhancement requests in bugzilla at

245788 Add a template variable ${selection} and allow Surround With action to deal consider it.
245790 Add a template variable ${clipboard}

The jist of the enhancement is that two new template variables should be added:

${selection} - this is replaced by what ever was the selection in the editor at the time of template insertion was invoked. Note that this requires a template invocation machanism that does not destroy the selection in text editor.
${clipboard} - this is replaced by the text content of the the clipboard.

Here is a use case:

template name: hyperlink
template pattern:

<a href="${clipboard}">${selection}</a>${cursor}

and with text in the clipboard and the text


selected in the Eclipse editor.

Invoking the hyperlink template using the Surround with... action yields:

<a herf="">Google</a>

Granted this would have been easy to type but imagine a complex URL copied into the clipboard from the browser address bar in place of "".

Please vote on the enhancement if you like this idea.

Friday, August 29, 2008

Self maintaining package level logger access class

Many times I have seen that programmers declare a static field which hold an instance of a Logger. I find this pattern repeated in many classes in the same package. Below is an example of a simple package level logger accessor class. It has an interesting property being a self maintaining code in that you can drop this code in any package and fix the package name by hand or even better let the IDE such as Eclipse provide the quick fix to correct the package for you.
package somepackage;

import java.util.logging.Logger;

* Self maintaining package level logger access
final class Log {
private static Logger logger;

// not thread safe
static Logger getLogger() {
if (logger == null) {
logger =
return logger;

private Log(){}


Monday, August 25, 2008

INFO: Eclipse View and Perspective IDs

Ant org.eclipse.ant.ui.views.AntView
Bookmarks org.eclipse.ui.views.BookmarkView
Breakpoints org.eclipse.debug.ui.BreakpointView
CVS Annotate
CVS Editors
CVS Repositories
Call Hierarchy org.eclipse.jdt.callhierarchy.view
Cheat Sheets org.eclipse.ui.cheatsheets.views.CheatSheetView
Classic Search
Console org.eclipse.ui.console.ConsoleView
Debug org.eclipse.debug.ui.DebugView
Declaration org.eclipse.jdt.ui.SourceView
Display org.eclipse.jdt.debug.ui.DisplayView
Error Log org.eclipse.pde.runtime.LogView
Expressions org.eclipse.debug.ui.ExpressionView
Hierarchy org.eclipse.jdt.ui.TypeHierarchy
Internal Web Browser org.eclipse.ui.browser.view
JUnit org.eclipse.jdt.junit.ResultView
Javadoc org.eclipse.jdt.ui.JavadocView
Members org.eclipse.jdt.ui.MembersView
Memory org.eclipse.debug.ui.MemoryView
Navigator org.eclipse.ui.views.ResourceNavigator
Outline org.eclipse.ui.views.ContentOutline
Package Explorer org.eclipse.jdt.ui.PackageExplorer
Packages org.eclipse.jdt.ui.PackagesView
Plug-in Dependencies org.eclipse.pde.ui.DependenciesView
Plug-in Registry org.eclipse.pde.runtime.RegistryBrowser
Plug-ins org.eclipse.pde.ui.PluginsView
Problems org.eclipse.ui.views.ProblemView
Progress org.eclipse.ui.views.ProgressView
Project Explorer org.eclipse.ui.navigator.ProjectExplorer
Projects org.eclipse.jdt.ui.ProjectsView
Properties org.eclipse.ui.views.PropertySheet
Registers org.eclipse.debug.ui.RegisterView
SVN Annotate org.tigris.subversion.subclipse.ui.annotations.AnnotateView
SVN Properties org.tigris.subversion.subclipse.ui.svnproperties.SvnPropertiesView
SVN Repositories org.tigris.subversion.subclipse.ui.repository.RepositoriesView
Tasks org.eclipse.ui.views.TaskList
Types org.eclipse.jdt.ui.TypesView
Variables org.eclipse.debug.ui.VariableView
Welcome org.eclipse.ui.internal.introview
CVS Repository Exploring
Debug org.eclipse.debug.ui.DebugPerspective
Java org.eclipse.jdt.ui.JavaPerspective
Java Browsing org.eclipse.jdt.ui.JavaBrowsingPerspective
Java Type Hierarchy org.eclipse.jdt.ui.JavaHierarchyPerspective
Plug-in Development org.eclipse.pde.ui.PDEPerspective
Resource org.eclipse.ui.resourcePerspective
SVN Repository Exploring org.tigris.subversion.subclipse.ui.svnPerspective
Team Synchronizing

Monday, August 18, 2008

Sunday, August 17, 2008

Friday, August 15, 2008