Frank's Eclipse and Java Blog

Sunday, February 13, 2005

NLS Keys revisited

In the previous post I mentioned that the Eclipse NLS keys search page does exactly what I was looking for, but it turns out I was not exactly correct there. NLS Keys tries to be a little too smart, and really ties in to the "Externalize Strings" refactoring feature of Eclipse. It does not simply look for uses of the property names, but performs a search for uses of the accessor class using the Java Search Engine (as opposed to the text search engine) and some additional magic. What I found was that if you for example write a method that accepts property names as parameters and look them up in the method using the accessor class, the NLS Keys page will report them as unused! Example:


public void showErrorDialog(String titleProp,
String messageProp) {
String title = Messages.getString(titleProp);
String message = Messages.getString(messageProp);
...
}


And somewhere else:


showErrorDialog("prop1", "prop2");


Then "prop1" and "prop2" will be wrongly reported as unused...

So back to plan A and write one myself...I simply want to report all property names that cannot be found anywhere else as literal strings, regardless of the use of any accessor class. The next series of posts will be about my experiences doing this.