use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class FunctionTest method testParseBigNumbers.
@Test
public void testParseBigNumbers() {
assertEquals(new BigInteger("99999999999999999999999999999999"), this.instance.exec("99999999999999999999999999999999"));
assertEquals(new BigInteger("99999999999999999999999999999999"), this.instance.exec("99999999999999999999999999999999N"));
assertEquals(new BigInteger("199999999999999999999999999999998"), this.instance.exec("99999999999999999999999999999999+99999999999999999999999999999999"));
Env env = new Env(null);
env.setInstance(this.instance);
assertEquals(new BigDecimal("99999999999999999999999999999999.99999999", RuntimeUtils.getMathContext(env)), this.instance.exec("99999999999999999999999999999999.99999999M"));
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class AviatorEvaluatorInstance method requireScript.
/**
* Loads a script from path and return it's exports with module caching.
*
* @param path
* @param args arguments to execute the script.
* @throws IOException
* @return the exports map
* @since 5.0.0
*/
public Map<String, Object> requireScript(final String path) throws IOException {
ensureFeatureEnabled(Feature.Module);
if (!path.endsWith(".av")) {
// internal modules
Map<String, Object> exports = (Env) this.moduleCache.get(path);
if (exports != null) {
return exports;
}
}
File file = tryFindScriptFile(path);
final String abPath = file.getAbsolutePath();
Map<String, Object> exports = (Env) this.moduleCache.get(abPath);
if (exports != null) {
return exports;
} else {
// TODO better lock
synchronized (abPath.intern()) {
exports = (Env) this.moduleCache.get(abPath);
if (exports != null) {
return exports;
}
exports = loadScript0(abPath);
this.moduleCache.put(abPath, exports);
return exports;
}
}
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class AviatorEvaluatorInstance method addModule.
/**
* Adds a module class and import it's public static methods as module's exports into module
* cache, return the exports map.
*
* @param moduleClazz
* @return the exports map
* @since 5.0.0
*/
public Env addModule(final Class<?> moduleClazz) throws NoSuchMethodException, IllegalAccessException {
String namespace = moduleClazz.getSimpleName();
Import importAnt = moduleClazz.getAnnotation(Import.class);
if (importAnt != null) {
namespace = importAnt.ns();
if (namespace == null || namespace.isEmpty() || !ExpressionParser.isJavaIdentifier(namespace)) {
throw new IllegalArgumentException("Invalid namespace in Import annotation: " + namespace);
}
}
Env exports = null;
synchronized (namespace.intern()) {
exports = (Env) this.moduleCache.get(namespace);
if (exports != null) {
return exports;
}
exports = loadModule(moduleClazz);
this.moduleCache.put(namespace, exports);
return exports;
}
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class BaseExpression method newEnv.
protected Env newEnv(final Map<String, Object> map, final boolean direct) {
Env env;
if (direct) {
env = new Env(map, map == Collections.EMPTY_MAP ? new HashMap<String, Object>() : map);
} else {
env = new Env(map);
}
env.configure(this.instance, this);
return env;
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class OptimizeCodeGenerator method getCompileEnv.
private Env getCompileEnv() {
if (this.compileEnv == null) {
this.compileEnv = new Env();
this.compileEnv.setInstance(this.instance);
}
return this.compileEnv;
}
Aggregations