Search in sources :

Example 81 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class DebugTools method decompile.

private static String decompile(CompiledExpression cExp, boolean nest, DecompileContext context) {
    ASTIterator iter = new ASTLinkedList(cExp.getFirstNode());
    ASTNode tk;
    StringBuffer sbuf = new StringBuffer();
    if (!nest) {
        sbuf.append("Expression Decompile\n-------------\n");
    }
    while (iter.hasMoreNodes()) {
        sbuf.append("(").append(context.node++).append(") ");
        if ((tk = iter.nextNode()) instanceof NestedStatement && ((NestedStatement) tk).getNestedStatement() instanceof CompiledExpression) {
            // noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("NEST [" + tk.getClass().getSimpleName() + "]: { " + tk.getName() + " }\n");
            sbuf.append(decompile((CompiledExpression) ((NestedStatement) tk).getNestedStatement(), true, context));
        }
        if (tk instanceof Substatement && ((Substatement) tk).getStatement() instanceof CompiledExpression) {
            // noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("NEST [" + tk.getClass().getSimpleName() + "]: { " + tk.getName() + " }\n");
            sbuf.append(decompile((CompiledExpression) ((Substatement) tk).getStatement(), true, context));
        } else // }
        if (tk.isDebuggingSymbol()) {
            // noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("DEBUG_SYMBOL :: " + tk.toString());
        } else if (tk.isLiteral()) {
            sbuf.append("LITERAL :: ").append(tk.getLiteralValue()).append("'");
        } else if (tk.isOperator()) {
            sbuf.append("OPERATOR [").append(getOperatorName(tk.getOperator())).append("]: ").append(tk.getName());
            if (tk.isOperator(Operator.END_OF_STMT))
                sbuf.append("\n");
        } else if (tk.isIdentifier()) {
            sbuf.append("REFERENCE :: ").append(tk.getClass().getSimpleName()).append(":").append(tk.getName());
        } else if (tk instanceof BinaryOperation) {
            BinaryOperation bo = (BinaryOperation) tk;
            sbuf.append("OPERATION [" + getOperatorName(bo.getOperation()) + "] {").append(bo.getLeft().getName()).append("} {").append(bo.getRight().getName()).append("}");
        } else {
            // noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("NODE [" + tk.getClass().getSimpleName() + "] :: " + tk.getName());
        }
        sbuf.append("\n");
    }
    sbuf.append("==END==");
    return sbuf.toString();
}
Also used : NestedStatement(org.mvel2.ast.NestedStatement) BinaryOperation(org.mvel2.ast.BinaryOperation) ASTLinkedList(org.mvel2.util.ASTLinkedList) ASTNode(org.mvel2.ast.ASTNode) ASTIterator(org.mvel2.util.ASTIterator) Substatement(org.mvel2.ast.Substatement) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 82 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class TypesAndInferenceTests method testParameterizedTypeInStrictMode4.

public void testParameterizedTypeInStrictMode4() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("base", Base.class);
    ExpressionCompiler compiler = new ExpressionCompiler("base.list.get(1).toUpperCase()", ctx);
    CompiledExpression ce = compiler.compile();
    assertEquals(String.class, ce.getKnownEgressType());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 83 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class TypesAndInferenceTests method testMVEL234.

public void testMVEL234() {
    StringBuffer buffer = new StringBuffer();
    buffer.append("import java.text.SimpleDateFormat;");
    buffer.append("if (\"test\".matches(\"[0-9]\")) {");
    buffer.append("  return false;");
    buffer.append("}else{");
    buffer.append("  SimpleDateFormat sqf = new SimpleDateFormat(\"yyyyMMdd\");");
    buffer.append("}");
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    try {
        CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression) CompileException(org.mvel2.CompileException)

Example 84 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class TypesAndInferenceTests method testMVEL228.

public void testMVEL228() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.setStrictTypeEnforcement(true);
    HashMap<String, Class> params = new HashMap<String, Class>();
    params.put("helper", ScriptHelper228.class);
    params.put("person", Person228.class);
    ctx.setInputs(params);
    String script = "helper.methodB(2);\n" + "person.getName2();";
    try {
        CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(script, ctx);
    } catch (Exception e) {
        return;
    }
    fail("Should have thrown an exception");
}
Also used : HashMap(java.util.HashMap) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression) CompileException(org.mvel2.CompileException)

Example 85 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class WithTests method testInlineWith.

public void testInlineWith() {
    CompiledExpression expr = new ExpressionCompiler("foo.{name='poopy', aValue='bar'}").compile();
    Foo f = (Foo) executeExpression(expr, createTestMap());
    assertEquals("poopy", f.getName());
    assertEquals("bar", f.aValue);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Aggregations

CompiledExpression (org.mvel2.compiler.CompiledExpression)81 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)65 ParserContext (org.mvel2.ParserContext)48 HashMap (java.util.HashMap)20 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)20 Foo (org.mvel2.tests.core.res.Foo)20 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)15 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)14 DataType (org.mule.runtime.api.metadata.DataType)11 HashSet (java.util.HashSet)10 Test (org.junit.Test)9 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)9 ParserContext (org.mule.mvel2.ParserContext)8 Map (java.util.Map)6 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)6 CompileException (org.mvel2.CompileException)6 ASTNode (org.mvel2.ast.ASTNode)6 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)6