Package org.mvel2.compiler

Examples of org.mvel2.compiler.CompiledExpression


    ctx.addInput("var1", MyInterface3.class);
    ctx.addImport(MyInterface2.class);
    ctx.addImport(MyInterface3.class);

    try {
      CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
    }
    catch (Exception e) {
      fail(e.getMessage());
    }
  }
View Full Code Here


    ctx.setStrongTyping(true);
    ctx.addInput("foo",
            Foo.class);

    try {
      CompiledExpression expr = new ExpressionCompiler("foo.aValue = 'bar'").compile(ctx);
    }
    catch (CompileException e) {
      assertTrue(false);
    }
  }
View Full Code Here

    public final void determineEgressParametricType() {
        final ParserContext parserContext = new ParserContext();
        parserContext.setStrongTyping(true);
        parserContext.addInput("strings", List.class, new Class[] { String.class });
       
        final CompiledExpression expr = new ExpressionCompiler("strings", parserContext)
                .compile();

        assert STRINGS.equals(MVEL.executeExpression(expr, new A())) : "faulty expression eval";

        final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();

        assert null != typeParameters : "no generic egress type";
        assert String.class.equals(typeParameters[0]) : "wrong generic egress type";
    }
View Full Code Here

    public final void determineEgressParametricTypeInExprChain() {
        final ParserContext parserContext = new ParserContext();
        parserContext.setStrongTyping(true);
        parserContext.addInput("strings", A.class);

        final CompiledExpression expr = new ExpressionCompiler("strings.strings", parserContext)
                .compile();

        assert STRINGS.equals(MVEL.executeExpression(expr, new B())) : "faulty expression eval";

        final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();

        assert null != typeParameters : "no generic egress type";
        assert String.class.equals(typeParameters[0]) : "wrong generic egress type";

    }
View Full Code Here

      Type type = egressTypes.get(expression);
      if (type != null) {
        return type;
      }
     
      CompiledExpression compiled = compileExpression(expression);
    final Class<?> egressClass = compiled.getKnownEgressType();
      final Type[] parameters = compiled.getParserContext().getLastTypeParameters();
     
      if (parameters == null) {
          // the class is not parameterised (generic)
        type = egressClass;
      }
View Full Code Here

  }

  public Evaluator compile(String expression) throws ExpressionCompileException {

    //do *not* inline
    final CompiledExpression compiled = compileExpression(expression);

    return new Evaluator() {
      @Nullable
      public Object evaluate(String expr, Object bean) {
        return MVEL.executeExpression(compiled, bean);
View Full Code Here

    };
  }

  private CompiledExpression compileExpression(String expression)
      throws ExpressionCompileException {
    final CompiledExpression compiledExpression = compiled.get(expression);

    //use cached copy
    if (null != compiledExpression)
      return compiledExpression;

    //otherwise compile expression and cache
    final ExpressionCompiler compiler = new ExpressionCompiler(expression, getParserContext());

    CompiledExpression tempCompiled;
    try {
      tempCompiled = compiler.compile();
    } catch (CompileException ce) {
      throw new ExpressionCompileException(expression, ce.getErrors());
    }
View Full Code Here

        if ( pkg != null ) {
            MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( this.id );
            factory.setNextFactory( data.getFunctionFactory() );
        }

        CompiledExpression compexpr = (CompiledExpression) this.expr;

        Object value;
        if ( MVELDebugHandler.isDebugMode() ) {
            if ( MVELDebugHandler.verbose ) {
                System.out.println( DebugTools.decompile( compexpr ) );
View Full Code Here

      MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg
          .getDialectRuntimeRegistry().getDialectData(this.id);
      factory.setNextFactory(data.getFunctionFactory());
    }

    CompiledExpression compexpr = (CompiledExpression) this.expr;

    pkg = knowledgeHelper.getWorkingMemory().getRuleBase().getPackage(
        knowledgeHelper.getRule().getPackage());

    ClassLoader tempClassLoader = Thread.currentThread()
        .getContextClassLoader();
    Thread.currentThread().setContextClassLoader(
        ((InternalRuleBase) workingMemory.getRuleBase())
            .getRootClassLoader());

    try {
          if (MVELDebugHandler.isDebugMode()) {
              if (MVELDebugHandler.verbose) {
                  System.out.println("Executing expression " + compexpr.getSourceName());
                  System.out.println(DebugTools.decompile(compexpr));
              }
              MVEL.executeDebugger(compexpr, null, factory);
          } else {
              MVEL.executeExpression(compexpr, null, factory);
View Full Code Here

        if ( pkg != null ) {
            MVELDialectRuntimeData data = ( MVELDialectRuntimeData ) pkg.getDialectRuntimeRegistry().getDialectData( id );
            factory.setNextFactory( data.getFunctionFactory() );
        }       
       
        CompiledExpression compexpr = (CompiledExpression) this.expr;

        if ( MVELDebugHandler.isDebugMode() ) {
            if ( MVELDebugHandler.verbose ) {
                System.out.println( DebugTools.decompile( compexpr ) );
            }
View Full Code Here

TOP

Related Classes of org.mvel2.compiler.CompiledExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.