Remove more Xlint skips
This commit is contained in:
parent
0786c506dc
commit
244120a065
|
@ -26,13 +26,9 @@ dependencies {
|
|||
compile 'org.mozilla:rhino:1.7.7'
|
||||
}
|
||||
|
||||
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
|
||||
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
|
||||
|
||||
integTest {
|
||||
cluster {
|
||||
systemProperty 'es.script.inline', 'on'
|
||||
systemProperty 'es.script.indexed', 'on'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,18 @@
|
|||
|
||||
package org.elasticsearch.script.javascript;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.CodeSource;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.elasticsearch.SpecialPermission;
|
||||
|
@ -49,18 +61,6 @@ import org.mozilla.javascript.ScriptableObject;
|
|||
import org.mozilla.javascript.SecurityController;
|
||||
import org.mozilla.javascript.WrapFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.CodeSource;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -348,12 +348,14 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements
|
|||
setJavaPrimitiveWrap(false); // RingoJS does that..., claims its annoying...
|
||||
}
|
||||
|
||||
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class<?> staticType) {
|
||||
if (javaObject instanceof Map) {
|
||||
return NativeMap.wrap(scope, (Map) javaObject);
|
||||
return NativeMap.wrap(scope, (Map<Object, Object>) javaObject);
|
||||
}
|
||||
if (javaObject instanceof List) {
|
||||
return NativeList.wrap(scope, (List) javaObject, staticType);
|
||||
return NativeList.wrap(scope, (List<Object>) javaObject, staticType);
|
||||
}
|
||||
return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.script.javascript.support;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
|
||||
/**
|
||||
* Wrapper for exposing maps in Rhino scripts.
|
||||
*
|
||||
|
@ -55,26 +55,17 @@ public class NativeMap implements Scriptable, Wrapper {
|
|||
this.map = map;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Wrapper#unwrap()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object unwrap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getClassName()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return "NativeMap";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object get(String name, Scriptable start) {
|
||||
// get the property from the underlying QName map
|
||||
if ("length".equals(name)) {
|
||||
|
@ -84,69 +75,47 @@ public class NativeMap implements Scriptable, Wrapper {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object get(int index, Scriptable start) {
|
||||
Object value = null;
|
||||
int i = 0;
|
||||
Iterator itrValues = map.values().iterator();
|
||||
Iterator<Object> itrValues = map.values().iterator();
|
||||
while (i++ <= index && itrValues.hasNext()) {
|
||||
value = itrValues.next();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean has(String name, Scriptable start) {
|
||||
// locate the property in the underlying map
|
||||
return map.containsKey(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean has(int index, Scriptable start) {
|
||||
return (index >= 0 && map.values().size() > index);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object)
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
map.put(name, value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void put(int index, Scriptable start, Object value) {
|
||||
// TODO: implement?
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#delete(java.lang.String)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void delete(String name) {
|
||||
map.remove(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#delete(int)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void delete(int index) {
|
||||
int i = 0;
|
||||
Iterator itrKeys = map.keySet().iterator();
|
||||
Iterator<Object> itrKeys = map.keySet().iterator();
|
||||
while (i <= index && itrKeys.hasNext()) {
|
||||
Object key = itrKeys.next();
|
||||
if (i == index) {
|
||||
|
@ -156,58 +125,37 @@ public class NativeMap implements Scriptable, Wrapper {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getPrototype()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Scriptable getPrototype() {
|
||||
return this.prototype;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void setPrototype(Scriptable prototype) {
|
||||
this.prototype = prototype;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getParentScope()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Scriptable getParentScope() {
|
||||
return this.parentScope;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void setParentScope(Scriptable parent) {
|
||||
this.parentScope = parent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getIds()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object[] getIds() {
|
||||
return map.keySet().toArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class)
|
||||
*/
|
||||
|
||||
public Object getDefaultValue(Class hint) {
|
||||
@Override
|
||||
public Object getDefaultValue(Class<?> hint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean hasInstance(Scriptable value) {
|
||||
if (!(value instanceof Wrapper))
|
||||
return false;
|
||||
|
|
|
@ -19,13 +19,6 @@
|
|||
|
||||
package org.elasticsearch.script.javascript.support;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.IdScriptableObject;
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
import org.mozilla.javascript.ScriptRuntime;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
@ -33,6 +26,13 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.IdScriptableObject;
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
import org.mozilla.javascript.ScriptRuntime;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
|
||||
/**
|
||||
* Value Converter to marshal objects between Java and Javascript.
|
||||
*
|
||||
|
@ -126,6 +126,7 @@ public final class ScriptValueConverter {
|
|||
value = list;
|
||||
} else if (value instanceof Map) {
|
||||
// ensure each value in the Map is unwrapped (which may have been an unwrapped NativeMap!)
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Object> map = (Map<Object, Object>) value;
|
||||
Map<Object, Object> copyMap = new HashMap<Object, Object>(map.size());
|
||||
for (Object key : map.keySet()) {
|
||||
|
@ -157,6 +158,7 @@ public final class ScriptValueConverter {
|
|||
Context.getCurrentContext(), scope, TYPE_DATE, new Object[]{date.getTime()});
|
||||
} else if (value instanceof Collection) {
|
||||
// recursively convert each value in the collection
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> collection = (Collection<Object>) value;
|
||||
Object[] array = new Object[collection.size()];
|
||||
int index = 0;
|
||||
|
@ -166,7 +168,9 @@ public final class ScriptValueConverter {
|
|||
// convert array to a native JavaScript Array
|
||||
value = Context.getCurrentContext().newArray(scope, array);
|
||||
} else if (value instanceof Map) {
|
||||
value = NativeMap.wrap(scope, (Map) value);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Object> map = (Map<Object, Object>) value;
|
||||
value = NativeMap.wrap(scope, map);
|
||||
}
|
||||
|
||||
// simple numbers, strings and booleans are wrapped automatically by Rhino
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.elasticsearch.script.javascript.support;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Implementation of a Scriptable Map. This is the best choice for maps that want to represent
|
||||
* JavaScript associative arrays - allowing access via key and integer index. It maintains and
|
||||
|
@ -53,6 +53,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#getClassName()
|
||||
*/
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return "ScriptableMap";
|
||||
}
|
||||
|
@ -60,6 +61,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@Override
|
||||
public Object get(String name, Scriptable start) {
|
||||
// get the property from the underlying QName map
|
||||
if ("length".equals(name)) {
|
||||
|
@ -72,10 +74,11 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@Override
|
||||
public Object get(int index, Scriptable start) {
|
||||
Object value = null;
|
||||
int i = 0;
|
||||
Iterator itrValues = this.values().iterator();
|
||||
Iterator<V> itrValues = this.values().iterator();
|
||||
while (i++ <= index && itrValues.hasNext()) {
|
||||
value = itrValues.next();
|
||||
}
|
||||
|
@ -85,6 +88,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@Override
|
||||
public boolean has(String name, Scriptable start) {
|
||||
// locate the property in the underlying map
|
||||
return containsKey(name);
|
||||
|
@ -93,6 +97,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@Override
|
||||
public boolean has(int index, Scriptable start) {
|
||||
return (index >= 0 && this.values().size() > index);
|
||||
}
|
||||
|
@ -100,6 +105,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
// add the property to the underlying QName map
|
||||
|
@ -109,6 +115,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void put(int index, Scriptable start, Object value) {
|
||||
// TODO: implement?
|
||||
}
|
||||
|
@ -116,6 +123,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#delete(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void delete(String name) {
|
||||
// remove the property from the underlying QName map
|
||||
remove(name);
|
||||
|
@ -124,9 +132,10 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#delete(int)
|
||||
*/
|
||||
@Override
|
||||
public void delete(int index) {
|
||||
int i = 0;
|
||||
Iterator itrKeys = this.keySet().iterator();
|
||||
Iterator<K> itrKeys = this.keySet().iterator();
|
||||
while (i <= index && itrKeys.hasNext()) {
|
||||
Object key = itrKeys.next();
|
||||
if (i == index) {
|
||||
|
@ -139,6 +148,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#getPrototype()
|
||||
*/
|
||||
@Override
|
||||
public Scriptable getPrototype() {
|
||||
return this.prototype;
|
||||
}
|
||||
|
@ -146,6 +156,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@Override
|
||||
public void setPrototype(Scriptable prototype) {
|
||||
this.prototype = prototype;
|
||||
}
|
||||
|
@ -153,6 +164,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#getParentScope()
|
||||
*/
|
||||
@Override
|
||||
public Scriptable getParentScope() {
|
||||
return this.parentScope;
|
||||
}
|
||||
|
@ -160,6 +172,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@Override
|
||||
public void setParentScope(Scriptable parent) {
|
||||
this.parentScope = parent;
|
||||
}
|
||||
|
@ -167,6 +180,7 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#getIds()
|
||||
*/
|
||||
@Override
|
||||
public Object[] getIds() {
|
||||
return keySet().toArray();
|
||||
}
|
||||
|
@ -174,13 +188,15 @@ public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implement
|
|||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class)
|
||||
*/
|
||||
public Object getDefaultValue(Class hint) {
|
||||
@Override
|
||||
public Object getDefaultValue(Class<?> hint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasInstance(Scriptable instance) {
|
||||
return instance instanceof ScriptableLinkedHashMap;
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
|
||||
package org.elasticsearch.script.javascript.support;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
|
||||
/**
|
||||
* Implementation of a Scriptable Map. This is the best choice where you want values to be
|
||||
* persisted directly to an underlying map supplied on construction. The class automatically
|
||||
|
@ -37,8 +37,8 @@ import java.util.Set;
|
|||
*
|
||||
*
|
||||
*/
|
||||
public class ScriptableWrappedMap implements ScriptableMap, Wrapper {
|
||||
private Map map;
|
||||
public class ScriptableWrappedMap implements ScriptableMap<Object, Object>, Wrapper {
|
||||
private Map<Object, Object> map;
|
||||
private Scriptable parentScope;
|
||||
private Scriptable prototype;
|
||||
|
||||
|
@ -54,38 +54,29 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper {
|
|||
/**
|
||||
* Construct
|
||||
*/
|
||||
public ScriptableWrappedMap(Map map) {
|
||||
public ScriptableWrappedMap(Map<Object, Object> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public ScriptableWrappedMap(Scriptable scope, Map map) {
|
||||
public ScriptableWrappedMap(Scriptable scope, Map<Object, Object> map) {
|
||||
this.parentScope = scope;
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Wrapper#unwrap()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object unwrap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getClassName()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return "ScriptableWrappedMap";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object get(String name, Scriptable start) {
|
||||
// get the property from the underlying QName map
|
||||
if ("length".equals(name)) {
|
||||
|
@ -95,69 +86,47 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object get(int index, Scriptable start) {
|
||||
Object value = null;
|
||||
int i = 0;
|
||||
Iterator itrValues = map.values().iterator();
|
||||
Iterator<Object> itrValues = map.values().iterator();
|
||||
while (i++ <= index && itrValues.hasNext()) {
|
||||
value = itrValues.next();
|
||||
}
|
||||
return ScriptValueConverter.wrapValue(this.parentScope != null ? this.parentScope : start, value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean has(String name, Scriptable start) {
|
||||
// locate the property in the underlying map
|
||||
return map.containsKey(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean has(int index, Scriptable start) {
|
||||
return (index >= 0 && map.values().size() > index);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object)
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
map.put(name, ScriptValueConverter.unwrapValue(value));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void put(int index, Scriptable start, Object value) {
|
||||
// TODO: implement?
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#delete(java.lang.String)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void delete(String name) {
|
||||
map.remove(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#delete(int)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void delete(int index) {
|
||||
int i = 0;
|
||||
Iterator itrKeys = map.keySet().iterator();
|
||||
Iterator<Object> itrKeys = map.keySet().iterator();
|
||||
while (i <= index && itrKeys.hasNext()) {
|
||||
Object key = itrKeys.next();
|
||||
if (i == index) {
|
||||
|
@ -167,58 +136,37 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getPrototype()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Scriptable getPrototype() {
|
||||
return this.prototype;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void setPrototype(Scriptable prototype) {
|
||||
this.prototype = prototype;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getParentScope()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Scriptable getParentScope() {
|
||||
return this.parentScope;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void setParentScope(Scriptable parent) {
|
||||
this.parentScope = parent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getIds()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object[] getIds() {
|
||||
return map.keySet().toArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class)
|
||||
*/
|
||||
|
||||
public Object getDefaultValue(Class hint) {
|
||||
@Override
|
||||
public Object getDefaultValue(Class<?> hint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean hasInstance(Scriptable value) {
|
||||
if (!(value instanceof Wrapper))
|
||||
return false;
|
||||
|
@ -226,106 +174,66 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper {
|
|||
return Map.class.isInstance(instance);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#clear()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.map.clear();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#containsKey(java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return this.map.containsKey(key);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#containsValue(java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return this.map.containsValue(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#entrySet()
|
||||
*/
|
||||
|
||||
public Set entrySet() {
|
||||
@Override
|
||||
public Set<Map.Entry<Object, Object>> entrySet() {
|
||||
return this.map.entrySet();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#get(java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
return this.map.get(key);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#isEmpty()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return (this.map.size() == 0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#keySet()
|
||||
*/
|
||||
|
||||
public Set keySet() {
|
||||
@Override
|
||||
public Set<Object> keySet() {
|
||||
return this.map.keySet();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object put(Object key, Object value) {
|
||||
return this.map.put(key, value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#putAll(java.util.Map)
|
||||
*/
|
||||
|
||||
public void putAll(Map t) {
|
||||
@Override
|
||||
public void putAll(Map<? extends Object, ? extends Object> t) {
|
||||
this.map.putAll(t);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#remove(java.lang.Object)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object remove(Object key) {
|
||||
return this.map.remove(key);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#size()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.map.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#values()
|
||||
*/
|
||||
|
||||
public Collection values() {
|
||||
@Override
|
||||
public Collection<Object> values() {
|
||||
return this.map.values();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (this.map != null ? this.map.toString() : super.toString());
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
|
||||
package org.elasticsearch.script.javascript;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
|
@ -28,12 +34,6 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
|
@ -59,6 +59,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase {
|
|||
assertThat(((Number) o).intValue(), equalTo(3));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMapAccess() {
|
||||
Map<String, Object> vars = new HashMap<String, Object>();
|
||||
|
||||
|
@ -75,15 +76,17 @@ public class JavaScriptScriptEngineTests extends ESTestCase {
|
|||
assertThat(((String) o), equalTo("2"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testJavaScriptObjectToMap() {
|
||||
Map<String, Object> vars = new HashMap<String, Object>();
|
||||
Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testJavaScriptObjectToMap", "js",
|
||||
se.compile("var obj1 = {}; obj1.prop1 = 'value1'; obj1.obj2 = {}; obj1.obj2.prop2 = 'value2'; obj1", Collections.emptyMap())), vars).run();
|
||||
Map obj1 = (Map) o;
|
||||
Map<String, Object> obj1 = (Map<String, Object>) o;
|
||||
assertThat((String) obj1.get("prop1"), equalTo("value1"));
|
||||
assertThat((String) ((Map<String, Object>) obj1.get("obj2")).get("prop2"), equalTo("value2"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testJavaScriptObjectMapInter() {
|
||||
Map<String, Object> vars = new HashMap<String, Object>();
|
||||
Map<String, Object> ctx = new HashMap<String, Object>();
|
||||
|
@ -102,6 +105,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase {
|
|||
assertThat((String) ((Map<String, Object>) ctx.get("obj2")).get("prop2"), equalTo("value2"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testJavaScriptInnerArrayCreation() {
|
||||
Map<String, Object> ctx = new HashMap<String, Object>();
|
||||
Map<String, Object> doc = new HashMap<String, Object>();
|
||||
|
@ -115,9 +119,10 @@ public class JavaScriptScriptEngineTests extends ESTestCase {
|
|||
|
||||
Map<String, Object> unwrap = (Map<String, Object>) script.unwrap(ctx);
|
||||
|
||||
assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class));
|
||||
assertThat(((Map<String, Object>) unwrap.get("doc")).get("field1"), instanceOf(List.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAccessListInScript() {
|
||||
Map<String, Object> vars = new HashMap<String, Object>();
|
||||
Map<String, Object> obj2 = MapBuilder.<String, Object>newMapBuilder().put("prop2", "value2").map();
|
||||
|
|
|
@ -26,9 +26,6 @@ dependencies {
|
|||
compile 'org.python:jython-standalone:2.7.0'
|
||||
}
|
||||
|
||||
compileJava.options.compilerArgs << "-Xlint:-unchecked"
|
||||
compileTestJava.options.compilerArgs << "-Xlint:-unchecked"
|
||||
|
||||
integTest {
|
||||
cluster {
|
||||
systemProperty 'es.script.inline', 'on'
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
|
||||
package org.elasticsearch.script.python;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
|
@ -28,11 +33,6 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
|
@ -58,6 +58,7 @@ public class PythonScriptEngineTests extends ESTestCase {
|
|||
assertThat(((Number) o).intValue(), equalTo(3));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMapAccess() {
|
||||
Map<String, Object> vars = new HashMap<String, Object>();
|
||||
|
||||
|
@ -74,6 +75,7 @@ public class PythonScriptEngineTests extends ESTestCase {
|
|||
assertThat(((String) o), equalTo("2"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testObjectMapInter() {
|
||||
Map<String, Object> vars = new HashMap<String, Object>();
|
||||
Map<String, Object> ctx = new HashMap<String, Object>();
|
||||
|
@ -92,6 +94,7 @@ public class PythonScriptEngineTests extends ESTestCase {
|
|||
assertThat((String) ((Map<String, Object>) ctx.get("obj2")).get("prop2"), equalTo("value2"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAccessListInScript() {
|
||||
Map<String, Object> vars = new HashMap<String, Object>();
|
||||
Map<String, Object> obj2 = MapBuilder.<String, Object>newMapBuilder().put("prop2", "value2").map();
|
||||
|
|
Loading…
Reference in New Issue