eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

Hovering over an NLS message doesn't show the contents if the bundle name isn't constant

Open
#553 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
59
Forks
127
Avg merge
23h 30m
Merged PRs (30d)
35

Description

### Introduction
When creating a message bundle using the "Externalize strings wizard", the java class is initialized with a `BUNDLE_NAME` variable which contains the fully-qualified name of the message properties file, like:

`private static final String BUNDLE_NAME = NlsDemoMsg.class.getPackageName() + ".nlsdemomsg"; //$NON-NLS-1$`

In this case, it would resolve to `com.example.jdt.nls.msg.nlsdemomsg` which indeed resolves to a file called `nlsdemomsg.properties` in the `com.example.jdt.nls.msg` package.

---
### Problem
When using any messages from a class created in this way, hovering over the message does not show the contents, and you are not able to quickly goto it in the properties file:
![No preview](https://user-images.githubusercontent.com/9405706/235176840-b10fbc95-9830-4a14-9eb4-e1e983347a1b.png)
![No goto](https://user-images.githubusercontent.com/9405706/235176940-664fcfc3-dce0-4bfb-935a-55b2aeafbf5b.png)

I am assuming this is PDE's version of the wizard since it uses `org.eclipse.osgi.util.NLS` instead of `ResourceBundle`, but the plain-old Java version does the same thing, using `Messages.getString("key")` instead. The hover and goto only work if the `BUNDLE_NAME` is a constant string.

---
### Workaround
If the `BUNDLE_NAME` is changed to be just the string itself, like

`private static final String BUNDLE_NAME = "com.example.jdt.nls.msg.nlsdemomsg"; //$NON-NLS-1$`

then those things work:
![Preview of the message](https://user-images.githubusercontent.com/9405706/235177270-64579edb-02c3-4a37-9ce8-290188dbae06.png)
![Able to goto the file](https://user-images.githubusercontent.com/9405706/235177345-321c1729-b890-48cd-9a0d-53b9196acf7f.png)

---
### Expected
Ideally these features would work in all cases, especially as the wizard that makes this file does it the first way by calling `getPackageName()`.

Contributor guide

Open the contributing guide

Research direction

Start with the Externalize strings wizard output and the hover/goto handling for BUNDLE_NAME expressions. Compare resolution of the getPackageName() form with a constant string, including the org.eclipse.osgi.util.NLS and ResourceBundle cases described in the report. Done means message hover contents and navigation work for generated bundles without changing BUNDLE_NAME manually.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.