Expression toString... Possible bug

From: Budhiraja, Nikhil (nikhil_budhiraj..anniemae.com)
Date: Wed Oct 06 2004 - 12:33:26 EDT

  • Next message: Kevin J. Menard, Jr.: "Modeler Question"

    Gurus,

    Just trying to print out an expression, but for some reason it doesn't
    put the parenthesis in the right place.

    after debugging, it looks like the 'parent' for the expression is never
    set if I build and add the expressions individually... And hence the
    'encodeAsString' doesn't put the parenthesis in the right place.

    E.g.
                    Expression first = Expression.fromString("a = 1");
                    Expression second = Expression.fromString("a = 2");
                    Expression third = Expression.fromString("a != 1");
                    Expression fourth = Expression.fromString("a != 2");
                    
                    Expression firstAndSecond = first.andExp(second);
                    Expression thirdAndFourth = third.andExp(fourth);
                    
                    Expression finalExpression =
    firstAndSecond.orExp(thirdAndFourth);
                    System.out.println("finalExpression =
    "+finalExpression);

    I expected to see
     ((a = 1) and (a = 2)) or ((a != 1) and (a != 2))

    But instead I see
    finalExpression = a = 1 and a = 2 or a != 1 and a != 2

    But if I do
    Expression.fromString("(a = 1 and a = 2) or (a != 1 and a != 2)"));

    I get the right result:
    finalExpression2 = ((a = 1) and (a = 2)) or ((a != 1) and (a != 2))

    Part of our code relies on "expression.toString", as I am using this
    epression to build a ejb-ql.

    Any pointers will be appreciated...and please let me know if I am doing
    anything wrong.

    Thanks
    Nik



    This archive was generated by hypermail 2.0.0 : Wed Oct 06 2004 - 12:33:32 EDT