Exemple #1
0
 /**
  * This is the starting point of the compiler.
  *
  * @param args Command line arguments to control the compiler
  */
 public static void main(String[] args) {
   try {
     run(args);
   } catch (FileNotFoundException e) {
     System.err.println("FILE NOT FOUND: " + e.getLocalizedMessage());
     System.exit(FILE_NOT_FOUND_ERROR);
   } catch (ParseException e) {
     System.err.println("PARSE ERROR: " + e.getLocalizedMessage());
     System.exit(PARSE_ERROR);
   } catch (ShadowException e) {
     System.err.println("ERROR IN FILE: " + e.getLocalizedMessage());
     e.printStackTrace();
     System.exit(TYPE_CHECK_ERROR);
   } catch (IOException e) {
     System.err.println("FILE DEPENDENCY ERROR: " + e.getLocalizedMessage());
     e.printStackTrace();
     System.exit(TYPE_CHECK_ERROR);
   } catch (org.apache.commons.cli.ParseException e) {
     System.err.println("COMMAND LINE ERROR: " + e.getLocalizedMessage());
     Arguments.printHelp();
     System.exit(COMMAND_LINE_ERROR);
   } catch (ConfigurationException e) {
     System.err.println("CONFIGURATION ERROR: " + e.getLocalizedMessage());
     Arguments.printHelp();
     System.exit(CONFIGURATION_ERROR);
   } catch (TypeCheckException e) {
     System.err.println("TYPE CHECK ERROR: " + e.getLocalizedMessage());
     System.exit(TYPE_CHECK_ERROR);
   } catch (CompileException e) {
     System.err.println("COMPILATION ERROR: " + e.getLocalizedMessage());
     System.exit(COMPILE_ERROR);
   }
 }
Exemple #2
0
  /**
   * typecheck and then compile this rule unless either action has been tried before
   *
   * @return true if the rule successfully type checks and then compiles under this call or a
   *     previous call or false if either operation has previously failed or fails under this call.
   */
  private synchronized boolean ensureTypeCheckedCompiled() {
    if (checkFailed) {
      return false;
    }

    if (!checked) {
      // ensure we don't trigger any code inside the type check or compile
      // n.b. we may still allow recursive triggering while executing
      boolean triggerEnabled = false;
      String detail = "";
      try {
        typeCheck();
        compile();
        checked = true;
        installed();
      } catch (TypeWarningException te) {
        checkFailed = true;
        if (Transformer.isVerbose()) {
          StringWriter stringWriter = new StringWriter();
          PrintWriter writer = new PrintWriter(stringWriter);
          writer.println(
              "Rule.ensureTypeCheckedCompiled : warning type checking rule " + getName());
          te.printStackTrace(writer);
          detail = stringWriter.toString();
          System.out.println(detail);
        }
      } catch (TypeException te) {
        checkFailed = true;
        StringWriter stringWriter = new StringWriter();
        PrintWriter writer = new PrintWriter(stringWriter);
        writer.println("Rule.ensureTypeCheckedCompiled : error type checking rule " + getName());
        te.printStackTrace(writer);
        detail = stringWriter.toString();
        System.out.println(detail);
      } catch (CompileException ce) {
        checkFailed = true;
        StringWriter stringWriter = new StringWriter();
        PrintWriter writer = new PrintWriter(stringWriter);
        writer.println("Rule.ensureTypeCheckedCompiled : error compiling rule " + getName());
        ce.printStackTrace(writer);
        detail = stringWriter.toString();
        System.out.println(detail);
      }

      ruleScript.recordCompile(triggerClass, loader, !checkFailed, detail);
      return !checkFailed;
    }

    return true;
  }
  public void testStrictTypingCompilationWithVarInsideConstructor() {
    ParserContext ctx = new ParserContext();
    ctx.addInput("$likes", String.class);
    ctx.addInput("results", List.class);
    ctx.addImport(Cheese.class);
    ctx.setStrongTyping(true);

    Serializable expr = null;
    try {
      expr =
          MVEL.compileExpression("Cheese c = new Cheese( $likes, 15 );\nresults.add( c ); ", ctx);
    } catch (CompileException e) {
      e.printStackTrace();
      fail("This should not fail:\n" + e.getMessage());
    }
    List results = new ArrayList();

    Map vars = new HashMap();
    vars.put("$likes", "stilton");
    vars.put("results", results);
    executeExpression(expr, vars);

    assertEquals(new Cheese("stilton", 15), results.get(0));
  }