Package org.codehaus.janino

Examples of org.codehaus.janino.ExpressionEvaluator


    if (evaluator_ == null)
    {
      //create the parser
      try
      {
        evaluator_ = new ExpressionEvaluator(
                      expression_,                       // expression
                      returnType_,                         // expressionType
                      varNames_.toArray(new String[0]),   // parameterNames
                      varTypes_.toArray(new Class<?>[0])   // parameterTypes
                  );
View Full Code Here


  @Override
  public void start() {
    try {
      assert context != null;
      ClassLoader cl = context.getClass().getClassLoader();
      ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE,
          getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, cl);
      super.start();
    } catch (Exception e) {
      addError(
          "Could not start evaluator with expression [" + expression + "]", e);
View Full Code Here

                while (idx < args.length - 1) {
                    arg = args[idx + 1];
                    if (arg.startsWith("predicate:")) {
                        String predicateExpression = arg.substring(10);
                        try {
                            IExpressionEvaluator ee = new ExpressionEvaluator();
                            ee.setClassName(JGrep.class.getName() + "PE");
                            mit.predicates.add((MethodInvocationPredicate) ee.createFastEvaluator(
                                predicateExpression,
                                MethodInvocationPredicate.class,
                                new String[] { "uc", "invocation", "method" }
                            ));
                        } catch (Exception ex) {
View Full Code Here

        new Integer(10), new Integer(11), });
  }

  private int jdk() throws Exception{
    // Compile the expression once; relatively slow.
    ExpressionEvaluator ee = new ExpressionEvaluator("c > d ? c : d", // expression
        int.class, // expressionType
        new String[] { "c", "d" }, // parameterNames
        new Class[] { int.class, int.class } // parameterTypes
    );

    // Evaluate it with varying parameter values; very fast.
    return  (Integer) ee.evaluate(new Object[] { // parameterValues
        new Integer(10), new Integer(11), });
  }
View Full Code Here

          pred_param_types[j++] = param_types[pv];
        }

        LOG.debug("eval: " + predicates.get(i) + " param len: "
            + pred_vars.size() + " ? " + pred_vars);
        ee_list[i] = new ExpressionEvaluator(predicates.get(i),
            boolean.class, pred_param_names, pred_param_types,
            new Class[0], null);
      } catch (NullPointerException exception) {
        String message = String.format("predicate [ %s ] failed",
            predicates.get(i));
View Full Code Here

    String[] parameterNames = {"e"};
    Class[] parameterTypes = {LoggingEvent.class};
    Class[] thrownExceptions = new Class[0];

    // Create "ExpressionEvaluator" object.
    ExpressionEvaluator ee = new ExpressionEvaluator(expression,
        optionalExpressionType, parameterNames, parameterTypes,
        thrownExceptions, null // optionalClassLoader
    );

    Object[] parameterValues = new Object[1];
    LoggerContext lc = new LoggerContext();
   
    Logger logger = lc.getLogger(JaninoTest.class);
    LoggingEvent loggingEvent = new LoggingEvent("toto", logger, Level.INFO, "hi", null);
    parameterValues[0] = loggingEvent;
   
    Object res = ee.evaluate(parameterValues);

    // Print expression result.
    System.out.println("Result = " + DemoBase.toString(res));
    System.out.println("Type = " + res.getClass().getName());
    loop(ee, parameterValues);

  //   loggingEvent.getMarker()
   
    expression = "import ch.qos.logback.classic.Level; (e.getMarker() != null) && (e.getMarker().contains(\"yo\"))";
    ee = new ExpressionEvaluator(expression,
        optionalExpressionType, parameterNames, parameterTypes,
        thrownExceptions, null);
    res = ee.evaluate(parameterValues);

    // Print expression result.
    System.out.println("Result = " + DemoBase.toString(res));
    System.out.println("Type = " + res.getClass().getName());
    loop(ee, parameterValues);
View Full Code Here

  public void start() {
    try {
      assert context != null;
      ClassLoader cl = context.getClass().getClassLoader();
      ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE,
          getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, cl);
      start = true;
    } catch (Exception e) {
      addError(
          "Could not start evaluator with expression [" + expression + "]", e);
View Full Code Here

    start = false;
  }

  public void start() {
    try {
      ee = new ExpressionEvaluator(getDecoratedExpression(),
          EXPRESSION_TYPE, getParameterNames(), getParameterTypes(),
          THROWN_EXCEPTIONS, null);
      start = true;
    } catch (Exception e) {
      addError("Could not start evaluator with expression [" + expression + "]", e);
View Full Code Here

    start = false;
  }

  public void start() {
    try {
      ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE,
          getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, null);
      start = true;
    } catch (Exception e) {
      addError(
          "Could not start evaluator with expression [" + expression + "]", e);
View Full Code Here

  @Override
  protected ScriptEvaluator getEvaluator( Class returnType, String[] parameterNames, Class[] parameterTypes )
    {
    try
      {
      return new ExpressionEvaluator( block, getReturnType(), parameterNames, parameterTypes );
      }
    catch( CompileException exception )
      {
      throw new OperationException( "could not compile expression: " + block, exception );
      }
View Full Code Here

TOP

Related Classes of org.codehaus.janino.ExpressionEvaluator

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.