Return-Path: Delivered-To: apmail-tapestry-commits-archive@minotaur.apache.org Received: (qmail 50044 invoked from network); 27 Apr 2009 17:26:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Apr 2009 17:26:48 -0000 Received: (qmail 36404 invoked by uid 500); 27 Apr 2009 17:26:48 -0000 Delivered-To: apmail-tapestry-commits-archive@tapestry.apache.org Received: (qmail 36341 invoked by uid 500); 27 Apr 2009 17:26:48 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 36332 invoked by uid 99); 27 Apr 2009 17:26:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2009 17:26:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2009 17:26:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 27AEA23889F5; Mon, 27 Apr 2009 17:26:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@tapestry.apache.org From: hlship@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090427172627.27AEA23889F5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 : | | ; +constant : 'true' | 'false' | | | ; 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"); + } }