Bug 408059 - [nls tooling] Recognize resource bundle usage (ResourceBundle.getString(String))
Summary: [nls tooling] Recognize resource bundle usage (ResourceBundle.getString(String))
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-14 15:32 EDT by Michael Rennie CLA
Modified: 2013-07-29 06:07 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2013-05-14 15:32:37 EDT
While running the tool to fix bug 407432, I found that out of the 750+ reported broken strings, only a handful of them actually were unused. Most of the strings are used via the pattern:

ResourceBundle.getBundle(<classname>).getString("stringname")

It would be awesome if the tool could detect this usage.
Comment 1 Dani Megert CLA 2013-05-16 08:02:22 EDT
(In reply to comment #0)
> I found that out of the 750+
> reported broken strings, 

Can you please tell on which project you ran it, so that we can use it as test case?
Comment 2 Michael Rennie CLA 2013-05-16 10:27:29 EDT
(In reply to comment #1)
> (In reply to comment #0)
> > I found that out of the 750+
> > reported broken strings, 
> 
> Can you please tell on which project you ran it, so that we can use it as
> test case?

I guess it would help if I had mentioned that :)

Try org.eclipse.jface or org.eclipse.ui.workbench
Comment 3 Dani Megert CLA 2013-05-17 06:57:05 EDT
I tried several results in both projects and they are all correct. Maybe you did not have all projects in your workspace? I saw some of your changes caused compile errors in the build.

Please provide some concrete wrongly reported unused string examples.
Comment 4 Michael Rennie CLA 2013-05-17 09:47:30 EDT
(In reply to comment #3)

> Please provide some concrete wrongly reported unused string examples.

Unused keys in: Theme.properties - org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes

Which is in fact used in org.eclipse.ui.internal.themes.Theme.getLabel()

There are more examples in platform UI and in Ant.

I also found there is a method in jface:

org.eclipse.jface.util.Util.translateString(ResourceBundle, String, String)

used to look up strings as well, so some strings looked up via that method are also tagged as unused. 

Another example, the keys from:

Unused keys in: ThemeRegistryReader.properties - org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes (7 matches)
Comment 5 Michael Rennie CLA 2013-05-17 09:57:51 EDT
Also any string accessed for a TextAction constructor.

For example:

org.eclipse.ant.internal.ui.editor.actions.ToggleMarkOccurrencesAction.ToggleMarkOccurrencesAction()

uses the string ToggleMarkOccurrencesAction.label from org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/actions/AntEditorActionMessages.properties but it is flagged as not used
Comment 6 Dani Megert CLA 2013-05-21 09:06:23 EDT
In general we only support the patterns that are generated by our wizard. If we want to support the ResourceBundle.getString(String)) pattern, then we also have to update the NLS hyperlinks and hovers.


(In reply to comment #5)
> Also any string accessed for a TextAction constructor.
> 
> For example:
> 
> org.eclipse.ant.internal.ui.editor.actions.ToggleMarkOccurrencesAction.
> ToggleMarkOccurrencesAction()
> 
> uses the string ToggleMarkOccurrencesAction.label from
> org.eclipse.ant.ui/Ant
> Editor/org/eclipse/ant/internal/ui/editor/actions/AntEditorActionMessages.
> properties but it is flagged as not used

This one will never work, as ResourceAction computes the key in the code.