summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Krejci <lkrejci@redhat.com>2013-01-02 10:57:44 (GMT)
committerLukas Krejci <lkrejci@redhat.com>2013-01-02 11:00:47 (GMT)
commitaf81247744ec551bd411435d2f3d0913bfe0ee95 (patch)
treeae09a08e7aa35319bc6d1600e745a92ab4fd5042
parent45a58220880d1a0b4749af319d8065936f734a57 (diff)
downloadrhq-af81247744ec551bd411435d2f3d0913bfe0ee95.zip
rhq-af81247744ec551bd411435d2f3d0913bfe0ee95.tar.gz
rhq-af81247744ec551bd411435d2f3d0913bfe0ee95.tar.xz
[BZ 844475] - Don't try to do code completion on native javascript arrays.
-rw-r--r--modules/enterprise/scripting/javascript/src/main/java/org/rhq/scripting/javascript/JavascriptCompletor.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/modules/enterprise/scripting/javascript/src/main/java/org/rhq/scripting/javascript/JavascriptCompletor.java b/modules/enterprise/scripting/javascript/src/main/java/org/rhq/scripting/javascript/JavascriptCompletor.java
index 78d3c9a..f33e029 100644
--- a/modules/enterprise/scripting/javascript/src/main/java/org/rhq/scripting/javascript/JavascriptCompletor.java
+++ b/modules/enterprise/scripting/javascript/src/main/java/org/rhq/scripting/javascript/JavascriptCompletor.java
@@ -43,6 +43,7 @@ import javax.script.ScriptContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mozilla.javascript.Function;
+import org.mozilla.javascript.NativeArray;
import org.mozilla.javascript.ScriptableObject;
import org.rhq.scripting.CodeCompletion;
@@ -184,7 +185,7 @@ public class JavascriptCompletor implements CodeCompletion {
if (!matches.isEmpty()) {
// BZ 871407 NPE on auto completion for javascript object
List<Object> nextList = matches.get(next);
- if (nextList == null || nextList.isEmpty()) {
+ if (nextList == null || nextList.isEmpty()) {
return -1;
}
Object rootObject = nextList.get(0);
@@ -393,7 +394,7 @@ public class JavascriptCompletor implements CodeCompletion {
}
}
}
-
+
//this was originally part of the code completor that lived in the CLI
//I don't think we need it, because the services are present under the
//same names in the context. This code can never add any new matches.
@@ -406,7 +407,7 @@ public class JavascriptCompletor implements CodeCompletion {
}
}
*/
-
+
return found;
}
@@ -474,7 +475,17 @@ public class JavascriptCompletor implements CodeCompletion {
}
private Map<String, List<Object>> findJavascriptContextMatches(ScriptableObject object, String start) {
+ // don't attempt ID completion on arrays.. While this would return the available indices in the array which
+ // is a very useful completion hint, we currently only support code completion on dots. I.e. if "a" was an
+ // array, code completion on "a." would return the indices of the array. The user could then be tempted to
+ // to use such completed constructs even though they're not a valid javascript ("a.0" is not a valid
+ // javascript expression).
+ if (object instanceof NativeArray) {
+ return Collections.emptyMap();
+ }
+
HashMap<String, List<Object>> ret = new HashMap<String, List<Object>>();
+
for (Object o : object.getIds()) {
String key = o.toString();