开发者

find unused properties in eclipse

I开发者_Go百科 have set of classes and (struts)jsp files which uses Message bundle. I want to find properties which are not used in project.One simple way would to search for each property (in given project) and if 0 result, delete it.

In eclipse there is a function like

Source > Find Broken Externalized Strings

I don't think it works. Not sure what its for. I get message

"no nls property files with corresponding accessor of class found in selection"


It seems like Eclipse expects to find the class that it generates in the "Externalize Strings..." command:

package com.foo.bar;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Messages {
    private static final String BUNDLE_NAME = "com.foo.bar.messages"; //$NON-NLS-1$

    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

    private Messages() {
    }

    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
}

Actually, after digging a little deeper, I found that Eclipse really wants the following:

private static final String BUNDLE_NAME = "com.foo.bar.messages"; //$NON-NLS-1$

public static String getString(String key) {
    ...
}

The package "com.foo.bar" must contain the file "messages.properties". You can run "Find Broken Externalized Strings" on any source file (or on the package) that you add these lines to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜