use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class StringJoinFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object target = arg1.getValue(env);
String split = FunctionUtils.getStringValue(arg2, env);
if (target == null) {
throw new ExpressionRuntimeException("Could not replace with null string");
}
return join(env, arg1, target, split);
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class StringSplitFunction method call.
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
String target = FunctionUtils.getStringValue(arg1, env);
if (target == null)
throw new ExpressionRuntimeException("Could not replace with null string");
String regex = FunctionUtils.getStringValue(arg2, env);
return AviatorRuntimeJavaType.valueOf(target.split(regex));
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class AviatorJavaType method tryCompareDate.
private int tryCompareDate(final Object thisValue, final Object otherValue) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS");
Date otherDate = simpleDateFormat.parse((String) otherValue);
return ((Date) thisValue).compareTo(otherDate);
} catch (Throwable t) {
throw new ExpressionRuntimeException("Compare date error", t);
}
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class ASMCodeGenerator method getResult.
/*
* (non-Javadoc)
*
* @see com.googlecode.aviator.code.CodeGenerator#getResult()
*/
@Override
public Expression getResult(final boolean unboxObject) {
end(unboxObject);
byte[] bytes = this.classWriter.toByteArray();
try {
Class<?> defineClass = ClassDefiner.defineClass(this.className, Expression.class, bytes, this.classLoader);
Constructor<?> constructor = defineClass.getConstructor(AviatorEvaluatorInstance.class, List.class, SymbolTable.class);
BaseExpression exp = (BaseExpression) constructor.newInstance(this.instance, new ArrayList<VariableMeta>(this.variables.values()), this.symbolTable);
exp.setLambdaBootstraps(this.lambdaBootstraps);
exp.setFuncsArgs(this.funcsArgs);
exp.setSourceFile(this.sourceFile);
return exp;
} catch (ExpressionRuntimeException e) {
throw e;
} catch (Throwable e) {
if (e.getCause() instanceof ExpressionRuntimeException) {
throw (ExpressionRuntimeException) e.getCause();
}
throw new CompileExpressionErrorException("define class error", e);
}
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class AviatorJavaTypeUnitTest method compareWithAviatorType.
@Test
public void compareWithAviatorType() {
AviatorJavaType intType = new AviatorJavaType("intType");
AviatorJavaType doubleType = new AviatorJavaType("doubleType");
AviatorJavaType boolType = new AviatorJavaType("boolType");
AviatorJavaType stringType = new AviatorJavaType("stringType");
AviatorJavaType charType = new AviatorJavaType("charType");
AviatorJavaType dateType = new AviatorJavaType("dateType");
Map<String, Object> env = new HashMap<String, Object>();
env.put("intType", 3);
env.put("boolType", Boolean.FALSE);
env.put("stringType", "hello");
env.put("charType", 'c');
env.put("dateType", new Date());
env.put("doubleType", 3.4);
AviatorNumber number = AviatorNumber.valueOf(3.4);
AviatorBoolean bool = AviatorBoolean.TRUE;
AviatorPattern pattern = new AviatorPattern("\\d+");
AviatorString string = new AviatorString("hello");
assertTrue(intType.innerCompare(number, env) < 0);
assertEquals(0, doubleType.innerCompare(number, env));
try {
intType.innerCompare(bool, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
intType.innerCompare(pattern, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
intType.innerCompare(string, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
stringType.innerCompare(number, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
stringType.innerCompare(bool, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
stringType.innerCompare(pattern, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertEquals(0, stringType.innerCompare(string, env));
try {
charType.innerCompare(number, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
charType.innerCompare(bool, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
charType.innerCompare(pattern, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertTrue(charType.innerCompare(string, env) < 0);
try {
dateType.innerCompare(number, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.innerCompare(bool, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.innerCompare(string, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.innerCompare(pattern, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
boolType.innerCompare(number, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
boolType.innerCompare(string, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
boolType.innerCompare(pattern, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertTrue(boolType.innerCompare(bool, env) < 0);
}
Aggregations