Sunday, August 31, 2008

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

I just filed two enhancement requests in bugzilla at Eclipse.org:

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 http://www.google.com/ in the clipboard and the text

Google|

selected in the Eclipse editor.

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

<a herf="http://www.google.com">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 "http://www.google.com/".

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 =
Logger.getLogger(Log.class.getPackage().getName());
}
return logger;
}

private Log(){}
}

Thoughts?

Monday, August 25, 2008

INFO: Eclipse View and Perspective IDs

Views
Ant org.eclipse.ant.ui.views.AntView
Bookmarks org.eclipse.ui.views.BookmarkView
Breakpoints org.eclipse.debug.ui.BreakpointView
CVS Annotate org.eclipse.team.ccvs.ui.AnnotateView
CVS Editors org.eclipse.team.ccvs.ui.EditorsView
CVS Repositories org.eclipse.team.ccvs.ui.RepositoriesView
Call Hierarchy org.eclipse.jdt.callhierarchy.view
Cheat Sheets org.eclipse.ui.cheatsheets.views.CheatSheetView
Classic Search org.eclipse.search.SearchResultView
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
Help org.eclipse.help.ui.HelpView
Hierarchy org.eclipse.jdt.ui.TypeHierarchy
History org.eclipse.team.ui.GenericHistoryView
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
Search org.eclipse.search.ui.views.SearchView
Synchronize org.eclipse.team.sync.views.SynchronizeView
Tasks org.eclipse.ui.views.TaskList
Types org.eclipse.jdt.ui.TypesView
Variables org.eclipse.debug.ui.VariableView
Welcome org.eclipse.ui.internal.introview
Perspectives
CVS Repository Exploring org.eclipse.team.cvs.ui.cvsPerspective
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 org.eclipse.team.ui.TeamSynchronizingPerspective

Monday, August 18, 2008

Sunday, August 17, 2008

Friday, August 15, 2008