Package de.odysseus.el.tree

Examples of de.odysseus.el.tree.Tree


   * @param type the expected type (may be <code>null</code>)
   */
  public TreeValueExpression(TreeStore store, FunctionMapper functions, VariableMapper variables, String expr, Class<?> type) {
    super();

    Tree tree = store.get(expr);

    this.builder = store.getBuilder();
    this.bindings = tree.bind(functions, variables);
    this.expr = expr;
    this.type = type;
    this.node = tree.getRoot();
    this.deferred = tree.isDeferred();
   
    if (type == null) {
      throw new NullPointerException(LocalMessages.get("error.value.notype"));
    }
  }
View Full Code Here


    AstNode t = text();
    if (symbol == EOF) {
      if (t == null) {
        t = new AstText("");
      }
      return new Tree(t, functions, identifiers, false);
    }
    AstEval e = eval();
    if (symbol == 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 (symbol != 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(new AstComposite(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 (ELException e) {
      System.out.println(e.getMessage());
      System.exit(0);
    }
    NodePrinter.dump(out, tree.getRoot());
    if (!tree.getFunctionNodes().iterator().hasNext() && !tree.getIdentifierNodes().iterator().hasNext()) {
      out.print(">> ");
      try {
        out.println(tree.getRoot().getValue(null, new SimpleContext(), null));
      } catch (ELException e) {
        out.println(e.getMessage());
      }
    }
    out.flush();
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

    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()) {
      out.print(">> ");
      try {
        out.println(tree.getRoot().getValue(new Bindings(null, null), new SimpleContext(), null));
      } catch (ELException e) {
        out.println(e.getMessage());
      }
    }
    out.flush();
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

   * @param type the expected type (may be <code>null</code>)
   */
  public TreeValueExpression(TreeStore store, FunctionMapper functions, VariableMapper variables, TypeConverter converter, String expr, Class<?> type) {
    super();

    Tree tree = store.get(expr);

    this.builder = store.getBuilder();
    this.bindings = tree.bind(functions, variables, converter);
    this.expr = expr;
    this.type = type;
    this.node = tree.getRoot();
    this.deferred = tree.isDeferred();
   
    if (type == null) {
      throw new NullPointerException(LocalMessages.get("error.value.notype"));
    }
  }
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, String expr, Class<?> returnType, Class<?>[] paramTypes) {
    super();

    Tree tree = store.get(expr);

    this.builder = store.getBuilder();
    this.bindings = tree.bind(functions, variables);
    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.setVariable("var_var_long_1", new TreeValueExpression(new TreeStore(BUILDER, null), null, context.getVariableMapper(), "${var_long_1}", long.class))
    context.setVariable("var_property_long_1", new TreeValueExpression(new TreeStore(BUILDER, null), null, context.getVariableMapper(), "${property_long_1}", long.class))
  }

  public void testEval() {
    Tree tree = null;
    Bindings bindings = null;

    tree = parse("${bad}");
    bindings = tree.bind(null, context.getVariableMapper());
    try { getNode(tree).eval(bindings, context); fail(); } catch (ELException e) {}
   
    tree = parse("${var_long_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    assertEquals(1l, getNode(tree).eval(bindings, context));

    tree = parse("${property_long_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    assertEquals(1l, getNode(tree).eval(bindings, context));

    tree = parse("${indentifier_string}");
    bindings = tree.bind(null, context.getVariableMapper());
    assertEquals("foo", getNode(tree).eval(bindings, context));

    tree = parse("${var_var_long_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    assertEquals(1l, getNode(tree).eval(bindings, context));

    tree = parse("${var_property_long_1}");
    bindings = tree.bind(null, context.getVariableMapper());
    assertEquals(1l, getNode(tree).eval(bindings, context));
  }
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.