views:

32

answers:

1

I'd like to implement eclipse plugin, which parses .properties files and remembers keys from these files for quick-searching them. It should work similar to Open Type or Open Resource, but with property keys.

I don't know what is best practice for implementing such plugin. Should it work as an builder? Should it register itself for workspace changes, and parse files on change? How can I quickly find all *.properties files via resources API?

+1  A: 

For implementing such feature I would recommend to do the following:

  • On a first start, scan all .properties files in workspace using the following code. The results need to be persisted on disk somehow, so you won't have to scan it on every start.

    IWorkspace workspace = ResourcesPlugin.getWorkspace(); workspace.getRoot().accept(new IResourceVisitor() { public boolean visit(IResource resource) { // process resource } }, IResource.DEPTH_INFINITE, false);

  • Add resource change listener using the following API:

    workspace.addResourceChangeListener(listener, flags);

This way you won't interfere with builders, which could potentially block them on long operation.

Eugene Kuleshov
Thank you Eugene. Wrt to visitor ... do I need to traverse all folders and files, and filter them on my own, or is there a way to limit visitor to .properties files only? I was hoping that I can somehow find all .properties files since there is already index of all files (used by CTRL-SHIFT-R).
Peter Štibraný
I don't think there is API that does the filtering, so visitior gets all the resources and there you can decide which ones you wanted to process, e.g. if(".properties".equals(resource.getName()) { /* process */ }
Eugene Kuleshov