Search in sources :

Example 11 with ExpressionRuntimeException

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);
}
Also used : ExpressionRuntimeException(com.googlecode.aviator.exception.ExpressionRuntimeException) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorString(com.googlecode.aviator.runtime.type.AviatorString)

Example 12 with ExpressionRuntimeException

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));
}
Also used : ExpressionRuntimeException(com.googlecode.aviator.exception.ExpressionRuntimeException)

Example 13 with ExpressionRuntimeException

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);
    }
}
Also used : ExpressionRuntimeException(com.googlecode.aviator.exception.ExpressionRuntimeException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 14 with ExpressionRuntimeException

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);
    }
}
Also used : BaseExpression(com.googlecode.aviator.BaseExpression) ExpressionRuntimeException(com.googlecode.aviator.exception.ExpressionRuntimeException) CompileExpressionErrorException(com.googlecode.aviator.exception.CompileExpressionErrorException) ArrayList(java.util.ArrayList)

Example 15 with ExpressionRuntimeException

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);
}
Also used : ExpressionRuntimeException(com.googlecode.aviator.exception.ExpressionRuntimeException) HashMap(java.util.HashMap) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)19 Date (java.util.Date)7 Test (org.junit.Test)7 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)6 HashMap (java.util.HashMap)6 AviatorString (com.googlecode.aviator.runtime.type.AviatorString)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ID (cn.devezhao.persist4j.engine.ID)1 MissingMetaExcetion (cn.devezhao.persist4j.metadata.MissingMetaExcetion)1 BaseExpression (com.googlecode.aviator.BaseExpression)1 CompileExpressionErrorException (com.googlecode.aviator.exception.CompileExpressionErrorException)1 ExpressionSyntaxErrorException (com.googlecode.aviator.exception.ExpressionSyntaxErrorException)1 NoSuchPropertyException (com.googlecode.aviator.exception.NoSuchPropertyException)1 NumberToken (com.googlecode.aviator.lexer.token.NumberToken)1 AviatorFunction (com.googlecode.aviator.runtime.type.AviatorFunction)1 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)1 AviatorPattern (com.googlecode.aviator.runtime.type.AviatorPattern)1 Env (com.googlecode.aviator.utils.Env)1 RebuildException (com.rebuild.core.RebuildException)1 RepeatedRecordsException (com.rebuild.core.service.general.RepeatedRecordsException)1