Package de.odysseus.el.tree

Examples of de.odysseus.el.tree.Tree


    assertEquals(1l, getNode(tree).getValue(bindings, context, null));
    assertEquals("1", getNode(tree).getValue(bindings, context, String.class));
  }
 
  public void testInvoke() {
    Tree tree = null;
    Bindings bindings = null;

    tree = parse("${bad}");
    bindings = tree.bind(null, context.getVariableMapper());
    try { getNode(tree).invoke(bindings, context, long.class, new Class[0], null); fail(); } catch (ELException e) {}
   
    tree = parse("${var_method_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    assertEquals(1l, getNode(tree).invoke(bindings, context, long.class, new Class[0], null));
   
    tree = parse("${property_method_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    assertEquals(1l, getNode(tree).invoke(bindings, context, null, new Class[0], null));

    // no return type - ok
    assertEquals(1l, getNode(tree).invoke(bindings, context, long.class, new Class[0], null));
    // bad return type
View Full Code Here


    // bad args
    try { getNode(tree).invoke(bindings, context, long.class, new Class[0], new Object[]{""}); fail(); } catch (ELException e) {}
  }

  public void testGetMethodInfo() {
    Tree tree = null;
    Bindings bindings = null;
    MethodInfo info = null;

    tree = parse("${bad}");
    bindings = tree.bind(null, context.getVariableMapper());
    try { getNode(tree).getMethodInfo(bindings, context, long.class, new Class[0]); fail(); } catch (ELException e) {}
   
    tree = parse("${var_method_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    info = getNode(tree).getMethodInfo(bindings, context, long.class, new Class[0]);
    assertEquals("method_1", info.getName());
    assertTrue(Arrays.equals(new Class[0], info.getParamTypes()));
    assertEquals(long.class, info.getReturnType());
   
    tree = parse("${property_method_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    info = getNode(tree).getMethodInfo(bindings, context, long.class, new Class[0]);
    assertEquals("method_1", info.getName());
    assertTrue(Arrays.equals(new Class[0], info.getParamTypes()));
    assertEquals(long.class, info.getReturnType());
View Full Code Here

   * @param paramTypes the expected parameter types (must not be <code>null</code> for lvalues)
   */
  public TreeMethodExpression(TreeStore store, FunctionMapper functions, VariableMapper variables, TypeConverter converter, String expr, Class<?> returnType, Class<?>[] paramTypes) {
    super();

    Tree tree = store.get(expr);

    this.builder = store.getBuilder();
    this.bindings = tree.bind(functions, variables, converter);
    this.expr = expr;
    this.type = returnType == void.class ? null : returnType;
    this.types = paramTypes;
    this.node = tree.getRoot();
    this.deferred = tree.isDeferred();
    this.is_void = returnType == void.class;

    if (node.isLiteralText()) {
      if (returnType == void.class) {
        throw new ELException(LocalMessages.get("error.method.literal.void", expr));
View Full Code Here

    context.getELResolver().setValue(context, null, "var111", new int[]{1,1,1});
  }

  public void testVarargs() {
    Builder builder = new Builder(Feature.VARARGS);
    Tree tree = null;

    tree = builder.build("${vararg:f()}");
    assertEquals(foovar(), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = builder.build("${vararg:f(1)}");
    assertEquals(foovar(1), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = builder.build("${vararg:f(1,1)}");
    assertEquals(foovar(1,1), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = builder.build("${vararg:f(null)}");
    assertEquals(foovar(0), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = builder.build("${vararg:f(var111)}");
    assertEquals(foovar(1,1,1), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), context));
  }
View Full Code Here

    tree = builder.build("${vararg:f(var111)}");
    assertEquals(foovar(1,1,1), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), context));
  }

  public void testEval() {
    Tree tree = null;

    tree = parse("${ns:f0()}");
    assertEquals(foo(), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = parse("${ns:f1(42)}");
    assertEquals(bar(42), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = parse("${ns:f2(21,21)}");
    assertEquals(foobar(21,21), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = parse("${g0()}");
    assertEquals(foo(), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = parse("${g1(42)}");
    assertEquals(bar(42), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));

    tree = parse("${g2(21,21)}");
    assertEquals(foobar(21,21), getNode(tree).eval(tree.bind(context.getFunctionMapper(), null), null));
  }
View Full Code Here

  public void testSetValue() {
    try { parseNode("${f()}").setValue(null, null, null); fail(); } catch (ELException e) {}
  }

  public void testGetValue() {
    Tree tree = null;

    tree = parse("${ns:f0()}");

    assertEquals(foo(), getNode(tree).getValue(tree.bind(context.getFunctionMapper(), null), null, null));
    assertEquals("" + foo(), getNode(tree).getValue(tree.bind(context.getFunctionMapper(), null), null, String.class));
  }
View Full Code Here

    bindings1 = new Bindings(new Method[0], new ValueExpression[0]);
    bindings2 = new Bindings(null, null);
    assertEquals(bindings1, bindings2);
    assertEquals(bindings1.hashCode(), bindings2.hashCode());

    Tree tree = parse("${ns:f()+v+g(1)}+x");
    bindings1 = tree.bind(context.getFunctionMapper(), context.getVariableMapper());
    bindings2 = tree.bind(context.getFunctionMapper(), context.getVariableMapper());
    assertEquals(bindings1, bindings2);
    assertEquals(bindings1.hashCode(), bindings2.hashCode());
  }
View Full Code Here

    AstNode t = text();
    if (token.getSymbol() == EOF) {
      if (t == null) {
        t = new AstText("");
      }
      return new Tree(t, functions, identifiers, false);
    }
    AstEval e = eval();
    if (token.getSymbol() == EOF && t == null) {
      return new Tree(e, functions, identifiers, e.isDeferred());
    }
    ArrayList<AstNode> list = new ArrayList<AstNode>();
    if (t != null) {
      list.add(t);
    }
    list.add(e);
    t = text();
    if (t != null) {
      list.add(t);
    }
    while (token.getSymbol() != EOF) {
      if (e.isDeferred()) {
        list.add(eval(true, true));
      } else {
        list.add(eval(true, false));
      }
      t = text();
      if (t != null) {
        list.add(t);
      }
    }
    return new Tree(createAstComposite(list), functions, identifiers, e.isDeferred());
  }
View Full Code Here

  public Tree get(String expression) {
    if (secondary == null) {
      return primary.get(expression);
    } else {
      Tree tree = primary.get(expression);
      if (tree == null) {
        tree = secondary.get(expression);
      }
      return tree;
    }
View Full Code Here

    if (args.length != 1) {
      System.err.println("usage: java " + Builder.class.getName() + " <expression string>");
      System.exit(1);
    }
    PrintWriter out = new PrintWriter(System.out);
    Tree tree = null;
    try {
      tree = new Builder(Feature.METHOD_INVOCATIONS).build(args[0]);
    } catch (TreeBuilderException e) {
      System.out.println(e.getMessage());
      System.exit(0);
    }
    NodePrinter.dump(out, tree.getRoot());
    if (!tree.getFunctionNodes().iterator().hasNext() && !tree.getIdentifierNodes().iterator().hasNext()) {
      ELContext context = new ELContext() {
        @Override
        public VariableMapper getVariableMapper() {
          return null;
        }
        @Override
        public FunctionMapper getFunctionMapper() {
          return null;
        }
        @Override
        public ELResolver getELResolver() {
          return null;
        }
      };
      out.print(">> ");
      try {
        out.println(tree.getRoot().getValue(new Bindings(null, null), context, null));
      } catch (ELException e) {
        out.println(e.getMessage());
      }
    }
    out.flush();
View Full Code Here

TOP

Related Classes of de.odysseus.el.tree.Tree

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.