Skip to content

Commit 910ba08

Browse files
committed
Improve goto declaration for ResourceBundles in JSF files and improve rendering
The goto declaration implementation now does not directly jump to the base properties file, but give the use the option to choose the intent property file also offering the other language files. Rendering of the popup was updated and svg icons added.
1 parent 7c34673 commit 910ba08

16 files changed

Lines changed: 695 additions & 151 deletions

File tree

enterprise/web.el/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
javac.source=1.8
17+
javac.release=17
1818
javac.compilerargs=-Xlint -Xlint:-serial
1919

2020
test-unit-sys-prop.web.project.jars=\

enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,19 @@ private void computeOccurrences(final ELParserResult parserResult) {
133133
try {
134134
jsource.runUserActionTask((CompilationController info) -> {
135135
info.toPhase(JavaSource.Phase.RESOLVED);
136-
occurrences.putAll(findMatchingTypes(CompilationContext.create(file, info), target, matching));
136+
CompilationContext ccontext = CompilationContext.create(file, info);
137+
occurrences.putAll(findMatchingTypes(ccontext, target, matching));
138+
if (this.occurrences.isEmpty()) {
139+
// perhaps the caret is on a resource bundle key node
140+
occurrences.putAll(findMatchingResourceBundleKeys(ccontext, target, parserResult));
141+
}
137142
}, true);
138143
} catch (IOException ex) {
139144
Exceptions.printStackTrace(ex);
140145
}
141-
142-
if (this.occurrences.isEmpty()) {
143-
// perhaps the caret is on a resource bundle key node
144-
occurrences.putAll(findMatchingResourceBundleKeys(target, parserResult));
145-
}
146146
}
147147

148-
private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(Pair<ELElement, Node> target, ELParserResult parserResult) {
148+
private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(CompilationContext info, Pair<ELElement, Node> target, ELParserResult parserResult) {
149149
ResourceBundles resourceBundles = ResourceBundles.get(parserResult.getFileObject());
150150
if (!resourceBundles.canHaveBundles()) {
151151
return Collections.emptyMap();
@@ -154,7 +154,7 @@ private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(Pair
154154
// the logic here is a bit strange, maybe should add new methods to ResourceBundles
155155
// for a more straightforward computation.
156156
// first, check whether the current EL elements has keys
157-
keys.addAll(resourceBundles.collectKeys(target.first().getNode()));
157+
keys.addAll(resourceBundles.collectKeys(target.first().getNode(), info.context()));
158158
if (keys.isEmpty()) {
159159
return Collections.emptyMap();
160160
}
@@ -176,7 +176,7 @@ private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(Pair
176176
if (!each.isValid()) {
177177
continue;
178178
}
179-
for (Pair<AstIdentifier, Node> candidate : resourceBundles.collectKeys(each.getNode())) {
179+
for (Pair<AstIdentifier, Node> candidate : resourceBundles.collectKeys(each.getNode(), info.context())) {
180180
if (candidate.second().equals(target.second())) {
181181
OffsetRange range = each.getOriginalOffset(candidate.second());
182182
result.put(range, ColoringAttributes.MARK_OCCURRENCES);

enterprise/web.el/src/org/netbeans/modules/web/el/ResourceBundles.java

Lines changed: 240 additions & 60 deletions
Large diffs are not rendered by default.

enterprise/web.el/src/org/netbeans/modules/web/el/completion/ELCodeCompletionHandler.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.netbeans.modules.web.el.spi.ELPlugin;
7777
import org.netbeans.modules.web.el.spi.ELVariableResolver.VariableInfo;
7878
import org.netbeans.modules.web.el.spi.Function;
79+
import org.netbeans.modules.web.el.spi.ResolverContext;
7980
import org.netbeans.modules.web.el.spi.ResourceBundle;
8081
import org.openide.filesystems.FileObject;
8182
import org.openide.util.Exceptions;
@@ -176,7 +177,7 @@ public void run(CompilationController info) throws Exception {
176177
// seems to be something like "sessionScope.^", so complete beans from the scope
177178
proposeBeansFromScope(ccontext, context, prefixMatcher, element, node, proposals);
178179
} else if (ELTypeUtilities.isResourceBundleVar(ccontext, node)) {
179-
proposeBundleKeysInDotNotation(context, prefixMatcher, element, node, proposals);
180+
proposeBundleKeysInDotNotation(ccontext, context, prefixMatcher, element, node, proposals);
180181
} else if (resolved == null) {
181182
if (target instanceof AstDotSuffix == false && node instanceof AstFunction == false) {
182183
proposeFunctions(ccontext, context, prefixMatcher, element, proposals);
@@ -603,12 +604,13 @@ private void proposeBundleKeysInArrayNotation(CodeCompletionContext context,
603604
if (!resourceBundles.canHaveBundles()) {
604605
return;
605606
}
607+
ResolverContext resolverContext = new ResolverContext();
606608
FileObject bundleFile = null;
607-
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(bundleKey);
609+
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(resolverContext, bundleKey);
608610
if (!bundleLocations.isEmpty()) {
609611
bundleFile = bundleLocations.get(0).getFile();
610612
}
611-
for (Map.Entry<String, String> entry : resourceBundles.getEntries(bundleKey).entrySet()) {
613+
for (Map.Entry<String, String> entry : resourceBundles.getEntries(resolverContext, bundleKey).entrySet()) {
612614
if (!prefix.matches(entry.getKey())) {
613615
continue;
614616
}
@@ -620,7 +622,8 @@ private void proposeBundleKeysInArrayNotation(CodeCompletionContext context,
620622
}
621623

622624
// "msg.key" notation
623-
private void proposeBundleKeysInDotNotation(CodeCompletionContext context,
625+
private void proposeBundleKeysInDotNotation(CompilationContext ccontext,
626+
CodeCompletionContext context,
624627
PrefixMatcher prefix,
625628
ELElement elElement,
626629
Node baseObjectNode,
@@ -632,11 +635,11 @@ private void proposeBundleKeysInDotNotation(CodeCompletionContext context,
632635
return;
633636
}
634637
FileObject bundleFile = null;
635-
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(bundleKey);
638+
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(ccontext.context(), bundleKey);
636639
if (!bundleLocations.isEmpty()) {
637640
bundleFile = bundleLocations.get(0).getFile();
638641
}
639-
for (Map.Entry<String, String> entry : resourceBundles.getEntries(bundleKey).entrySet()) {
642+
for (Map.Entry<String, String> entry : resourceBundles.getEntries(ccontext.context(), bundleKey).entrySet()) {
640643
if (!prefix.matches(entry.getKey())) {
641644
continue;
642645
}

enterprise/web.el/src/org/netbeans/modules/web/el/completion/ELResourceBundleKeyCompletionItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* @author Erno Mononen
4040
*/
41-
final class ELResourceBundleKeyCompletionItem extends DefaultCompletionProposal {
41+
public final class ELResourceBundleKeyCompletionItem extends DefaultCompletionProposal {
4242

4343
private static final String ICON_PATH = "org/netbeans/modules/web/el/completion/resources/propertiesKey.gif";//NOI18N
4444

Lines changed: 51 additions & 0 deletions
Loading
Lines changed: 54 additions & 0 deletions
Loading

enterprise/web.el/src/org/netbeans/modules/web/el/hints/ResourceBundleKeys.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected void run(CompilationContext info, RuleContext context, List<Hint> resu
7373
}
7474
for (Pair<AstIdentifier, Node> pair : resourceBundles.collectKeys(each.getNode(), info.context())) {
7575
String clearedKey = pair.second().getImage().replace("'", "").replace("\"", "");
76-
if (!resourceBundles.isValidKey(pair.first().getImage(), clearedKey)) {
76+
if (!resourceBundles.isValidKey(info.context(), pair.first().getImage(), clearedKey)) {
7777
Hint hint = new Hint(this,
7878
NbBundle.getMessage(ResourceBundleKeys.class, "ResourceBundleKeys_Unknown", clearedKey),
7979
elResult.getFileObject(),

0 commit comments

Comments
 (0)