You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/04/14 00:24:01 UTC

svn commit: r1091958 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services: PropertyConduitDelegate.java PropertyConduitSourceImpl.java

Author: hlship
Date: Wed Apr 13 22:24:01 2011
New Revision: 1091958

URL: http://svn.apache.org/viewvc?rev=1091958&view=rev
Log:
TAP5-853: Re-implement range ops with subexpressions

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java?rev=1091958&r1=1091957&r2=1091958&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java Wed Apr 13 22:24:01 2011
@@ -23,7 +23,7 @@ import org.apache.tapestry5.ioc.internal
 import org.apache.tapestry5.ioc.services.TypeCoercer;
 
 /**
- * Base class for {@link org.apache.tapestry5.PropertyConduit} instances created by the
+ * Companion class for {@link org.apache.tapestry5.PropertyConduit} instances created by the
  * {@link org.apache.tapestry5.services.PropertyConduitSource}.
  */
 @SuppressWarnings("all")

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java?rev=1091958&r1=1091957&r2=1091958&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java Wed Apr 13 22:24:01 2011
@@ -664,7 +664,7 @@ public class PropertyConduitSourceImpl i
                     // top level, which
                     // means we didn't need the navigate method after all.
 
-                    // createPlasticRangeOpGetter(node, "root");
+                    createPlasticRangeOpGetter(node);
                     createPlasticNoOpSetter();
 
                     conduitPropertyType = IntegerRange.class;
@@ -752,6 +752,28 @@ public class PropertyConduitSourceImpl i
             }
         }
 
+        private void createPlasticRangeOpGetter(final Tree rangeNode)
+        {
+            plasticClass.introduceMethod(GET, new InstructionBuilderCallback()
+            {
+                public void doBuild(InstructionBuilder builder)
+                {
+                    // Put the delegate on top of the stack
+
+                    builder.loadThis().getField(delegateField);
+
+                    invokeMethod(builder, DelegateMethods.RANGE, rangeNode, 0);
+
+                    builder.returnResult();
+                }
+            });
+        }
+
+        private Object foo(PropertyConduitDelegate d)
+        {
+            return d.range(1, 99);
+        }
+
         private void createRangeOpGetter(Tree node, String rootName)
         {
             BodyBuilder builder = new BodyBuilder().begin();
@@ -1258,7 +1280,7 @@ public class PropertyConduitSourceImpl i
             }
             else
             {
-                invokeMethod(builder, info.getReadMethod(), termNode);
+                invokeMethod(builder, info.getReadMethod(), termNode, 1);
             }
 
             return termType;
@@ -1269,10 +1291,16 @@ public class PropertyConduitSourceImpl i
          * to be evaluated, and potentially coerced, so that they may be passed to the method.
          * 
          * @param builder
+         *            constructs code
          * @param method
-         * @param invokeNode
+         *            method to invoke
+         * @param node
+         *            INVOKE or RANGEOP node
+         * @param childOffset
+         *            offset within the node to the first child expression (1 in an INVOKE node because the
+         *            first child is the method name, 0 in a RANGEOP node)
          */
-        private void invokeMethod(InstructionBuilder builder, Method method, Tree invokeNode)
+        private void invokeMethod(InstructionBuilder builder, Method method, Tree node, int childOffset)
         {
             // We start with the target object for the method on top of the stack.
             // Next, we have to push each method parameter, which may include boxing/deboxing
@@ -1285,7 +1313,7 @@ public class PropertyConduitSourceImpl i
 
             for (int i = 0; i < parameterTypes.length; i++)
             {
-                Class expressionType = buildSubexpression(builder, null, invokeNode.getChild(i + 1));
+                Class expressionType = buildSubexpression(builder, null, node.getChild(i + childOffset));
 
                 // The value left on the stack is not primitive, and expressionType represents
                 // its real type.
@@ -1294,8 +1322,12 @@ public class PropertyConduitSourceImpl i
 
                 if (!parameterType.isAssignableFrom(expressionType))
                 {
+                    if (expressionType.isPrimitive())
+                    {
+                        builder.boxPrimitive(expressionType.getName());
+                    }
+
                     builder.loadThis().getField(delegateField);
-                    // TODO: Will this work for wide primitives?
                     builder.swap().loadTypeConstant(PlasticUtils.toWrapperType(parameterType));
                     builder.invoke(DelegateMethods.COERCE);
 
@@ -1551,7 +1583,7 @@ public class PropertyConduitSourceImpl i
                     }
                     else
                     {
-                        invokeMethod(builder, method, term);
+                        invokeMethod(builder, method, term, 1);
                     }
 
                     builder.dupe().when(Condition.NULL, new InstructionBuilderCallback()
@@ -2102,6 +2134,20 @@ public class PropertyConduitSourceImpl i
         }
     }
 
+    private Class processConstant(InstructionBuilder builder, Tree integerNode)
+    {
+        long value = Long.parseLong(integerNode.getText());
+
+        if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE)
+        {
+            builder.loadConstant((int) value);
+            return int.class;
+        }
+
+        builder.loadConstant(value);
+        return long.class;
+    }
+
     /**
      * May be invoked from fabricated PropertyConduit instances.
      */
@@ -2112,4 +2158,5 @@ public class PropertyConduitSourceImpl i
 
         return new NullPointerException(message);
     }
+
 }