tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r769063 - in /tapestry/tapestry5/trunk: src/site/apt/guide/ tapestry-core/src/main/java/org/apache/tapestry5/annotations/ tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ tapestry-core/src/test/java/org/apache/tapestry5/i...
Date Mon, 27 Apr 2009 17:26:26 GMT
Author: hlship
Date: Mon Apr 27 17:26:26 2009
New Revision: 769063

URL: http://svn.apache.org/viewvc?rev=769063&view=rev
Log:
TAP5-666: Property expression can not pass a boolean constant into a method

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/Bedrock.java
  (with props)
Modified:
    tapestry/tapestry5/trunk/src/site/apt/guide/propexp.apt
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/SessionState.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BasePropertyConduit.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImplTest.java

Modified: tapestry/tapestry5/trunk/src/site/apt/guide/propexp.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/guide/propexp.apt?rev=769063&r1=769062&r2=769063&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/apt/guide/propexp.apt (original)
+++ tapestry/tapestry5/trunk/src/site/apt/guide/propexp.apt Mon Apr 27 17:26:26 2009
@@ -49,9 +49,9 @@
 ---
 expression : keyword | rangeOp | constant | propertyChain | list | notOp;
 
-keyword : 'null' | 'true' | 'false' | 'this';
+keyword : 'null' | 'this';
 
-constant : <integer> | <decimal> | <string>;
+constant : 'true' | 'false' | <integer> | <decimal> | <string>;
 
 rangeOp :  rangeOpArg '..' rangeOpArg;
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/SessionState.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/SessionState.java?rev=769063&r1=769062&r2=769063&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/SessionState.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/SessionState.java
Mon Apr 27 17:26:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2009 ${ORG}
+// Copyright 2009 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BasePropertyConduit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BasePropertyConduit.java?rev=769063&r1=769062&r2=769063&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BasePropertyConduit.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BasePropertyConduit.java
Mon Apr 27 17:26:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@
         return typeCoercer.coerce(value, type);
     }
 
-    public final Boolean invert(Object value)
+    public final boolean invert(Object value)
     {
         return coerce(value, Boolean.class).equals(Boolean.FALSE);
     }

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=769063&r1=769062&r2=769063&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
Mon Apr 27 17:26:26 2009
@@ -159,31 +159,19 @@
 
     private class GeneratedTerm
     {
-        private final Class type;
+        final Class type;
 
-        private final String variableName;
+        final String variableName;
 
+        /**
+         * @param type         type of variable
+         * @param variableName name of variable
+         */
         private GeneratedTerm(Class type, String variableName)
         {
             this.type = type;
             this.variableName = variableName;
         }
-
-        /**
-         * The name of the variable that contains the evaluation of the term.
-         */
-        String getVariableName()
-        {
-            return variableName;
-        }
-
-        /**
-         * The type of the variable (used to determine what methods/properties may be dereferenced).
-         */
-        Class getType()
-        {
-            return type;
-        }
     }
 
     private final PropertyAccess access;
@@ -399,9 +387,9 @@
             {
                 GeneratedTerm term = processDerefNode(navBuilder, activeType, node, previousVariableName);
 
-                activeType = term.getType();
+                activeType = term.type;
 
-                previousVariableName = term.getVariableName();
+                previousVariableName = term.variableName;
 
                 // Second term is the continuation, possibly another chained DEREF, etc.
                 node = node.getChild(1);
@@ -493,7 +481,7 @@
 
             addRootVariable(builder);
 
-            builder.addln("return %s;", createMethodInvocation(builder, node, 0, INVERT));
+            builder.addln("return ($w) %s;", createMethodInvocation(builder, node, 0, INVERT));
 
             builder.end();
 
@@ -526,7 +514,7 @@
             {
                 GeneratedTerm generatedTerm = subexpression(builder, node.getChild(i));
 
-                builder.addln("%s.add(($w) %s);", listName, generatedTerm.getVariableName());
+                builder.addln("%s.add(($w) %s);", listName, generatedTerm.variableName);
             }
 
             return listName;
@@ -537,7 +525,7 @@
             String flagName = nextVariableName(Boolean.class);
             GeneratedTerm term = subexpression(builder, node.getChild(0));
 
-            builder.addln("Boolean %s = invert(($w) %s);", flagName, term.getVariableName());
+            builder.addln("boolean %s = invert(($w) %s);", flagName, term.variableName);
 
             return flagName;
         }
@@ -558,12 +546,21 @@
             {
                 switch (node.getType())
                 {
+                    case TRUE:
+                    case FALSE:
+
+                        previousVariableName = node.getType() == TRUE ? "true" : "false";
+                        activeType = boolean.class;
+
+                        node = null;
+                        break;
+
                     case INTEGER:
 
                         long integerValue = Long.parseLong(node.getText());
 
-                        previousVariableName = addInjection(long.class, integerValue);
-                        activeType = Long.class;
+                        previousVariableName = String.format("%dL", integerValue);
+                        activeType = long.class;
 
                         node = null;
 
@@ -573,8 +570,8 @@
 
                         double decimalValue = Double.parseDouble(node.getText());
 
-                        previousVariableName = addInjection(double.class, decimalValue);
-                        activeType = Double.class;
+                        previousVariableName = String.format("%fd", decimalValue);
+                        activeType = double.class;
 
                         node = null;
 
@@ -583,6 +580,7 @@
                     case STRING:
 
                         String stringValue = node.getText();
+                        // Injecting is easier; don't have to fuss with escaping quotes or
such.
                         previousVariableName = addInjection(String.class, stringValue);
                         activeType = String.class;
 
@@ -595,8 +593,8 @@
 
                         GeneratedTerm generated = processDerefNode(builder, activeType, node,
previousVariableName);
 
-                        previousVariableName = generated.getVariableName();
-                        activeType = generated.getType();
+                        previousVariableName = generated.variableName;
+                        activeType = generated.type;
 
                         node = node.getChild(1);
 
@@ -608,8 +606,8 @@
                         generated = addAccessForPropertyOrMethod(builder, activeType, node,
previousVariableName,
                                                                  NullHandling.IGNORE);
 
-                        previousVariableName = generated.getVariableName();
-                        activeType = generated.getType();
+                        previousVariableName = generated.variableName;
+                        activeType = generated.type;
 
                         node = null;
 
@@ -634,7 +632,8 @@
                         break;
 
                     default:
-                        throw unexpectedNodeType(node, INTEGER, DECIMAL, STRING, DEREF, SAFEDEREF,
IDENTIFIER, INVOKE,
+                        throw unexpectedNodeType(node, TRUE, FALSE, INTEGER, DECIMAL, STRING,
DEREF, SAFEDEREF,
+                                                 IDENTIFIER, INVOKE,
                                                  LIST);
                 }
             }
@@ -754,9 +753,9 @@
                 // child(0) is the method name, child(1) is the first parameter, etc.
 
                 GeneratedTerm generatedTerm = subexpression(bodyBuilder, node.getChild(i
+ childOffset));
-                String variableName = generatedTerm.getVariableName();
+                String variableName = generatedTerm.variableName;
 
-                Class actualType = generatedTerm.getType();
+                Class actualType = generatedTerm.type;
 
                 Class parameterType = parameterTypes[i];
 
@@ -778,7 +777,7 @@
                 }
                 else
                 {
-                    needsUnwrap = parameterType.isPrimitive();
+                    needsUnwrap = parameterType.isPrimitive() && !actualType.isPrimitive();
                 }
 
                 if (i > 0) builder.append(", ");

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/Bedrock.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/Bedrock.java?rev=769063&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/Bedrock.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/Bedrock.java
Mon Apr 27 17:26:26 2009
@@ -0,0 +1,23 @@
+// Copyright 2009 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+public class Bedrock
+{
+    public String toName(boolean fred)
+    {
+        return fred ? "Fred" : "Barney";
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/Bedrock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImplTest.java?rev=769063&r1=769062&r2=769063&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImplTest.java
Mon Apr 27 17:26:26 2009
@@ -384,7 +384,7 @@
     }
 
     @Test
-    public void no_operator_in_subexpression()
+    public void not_operator_in_subexpression()
     {
         PropertyConduit conduit = source.create(Switch.class, "label(! value)");
 
@@ -446,4 +446,16 @@
                          "Error parsing property expression 'fred {': Unable to parse input
at character position 6.");
         }
     }
+
+    @Test
+    public void boolean_constant_as_method_parameter()
+    {
+        Bedrock bedrock = new Bedrock();
+
+        PropertyConduit trueConduit = source.create(Bedrock.class, "toName(true)");
+        PropertyConduit falseConduit = source.create(Bedrock.class, "toName(false)");
+
+        assertEquals(trueConduit.get(bedrock), "Fred");
+        assertEquals(falseConduit.get(bedrock), "Barney");
+    }
 }



Mime
View raw message