Search in sources :

Example 6 with Expression

use of japa.parser.ast.expr.Expression in project enumerable by hraberg.

the class ExpressionTreeTest method parseViaASM.

Expression parseViaASM(String expression, Class<?> returnValue, Param... parameters) throws Exception {
    Class<?> c = compileExpression(expression, returnValue, parameters);
    Class<?>[] parameterTypes = new Class<?>[parameters.length];
    String[] parameterNames = new String[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        parameterNames[i] = parameters[i].name;
        parameterTypes[i] = parameters[i].type;
    }
    Method method = c.getDeclaredMethod("eval", parameterTypes);
    debug("compiling: " + expression);
    debug("asm:");
    if (debug)
        printASMifiedMethod(method);
    Expression result = parseExpressionFromSingleMethodClass(c, parameterNames);
    debug("decompiled: " + result + (result == null ? "" : " // " + result.getClass()));
    debug("");
    return result;
}
Also used : Expression(japa.parser.ast.expr.Expression) Method(java.lang.reflect.Method)

Aggregations

Expression (japa.parser.ast.expr.Expression)6 ParseException (japa.parser.ParseException)4 CompilationUnit (japa.parser.ast.CompilationUnit)4 MethodCallExpr (japa.parser.ast.expr.MethodCallExpr)4 VoidVisitorAdapter (japa.parser.ast.visitor.VoidVisitorAdapter)4 ArrayList (java.util.ArrayList)4 AssignExpr (japa.parser.ast.expr.AssignExpr)2 Method (java.lang.reflect.Method)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1