简体   繁体   中英

find unused properties in eclipse

I 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM