Commits

Anonymous committed b04d935

ASTTest had been quietly failing since the last set of changes. Not good for performance...

Comments (0)

Files changed (5)

src/java/ognl/ASTAdd.java

                         && ASTConst.class.isInstance(_children[i])) {
                         
                         expr = expr.replaceAll("'", "\"");
+                        context.setCurrentType(String.class);
                     } else {
                         if (!ASTVarRef.class.isAssignableFrom(_children[i].getClass())
                             && !ASTProperty.class.isInstance(_children[i])

src/java/ognl/ASTAnd.java

             if (!OgnlRuntime.isBoolean(first) && !context.getCurrentType().isPrimitive())
                 first = OgnlRuntime.getCompiler().createLocalReference(context, first, context.getCurrentType());
 
-            Class firstType = context.getCurrentType();
-
             String second = OgnlRuntime.getChildSource(context, target, _children[1]);
             if (!OgnlRuntime.isBoolean(second) && !context.getCurrentType().isPrimitive())
                 second = OgnlRuntime.getCompiler().createLocalReference(context, second, context.getCurrentType());
 
-            Class secondType = context.getCurrentType();
-
-            boolean mismatched = (firstType.isPrimitive() && !secondType.isPrimitive())
-                                 || (!firstType.isPrimitive() && secondType.isPrimitive());
-
             result += "ognl.OgnlOps.booleanValue(" + first + ")";
             
             result += " ? ";
 
-            result += (mismatched ? " ($w) " : " ($w) ") + second;
+            result += " ($w) "  + second;
             result += " : ";
 
-            result += (mismatched ? " ($w) " : " ($w) ") + first;
+            result += " ($w) " + first;
 
             result += "";
 

src/java/ognl/ASTTest.java

 
 import ognl.enhance.UnsupportedCompilationException;
 
-
-
 /**
  * @author Luke Blanshard (blanshlu@netscape.net)
  * @author Drew Davidson (drew@ognl.org)
         if (target == null)
             throw new UnsupportedCompilationException("evaluation resulted in null expression.");
 
-        if (_children.length != 2)
-            throw new UnsupportedCompilationException("Can only compile test expressions with two children.");
+        if (_children.length != 3)
+            throw new UnsupportedCompilationException("Can only compile test expressions with two children." + _children.length);
 
-        String result = (_parent == null || NumericExpression.class.isAssignableFrom(_parent.getClass())) ? "" : "(";
+        String result = "";
+        //String result = (_parent == null || NumericExpression.class.isAssignableFrom(_parent.getClass())) ? "" : "(";
         
         try {
 
             String first = OgnlRuntime.getChildSource(context, target, _children[0]);
-            if (!OgnlRuntime.isBoolean(first))
+            if (!OgnlRuntime.isBoolean(first) && !context.getCurrentType().isPrimitive())
                 first = OgnlRuntime.getCompiler().createLocalReference(context, first, context.getCurrentType());
-            
-            Class firstType = context.getCurrentType();
 
             String second = OgnlRuntime.getChildSource(context, target, _children[1]);
-             if (!OgnlRuntime.isBoolean(second))
+             if (!OgnlRuntime.isBoolean(second) && !context.getCurrentType().isPrimitive())
                  second = OgnlRuntime.getCompiler().createLocalReference(context, second, context.getCurrentType());
             
-            Class secondType = context.getCurrentType();
-            
-            boolean mismatched = (firstType.isPrimitive() && !secondType.isPrimitive())
-                                 || (!firstType.isPrimitive() && secondType.isPrimitive()) ? true : false;
-            
+            String third = OgnlRuntime.getChildSource(context, target, _children[2]);
+             if (!OgnlRuntime.isBoolean(third) && !context.getCurrentType().isPrimitive())
+                 third = OgnlRuntime.getCompiler().createLocalReference(context, third, context.getCurrentType());
+
             result += "ognl.OgnlOps.booleanValue(" + first + ")";
 
             result += " ? ";
 
-            result += (mismatched ? " ($w) " : "") + first;
+            result += " ($w) " + second;
             result += " : ";
 
-            result += (mismatched ? " ($w) " : "") + second;
-            
-            if (_parent != null && !NumericExpression.class.isAssignableFrom(_parent.getClass())) {
-                result = result + ")";
-            }
-            
+            result += " ($w) " + third;
+
+            context.setCurrentObject(target);
+            context.setCurrentType(Object.class);
+
             return result;
         
         } catch (NullPointerException e) {

src/java/ognl/enhance/ExpressionCompiler.java

 
         } catch (UnsupportedCompilationException uc) {
 
+            //uc.printStackTrace();
+
             nodeMember = new CtField(nodeClass, "_node", newClass);
 
             newClass.addField(nodeMember);
 
         } catch (UnsupportedCompilationException uc) {
 
+            //uc.printStackTrace();
+            
             if (nodeMember == null) {
 
                 nodeMember = new CtField(nodeClass, "_node", newClass);
             }
 
         } catch (Throwable t) {
+            //t.printStackTrace();
+            
             throw new RuntimeException("Error compiling expression on object " + root
                                        + " with expression node " + expression + " getter body: " + getBody
                                        + " setter body: " + setBody, t);
 
         body = body.replaceAll("\\.\\.", ".");
 
-        // System.out.println("Getter Body: ===================================\n" + body);
+        //System.out.println("Getter Body: ===================================\n" + body);
         valueGetter.setBody(body);
 
         newClass.addMethod(valueGetter);

src/test/java/org/ognl/test/PropertyTest.java

             { ROOT, "map.(#this != null ? #this['size'] : null)", ROOT.getMap().get(Root.SIZE_STRING) },
             { ROOT, "map[^].(#this == null ? 'empty' : #this)", new Integer(99) },
             { ROOT, "map[$].(#this == null ? 'empty' : #this)", "empty" },
-            { ROOT, "map[$].(#root == null ? 'empty' : #root)", ROOT }, 
+            { ROOT, "map[$].(#root == null ? 'empty' : #root)", ROOT },
             { ROOT, "((selected != null) && (currLocale.toString() == selected.toString())) ? 'first' : 'second'", "first" },
             { ROOT, "{stringValue, getMap()}", Arrays.asList(new Object[]{ROOT.getStringValue(), ROOT.getMap()})},
             { ROOT, "{'stringValue', map[\"test\"].map[\"size\"]}", Arrays.asList(new Object[]{"stringValue", ROOT.getMap().get("size")}) },
             { ROOT, "'last ' + getCurrentClass(@org.ognl.test.PropertyTest@VALUE)", "last foo stop"},
             { ROOT, "@org.ognl.test.PropertyTest@formatValue(property.millis, true, true)", formatValue((int)((Bean2)ROOT.getProperty()).getMillis(), true, true) },
             { ROOT, "nullObject || !readonly", Boolean.TRUE },
-            { ROOT, "testDate == null ? '-' : @org.ognl.test.PropertyTest@DATETIME_FORMAT.format(testDate)", DATETIME_FORMAT.format(ROOT.getTestDate()) }
+            { ROOT, "testDate == null ? '-' : @org.ognl.test.PropertyTest@DATETIME_FORMAT.format(testDate)", DATETIME_FORMAT.format(ROOT.getTestDate()) },
+            { ROOT, "disabled ? 'disabled' : 'othernot'", "disabled" }
     };
 
     public static String formatValue(int millis, boolean b1, boolean b2)