Search in sources :

Example 41 with CompileException

use of org.mule.mvel2.CompileException in project mvel by mikebrock.

the class Soundslike method getReducedValue.

public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    try {
        String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory));
        if (i == null)
            throw new ClassCastException();
        String x = (String) stmt.getReducedValue(ctx, thisValue, factory);
        if (x == null)
            throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), stmt.getStart());
        return soundex(i).equals(soundex(x));
    } catch (ClassCastException e) {
        throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart());
    }
}
Also used : CompileException(org.mvel2.CompileException)

Example 42 with CompileException

use of org.mule.mvel2.CompileException in project mvel by mikebrock.

the class TemplateCompiler method captureOrbInternal.

private int captureOrbInternal() {
    try {
        ParserContext pCtx = new ParserContext();
        cursor = balancedCaptureWithLineAccounting(template, start = cursor, length, '{', pCtx);
        line += pCtx.getLineCount();
        int ret = start + 1;
        start = cursor + 1;
        return ret;
    } catch (CompileException e) {
        e.setLineNumber(line);
        e.setColumn((cursor - colStart) + 1);
        throw e;
    }
}
Also used : CompileException(org.mvel2.CompileException) ParserContext(org.mvel2.ParserContext)

Example 43 with CompileException

use of org.mule.mvel2.CompileException in project mvel by mvel.

the class CoreConfidenceTests method testUntypedClone.

public void testUntypedClone() {
    String expression = "obj.clone();";
    ParserContext context = new ParserContext();
    context.setStrongTyping(false);
    context.setStrictTypeEnforcement(false);
    MVEL.analyze(expression, context);
    try {
        context.addInput("obj", Object.class);
        context.setStrongTyping(true);
        context.setStrictTypeEnforcement(true);
        MVEL.analyze(expression, context);
        fail("Must fail with strong typing");
    } catch (CompileException e) {
    }
}
Also used : CompileException(org.mvel2.CompileException) ParserContext(org.mvel2.ParserContext)

Example 44 with CompileException

use of org.mule.mvel2.CompileException in project mvel by mvel.

the class CoreConfidenceTests method testStrTriangleEqualsEquals.

public void testStrTriangleEqualsEquals() {
    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    try {
        ParserConfiguration pconf = new ParserConfiguration();
        ParserContext pctx = new ParserContext(pconf);
        pctx.addInput("this", Triangle.class);
        pctx.setStrongTyping(true);
        String str = "this.strLabel == this";
        try {
            ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
            fail("should have failed");
        } catch (CompileException e) {
            System.out.println();
            return;
        }
    } finally {
        MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = false;
    }
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) CompileException(org.mvel2.CompileException) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 45 with CompileException

use of org.mule.mvel2.CompileException in project mvel by mvel.

the class CoreConfidenceTests method testNullCollection.

public void testNullCollection() throws CompileException {
    boolean allowCompilerOverride = MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING;
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    String[] names = { "missing" };
    String[] values = { null };
    try {
        MVEL.executeExpression((CompiledExpression) MVEL.compileExpression("1; missing[3]"), new IndexedVariableResolverFactory(names, values));
        fail("Should throw a NullPointerExcption");
    } catch (Exception e) {
    } finally {
        MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = allowCompilerOverride;
    }
}
Also used : CompileException(org.mvel2.CompileException) IOException(java.io.IOException) IndexedVariableResolverFactory(org.mvel2.integration.impl.IndexedVariableResolverFactory)

Aggregations

CompileException (org.mvel2.CompileException)83 ParserContext (org.mvel2.ParserContext)14 Map (java.util.Map)13 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)13 PropertyAccessException (org.mvel2.PropertyAccessException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 List (java.util.List)11 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)9 Method (java.lang.reflect.Method)7 TypeDescriptor (org.mvel2.ast.TypeDescriptor)7 Field (java.lang.reflect.Field)6 HashMap (java.util.HashMap)6 EndOfStatement (org.mvel2.ast.EndOfStatement)6 Proto (org.mvel2.ast.Proto)6 Constructor (java.lang.reflect.Constructor)5 Member (java.lang.reflect.Member)5 ASTNode (org.mvel2.ast.ASTNode)5 LiteralNode (org.mvel2.ast.LiteralNode)5 Collection (java.util.Collection)4