Пример #1
0
  public void testGenericInference2() {
    ParserContext ctx;
    MVEL.analysisCompile(
        "$result = person.maptributes['fooey'].name",
        ctx = ParserContext.create().stronglyTyped().withInput("person", Person.class));

    assertEquals(String.class, ctx.getVarOrInputTypeOrNull("$result"));
  }
Пример #2
0
  public void testStaticFieldAccessForInputsWithStrictStrong() {
    ParserContext pCtx = ParserContext.create();
    pCtx.setStrictTypeEnforcement(true);
    pCtx.setStrongTyping(true);
    MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx);

    assertFalse(pCtx.getInputs().containsKey("java"));

    assertEquals(0, pCtx.getInputs().size());

    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    pCtx = ParserContext.create();
    pCtx.setStrictTypeEnforcement(true);
    pCtx.setStrongTyping(true);
    MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx);

    assertFalse(pCtx.getInputs().containsKey("java"));

    assertEquals(0, pCtx.getInputs().size());
  }
Пример #3
0
  public void testVarInputs5() {
    ParserContext pCtx = ParserContext.create().withInput("list", List.class);
    MVEL.analysisCompile(
        "String nodeName = list[0];\nSystem.out.println(nodeName);nodeName = list[1];\nSystem.out.println(nodeName);",
        pCtx);

    assertEquals(1, pCtx.getInputs().size());

    assertTrue(pCtx.getInputs().containsKey("list"));

    assertEquals(1, pCtx.getVariables().size());

    assertTrue(pCtx.getVariables().containsKey("nodeName"));

    assertEquals(List.class, pCtx.getVarOrInputType("list"));
    assertEquals(String.class, pCtx.getVarOrInputType("nodeName"));
  }
Пример #4
0
  public void testStaticFieldAccessForInputs() {
    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    ParserContext pCtx = ParserContext.create();
    MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx);

    assertFalse(pCtx.getInputs().containsKey("java"));

    assertEquals(0, pCtx.getInputs().size());

    //        MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    //
    //        pCtx = ParserContext.create();
    //        MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx);
    //
    //        assertFalse(pCtx.getInputs().containsKey("java"));
    //
    //        assertEquals(0,
    //                pCtx.getInputs().size());
  }
Пример #5
0
  public void testVarInputs() {
    ParserContext pCtx = ParserContext.create();
    MVEL.analysisCompile(
        "test != foo && bo.addSomething(trouble) "
            + "&& 1 + 2 / 3 == 1; String bleh = foo; twa = bleh;",
        pCtx);

    assertEquals(4, pCtx.getInputs().size());

    assertTrue(pCtx.getInputs().containsKey("test"));
    assertTrue(pCtx.getInputs().containsKey("foo"));
    assertTrue(pCtx.getInputs().containsKey("bo"));
    assertTrue(pCtx.getInputs().containsKey("trouble"));

    assertEquals(2, pCtx.getVariables().size());

    assertTrue(pCtx.getVariables().containsKey("bleh"));
    assertTrue(pCtx.getVariables().containsKey("twa"));

    assertEquals(String.class, pCtx.getVarOrInputType("bleh"));
  }
Пример #6
0
  public void testGenericInference() {
    String expression = "$result = person.footributes[0].name";

    ParserContext ctx;
    MVEL.analysisCompile(
        expression, ctx = ParserContext.create().stronglyTyped().withInput("person", Person.class));

    assertEquals(String.class, ctx.getVarOrInputTypeOrNull("$result"));

    Serializable s =
        MVEL.compileExpression(
            expression, ParserContext.create().stronglyTyped().withInput("person", Person.class));

    Map<String, Object> vars = new HashMap<String, Object>();
    Person p = new Person();
    p.setFootributes(new ArrayList<Foo>());
    p.getFootributes().add(new Foo());

    vars.put("person", p);

    assertEquals("dog", executeExpression(s, vars));
  }