Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion enterprise/web.el/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
javac.source=1.8
javac.release=17
javac.compilerargs=-Xlint -Xlint:-serial

test-unit-sys-prop.web.project.jars=\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ private void computeOccurrences(final ELParserResult parserResult) {
try {
jsource.runUserActionTask((CompilationController info) -> {
info.toPhase(JavaSource.Phase.RESOLVED);
occurrences.putAll(findMatchingTypes(CompilationContext.create(file, info), target, matching));
CompilationContext ccontext = CompilationContext.create(file, info);
occurrences.putAll(findMatchingTypes(ccontext, target, matching));
if (this.occurrences.isEmpty()) {
// perhaps the caret is on a resource bundle key node
occurrences.putAll(findMatchingResourceBundleKeys(ccontext, target, parserResult));
}
}, true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}

if (this.occurrences.isEmpty()) {
// perhaps the caret is on a resource bundle key node
occurrences.putAll(findMatchingResourceBundleKeys(target, parserResult));
}
}

private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(Pair<ELElement, Node> target, ELParserResult parserResult) {
private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(CompilationContext info, Pair<ELElement, Node> target, ELParserResult parserResult) {
ResourceBundles resourceBundles = ResourceBundles.get(parserResult.getFileObject());
if (!resourceBundles.canHaveBundles()) {
return Collections.emptyMap();
Expand All @@ -154,7 +154,7 @@ private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(Pair
// the logic here is a bit strange, maybe should add new methods to ResourceBundles
// for a more straightforward computation.
// first, check whether the current EL elements has keys
keys.addAll(resourceBundles.collectKeys(target.first().getNode()));
keys.addAll(resourceBundles.collectKeys(target.first().getNode(), info.context()));
if (keys.isEmpty()) {
return Collections.emptyMap();
}
Expand All @@ -176,7 +176,7 @@ private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(Pair
if (!each.isValid()) {
continue;
}
for (Pair<AstIdentifier, Node> candidate : resourceBundles.collectKeys(each.getNode())) {
for (Pair<AstIdentifier, Node> candidate : resourceBundles.collectKeys(each.getNode(), info.context())) {
if (candidate.second().equals(target.second())) {
OffsetRange range = each.getOriginalOffset(candidate.second());
result.put(range, ColoringAttributes.MARK_OCCURRENCES);
Expand Down
299 changes: 239 additions & 60 deletions enterprise/web.el/src/org/netbeans/modules/web/el/ResourceBundles.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.netbeans.modules.web.el.spi.ELPlugin;
import org.netbeans.modules.web.el.spi.ELVariableResolver.VariableInfo;
import org.netbeans.modules.web.el.spi.Function;
import org.netbeans.modules.web.el.spi.ResolverContext;
import org.netbeans.modules.web.el.spi.ResourceBundle;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions;
Expand Down Expand Up @@ -176,7 +177,7 @@ public void run(CompilationController info) throws Exception {
// seems to be something like "sessionScope.^", so complete beans from the scope
proposeBeansFromScope(ccontext, context, prefixMatcher, element, node, proposals);
} else if (ELTypeUtilities.isResourceBundleVar(ccontext, node)) {
proposeBundleKeysInDotNotation(context, prefixMatcher, element, node, proposals);
proposeBundleKeysInDotNotation(ccontext, context, prefixMatcher, element, node, proposals);
} else if (resolved == null) {
if (target instanceof AstDotSuffix == false && node instanceof AstFunction == false) {
proposeFunctions(ccontext, context, prefixMatcher, element, proposals);
Expand Down Expand Up @@ -603,12 +604,13 @@ private void proposeBundleKeysInArrayNotation(CodeCompletionContext context,
if (!resourceBundles.canHaveBundles()) {
return;
}
ResolverContext resolverContext = new ResolverContext();
FileObject bundleFile = null;
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(bundleKey);
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(resolverContext, bundleKey);
if (!bundleLocations.isEmpty()) {
bundleFile = bundleLocations.get(0).getFile();
}
for (Map.Entry<String, String> entry : resourceBundles.getEntries(bundleKey).entrySet()) {
for (Map.Entry<String, String> entry : resourceBundles.getEntries(resolverContext, bundleKey).entrySet()) {
if (!prefix.matches(entry.getKey())) {
continue;
}
Expand All @@ -620,7 +622,8 @@ private void proposeBundleKeysInArrayNotation(CodeCompletionContext context,
}

// "msg.key" notation
private void proposeBundleKeysInDotNotation(CodeCompletionContext context,
private void proposeBundleKeysInDotNotation(CompilationContext ccontext,
CodeCompletionContext context,
PrefixMatcher prefix,
ELElement elElement,
Node baseObjectNode,
Expand All @@ -632,11 +635,11 @@ private void proposeBundleKeysInDotNotation(CodeCompletionContext context,
return;
}
FileObject bundleFile = null;
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(bundleKey);
List<Location> bundleLocations = resourceBundles.getLocationsForBundleIdent(ccontext.context(), bundleKey);
if (!bundleLocations.isEmpty()) {
bundleFile = bundleLocations.get(0).getFile();
}
for (Map.Entry<String, String> entry : resourceBundles.getEntries(bundleKey).entrySet()) {
for (Map.Entry<String, String> entry : resourceBundles.getEntries(ccontext.context(), bundleKey).entrySet()) {
if (!prefix.matches(entry.getKey())) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.web.el.completion;

import org.netbeans.modules.csl.api.ElementHandle;
import org.netbeans.modules.web.el.ELElement;
import org.openide.filesystems.FileObject;

public class ELCompletionUtil {

public static ElementHandle getResourceBundleElementHandle(String key, String value, ELElement element, FileObject bundleFile) {
return new ELResourceBundleKeyCompletionItem(key, value, element, bundleFile).getElement();
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void run(CompilationContext info, RuleContext context, List<Hint> resu
}
for (Pair<AstIdentifier, Node> pair : resourceBundles.collectKeys(each.getNode(), info.context())) {
String clearedKey = pair.second().getImage().replace("'", "").replace("\"", "");
if (!resourceBundles.isValidKey(pair.first().getImage(), clearedKey)) {
if (!resourceBundles.isValidKey(info.context(), pair.first().getImage(), clearedKey)) {
Hint hint = new Hint(this,
NbBundle.getMessage(ResourceBundleKeys.class, "ResourceBundleKeys_Unknown", clearedKey),
elResult.getFileObject(),
Expand Down
Loading