Author: nbelaevski
Date: 2010-02-21 18:23:03 -0500 (Sun, 21 Feb 2010)
New Revision: 16480
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/HelperMethod.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanResultOperationTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/BaseTemplateMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToBooleanMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/HelperMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-schemas-aggregator.xsd
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-boolean-method.ftl
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/types/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/coercions.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/CoercionsTest.java
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java
Modified:
root/cdk/trunk/plugins/attributes/src/main/java/org/richfaces/cdk/attributes/Attribute.java
root/cdk/trunk/plugins/attributes/src/test/java/org/richfaces/cdk/attributes/AttributesTest.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/Type.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBinaryOperationTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIntegerTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticIntegerOperationTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticOperationTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanOperationTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/EqualityTestTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ITreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EncodeMethodPrefaceStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EqualsCheckingMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/StartElementStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributeStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteTextStatement.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/xml-configured-component/src/main/templates/testPanel.xml
Log:
TODOs & fixes for CDK
https://jira.jboss.org/jira/browse/RF-8310
Modified:
root/cdk/trunk/plugins/attributes/src/main/java/org/richfaces/cdk/attributes/Attribute.java
===================================================================
---
root/cdk/trunk/plugins/attributes/src/main/java/org/richfaces/cdk/attributes/Attribute.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/attributes/src/main/java/org/richfaces/cdk/attributes/Attribute.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -144,7 +144,7 @@
*/
@XmlElement(name = "component-attribute-name")
public String getComponentAttributeName() {
- return componentAttributeName;
+ return componentAttributeName != null ? componentAttributeName : name;
}
/**
Modified:
root/cdk/trunk/plugins/attributes/src/test/java/org/richfaces/cdk/attributes/AttributesTest.java
===================================================================
---
root/cdk/trunk/plugins/attributes/src/test/java/org/richfaces/cdk/attributes/AttributesTest.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/attributes/src/test/java/org/richfaces/cdk/attributes/AttributesTest.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,7 +21,11 @@
*/
package org.richfaces.cdk.attributes;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.StringReader;
import java.io.StringWriter;
@@ -129,6 +133,7 @@
Attribute restoredIdAttribute = restoredSpanAttributes.get("id");
assertNotNull(restoredIdAttribute);
assertEquals("id", restoredIdAttribute.getName());
+ assertEquals("id", restoredIdAttribute.getComponentAttributeName());
assertEquals("id", restoredIdAttribute.getKey());
assertNull(restoredIdAttribute.getDefaultValue());
assertFalse(restoredIdAttribute.isRequired());
@@ -144,16 +149,19 @@
Attribute restoredAltAttribute = restoredImgAttributes.get("alt");
assertNotNull(restoredAltAttribute);
assertEquals("alt", restoredAltAttribute.getName());
+ assertEquals("alt", restoredAltAttribute.getComponentAttributeName());
assertTrue(restoredAltAttribute.isRequired());
Attribute restoredSrcAttribute = restoredImgAttributes.get("src");
assertNotNull(restoredSrcAttribute);
assertEquals("src", restoredSrcAttribute.getName());
+ assertEquals("src", restoredSrcAttribute.getComponentAttributeName());
assertEquals(Kind.URI, restoredSrcAttribute.getKind());
Attribute restoredDirAttribute = restoredImgAttributes.get("dir");
assertNotNull(restoredDirAttribute);
assertEquals("dir", restoredDirAttribute.getName());
+ assertEquals("dir", restoredDirAttribute.getComponentAttributeName());
assertEquals("ltr", restoredDirAttribute.getDefaultValue());
Attribute restoredClassAttribute = restoredImgAttributes.get("class");
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -49,6 +49,7 @@
public static final String COMMA = ",";
public static final String IS_EQUAL_FUNCTION = "isEqual";
public static final String CONVERT_TO_STRING_FUNCTION = "convertToString";
+ public static final String CONVERT_TO_BOOLEAN_FUNCTION =
"convertToBoolean";
public static final String DOT = ".";
public static final String DOUBLE_VALUE_OF_FUNCTION = "Double.valueOf";
public static final String EXCLAMATION_MARK = "!";
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -88,6 +88,7 @@
import org.richfaces.cdk.parser.el.node.BinaryArithmeticIntegerOperationTreeNode;
import org.richfaces.cdk.parser.el.node.BinaryArithmeticOperationTreeNode;
import org.richfaces.cdk.parser.el.node.BinaryBooleanOperationTreeNode;
+import org.richfaces.cdk.parser.el.node.BinaryBooleanResultOperationTreeNode;
import org.richfaces.cdk.parser.el.node.ConstantValueTreeNode;
import org.richfaces.cdk.parser.el.node.EqualityTestTreeNode;
import org.richfaces.cdk.parser.el.node.ITreeNode;
@@ -209,13 +210,13 @@
} else if (child instanceof AstEqual) {
treeNode = new EqualityTestTreeNode(child);
} else if (child instanceof AstGreaterThan) {
- treeNode = new BinaryBooleanOperationTreeNode(child,
ELNodeConstants.GREATER_THEN_OPERATOR);
+ treeNode = new BinaryBooleanResultOperationTreeNode(child,
ELNodeConstants.GREATER_THEN_OPERATOR);
} else if (child instanceof AstGreaterThanEqual) {
- treeNode = new BinaryBooleanOperationTreeNode(child,
ELNodeConstants.GREATER_THEN_OR_EQUALITY_OPERATOR);
+ treeNode = new BinaryBooleanResultOperationTreeNode(child,
ELNodeConstants.GREATER_THEN_OR_EQUALITY_OPERATOR);
} else if (child instanceof AstLessThan) {
- treeNode = new BinaryBooleanOperationTreeNode(child,
ELNodeConstants.LESS_THEN_OPERATOR);
+ treeNode = new BinaryBooleanResultOperationTreeNode(child,
ELNodeConstants.LESS_THEN_OPERATOR);
} else if (child instanceof AstLessThanEqual) {
- treeNode = new BinaryBooleanOperationTreeNode(child,
ELNodeConstants.LESS_THEN_OR_EQUALITY_OPERATOR);
+ treeNode = new BinaryBooleanResultOperationTreeNode(child,
ELNodeConstants.LESS_THEN_OR_EQUALITY_OPERATOR);
} else if (child instanceof AstNotEqual) {
treeNode = new EqualityTestTreeNode(child, true);
} else if (child instanceof AstOr) {
@@ -459,4 +460,19 @@
public static void clearCaches() {
classDataCache.clear();
}
+
+ public static String coerceToType(String valueString, ELVisitor visitor, Type
expectedType) {
+ if (!expectedType.isAssignableFrom(visitor.getExpressionType())) {
+ for (HelperMethod conversionMethod: HelperMethod.getConversionMethods()) {
+ Type returnType =
TypesFactory.getType(conversionMethod.getReturnType());
+ if (expectedType.isAssignableFrom(returnType)) {
+ visitor.getUsedHelperMethods().add(conversionMethod);
+ visitor.setExpressionType(returnType);
+ return conversionMethod.getName() + "(" + valueString +
")";
+ }
+ }
+ }
+
+ return valueString;
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,16 +21,19 @@
package org.richfaces.cdk.parser.el;
+import static org.richfaces.cdk.parser.el.HelperMethod.TO_STRING_CONVERSION;
import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
+import java.text.MessageFormat;
+import java.util.EnumSet;
import java.util.Map;
+import java.util.Set;
import org.jboss.el.parser.AstCompositeExpression;
import org.jboss.el.parser.ELParser;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.node.ITreeNode;
import org.richfaces.cdk.parser.el.types.TypesFactory;
-
/**
* Entry point for parsing EL expressions. @see parse() method.
*
@@ -38,43 +41,46 @@
*/
public final class ELVisitor {
- boolean useConversionToString;
- boolean useEmptinessCheck;
- boolean useEqualsCheck;
-
private String parsedExpression = null;
- private Type variableType = null;
- public boolean isUseConversionToString() {
- return useConversionToString;
- }
+ private Type expressionType = null;
- public void setUseConversionToString(boolean needConversion) {
- this.useConversionToString = needConversion;
- }
+ private Map<String, Type> variables = null;
+
+ private Set<HelperMethod> usedHelperMethods =
EnumSet.noneOf(HelperMethod.class);
- public boolean isUseEmptinessCheck() {
- return useEmptinessCheck;
+ private Set<HelperMethod> usedConversionMethods =
EnumSet.noneOf(HelperMethod.class);
+
+ public Type getExpressionType() {
+ return expressionType;
}
- public void setUseEmptinessCheck(boolean useCheckForEmpty) {
- this.useEmptinessCheck = useCheckForEmpty;
+ public void setExpressionType(Type variableType) {
+ this.expressionType = variableType;
}
- public boolean isUseEqualsCheck() {
- return useEqualsCheck;
+ /**
+ * @return the variables
+ */
+ public Map<String, Type> getVariables() {
+ return variables;
}
- public void setUseEqualsCheck(boolean useEqualsCheck) {
- this.useEqualsCheck = useEqualsCheck;
- }
+ public Type getVariable(String name) throws ParsingException {
+ Type variableType = variables.get(name);
+ if (variableType == null) {
+ throw new ParsingException(MessageFormat.format(
+ "No type found in context for identifier ''{0}'',
handling as generic Object", name));
+ }
- public Type getVariableType() {
return variableType;
}
-
- public void setVariableType(Type variableType) {
- this.variableType = variableType;
+
+ /**
+ * @return the uses
+ */
+ public Set<HelperMethod> getUsedHelperMethods() {
+ return usedHelperMethods;
}
/**
@@ -92,25 +98,28 @@
* @return generated Java code.
* @throws ParsingException - if error occurred during parsing.
*/
- public void parse(String expression, Map<String, Type> contextMap) throws
ParsingException {
+ public void parse(String expression, Map<String, Type> contextMap, Type
expectedType) throws ParsingException {
reset();
Node ret = ELParser.parse(expression);
+ variables = contextMap;
if (ret instanceof AstCompositeExpression && ret.jjtGetNumChildren()
>= 2) {
//AstCompositeExpression with 2+ children is a mixed expression
- this.setUseConversionToString(true);
+ getUsedHelperMethods().add(TO_STRING_CONVERSION);
}
if (ret != null && ret.jjtGetNumChildren() > 0) {
- parsedExpression = this.visit(ret, contextMap);
+ parsedExpression = this.visit(ret);
} else {
parsedExpression = getEscapedString("");
- variableType = TypesFactory.getType(String.class);
+ expressionType = TypesFactory.getType(String.class);
}
+
+ parsedExpression = ELParserUtils.coerceToType(parsedExpression, this,
expectedType);
}
- private String visit(Node node, Map<String, Type> context) throws
ParsingException {
+ private String visit(Node node) throws ParsingException {
int numChildren = node.jjtGetNumChildren();
StringBuilder sb = new StringBuilder();
@@ -119,7 +128,7 @@
ITreeNode treeNode = ELParserUtils.determineNodeType(child);
- treeNode.visit(sb, context, this);
+ treeNode.visit(sb, this);
if (i != numChildren - 1) {
sb.append(" + ");
@@ -131,9 +140,9 @@
private void reset() {
parsedExpression = null;
- useConversionToString = false;
- useEmptinessCheck = false;
- useEqualsCheck = false;
- variableType = null;
+ usedHelperMethods.clear();
+ variables = null;
+ expressionType = null;
}
+
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/HelperMethod.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/HelperMethod.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/HelperMethod.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.parser.el;
+
+import static org.richfaces.cdk.parser.el.ELNodeConstants.CONVERT_TO_BOOLEAN_FUNCTION;
+import static org.richfaces.cdk.parser.el.ELNodeConstants.CONVERT_TO_STRING_FUNCTION;
+import static org.richfaces.cdk.parser.el.ELNodeConstants.IS_EMPTY_FUNCTION;
+import static org.richfaces.cdk.parser.el.ELNodeConstants.IS_EQUAL_FUNCTION;
+
+import java.util.EnumSet;
+import java.util.Set;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public enum HelperMethod {
+
+ TO_STRING_CONVERSION(CONVERT_TO_STRING_FUNCTION, String.class, Object.class),
+ TO_BOOLEAN_CONVERSION(CONVERT_TO_BOOLEAN_FUNCTION, Boolean.TYPE, Object.class),
+ EMPTINESS_CHECK(IS_EMPTY_FUNCTION, Boolean.TYPE, Object.class),
+ EQUALS_CHECK(IS_EQUAL_FUNCTION, Boolean.TYPE, Object.class, Object.class);
+
+ private static final Set<HelperMethod> CONVERSION_METHODS =
EnumSet.of(TO_STRING_CONVERSION, TO_BOOLEAN_CONVERSION);
+
+ private String name;
+
+ private Class<?> returnType;
+
+ private Class<?>[] argumentTypes;
+
+ private HelperMethod(String name, Class<?> returnType, Class<?>...
argumentTypes) {
+ this.name = name;
+ this.returnType = returnType;
+ this.argumentTypes = argumentTypes;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class<?> getReturnType() {
+ return returnType;
+ }
+
+ public Class<?>[] getArgumentTypes() {
+ return argumentTypes;
+ }
+
+ public static Set<HelperMethod> getConversionMethods() {
+ return CONVERSION_METHODS;
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/Type.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/Type.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/Type.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -27,6 +27,7 @@
* @author Nick Belaevski
*
*/
+//TODO unit-test thoroughly all implementations of this interface
public interface Type {
public String getCode();
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBinaryOperationTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBinaryOperationTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBinaryOperationTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,8 +21,6 @@
*/
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
-
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
@@ -30,9 +28,13 @@
import org.richfaces.cdk.parser.el.Type;
/**
- * <p>Abstract class for all binary (having two operands) operation expression
nodes</p>
- * <p>For operands <code>A</code> and <code>B</code> and
operator <code>x</code> output is <code>(A x B)</code></p>
- *
+ * <p>
+ * Abstract class for all binary (having two operands) operation expression nodes
+ * </p>
+ * <p>
+ * For operands <code>A</code> and <code>B</code> and operator
<code>x</code> output is <code>(A x B)</code>
+ * </p>
+ *
* @author Nick Belaevski
*/
public abstract class AbstractBinaryOperationTreeNode extends AbstractTreeNode {
@@ -47,16 +49,21 @@
protected abstract Type getOperationType(Type firstArgumentType, Type
secondArgumentType);
- /* (non-Javadoc)
- * @see
org.richfaces.cdk.parser.el.node.AbstractTreeNode#visit(java.lang.StringBuilder,
java.util.Map, org.richfaces.cdk.parser.el.ELVisitor)
- */
+ protected abstract String getCoercedChildOutput(int childIndex, ELVisitor visitor)
+ throws ParsingException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.richfaces.cdk.parser.el.node.AbstractTreeNode#visit(java.lang.StringBuilder,
java.util.Map,
+ * org.richfaces.cdk.parser.el.ELVisitor)
+ */
@Override
- public void visit(StringBuilder sb, Map<String, Type> context,
- ELVisitor visitor) throws ParsingException {
- String firstChildOutput = getChildOutput(0, context, visitor);
- Type firstChildType = visitor.getVariableType();
- String secondChildOutput = getChildOutput(1, context, visitor);
- Type secondChildType = visitor.getVariableType();
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
+ String firstChildOutput = getCoercedChildOutput(0, visitor);
+ Type firstChildType = visitor.getExpressionType();
+ String secondChildOutput = getCoercedChildOutput(1, visitor);
+ Type secondChildType = visitor.getExpressionType();
sb.append(ELNodeConstants.LEFT_BRACKET);
@@ -66,6 +73,6 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
- visitor.setVariableType(getOperationType(firstChildType, secondChildType));
+ visitor.setExpressionType(getOperationType(firstChildType, secondChildType));
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
@@ -48,10 +47,10 @@
super(node);
}
- protected void visitMethod(StringBuilder sb, Map<String, Type> context,
ELVisitor visitor, String methodName)
+ protected void visitMethod(StringBuilder sb, ELVisitor visitor, String methodName)
throws ParsingException {
- Class<?> methodHolderClass = visitor.getVariableType().getRawType();
+ Class<?> methodHolderClass = visitor.getExpressionType().getRawType();
List<Type> argumentTypes = new ArrayList<Type>();
sb.append(ELNodeConstants.DOT);
@@ -64,11 +63,11 @@
if (k != 0) {
sb.append(ELNodeConstants.COMMA);
}
- String childOutput = getChildOutput(k, context, visitor);
+ String childOutput = getChildOutput(k, visitor);
sb.append(childOutput);
// TODO: handle generic matches -?
- argumentTypes.add(visitor.getVariableType());
+ argumentTypes.add(visitor.getExpressionType());
}
sb.append(ELNodeConstants.RIGHT_BRACKET);
@@ -83,6 +82,6 @@
returnType = TypesFactory.getType(Object.class);
}
- visitor.setVariableType(returnType);
+ visitor.setExpressionType(returnType);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,14 +21,12 @@
package org.richfaces.cdk.parser.el.node;
-import java.text.MessageFormat;
-import java.util.Map;
-
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELParserUtils;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.parser.el.Type;
+import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
* This abstract class implement some methods of ITreeNode interface to using in
subclasses.
@@ -53,26 +51,20 @@
* @return
* @throws ParsingException
*/
- protected String getChildOutput(int childIndex, Map<String, Type> context,
ELVisitor visitor)
+ protected String getChildOutput(int childIndex, ELVisitor visitor)
throws ParsingException {
StringBuilder sb = new StringBuilder();
- getChild(childIndex).visit(sb, context, visitor);
+ getChild(childIndex).visit(sb, visitor);
return sb.toString();
}
- protected Type getIdentifierFromContext(Map<String, Type> context, String
identifierName) throws ParsingException {
- Type identifierType = context.get(identifierName);
-
- if (identifierType == null) {
- throw new ParsingException(MessageFormat.format(
- "No type found in context for identifier ''{0}'',
handling as generic Object", identifierName));
- }
-
- return identifierType;
+ protected String coerceToBoolean(String value, ELVisitor visitor) {
+ Type booleanType = TypesFactory.getType(Boolean.TYPE);
+ return ELParserUtils.coerceToType(value, visitor, booleanType);
}
-
+
/**
* Return node of current wrapper.
*
@@ -120,14 +112,14 @@
/**
* Return child of wrapped node by specified index. Abstract operation to override in
subclasses.
- *
* @param index
* - index of child.
+ *
* @throws ParsingException
* - if error occurred(child not found).
* @return wrapper for child
*
*/
- public abstract void visit(StringBuilder sb, Map<String, Type> context,
ELVisitor visitor) throws ParsingException;
+ public abstract void visit(StringBuilder sb, ELVisitor visitor) throws
ParsingException;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,7 +21,6 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
@@ -41,9 +40,9 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
- Type variableType = visitor.getVariableType();
- String suffixValue = getChildOutput(0, context, visitor);
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
+ Type variableType = visitor.getExpressionType();
+ String suffixValue = getChildOutput(0, visitor);
if (variableType.isArray()) {
sb.append(ELNodeConstants.LEFT_SQUARE_BRACKET);
@@ -61,6 +60,6 @@
if (containerType == null) {
containerType = TypesFactory.getType(Object.class);
}
- visitor.setVariableType(containerType);
+ visitor.setExpressionType(containerType);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,7 +23,6 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
@@ -43,13 +42,13 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
//condition ? correctConditionBranch : incorrectConditionBranch
- String condition = getChildOutput(0, context, visitor);
- String correctConditionBranch = getChildOutput(1, context, visitor);
- Type correctConditionBranchType = visitor.getVariableType();
- String incorrectConditionBranch = getChildOutput(2, context, visitor);
- Type incorrectConditionBranchType = visitor.getVariableType();
+ String condition = coerceToBoolean(getChildOutput(0, visitor), visitor);
+ String correctConditionBranch = getChildOutput(1, visitor);
+ Type correctConditionBranchType = visitor.getExpressionType();
+ String incorrectConditionBranch = getChildOutput(2, visitor);
+ Type incorrectConditionBranchType = visitor.getExpressionType();
sb.append(ELNodeConstants.LEFT_BRACKET);
@@ -62,9 +61,9 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
if (!correctConditionBranchType.isNullType()) {
- visitor.setVariableType(correctConditionBranchType);
+ visitor.setExpressionType(correctConditionBranchType);
} else {
- visitor.setVariableType(incorrectConditionBranchType);
+ visitor.setExpressionType(incorrectConditionBranchType);
}
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,13 +21,13 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
+import static org.richfaces.cdk.parser.el.HelperMethod.TO_STRING_CONVERSION;
+
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
@@ -42,22 +42,22 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
int childrenCount = getChildrenCount();
for (int i = 0; i < childrenCount; i++) {
- if (visitor.isUseConversionToString()) {
+ if (visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION)) {
sb.append(ELNodeConstants.CONVERT_TO_STRING_FUNCTION);
sb.append(ELNodeConstants.LEFT_BRACKET);
}
ITreeNode treeNode = getChild(i);
- treeNode.visit(sb, context, visitor);
+ treeNode.visit(sb, visitor);
- if (visitor.isUseConversionToString()) {
+ if (visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION)) {
sb.append(ELNodeConstants.RIGHT_BRACKET);
- visitor.setVariableType(TypesFactory.getType(String.class));
+ visitor.setExpressionType(TypesFactory.getType(String.class));
} /* otherwise variableType will be set in child's visit invocation */
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,13 +23,12 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
+import static org.richfaces.cdk.parser.el.HelperMethod.EMPTINESS_CHECK;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
@@ -44,17 +43,17 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
- visitor.setUseEmptinessCheck(true);
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
+ visitor.getUsedHelperMethods().add(EMPTINESS_CHECK);
sb.append(ELNodeConstants.IS_EMPTY_FUNCTION);
sb.append(ELNodeConstants.LEFT_BRACKET);
- String childOutput = getChildOutput(0, context, visitor);
+ String childOutput = getChildOutput(0, visitor);
sb.append(childOutput);
sb.append(ELNodeConstants.RIGHT_BRACKET);
- visitor.setVariableType(TypesFactory.getType(Boolean.TYPE));
+ visitor.setExpressionType(TypesFactory.getType(Boolean.TYPE));
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,13 +23,11 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
@@ -44,12 +42,12 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(ELNodeConstants.DOUBLE_VALUE_OF_FUNCTION);
sb.append(ELNodeConstants.LEFT_BRACKET);
sb.append(getNode().getImage());
sb.append(ELNodeConstants.RIGHT_BRACKET);
- visitor.setVariableType(TypesFactory.getType(Double.TYPE));
+ visitor.setExpressionType(TypesFactory.getType(Double.TYPE));
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,7 +21,6 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.AstFunction;
import org.jboss.el.parser.Node;
@@ -44,7 +43,7 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
AstFunction functionNode = (AstFunction) getNode();
String functionPrefix = functionNode.getPrefix();
String functionName = functionNode.getLocalName();
@@ -59,9 +58,9 @@
sb.append(identifierName);
- Type identifierType = getIdentifierFromContext(context, identifierName);
- visitor.setVariableType(identifierType);
+ Type identifierType = visitor.getVariable(identifierName);
+ visitor.setExpressionType(identifierType);
- visitMethod(sb, context, visitor, functionName);
+ visitMethod(sb, visitor, functionName);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,7 +21,6 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELVisitor;
@@ -40,13 +39,13 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
String identifierName = getNode().getImage();
- Type identifierType = getIdentifierFromContext(context, identifierName);
+ Type identifierType = visitor.getVariable(identifierName);
//TODO: implement variable mapper like "utils" ->
"this.getUtils()"
- visitor.setVariableType(identifierType);
+ visitor.setExpressionType(identifierType);
sb.append(identifierName);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIntegerTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIntegerTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIntegerTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,12 +23,10 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
@@ -43,8 +41,8 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(getNode().getImage());
- visitor.setVariableType(TypesFactory.getType(Integer.TYPE));
+ visitor.setExpressionType(TypesFactory.getType(Integer.TYPE));
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,13 +23,11 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
-import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
@@ -44,11 +42,11 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
if (getNode().getImage() != null) {
sb.append(getEscapedString(getNode().getImage()));
- visitor.setVariableType(TypesFactory.getType(String.class));
+ visitor.setExpressionType(TypesFactory.getType(String.class));
}
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,12 +21,10 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
/**
* This class extend AbstractTreeNode and wrap AstMethodSuffix node.
@@ -40,9 +38,9 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
String methodName = getNode().getImage();
- visitMethod(sb, context, visitor, methodName);
+ visitMethod(sb, visitor, methodName);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,13 +23,11 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
/**
* This class extend AbstractTreeNode and wrap AstNegative node.
@@ -43,10 +41,10 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(ELNodeConstants.NEGATIVE);
- String childOutput = getChildOutput(0, context, visitor);
+ String childOutput = getChildOutput(0, visitor);
sb.append(childOutput);
//variable type has been already set by getChildOuput()
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,13 +23,11 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
/**
* This class extend AbstractTreeNode and wrap AstNot node.
@@ -43,10 +41,10 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(ELNodeConstants.LEFT_BRACKET);
sb.append(ELNodeConstants.EXCLAMATION_MARK);
- String childOutput = getChildOutput(0, context, visitor);
+ String childOutput = coerceToBoolean(getChildOutput(0, visitor), visitor);
sb.append(childOutput);
sb.append(ELNodeConstants.RIGHT_BRACKET);
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,7 +23,6 @@
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
@@ -70,10 +69,10 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
String propertyName = getNode().getImage();
- Type variableType = visitor.getVariableType();
+ Type variableType = visitor.getExpressionType();
Class<?> clazz = variableType.getRawType();
String readMethodName;
@@ -88,7 +87,7 @@
readMethodReturnType = TypesFactory.getType(Object.class);
}
- visitor.setVariableType(readMethodReturnType);
+ visitor.setExpressionType(readMethodReturnType);
sb.append(ELNodeConstants.DOT);
sb.append(readMethodName);
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,14 +23,12 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.AstString;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
-import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
@@ -45,9 +43,9 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(getEscapedString(((AstString) getNode()).getString()));
- visitor.setVariableType(TypesFactory.getType(String.class));
+ visitor.setExpressionType(TypesFactory.getType(String.class));
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,12 +21,10 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
/**
* This class extend AbstractTreeNode and wrap AstValue node.
@@ -39,10 +37,10 @@
}
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
int childrenCount = getChildrenCount();
for (int i = 0; i < childrenCount; i++) {
- String childOutput = getChildOutput(i, context, visitor);
+ String childOutput = getChildOutput(i, visitor);
sb.append(childOutput);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticIntegerOperationTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticIntegerOperationTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticIntegerOperationTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -23,6 +23,8 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
@@ -49,4 +51,15 @@
return TypesFactory.getType(Integer.TYPE);
}
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.parser.el.node.AbstractBinaryOperationTreeNode#getCoercedChildOutput(int,
java.util.Map, org.richfaces.cdk.parser.el.ELVisitor)
+ */
+ @Override
+ protected String getCoercedChildOutput(int childIndex, ELVisitor visitor)
+ throws ParsingException {
+
+ //TODO implement coercion to number
+ return getChildOutput(childIndex, visitor);
+ }
+
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticOperationTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticOperationTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryArithmeticOperationTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -22,6 +22,8 @@
package org.richfaces.cdk.parser.el.node;
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
@@ -57,4 +59,15 @@
return TypesFactory.getType(Integer.TYPE);
}
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.parser.el.node.AbstractBinaryOperationTreeNode#getCoercedChildOutput(int,
java.util.Map, org.richfaces.cdk.parser.el.ELVisitor)
+ */
+ @Override
+ protected String getCoercedChildOutput(int childIndex, ELVisitor visitor)
+ throws ParsingException {
+
+ //TODO implement coercion to number
+ return getChildOutput(childIndex, visitor);
+ }
+
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanOperationTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanOperationTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanOperationTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -22,6 +22,8 @@
package org.richfaces.cdk.parser.el.node;
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
@@ -48,4 +50,10 @@
return TypesFactory.getType(Boolean.TYPE);
}
+ @Override
+ protected String getCoercedChildOutput(int childIndex, ELVisitor visitor)
+ throws ParsingException {
+
+ return coerceToBoolean(getChildOutput(childIndex, visitor), visitor);
+ }
}
Copied:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanResultOperationTreeNode.java
(from rev 16477,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanOperationTreeNode.java)
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanResultOperationTreeNode.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryBooleanResultOperationTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.parser.el.node;
+
+import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
+import org.richfaces.cdk.parser.el.Type;
+import org.richfaces.cdk.parser.el.types.TypesFactory;
+
+/**
+ * @author Nick Belaevski
+ * @since 4.0
+ */
+public class BinaryBooleanResultOperationTreeNode extends AbstractBinaryOperationTreeNode
{
+
+ /**
+ * @param node
+ * @param operatorString
+ */
+ public BinaryBooleanResultOperationTreeNode(Node node, String operatorString) {
+ super(node, operatorString);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.parser.el.node.AbstractBinaryOperationTreeNode#getOperationType(java.lang.reflect.Type,
java.lang.reflect.Type)
+ */
+ @Override
+ protected Type getOperationType(Type firstArgumentType,
+ Type secondArgumentType) {
+ return TypesFactory.getType(Boolean.TYPE);
+ }
+
+ @Override
+ protected String getCoercedChildOutput(int childIndex, ELVisitor visitor)
+ throws ParsingException {
+
+ return getChildOutput(childIndex, visitor);
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,7 +21,6 @@
*/
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
@@ -63,9 +62,9 @@
* org.richfaces.cdk.parser.el.ELVisitor)
*/
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(value);
- visitor.setVariableType(type);
+ visitor.setExpressionType(type);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/EqualityTestTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/EqualityTestTreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/EqualityTestTreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
+import static org.richfaces.cdk.parser.el.HelperMethod.EQUALS_CHECK;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELNodeConstants;
@@ -75,11 +75,11 @@
* @see
org.richfaces.cdk.parser.el.node.AbstractTreeNode#visit(java.lang.StringBuilder,
java.util.Map, org.richfaces.cdk.parser.el.ELVisitor)
*/
@Override
- public void visit(StringBuilder sb, Map<String, Type> context, ELVisitor
visitor) throws ParsingException {
- String firstChildOutput = getChildOutput(0, context, visitor);
- Type firstChildType = visitor.getVariableType();
- String secondChildOutput = getChildOutput(1, context, visitor);
- Type secondChildType = visitor.getVariableType();
+ public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
+ String firstChildOutput = getChildOutput(0, visitor);
+ Type firstChildType = visitor.getExpressionType();
+ String secondChildOutput = getChildOutput(1, visitor);
+ Type secondChildType = visitor.getExpressionType();
if (useIsEqualsMethod(firstChildType, secondChildType)) {
@@ -97,7 +97,7 @@
sb.append(secondChildOutput);
sb.append(ELNodeConstants.RIGHT_BRACKET);
- visitor.setUseEqualsCheck(true);
+ visitor.getUsedHelperMethods().add(EQUALS_CHECK);
} else {
sb.append(ELNodeConstants.LEFT_BRACKET);
@@ -114,7 +114,7 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
}
- visitor.setVariableType(TypesFactory.getType(Boolean.TYPE));
+ visitor.setExpressionType(TypesFactory.getType(Boolean.TYPE));
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ITreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ITreeNode.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ITreeNode.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -21,12 +21,10 @@
package org.richfaces.cdk.parser.el.node;
-import java.util.Map;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
-import org.richfaces.cdk.parser.el.Type;
/**
* Interface for all wrappers of org.jboss.el.parser.Node class.
@@ -44,14 +42,13 @@
/**
* Visit current node. Generate Java code, that represent current node.
- *
- * @param stringBuilder instance to collect information.
- * @param context - context to resolve beans
* @param visitor - ELVisitor
+ * @param stringBuilder instance to collect information.
+ *
* @return instance of org.jboss.el.parser.Node
* @throws ParsingException - if error occurred during parsing process.
*/
- void visit(StringBuilder sb, Map<String, Type> context, ELVisitor visitor)
throws ParsingException;
+ void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException;
/**
* Return child of wrapped node by specified index
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.templatecompiler;
-
-import org.richfaces.builder.model.MethodBodyStatement;
-
-/**
- * @author Nick Belaevski
- */
-public class AbstractTemplateMethodBodyStatement implements MethodBodyStatement {
-
- private String templateName;
-
- protected AbstractTemplateMethodBodyStatement(String templateName) {
- super();
- this.templateName = templateName;
- }
-
- @Override
- public String getCode(FreeMarkerRenderer renderer) {
- return renderer.renderSnippet(templateName, this);
- }
-
-}
Copied:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/BaseTemplateMethodBodyStatement.java
(from rev 16471,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java)
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/BaseTemplateMethodBodyStatement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/BaseTemplateMethodBodyStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler;
+
+import org.richfaces.builder.model.MethodBodyStatement;
+
+/**
+ * @author Nick Belaevski
+ */
+public class BaseTemplateMethodBodyStatement implements MethodBodyStatement {
+
+ private String templateName;
+
+ protected BaseTemplateMethodBodyStatement(String templateName) {
+ super();
+ this.templateName = templateName;
+ }
+
+ @Override
+ public String getCode(FreeMarkerRenderer renderer) {
+ return renderer.renderSnippet(templateName, this);
+ }
+
+}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToBooleanMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToBooleanMethodBodyStatement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToBooleanMethodBodyStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler;
+
+/**
+ * @author Nick Belaevski
+ */
+public class ConversionToBooleanMethodBodyStatement extends HelperMethodBodyStatement {
+
+ public ConversionToBooleanMethodBodyStatement() {
+ super("conversion-to-boolean-method", new String[]
{"object"});
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -24,9 +24,9 @@
/**
* @author Nick Belaevski
*/
-public class ConversionToStringMethodBodyStatement extends
AbstractTemplateMethodBodyStatement {
+public class ConversionToStringMethodBodyStatement extends HelperMethodBodyStatement {
public ConversionToStringMethodBodyStatement() {
- super("conversion-to-string-method");
+ super("conversion-to-string-method", new String[]
{"object"});
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -26,7 +26,7 @@
/**
* @author Nick Belaevski
*/
-public class DefineObjectStatement extends AbstractTemplateMethodBodyStatement {
+public class DefineObjectStatement extends BaseTemplateMethodBodyStatement {
private Type type;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -24,9 +24,9 @@
/**
* @author Nick Belaevski
*/
-public class EmptinessCheckingMethodBodyStatement extends
AbstractTemplateMethodBodyStatement {
+public class EmptinessCheckingMethodBodyStatement extends HelperMethodBodyStatement {
public EmptinessCheckingMethodBodyStatement() {
- super("emptiness-check-method");
+ super("emptiness-check-method", new String[] {"object"});
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EncodeMethodPrefaceStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EncodeMethodPrefaceStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EncodeMethodPrefaceStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -24,7 +24,7 @@
/**
* @author Nick Belaevski
*/
-public class EncodeMethodPrefaceStatement extends AbstractTemplateMethodBodyStatement {
+public class EncodeMethodPrefaceStatement extends BaseTemplateMethodBodyStatement {
/**
* @param templateName
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EqualsCheckingMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EqualsCheckingMethodBodyStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EqualsCheckingMethodBodyStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -25,9 +25,9 @@
* @author Nick Belaevski
*
*/
-public class EqualsCheckingMethodBodyStatement extends
AbstractTemplateMethodBodyStatement {
+public class EqualsCheckingMethodBodyStatement extends HelperMethodBodyStatement {
public EqualsCheckingMethodBodyStatement() {
- super("equals-check-method");
+ super("equals-check-method", new String[] {"o1",
"o2"});
}
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/HelperMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/HelperMethodBodyStatement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/HelperMethodBodyStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class HelperMethodBodyStatement extends BaseTemplateMethodBodyStatement {
+
+ private String[] argumentNames;
+
+ protected HelperMethodBodyStatement(String templateName, String[] argumentNames) {
+ super(templateName);
+
+ this.argumentNames = argumentNames;
+ }
+
+ public String[] getArgumentNames() {
+ return argumentNames;
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -30,6 +30,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
+import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
@@ -50,7 +51,6 @@
import org.richfaces.builder.model.JavaMethod;
import org.richfaces.builder.model.JavaModifier;
import org.richfaces.builder.model.MethodBody;
-import org.richfaces.builder.model.MethodBodyStatement;
import org.richfaces.builder.model.MethodBodyStatementsContainer;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.Logger;
@@ -62,6 +62,7 @@
import org.richfaces.cdk.model.Property;
import org.richfaces.cdk.parser.el.ELParserUtils;
import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.HelperMethod;
import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.parser.el.types.TypesFactory;
@@ -106,7 +107,7 @@
/**
*
*/
- static final String COMPONENT_VARIABLE = "cc";
+ static final String COMPONENT_VARIABLE = "component";
/**
*
*/
@@ -129,87 +130,21 @@
*/
private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME =
"PASS_THROUGH_ATTRIBUTES";
- private static final Set<String> DEFAULT_NAMESPACES =
ImmutableSet.of(Template.XHTML_EL_NAMESPACE,Template.XHTML_NAMESPACE);
+ private static final Set<String> DEFAULT_NAMESPACES =
ImmutableSet.of(Template.XHTML_EL_NAMESPACE,
+ Template.XHTML_NAMESPACE);
- private enum ServiceMethods {
- EMPTY_CHECK("isEmpty", boolean.class, new Argument("object",
Object.class)) {
+ private static final EnumMap<HelperMethod, HelperMethodBodyStatement>
HELPER_METHOD_BODIES =
+ new EnumMap<HelperMethod, HelperMethodBodyStatement>(HelperMethod.class);
- @Override
- public MethodBodyStatement createMethodBodyStatement() {
- return new EmptinessCheckingMethodBodyStatement();
- }
-
- @Override
- public boolean isServiceMethodRequired(ELVisitor visitor) {
- return visitor.isUseEmptinessCheck();
- }
-
- },
-
- TO_STRING_CONVERSION("convertToString", String.class, new
Argument("object",
- Object.class)) {
-
- @Override
- public MethodBodyStatement createMethodBodyStatement() {
- return new ConversionToStringMethodBodyStatement();
- }
-
- @Override
- public boolean isServiceMethodRequired(ELVisitor visitor) {
- return visitor.isUseConversionToString();
- }
-
- },
-
- EQUALS_CHECK("isEqual", boolean.class, new Argument("o1",
Object.class),
- new Argument("o2", Object.class)) {
-
- @Override
- public MethodBodyStatement createMethodBodyStatement() {
- return new EqualsCheckingMethodBodyStatement();
- }
-
- @Override
- public boolean isServiceMethodRequired(ELVisitor visitor) {
- return visitor.isUseEqualsCheck();
- }
-
- };
-
- private String name;
-
- private Class<?> returnType;
-
- private Argument[] arguments;
-
- private ServiceMethods(String name, Class<?> returnType, Argument...
arguments) {
- this.name = name;
- this.returnType = returnType;
- this.arguments = arguments;
- }
-
- abstract MethodBodyStatement createMethodBodyStatement();
-
- abstract boolean isServiceMethodRequired(ELVisitor visitor);
-
- void createMethod(JavaClass generatedClass) {
- JavaMethod serviceMethod = new JavaMethod(name, returnType, arguments);
-
- serviceMethod.addModifier(JavaModifier.PRIVATE);
- serviceMethod.addModifier(JavaModifier.STATIC);
- serviceMethod.addModifier(JavaModifier.FINAL);
-
- MethodBody serviceMethodBody = new MethodBody(serviceMethod);
- serviceMethod.setMethodBody(serviceMethodBody);
- serviceMethodBody.addStatement(createMethodBodyStatement());
-
- generatedClass.addMethod(serviceMethod);
- }
+ static {
+ HELPER_METHOD_BODIES.put(HelperMethod.EMPTINESS_CHECK, new
EmptinessCheckingMethodBodyStatement());
+ HELPER_METHOD_BODIES.put(HelperMethod.EQUALS_CHECK, new
EqualsCheckingMethodBodyStatement());
+ HELPER_METHOD_BODIES.put(HelperMethod.TO_BOOLEAN_CONVERSION, new
ConversionToBooleanMethodBodyStatement());
+ HELPER_METHOD_BODIES.put(HelperMethod.TO_STRING_CONVERSION, new
ConversionToStringMethodBodyStatement());
}
-
+
private final Logger log;
-
private MethodBodyStatementsContainer currentStatement;
private Schema attributesSchema = null;
@@ -221,7 +156,7 @@
private Map<String, Type> localsTypesMap;
private ClassLoader classLoader;
- private Set<ServiceMethods> addedServiceMethods =
EnumSet.noneOf(ServiceMethods.class);
+ private Set<HelperMethod> addedHelperMethods =
EnumSet.noneOf(HelperMethod.class);
private Type lastCompiledExpressionType;
private int passThroughCounter;
@@ -255,24 +190,45 @@
this.createMethodContext();
}
- private void addServiceMethod(ServiceMethods serviceMethod) {
- if (addedServiceMethods.add(serviceMethod)) {
- serviceMethod.createMethod(generatedClass);
+ private void addHelperMethod(HelperMethod helperMethod) {
+ if (addedHelperMethods.add(helperMethod)) {
+ HelperMethodBodyStatement methodBodyStatement =
HELPER_METHOD_BODIES.get(helperMethod);
+
+ String[] argumentNames = methodBodyStatement.getArgumentNames();
+ Class<?>[] argumentTypes = helperMethod.getArgumentTypes();
+
+ assert argumentNames.length == argumentTypes.length;
+
+ Argument[] arguments = new Argument[argumentTypes.length];
+ for (int i = 0; i < arguments.length; i++) {
+ arguments[i] = new Argument(argumentNames[i], argumentTypes[i]);
+ }
+
+ JavaMethod helperJavaMethod = new JavaMethod(helperMethod.getName(),
+ helperMethod.getReturnType(), arguments);
+
+ helperJavaMethod.addModifier(JavaModifier.PRIVATE);
+ helperJavaMethod.addModifier(JavaModifier.STATIC);
+ helperJavaMethod.addModifier(JavaModifier.FINAL);
+
+ MethodBody helperJavaMethodBody = new MethodBody(helperJavaMethod);
+ helperJavaMethod.setMethodBody(helperJavaMethodBody);
+ helperJavaMethodBody.addStatement(methodBodyStatement);
+
+ generatedClass.addMethod(helperJavaMethod);
}
}
private String compileEl(String expression, Class<?> type) {
try {
ELVisitor elVisitor = new ELVisitor();
- elVisitor.parse(expression, localsTypesMap);
+ elVisitor.parse(expression, localsTypesMap, TypesFactory.getType(type));
- lastCompiledExpressionType = elVisitor.getVariableType();
+ lastCompiledExpressionType = elVisitor.getExpressionType();
String parsedExpression = elVisitor.getParsedExpression();
- for (ServiceMethods serviceMethod : ServiceMethods.values()) {
- if (serviceMethod.isServiceMethodRequired(elVisitor)) {
- addServiceMethod(serviceMethod);
- }
+ for (HelperMethod helperMethod : elVisitor.getUsedHelperMethods()) {
+ addHelperMethod(helperMethod);
}
return parsedExpression + "/* " + expression.trim() + "
*/";
@@ -329,15 +285,13 @@
sb.append(")");
- String attributeName;
- if (!Strings.isEmpty(componentAttributeName)) {
+ String attributeName = htmlAttributeName;
+ if (!attributeName.equals(componentAttributeName)) {
attributeName = componentAttributeName;
sb.append(".setComponentAttributeName(");
sb.append(getEscapedString(componentAttributeName));
sb.append(")");
- } else {
- attributeName = htmlAttributeName;
}
Property property = attributes.get(attributeName);
@@ -353,8 +307,7 @@
public String apply(EventName from) {
return from.getName();
}
- }
- );
+ });
sb.append(getEscapedStringsArray(eventNamesStrings));
@@ -365,7 +318,7 @@
return sb.toString();
}
- private JavaField createPassThroughField(Map<String, Attribute>
htmlAttributesMap) {
+ private String createPassThroughField(Map<String, Attribute> htmlAttributesMap)
{
String fieldName = PASS_THROUGH_ATTRIBUTES_FIELD_NAME;
if (passThroughCounter >= 0) {
fieldName += ("_" + passThroughCounter);
@@ -403,8 +356,9 @@
fieldValue.append("))");
passThroughField.setValue(fieldValue.toString());
+ generatedClass.addField(passThroughField);
- return passThroughField;
+ return fieldName;
}
private void createMethodContext() {
@@ -527,7 +481,7 @@
Map<QName, Object> sortedElementAttributes = new TreeMap<QName,
Object>(QNAME_COMPARATOR);
sortedElementAttributes.putAll(elementAttributes);
-
+
for (Map.Entry<QName, Object> attribute :
sortedElementAttributes.entrySet()) {
QName attributeName = attribute.getKey();
Object attributeValue = attribute.getValue();
@@ -547,7 +501,7 @@
if (writtenAttributes.add(attributeLocalName)) {
generatedClass.addImport(RENDER_KIT_UTILS_CLASS_NAME);
currentStatement.addStatement(new
WriteAttributeStatement(attributeLocalName, compileEl(
- attributeValue.toString(), String.class)));
+ attributeValue.toString(), Object.class)));
}
}
}
@@ -570,10 +524,9 @@
}
if (!actualAttributesMap.isEmpty()) {
- JavaField passThroughField =
createPassThroughField(actualAttributesMap);
- generatedClass.addField(passThroughField);
+ String passThroughFieldName =
createPassThroughField(actualAttributesMap);
generatedClass.addImport(RENDER_KIT_UTILS_CLASS_NAME);
- currentStatement.addStatement(new
WriteAttributesSetStatement(passThroughField.getName()));
+ currentStatement.addStatement(new
WriteAttributesSetStatement(passThroughFieldName));
}
}
}
@@ -631,7 +584,7 @@
*/
@Override
public void startElement(CdkIfElement cdkIfElement) {
- String compiledTestExpression = compileEl(cdkIfElement.getTest(),
Boolean.class);
+ String compiledTestExpression = compileEl(cdkIfElement.getTest(), Boolean.TYPE);
pushStatement(new IfElseStatement());
pushStatement(new IfStatement(compiledTestExpression));
@@ -679,7 +632,7 @@
*/
@Override
public void startElement(CdkWhenElement cdkWhenElement) {
- String compiledTestExpression = compileEl(cdkWhenElement.getTest(),
Boolean.class);
+ String compiledTestExpression = compileEl(cdkWhenElement.getTest(),
Boolean.TYPE);
pushStatement(new IfStatement(compiledTestExpression));
}
@@ -745,7 +698,14 @@
}
if (!Strings.isEmpty(value)) {
- value = compileEl(value, Object.class);
+ Class<?> valueType;
+ if (type != null) {
+ valueType = type.getRawType();
+ } else {
+ valueType = Object.class;
+ }
+
+ value = compileEl(value, valueType);
if (type == null) {
type = lastCompiledExpressionType;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/StartElementStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/StartElementStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/StartElementStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -25,7 +25,7 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class StartElementStatement extends AbstractTemplateMethodBodyStatement {
+public class StartElementStatement extends BaseTemplateMethodBodyStatement {
private String elementName;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributeStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributeStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributeStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -24,7 +24,7 @@
/**
* @author Nick Belaevski
*/
-public class WriteAttributeStatement extends AbstractTemplateMethodBodyStatement {
+public class WriteAttributeStatement extends BaseTemplateMethodBodyStatement {
private String attributeName;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -25,7 +25,7 @@
/**
* @author Nick Belaevski
*/
-public class WriteAttributesSetStatement extends AbstractTemplateMethodBodyStatement {
+public class WriteAttributesSetStatement extends BaseTemplateMethodBodyStatement {
private String passThroughFieldName;
@@ -40,4 +40,5 @@
public String getPassThroughFieldName() {
return passThroughFieldName;
}
+
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteTextStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteTextStatement.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteTextStatement.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -24,7 +24,7 @@
/**
* @author Nick Belaevski
*/
-public class WriteTextStatement extends AbstractTemplateMethodBodyStatement {
+public class WriteTextStatement extends BaseTemplateMethodBodyStatement {
private String textExpression;
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-schemas-aggregator.xsd
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-schemas-aggregator.xsd
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-schemas-aggregator.xsd 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,27 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+
+ <!--
+ JBoss, Home of Professional Open Source Copyright ${year}, Red Hat,
+ Inc. and individual contributors by the @authors tag. See the
+ copyright.txt in the distribution for a full listing of individual
+ contributors. This is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version. This software is
+ distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details. You should have received a copy of the GNU
+ Lesser General Public License along with this software; if not, write
+ to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ Boston, MA 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ -->
+
+<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:abc"
+
xmlns:xml="http://www.w3.org/XML/1998/namespace">
+
+ <xs:import schemaLocation="cdk-template.xsd"
namespace="http://richfaces.org/cdk/core" />
+ <xs:import schemaLocation="cdk-composite.xsd"
namespace="http://richfaces.org/cdk/jsf/composite" />
+ <xs:import schemaLocation="cdk-jstl-core.xsd"
namespace="http://richfaces.org/cdk/jstl/core" />
+
+</xs:schema>
Modified:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-02-21
23:23:03 UTC (rev 16480)
@@ -127,6 +127,8 @@
rendering.
</span>
</p>
+ <p>If "disabled" attribute of the component is true (i.e. boolean
true or "true"), then
+ attributes that have associated behavior events are not encoded.</p>
</xs:documentation>
</xs:annotation>
<xs:simpleType>
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-boolean-method.ftl
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-boolean-method.ftl
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-boolean-method.ftl 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,9 @@
+if (object == null) {
+ return false;
+}
+
+if (object instanceof Boolean) {
+ return Boolean.TRUE.equals(object);
+}
+
+return Boolean.valueOf(object.toString());
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -25,6 +25,10 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.richfaces.cdk.parser.el.HelperMethod.EMPTINESS_CHECK;
+import static org.richfaces.cdk.parser.el.HelperMethod.EQUALS_CHECK;
+import static org.richfaces.cdk.parser.el.HelperMethod.TO_BOOLEAN_CONVERSION;
+import static org.richfaces.cdk.parser.el.HelperMethod.TO_STRING_CONVERSION;
import java.util.HashMap;
import java.util.List;
@@ -56,100 +60,105 @@
public void testNull() throws Exception {
parseExpression("#{null}");
assertEquals("null", visitor.getParsedExpression());
- assertTrue(visitor.getVariableType().isNullType());
+ assertTrue(visitor.getExpressionType().isNullType());
}
@Test
public void testTrue() throws Exception {
parseExpression("#{true}");
assertEquals("true", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testFalse() throws Exception {
parseExpression("#{false}");
assertEquals("false", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testFloat() throws Exception {
parseExpression("#{5.0}");
assertEquals("Double.valueOf(5.0)", visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{5.012e+34}");
assertEquals("Double.valueOf(5.012e+34)",
visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testNegative() throws Exception {
parseExpression("#{-5}");
assertEquals("-5", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testNegativeFloat() throws Exception {
parseExpression("#{-5.0}");
assertEquals("-Double.valueOf(5.0)", visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testNotEqual() throws Exception {
parseExpression("#{1 ne 3}");
assertEquals("(1 != 3)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertFalse(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{2 != 3}");
assertEquals("(2 != 3)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertFalse(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action != 2}");
assertEquals("!isEqual(action,2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{2 ne action}");
assertEquals("!isEqual(2,action)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action != clientId}");
assertEquals("!isEqual(action,clientId)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action ne clientId}");
assertEquals("!isEqual(action,clientId)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action ne null}");
assertEquals("(action != null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertFalse(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{2 != null}");
assertEquals("!isEqual(2,null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
}
@Test
public void testNot() throws Exception {
parseExpression("#{not test}");
assertEquals("(!test)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{!otherTest}");
assertEquals("(!otherTest)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{!action}");
+ assertEquals("(!convertToBoolean(action))",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
}
@Test
@@ -157,210 +166,235 @@
// TODO: tests involving double values
parseExpression("#{1+2}");
assertEquals("(1 + 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testMinus() throws Exception {
parseExpression("#{1-2}");
assertEquals("(1 - 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testDiv() throws Exception {
parseExpression("#{1/2}");
assertEquals("(1 / 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testMult() throws Exception {
parseExpression("#{1*2}");
assertEquals("(1 * 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testMod() throws Exception {
parseExpression("#{1%2}");
assertEquals("(1 % 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testAnd() throws Exception {
parseExpression("#{test and otherTest}");
assertEquals("(test && otherTest)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{otherTest && test}");
assertEquals("(otherTest && test)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{action and otherTest}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(convertToBoolean(action) && otherTest)",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{test && action}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(test && convertToBoolean(action))",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testOr() throws Exception {
parseExpression("#{test or otherTest}");
assertEquals("(test || otherTest)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{otherTest || test}");
assertEquals("(otherTest || test)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{action or otherTest}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(convertToBoolean(action) || otherTest)",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{test || action}");
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ assertEquals("(test || convertToBoolean(action))",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testEquals() throws Exception {
parseExpression("#{1 eq 2}");
assertEquals("(1 == 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertFalse(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{3 == 2}");
assertEquals("(3 == 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertFalse(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action == 2}");
assertEquals("isEqual(action,2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{2 eq action}");
assertEquals("isEqual(2,action)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action == clientId}");
assertEquals("isEqual(action,clientId)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action eq clientId}");
assertEquals("isEqual(action,clientId)",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{action eq null}");
assertEquals("(action == null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertFalse(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
parseExpression("#{2 == null}");
assertEquals("isEqual(2,null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
- assertTrue(visitor.isUseEqualsCheck());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
}
@Test
public void testGreatThen() throws Exception {
parseExpression("#{1 gt 2}");
assertEquals("(1 > 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{3 > 2}");
assertEquals("(3 > 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testLessThen() throws Exception {
parseExpression("#{1 lt 2}");
assertEquals("(1 < 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{3 < 2}");
assertEquals("(3 < 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testLessThenEquals() throws Exception {
parseExpression("#{1 le 2}");
assertEquals("(1 <= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{3 <= 2}");
assertEquals("(3 <= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testGreatThenEquals() throws Exception {
parseExpression("#{1 ge 2}");
assertEquals("(1 >= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{3 >= 2}");
assertEquals("(3 >= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testChoice() throws Exception {
parseExpression("#{test ? 2 : 3}");
assertEquals("(test ? 2 : 3)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
parseExpression("#{test ? null : 'string'}");
assertEquals("(test ? null : \"string\")",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{action ? null : 'string'}");
+ assertEquals("(convertToBoolean(action) ? null :
\"string\")", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
}
@Test
public void testInteger() throws Exception {
parseExpression("#{152}");
assertEquals("152", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testString() throws Exception {
parseExpression("#{\"nabc\"}");
assertEquals("\"nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
parseExpression("#{'nabc'}");
assertEquals("\"nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
parseExpression("#{'\tabc'}");
assertEquals("\"\\tabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
parseExpression("#{'/nabc'}");
assertEquals("\"/nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
parseExpression("#{'na\"bc'}");
assertEquals("\"na\\\"bc\"",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
parseExpression("#{'na\\\\bc'}");
assertEquals("\"na\\\\bc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
public void testIdentifier() throws Exception {
parseExpression("#{clientId}");
assertEquals("clientId", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
public void testLiteral() throws Exception {
parseExpression("clientId");
assertEquals("\"clientId\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
public void testMethodReturnMap() throws Exception {
parseExpression("#{action.facets}");
assertEquals("action.getFacets()", visitor.getParsedExpression());
- Type variableType = visitor.getVariableType();
+ Type variableType = visitor.getExpressionType();
assertEquals(Map.class, variableType.getRawType());
assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
@@ -372,15 +406,15 @@
public void testMethodReturnMapElement() throws Exception {
parseExpression("#{action.getFacet('header')}");
assertEquals("action.getFacet(\"header\")",
visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getVariableType().getRawType());
+ assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
parseExpression("#{action.facets['header']}");
assertEquals("action.getFacets().get(\"header\")",
visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getVariableType().getRawType());
+ assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
parseExpression("#{action.rawMap['something']}");
assertEquals("action.getRawMap().get(\"something\")",
visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getVariableType().getRawType());
+ assertEquals(Object.class, visitor.getExpressionType().getRawType());
}
// @Test
@@ -392,7 +426,7 @@
public void testMethodReturnMapElement2() throws Exception {
parseExpression("#{action.facets.toString()}");
assertEquals("action.getFacets().toString()",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
@@ -401,28 +435,28 @@
//
resolveExpression("#{action.getFacet('header').rendered}"));
parseExpression("#{action.facets['header'].rendered}");
assertEquals("action.getFacets().get(\"header\").isRendered()",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testMethod() throws Exception {
parseExpression("#{action.readOnly}");
assertEquals("action.isReadOnly()", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testNestedMethod() throws Exception {
parseExpression("#{action.testBean2.string}");
assertEquals("action.getTestBean2().getString()",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
public void testMethodReturnList() throws Exception {
parseExpression("#{action.components}");
assertEquals("action.getComponents()", visitor.getParsedExpression());
- Type variableType = visitor.getVariableType();
+ Type variableType = visitor.getExpressionType();
assertEquals(List.class, variableType.getRawType());
assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
}
@@ -431,28 +465,28 @@
public void testMethodReturnListElement() throws Exception {
parseExpression("#{action.components[0]}");
assertEquals("action.getComponents().get(0)",
visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getVariableType().getRawType());
+ assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
}
@Test
public void testMethodReturnListElement2() throws Exception {
parseExpression("#{action.components[0].rendered}");
assertEquals("action.getComponents().get(0).isRendered()",
visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testMethodReturnArray() throws Exception {
parseExpression("#{action.array}");
assertEquals("action.getArray()", visitor.getParsedExpression());
- assertEquals(UIComponent[].class, visitor.getVariableType().getRawType());
+ assertEquals(UIComponent[].class, visitor.getExpressionType().getRawType());
}
@Test
public void testMethodReturnArrayElement() throws Exception {
parseExpression("#{action.array[0]}");
assertEquals("action.getArray()[0]", visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getVariableType().getRawType());
+ assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
}
@Test
@@ -461,55 +495,55 @@
assertEquals("this.getType(action.getArray()[0].isRendered(),action.isReadOnly(),true)",
visitor
.getParsedExpression());
- Type variableType = visitor.getVariableType();
+ Type variableType = visitor.getExpressionType();
parseExpression("#{action.count(123)}");
assertEquals("action.count(123)", visitor.getParsedExpression());
- assertEquals(Integer.class, visitor.getVariableType().getRawType());
+ assertEquals(Integer.class, visitor.getExpressionType().getRawType());
parseExpression("#{action.count(clientId)}");
assertEquals("action.count(clientId)", visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getVariableType().getRawType());
+ assertEquals(Object.class, visitor.getExpressionType().getRawType());
}
@Test
public void testEmpty() throws Exception {
parseExpression("#{empty action.array}");
assertEquals("isEmpty(action.getArray())",
visitor.getParsedExpression());
- assertTrue(visitor.isUseEmptinessCheck());
- assertEquals(Boolean.TYPE, visitor.getVariableType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(EMPTINESS_CHECK));
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testFunction() throws Exception {
parseExpression("#{super:getType()}");
assertEquals("super.getType()", visitor.getParsedExpression());
- Type variableType = visitor.getVariableType();
+ Type variableType = visitor.getExpressionType();
}
@Test
public void testLiteralWithDeferred() throws Exception {
parseExpression("#{1}#{2}");
assertEquals("convertToString(1) + convertToString(2)",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
parseExpression("abs #{getType()}");
assertEquals("\"abs \" + convertToString(this.getType())",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
public void testLiteralWithDeferred2() throws Exception {
parseExpression("#{getType()} abs ");
assertEquals("convertToString(this.getType()) + \" abs \"",
visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
@Test
public void testThisFunction() throws Exception {
parseExpression("#{getType()}");
assertEquals("this.getType()", visitor.getParsedExpression());
- Type variableType = visitor.getVariableType();
+ Type variableType = visitor.getExpressionType();
parseExpression("#{this.getType()}");
assertEquals("this.getType()", visitor.getParsedExpression());
@@ -519,14 +553,14 @@
public void testVariableFunction() throws Exception {
parseExpression("#{objectVar.getType()}");
assertEquals("objectVar.getType()", visitor.getParsedExpression());
- Type variableType = visitor.getVariableType();
+ Type variableType = visitor.getExpressionType();
}
@Test
public void testNonExistingMethod() throws Exception {
parseExpression("#{action.doSomething(clientId, 123)}");
assertEquals("action.doSomething(clientId,123)",
visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getVariableType().getRawType());
+ assertEquals(Object.class, visitor.getExpressionType().getRawType());
}
@Test
@@ -544,17 +578,51 @@
public void testWrongExpression2() throws Exception {
parseExpression("#{action.property}");
assertEquals("action.getProperty()", visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getVariableType().getRawType());
+ assertEquals(Object.class, visitor.getExpressionType().getRawType());
}
@Test
public void testEmptyString() throws Exception {
parseExpression("");
assertEquals("\"\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getVariableType().getRawType());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
}
+ @Test
+ public void testBooleanReturnType() throws Exception {
+ parseExpression("#{clientId}", Boolean.TYPE);
+
+ assertEquals("convertToBoolean(clientId)",
visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+
+ parseExpression("#{test}", Boolean.TYPE);
+
+ assertEquals("test", visitor.getParsedExpression());
+ assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ }
+
+ @Test
+ public void testStringReturnType() throws Exception {
+ parseExpression("#{clientId}", String.class);
+
+ assertEquals("clientId", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+ assertFalse(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
+
+ parseExpression("#{test}", String.class);
+
+ assertEquals("convertToString(test)", visitor.getParsedExpression());
+ assertEquals(String.class, visitor.getExpressionType().getRawType());
+ assertTrue(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
+ }
+
private void parseExpression(String expression) throws ParsingException {
+ parseExpression(expression, Object.class);
+ }
+
+ private void parseExpression(String expression, Class<?> returnType) throws
ParsingException {
Map<String, Type> contextMap = new HashMap<String, Type>();
contextMap.put("action",
TypesFactory.getType(org.richfaces.cdk.parser.el.test.Bean.class));
@@ -565,6 +633,6 @@
contextMap.put("super", TypesFactory.getType(Object.class));
contextMap.put("objectVar", TypesFactory.getType(Object.class));
- visitor.parse(expression, contextMap);
+ visitor.parse(expression, contextMap, TypesFactory.getType(returnType));
}
}
Modified:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml 2010-02-21
23:23:03 UTC (rev 16480)
@@ -32,15 +32,15 @@
</cc:interface>
<cc:implementation>
start
- <c:if test="#{cc.attributes['ifTest'] !=
null}">if content</c:if>
+ <c:if test="#{component.attributes['ifTest'] !=
null}">if content</c:if>
<c:choose>
- <c:when test="#{cc.attributes['anotherTest'] !=
null}">when content</c:when>
- <c:when test="#{cc.attributes['coolTest'] !=
null}">
- <c:if test="#{cc.attributes['nestedIfTest'] !=
null}">nested if content</c:if>
+ <c:when test="#{component.attributes['anotherTest']
!= null}">when content</c:when>
+ <c:when test="#{component.attributes['coolTest'] !=
null}">
+ <c:if
test="#{component.attributes['nestedIfTest'] != null}">nested if
content</c:if>
</c:when>
<c:otherwise>otherwise content</c:otherwise>
</c:choose>
- <c:forEach items="#{cc.children}"
var="iterationVar">
+ <c:forEach items="#{component.children}"
var="iterationVar">
forEach content
</c:forEach>
finish
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/coercions.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/coercions.template.xml
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/coercions.template.xml 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.cdk.renderkit.html.CoercedRenderer</cdk:class>
+ <cdk:component-family>org.richfaces.cdk.CoercedComponent</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.cdk.CoercedRenderer</cdk:renderer-type>
+ </cc:interface>
+
+ <cc:implementation>
+ <c:if test="#{component.attributes['flag']}">
+ Flag
+ </c:if>
+
+ <cdk:object type="boolean" name="anotherFlag"
value="#{component.attributes['anotherFlag']}" />
+ <c:if test="#{anotherFlag}">
+ AnotherFlag
+ </c:if>
+
+ <cdk:object name="someObject" type="Object"
value="#{component.attributes['someObject']}" />
+ <cdk:object name="string" type="String"
value="#{someObject}" />
+ #{string.length()}
+
+ </cc:implementation>
+</cdk:root>
Modified:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/grid.template.xml 2010-02-21
23:23:03 UTC (rev 16480)
@@ -15,7 +15,7 @@
<table id="#{clientId}">
<tbody>
<cdk:body>
- <c:forEach items="#{cc.children}" var="child">
+ <c:forEach items="#{component.children}" var="child">
<tr>
<td>
<cdk:call>
Modified:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/input.template.xml 2010-02-21
23:23:03 UTC (rev 16480)
@@ -14,13 +14,13 @@
<span id="#{clientId}">
<cdk:body />
- <cdk:object name="componentIsDisabled"
value="#{cc.attributes['disabled'] == true}" />
+ <cdk:object name="componentIsDisabled"
value="#{component.attributes['disabled'] == true}" />
<c:choose>
<c:when test="#{not componentIsDisabled}">
<input type="text" />
- <cdk:object name="image"
value="#{cc.attributes['image']}" />
- <cdk:object name="disabledImage"
value="#{cc.attributes['disabledImage']}" />
+ <cdk:object name="image"
value="#{component.attributes['image']}" />
+ <cdk:object name="disabledImage"
value="#{component.attributes['disabledImage']}" />
<c:choose>
<c:when test="#{disabledImage != null}">
<img src="#{disabledImage}" alt="" />
Modified:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/link.template.xml 2010-02-21
23:23:03 UTC (rev 16480)
@@ -11,12 +11,12 @@
</cc:interface>
<cc:implementation>
- <a id="#{clientId}" href="#{cc.attributes['href']}"
cdk:passThroughWithExclusions="target rel rev">
- <cdk:object name="imageSource"
value="#{cc.attributes['imageSource']}" />
+ <a id="#{clientId}"
href="#{component.attributes['href']}"
cdk:passThroughWithExclusions="target rel rev">
+ <cdk:object name="imageSource"
value="#{component.attributes['imageSource']}" />
<c:if test="#{not empty imageSource}">
- <img src="#{imageSource}" alt="" class="rich-link
#{cc.attributes['linkImageStyleClass']}
#{cc.attributes['imageStyleClass']}" />
+ <img src="#{imageSource}" alt="" class="rich-link
#{component.attributes['linkImageStyleClass']}
#{component.attributes['imageStyleClass']}" />
</c:if>
- value: #{cc.attributes['value']}; differentValue:
#{cc.attributes['differentValue']}; anotherValue:
#{cc.attributes['anotherValue']};
+ value: #{component.attributes['value']}; differentValue:
#{component.attributes['differentValue']}; anotherValue:
#{component.attributes['anotherValue']};
</a>
</cc:implementation>
</cdk:root>
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/CoercionsTest.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/CoercionsTest.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/CoercionsTest.java 2010-02-21
23:23:03 UTC (rev 16480)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import static org.easymock.EasyMock.eq;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.cdk.renderkit.html.CoercedRenderer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class CoercionsTest extends BaseRendererTest {
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Test
+ public void testEncodeEnd() throws Exception {
+ responseWriter.writeText(eq("0"), EasyMock.<String>isNull());
+
+ replayAll();
+
+ CoercedRenderer renderer = new CoercedRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndObjectCoercedToString() throws Exception {
+ componentAttributes.put("someObject", "test value");
+
+ responseWriter.writeText(eq(String.valueOf("test value".length())),
EasyMock.<String>isNull());
+
+ replayAll();
+
+ CoercedRenderer renderer = new CoercedRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndWithBooleanFlags() throws Exception {
+ componentAttributes.put("flag", Boolean.FALSE);
+ componentAttributes.put("anotherFlag", Boolean.TRUE);
+
+ responseWriter.writeText(eq("AnotherFlag"),
EasyMock.<String>isNull());
+ responseWriter.writeText(eq("0"), EasyMock.<String>isNull());
+
+ replayAll();
+
+ CoercedRenderer renderer = new CoercedRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+
+ @Test
+ public void testEncodeEndWithStringFlags() throws Exception {
+ componentAttributes.put("flag", "true");
+ componentAttributes.put("anotherFlag", "false");
+
+ responseWriter.writeText(eq("Flag"), EasyMock.<String>isNull());
+ responseWriter.writeText(eq("0"), EasyMock.<String>isNull());
+
+ replayAll();
+
+ CoercedRenderer renderer = new CoercedRenderer();
+ renderer.encodeEnd(facesContext, component);
+ }
+}
\ No newline at end of file
Modified:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/xml-configured-component/src/main/templates/testPanel.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/xml-configured-component/src/main/templates/testPanel.xml 2010-02-21
23:19:48 UTC (rev 16479)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/xml-configured-component/src/main/templates/testPanel.xml 2010-02-21
23:23:03 UTC (rev 16480)
@@ -32,12 +32,12 @@
</cc:interface>
<cc:implementation>
<div>
- <c:if test="#{cc.facets['header'] != null}">
+ <c:if test="#{component.facets['header'] !=
null}">
<div class="tpHeader">
- <cdk:call
expression='cc.getFacet("header").encodeAll(facesContext)'/>
+ <cdk:call
expression='component.getFacet("header").encodeAll(facesContext)'/>
</div>
</c:if>
- <c:forEach items="#{cc.children}"
var="iterationVar">
+ <c:forEach items="#{component.children}"
var="iterationVar">
<cdk:call
expression='((javax.faces.component.UIComponent)iterationVar).encodeAll(facesContext)'/>
</c:forEach>
</div>