JBoss Rich Faces SVN: r17682 - in root/cdk/branches/RF8755/plugins/generator/src: main/java/org/richfaces/cdk/templatecompiler/el and 4 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-29 20:47:26 -0400 (Tue, 29 Jun 2010)
New Revision: 17682
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java
Removed:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AbstractTemplateMethodBodyStatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToBooleanMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToStringMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EmptinessCheckingMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EqualsCheckingMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodBodyStatement.java
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstMethodSuffixTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstValueTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
Log:
start template renderer refactor.
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -28,6 +28,7 @@
import static org.richfaces.cdk.util.JavaUtils.getEscapedStringsArray;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
@@ -51,6 +52,7 @@
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaAnnotation;
import org.richfaces.cdk.templatecompiler.builder.model.JavaClass;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
@@ -76,6 +78,7 @@
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
+import org.richfaces.cdk.templatecompiler.statements.AttributesStatement;
import org.richfaces.cdk.templatecompiler.statements.ConstantReturnMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ConversionToBooleanMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ConversionToStringMethodBodyStatement;
@@ -85,6 +88,7 @@
import org.richfaces.cdk.templatecompiler.statements.EndElementStatement;
import org.richfaces.cdk.templatecompiler.statements.EqualsCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ForEachStatement;
+import org.richfaces.cdk.templatecompiler.statements.HelperJavaMethod;
import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
@@ -149,40 +153,26 @@
private static final Set<String> DEFAULT_NAMESPACES = ImmutableSet.of(Template.XHTML_EL_NAMESPACE,
Template.XHTML_NAMESPACE);
- private static final EnumMap<HelperMethod, HelperMethodBodyStatement> HELPER_METHOD_BODIES =
- new EnumMap<HelperMethod, HelperMethodBodyStatement>(HelperMethod.class);
-
- 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 final Injector injector;
+ private final TypesFactory typesFactory;
+ private final HelperMethodFactory helperMethodFactory;
+ private final CompositeInterface compositeInterface;
+ private final Collection<PropertyBase> attributes;
private StatementsContainer currentStatement;
private JavaClass generatedClass;
- private CompositeInterface compositeInterface;
-
- private final ELParser parser;
-
private Set<HelperMethod> addedHelperMethods = EnumSet.noneOf(HelperMethod.class);
- private ELType lastCompiledExpressionType;
private int passThroughCounter;
- private final Collection<PropertyBase> attributes;
- private final Injector injector;
- private final HelperMethodFactory helperMethodFactory;
-
public RendererClassVisitor(CompositeInterface compositeInterface, Collection<PropertyBase> attributes, Logger log,
- Injector injector, ELParser parser, HelperMethodFactory helperFactory) {
+ Injector injector, TypesFactory typesFactory, HelperMethodFactory helperFactory) {
this.compositeInterface = compositeInterface;
this.attributes = attributes;
this.injector = injector;
- this.parser = parser;
+ this.typesFactory = typesFactory;
this.log = log;
this.helperMethodFactory = helperFactory;
}
@@ -212,26 +202,21 @@
private void addHelperMethod(HelperMethod helperMethod) {
if (addedHelperMethods.add(helperMethod)) {
JavaMethod helperJavaMethod = helperMethodFactory.getHelperMethod(helperMethod);
- generatedClass.addMethod(helperJavaMethod);
+ if (helperJavaMethod.isHidden()) {
+ generatedClass.addImports(helperJavaMethod.getRequiredImports());
+ } else {
+ generatedClass.addMethod(helperJavaMethod);
+ }
+ addHelperMethods(helperJavaMethod.getMethodBody());
}
}
- private String compileEl(String expression, Class<?> type) {
- try {
- ELVisitor elVisitor = new ELVisitor();
- elVisitor.parse(expression, currentStatement, TypesFactoryImpl.getType(type));
-
- lastCompiledExpressionType = elVisitor.getExpressionType();
- String parsedExpression = elVisitor.getParsedExpression();
-
- for (HelperMethod helperMethod : elVisitor.getUsedHelperMethods()) {
- addHelperMethod(helperMethod);
+ private void addHelperMethods(JavaStatement statement) {
+ if (statement instanceof TemplateStatement) {
+ TemplateStatement templateStatement = (TemplateStatement) statement;
+ for (HelperMethod helper : templateStatement.getRequiredMethods()) {
+ addHelperMethod(helper);
}
-
- return parsedExpression + "/* " + expression.trim() + " */";
- } catch (ParsingException e) {
- // TODO Auto-generated catch block
- throw new RuntimeException(e.getMessage(), e);
}
}
@@ -248,27 +233,8 @@
return false;
}
- private ELType createTypeOfKnownClass(JavaClass initialClass, Class<?> knownSuperClass) {
- assert !knownSuperClass.isInterface();
-
- ELType result = null;
-
- JavaClass javaClass = initialClass;
- while (javaClass != null) {
- ELType type = TypesFactoryImpl.getType(javaClass.getName(), parser);
- if (knownSuperClass.isAssignableFrom(type.getRawType())) {
- result = type;
- break;
- }
-
- javaClass = javaClass.getSuperClass();
- }
-
- if (result == null) {
- result = TypesFactoryImpl.getType(knownSuperClass);
- }
-
- return result;
+ private ELType getType(Type type) {
+ return typesFactory.getType(type);
}
private String createPassThroughAttributeCode(String htmlAttributeName, String componentAttributeName) {
@@ -360,47 +326,38 @@
private void createMethodContext() {
this.currentStatement = new StatementsContainer();
- currentStatement.setVariable(FACES_CONTEXT_VARIABLE, TypesFactoryImpl.getType(FacesContext.class));
- currentStatement.setVariable(RESPONSE_WRITER_VARIABLE, TypesFactoryImpl.getType(ResponseWriter.class));
- currentStatement.setVariable(CLIENT_ID_VARIABLE, TypesFactoryImpl.getType(String.class));
+ currentStatement.setVariable(FACES_CONTEXT_VARIABLE, getType(FacesContext.class));
+ currentStatement.setVariable(RESPONSE_WRITER_VARIABLE, getType(ResponseWriter.class));
+ currentStatement.setVariable(CLIENT_ID_VARIABLE, getType(String.class));
// TODO: try load component class
- currentStatement.setVariable(COMPONENT_VARIABLE, TypesFactoryImpl.getType(UIComponent.class));
+ currentStatement.setVariable(COMPONENT_VARIABLE, getType(UIComponent.class));
- ELType generatedClassType = createTypeOfKnownClass(generatedClass, Renderer.class);
+ ELType generatedClassType = typesFactory.getType(generatedClass.getName());
currentStatement.setVariable(THIS_VARIABLE, generatedClassType);
- ELType generatedClassSuperType = createTypeOfKnownClass(generatedClass.getSuperClass(), Renderer.class);
+ ELType generatedClassSuperType = typesFactory.getType(generatedClass.getSuperClass().getName());
currentStatement.setVariable(SUPER_VARIABLE, generatedClassSuperType);
}
private void flushToEncodeMethod(String encodeMethodName) {
if (!this.currentStatement.isEmpty()) {
- Argument facesContextArgument = new Argument(FACES_CONTEXT_VARIABLE, FacesContext.class);
- Argument componentArgument = new Argument(COMPONENT_VARIABLE, UIComponent.class);
+ Argument facesContextArgument = new Argument(FACES_CONTEXT_VARIABLE, getType(FacesContext.class));
+ Argument componentArgument = new Argument(COMPONENT_VARIABLE, getType(UIComponent.class));
JavaMethod javaMethod = new JavaMethod(encodeMethodName, facesContextArgument, componentArgument);
javaMethod.addModifier(JavaModifier.PUBLIC);
- javaMethod.addAnnotation(Override.class);
- javaMethod.getExceptions().add(IOException.class);
- currentStatement.addStatement(0, new EncodeMethodPrefaceStatement());
+ javaMethod.addAnnotation(new JavaAnnotation(getType(Override.class)));
+ javaMethod.getExceptions().add(getType(IOException.class));
+ currentStatement.addStatement(0, createStatement(EncodeMethodPrefaceStatement.class));
javaMethod.setMethodBody(currentStatement);
- generatedClass.addMethod(javaMethod);
- Iterable<ELType> importsList = currentStatement.getRequiredImports();
- for (ELType importedClass : importsList) {
- generatedClass.addImport(importedClass.getRawType());
- for (Class<?> classToImport : importedClass.getRequiredImports()) {
- generatedClass.addImport(classToImport);
- }
- }
- for (HelperMethod helper : currentStatement.getRequiredMethods()) {
- addHelperMethod(helper);
- }
+ addHelperMethods(currentStatement);
for (JavaField field : currentStatement.getRequiredFields()) {
generatedClass.addField(field);
}
+ generatedClass.addMethod(javaMethod);
}
createMethodContext();
@@ -414,15 +371,14 @@
private void createRendersChildrenMethod() {
Boolean rendersChildren = compositeInterface.getRendersChildren();
if (rendersChildren != null) {
- JavaMethod rendersChildrenMethod = new JavaMethod("getRendersChildren", Boolean.TYPE);
+ JavaMethod rendersChildrenMethod = new JavaMethod("getRendersChildren", TypesFactory.BOOLEAN_TYPE);
rendersChildrenMethod.addModifier(JavaModifier.PUBLIC);
- rendersChildrenMethod.addAnnotation(Override.class);
+ rendersChildrenMethod.addAnnotation(new JavaAnnotation(getType(Override.class)));
- rendersChildrenMethod.setMethodBody(new ConstantReturnMethodBodyStatement(Boolean
- .toString(compositeInterface.getRendersChildren())));
-
+ ConstantReturnMethodBodyStatement statement = createStatement(ConstantReturnMethodBodyStatement.class);
+ statement.setReturnValue(Boolean.toString(compositeInterface.getRendersChildren()));
+ rendersChildrenMethod.setMethodBody(statement);
generatedClass.addMethod(rendersChildrenMethod);
-
}
}
@@ -435,9 +391,9 @@
currentStatement = currentStatement.getParent();
}
- protected void addStatement(JavaStatement statement) {
- // TODO - add imports, fields and helper methods required by statement.
- addStatement(statement);
+ protected void addStatement(TemplateStatement statement) {
+ addHelperMethods(statement);
+ currentStatement.addStatement(statement);
}
/**
@@ -490,66 +446,65 @@
// TODO: add support
return;
}
-
- addStatement(new StartElementStatement(elementName.getLocalPart()));
-
- if (elementAttributes != null) {
- Set<String> writtenAttributes = new HashSet<String>();
- boolean shouldEncodePassThrough = false;
- String[] passThroughExclusions = null;
-
- 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();
-
- if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
- // TODO: add support
- if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI())
- && "passThroughWithExclusions".equals(attributeName.getLocalPart())) {
-
- shouldEncodePassThrough = true;
- if (attributeValue != null) {
- passThroughExclusions = attributeValue.toString().split("\\s+");
- }
- }
- } else {
- String attributeLocalName = attributeName.getLocalPart();
- if (writtenAttributes.add(attributeLocalName)) {
- addRendererUtilsImport();
- addStatement(new WriteAttributeStatement(attributeLocalName, compileEl(
- attributeValue.toString(), Object.class)));
- }
- }
- }
-
- if (shouldEncodePassThrough) {
- Element attributesElement = attributesSchema.getElements().get(elementName.getLocalPart());
- if (attributesElement != null) {
- // make a copy of original set
- TreeMap<String, Attribute> actualAttributesMap =
- new TreeMap<String, Attribute>(attributesElement.getAttributes());
-
- if (passThroughExclusions != null) {
- for (String passThroughExclusion : passThroughExclusions) {
- actualAttributesMap.remove(passThroughExclusion);
- }
- }
-
- for (String writtenAttribute : writtenAttributes) {
- actualAttributesMap.remove(writtenAttribute);
- }
-
- if (!actualAttributesMap.isEmpty()) {
- String passThroughFieldName = createPassThroughField(actualAttributesMap);
- addRendererUtilsImport();
- addStatement(new WriteAttributesSetStatement(passThroughFieldName));
- }
- }
- }
- }
+ StartElementStatement startElementStatement = createStatement(StartElementStatement.class);
+ addStatement(startElementStatement);
+ startElementStatement.setElementName(elementName.getLocalPart());
+ AttributesStatement attributesStatement = createStatement(AttributesStatement.class);
+ addStatement(attributesStatement);
+ attributesStatement.setAttributes(elementAttributes);
+// Set<String> writtenAttributes = new HashSet<String>();
+// boolean shouldEncodePassThrough = false;
+// String[] passThroughExclusions = null;
+//
+// 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();
+//
+// if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
+// // TODO: add support
+// if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI())
+// && "passThroughWithExclusions".equals(attributeName.getLocalPart())) {
+//
+// shouldEncodePassThrough = true;
+// if (attributeValue != null) {
+// passThroughExclusions = attributeValue.toString().split("\\s+");
+// }
+// }
+// } else {
+// String attributeLocalName = attributeName.getLocalPart();
+// if (writtenAttributes.add(attributeLocalName)) {
+// addStatement(new WriteAttributeStatement(attributeLocalName, compileEl(
+// attributeValue.toString(), Object.class)));
+// }
+// }
+// }
+//
+// if (shouldEncodePassThrough) {
+// Element attributesElement = attributesSchema.getElements().get(elementName.getLocalPart());
+// if (attributesElement != null) {
+// // make a copy of original set
+// TreeMap<String, Attribute> actualAttributesMap =
+// new TreeMap<String, Attribute>(attributesElement.getAttributes());
+//
+// if (passThroughExclusions != null) {
+// for (String passThroughExclusion : passThroughExclusions) {
+// actualAttributesMap.remove(passThroughExclusion);
+// }
+// }
+//
+// for (String writtenAttribute : writtenAttributes) {
+// actualAttributesMap.remove(writtenAttribute);
+// }
+//
+// if (!actualAttributesMap.isEmpty()) {
+// String passThroughFieldName = createPassThroughField(actualAttributesMap);
+// addStatement(new WriteAttributesSetStatement(passThroughFieldName));
+// }
+// }
+// }
}
/*
@@ -562,7 +517,9 @@
@Override
public void endElement(AnyElement anyElement) throws CdkException {
QName elementName = anyElement.getName();
- addStatement(new EndElementStatement(elementName.getLocalPart()));
+ EndElementStatement endElementStatement = createStatement(EndElementStatement.class);
+ endElementStatement.setElementName(elementName.getLocalPart());
+ addStatement(endElementStatement);
}
/*
@@ -725,7 +682,7 @@
ELType type = null;
if (!Strings.isEmpty(typeString)) {
- type = TypesFactoryImpl.getType(typeString, parser);
+ type = TypesFactoryImpl.getType(typeString, typesFactory);
}
if (!Strings.isEmpty(value)) {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -27,6 +27,7 @@
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.model.PropertyBase;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
@@ -40,7 +41,7 @@
*/
public class VisitorFactoryImpl implements TemplateVisitorFactory<RendererClassVisitor> {
- final ELParser parser;
+ final TypesFactory typesFactory;
final Logger log;
final Injector injector;
private final HelperMethodFactory helpersFactory;
@@ -52,8 +53,8 @@
* @param log
*/
@Inject
- public VisitorFactoryImpl(ELParser parser, Logger log, Injector injector,HelperMethodFactory helpersFactory) {
- this.parser = parser;
+ public VisitorFactoryImpl(TypesFactory typesFactory, Logger log, Injector injector,HelperMethodFactory helpersFactory) {
+ this.typesFactory = typesFactory;
this.log = log;
this.injector = injector;
this.helpersFactory = helpersFactory;
@@ -64,7 +65,7 @@
*/
@Override
public RendererClassVisitor createVisitor(CompositeInterface composite, Collection<PropertyBase> attributes) {
- return new RendererClassVisitor(composite, attributes, log,injector,parser,helpersFactory);
+ return new RendererClassVisitor(composite, attributes, log,injector,typesFactory,helpersFactory);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -116,7 +116,9 @@
private boolean mixedExpression;
+ private boolean literal = true;
+
public ELVisitor(Logger log, TypesFactory typesFactory) {
this.log = log;
this.typesFactory = typesFactory;
@@ -128,6 +130,25 @@
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the literal
+ */
+ @Override
+ public boolean isLiteral() {
+ return this.literal;
+ }
+
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param literal the literal to set
+ */
+ public void setLiteral(boolean literal) {
+ this.literal = literal;
+ }
+
+
public ELType getExpressionType() {
return expressionType;
}
@@ -167,6 +188,7 @@
//AstCompositeExpression with 2+ children is a mixed expression
usedHelperMethods.add(TO_STRING_CONVERSION);
this.mixedExpression = true;
+ this.literal = false;
}
if (ret != null && ret.jjtGetNumChildren() > 0) {
@@ -190,6 +212,7 @@
return conversionMethod.getName() + "(" + valueString + ")";
}
}
+ setLiteral(false);
}
return valueString;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -80,6 +80,7 @@
returnType = TypesFactory.OBJECT_TYPE;
}
+ visitor.setLiteral(false);
visitor.setExpressionType(returnType);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -60,6 +60,7 @@
if (containerType == null) {
containerType = TypesFactory.OBJECT_TYPE;
}
+ visitor.setLiteral(false);
visitor.setExpressionType(containerType);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -60,6 +60,7 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
+ visitor.setLiteral(false);
if (!correctConditionBranchType.isNullType()) {
visitor.setExpressionType(correctConditionBranchType);
} else {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -55,5 +55,6 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
visitor.setExpressionType(TypesFactory.BOOLEAN_TYPE);
+ visitor.setLiteral(false);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -62,5 +62,6 @@
visitor.setExpressionType(identifierType);
visitMethod(sb, visitor, functionName);
+ visitor.setLiteral(false);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -47,5 +47,6 @@
//TODO: implement variable mapper like "utils" -> "this.getUtils()"
visitor.setExpressionType(identifierType);
sb.append(identifierName);
+ visitor.setLiteral(false);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstMethodSuffixTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstMethodSuffixTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstMethodSuffixTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -42,5 +42,6 @@
String methodName = getNode().getImage();
visitMethod(sb, visitor, methodName);
+ visitor.setLiteral(false);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -55,5 +55,6 @@
sb.append(readMethodName);
sb.append(ELNodeConstants.LEFT_BRACKET);
sb.append(ELNodeConstants.RIGHT_BRACKET);
+ visitor.setLiteral(false);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstValueTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstValueTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstValueTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -43,6 +43,7 @@
String childOutput = getChildOutput(i, visitor);
sb.append(childOutput);
}
+ visitor.setLiteral(false);
//variable type has been already set by getChildOuput()
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -66,6 +66,9 @@
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(value);
visitor.setExpressionType(type);
+ if(type.isNullType()){
+ visitor.setLiteral(false);
+ }
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -114,6 +114,7 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
}
+ visitor.setLiteral(false);
visitor.setExpressionType(TypesFactory.BOOLEAN_TYPE);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -30,6 +30,8 @@
import org.richfaces.cdk.CdkException;
+import com.google.common.collect.Maps;
+
/**
* <p class="changed_added_4_0"></p>
*
@@ -39,7 +41,7 @@
private QName name;
- private Map<QName, Object> attributes;
+ private Map<QName, Object> attributes = Maps.newHashMap();
/**
* <p class="changed_added_4_0"></p>
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AbstractTemplateMethodBodyStatementsContainer.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AbstractTemplateMethodBodyStatementsContainer.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AbstractTemplateMethodBodyStatementsContainer.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -1,42 +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.statements;
-
-
-/**
- * @author Nick Belaevski
- */
-public class AbstractTemplateMethodBodyStatementsContainer extends StatementsContainer {
-
- private String templateName;
-
- protected AbstractTemplateMethodBodyStatementsContainer(String templateName) {
- super();
- this.templateName = templateName;
- }
-
- @Override
- public String getCode() {
- return renderer.renderSnippet(templateName, this);
- }
-
-}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -0,0 +1,35 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.richfaces.cdk.attributes.Schema;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.model.Template;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.name.Named;
+
+public class AttributesStatement extends StatementsContainer {
+
+ private final Schema attributesSchema;
+ private final Provider<WriteAttributeStatement> statementProvider;
+ private final Provider<WriteAttributesSetStatement> passThroughStatementProvider;
+ private final ELParser parser;
+
+ @Inject
+ public AttributesStatement((a)Named(Template.XHTML_EL_NAMESPACE) Schema attributesSchema,
+ Provider<WriteAttributeStatement> attributeStatementProvider,
+ Provider<WriteAttributesSetStatement> passThroughStatementProvider, ELParser parser) {
+ this.attributesSchema = attributesSchema;
+ this.statementProvider = attributeStatementProvider;
+ this.passThroughStatementProvider = passThroughStatementProvider;
+ this.parser = parser;
+ }
+
+ public void setAttributes(Map<QName, Object> attributes) {
+
+ }
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -1,65 +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.statements;
-
-import java.util.Collections;
-
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
-import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
-import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class BaseTemplateMethodBodyStatement implements TemplateStatement {
-
- private final String templateName;
- private final FreeMarkerRenderer renderer;
-
- protected BaseTemplateMethodBodyStatement(FreeMarkerRenderer renderer,String templateName) {
- super();
- this.renderer = renderer;
- this.templateName = templateName;
- }
-
- @Override
- public String getCode() {
- return renderer.renderSnippet(templateName, this);
- }
-
- @Override
- public Iterable<JavaImport> getRequiredImports() {
- return Collections.emptySet();
- }
-
- @Override
- public Iterable<JavaField> getRequiredFields() {
- return Collections.emptySet();
- }
-
- @Override
- public Iterable<HelperMethod> getRequiredMethods() {
- return Collections.emptySet();
- }
-
-}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -21,21 +21,33 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*
*/
-public class ConstantReturnMethodBodyStatement extends BaseTemplateMethodBodyStatement {
+public class ConstantReturnMethodBodyStatement extends TemplateStatementBase {
private String returnValue;
- public ConstantReturnMethodBodyStatement(String returnValue) {
- super("constant-return");
+ @Inject
+ public ConstantReturnMethodBodyStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"constant-return");
- this.returnValue = returnValue;
}
public String getReturnValue() {
return returnValue;
}
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param returnValue the returnValue to set
+ */
+ public void setReturnValue(String returnValue) {
+ this.returnValue = returnValue;
+ }
}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToBooleanMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToBooleanMethodBodyStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToBooleanMethodBodyStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -1,32 +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.statements;
-
-/**
- * @author Nick Belaevski
- */
-public class ConversionToBooleanMethodBodyStatement extends HelperMethodBodyStatement {
-
- public ConversionToBooleanMethodBodyStatement() {
- super("conversion-to-boolean-method", new String[] {"object"});
- }
-}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToStringMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToStringMethodBodyStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConversionToStringMethodBodyStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -1,32 +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.statements;
-
-/**
- * @author Nick Belaevski
- */
-public class ConversionToStringMethodBodyStatement extends HelperMethodBodyStatement {
-
- public ConversionToStringMethodBodyStatement() {
- super("conversion-to-string-method", new String[] {"object"});
- }
-}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -26,7 +26,7 @@
/**
* @author Nick Belaevski
*/
-public class DefineObjectStatement extends BaseTemplateMethodBodyStatement {
+public class DefineObjectStatement extends TemplateStatementBase {
private ELType type;
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -0,0 +1,54 @@
+/*
+ * 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.statements;
+
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
+/**
+ * @author Nick Belaevski
+ * @since 4.0
+ */
+public class ElementStatement extends TemplateStatementBase {
+
+ private String elementName;
+
+ public ElementStatement(FreeMarkerRenderer renderer,String template) {
+ super(renderer,template);
+ }
+
+
+ /**
+ * @return the elementName
+ */
+ public String getElementName() {
+ return elementName;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param elementName the elementName to set
+ */
+ public void setElementName(String elementName) {
+ this.elementName = elementName;
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EmptinessCheckingMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EmptinessCheckingMethodBodyStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EmptinessCheckingMethodBodyStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -1,32 +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.statements;
-
-/**
- * @author Nick Belaevski
- */
-public class EmptinessCheckingMethodBodyStatement extends HelperMethodBodyStatement {
-
- public EmptinessCheckingMethodBodyStatement() {
- super("emptiness-check-method", new String[] {"object"});
- }
-}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -21,16 +21,21 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
-public class EncodeMethodPrefaceStatement extends BaseTemplateMethodBodyStatement {
+public class EncodeMethodPrefaceStatement extends TemplateStatementBase {
/**
* @param templateName
*/
- public EncodeMethodPrefaceStatement() {
- super("encode-method-preface");
+ @Inject
+ public EncodeMethodPrefaceStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"encode-method-preface");
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -21,14 +21,19 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
* @since 4.0
*/
-public class EndElementStatement extends StartElementStatement {
+public class EndElementStatement extends ElementStatement {
- public EndElementStatement(String elementName) {
- super("end-element", elementName);
+ @Inject
+ public EndElementStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"end-element");
}
}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EqualsCheckingMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EqualsCheckingMethodBodyStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EqualsCheckingMethodBodyStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -1,33 +0,0 @@
-/*
- * 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.statements;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class EqualsCheckingMethodBodyStatement extends HelperMethodBodyStatement {
-
- public EqualsCheckingMethodBodyStatement() {
- super("equals-check-method", new String[] {"o1", "o2"});
- }
-}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -24,7 +24,7 @@
/**
* @author Nick Belaevski
*/
-public class ForEachStatement extends AbstractTemplateMethodBodyStatementsContainer {
+public class ForEachStatement extends TemplateStatementsContainerBase {
private String itemsExpression;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -23,7 +23,9 @@
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* <p class="changed_added_4_0"></p>
@@ -31,5 +33,15 @@
*
*/
public class HelperJavaMethod extends JavaMethod {
+
+ public HelperJavaMethod(String name, ELType returnType, Argument[] arguments) {
+ super(name, returnType, arguments);
+ }
+
+ public HelperJavaMethod(String name) {
+ super(name);
+ }
+
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -26,6 +26,8 @@
import java.util.EnumSet;
import java.util.Set;
+import javax.faces.context.FacesContext;
+
/**
* @author Nick Belaevski
*
@@ -35,7 +37,8 @@
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);
+ EQUALS_CHECK(IS_EQUAL_FUNCTION, Boolean.TYPE, Object.class, Object.class),
+ WRITE_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class);
private static final Set<HelperMethod> CONVERSION_METHODS = EnumSet.of(TO_STRING_CONVERSION, TO_BOOLEAN_CONVERSION);
@@ -45,7 +48,6 @@
private Class<?>[] argumentTypes;
- private boolean utilsMethod = false;
private HelperMethod(String name, Class<?> returnType, Class<?>... argumentTypes) {
this.name = name;
@@ -53,21 +55,6 @@
this.argumentTypes = argumentTypes;
}
- private HelperMethod(String name, Class<?> returnType, boolean utils, Class<?>... argumentTypes) {
- this.name = name;
- this.returnType = returnType;
- this.argumentTypes = argumentTypes;
- this.utilsMethod=utils;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the utilsMethod
- */
- public boolean isUtilsMethod() {
- return this.utilsMethod;
- }
-
public String getName() {
return name;
}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodBodyStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodBodyStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -1,41 +0,0 @@
-/*
- * 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.statements;
-
-/**
- * @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/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -23,6 +23,8 @@
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.EnumMap;
+
import org.richfaces.cdk.Generator;
import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
@@ -31,6 +33,7 @@
import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.internal.Nullable;
import com.google.inject.name.Named;
@@ -47,18 +50,30 @@
private final FreeMarkerRenderer renderer;
private final TypesFactory typesFactory;
private final String rendererUtilsClass;
+ private final EnumMap<HelperMethod, JavaMethod> helperMethods =
+ Maps.newEnumMap(HelperMethod.class);
+
@Inject
public HelperMethodFactoryImpl(FreeMarkerRenderer renderer, TypesFactory typesFactory,
@Named(Generator.RENDERER_UTILS_CLASS) @Nullable String rendererUtilsClass) {
this.renderer = renderer;
this.typesFactory = typesFactory;
this.rendererUtilsClass = rendererUtilsClass;
+ initHelperMethods();
}
- private JavaMethod buildHelperMethod(HelperMethod helperMethod, String templateName, String... argumentNames) {
- if (helperMethod.isUtilsMethod() && null != rendererUtilsClass) {
- return new RendererUtilsMethod(helperMethod, rendererUtilsClass);
+ protected void initHelperMethods() {
+ buildHelperMethod(HelperMethod.EMPTINESS_CHECK, false, "emptiness-check-method", "object");
+ buildHelperMethod(HelperMethod.EQUALS_CHECK, false, "equals-check-method", "o1", "o2");
+ buildHelperMethod(HelperMethod.TO_BOOLEAN_CONVERSION, false,"conversion-to-boolean-method", "object");
+ buildHelperMethod(HelperMethod.TO_STRING_CONVERSION, false, "conversion-to-string-method", "object");
+ }
+
+ private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod, String templateName, String... argumentNames) {
+ JavaMethod helperJavaMethod;
+ if (utilsMethod && null != rendererUtilsClass) {
+ helperJavaMethod = new RendererUtilsMethod(helperMethod, rendererUtilsClass);
} else {
Class<?>[] argumentTypes = helperMethod.getArgumentTypes();
Argument[] arguments = new Argument[argumentTypes.length];
@@ -67,12 +82,13 @@
arguments[i] = new Argument(argumentName, typesFactory.getType(argumentTypes[i]));
}
ELType returnType = typesFactory.getType(helperMethod.getReturnType());
- JavaMethod helperJavaMethod = new JavaMethod(helperMethod.getName(), returnType, arguments);
+ helperJavaMethod = new JavaMethod(helperMethod.getName(), returnType, arguments);
helperJavaMethod.addModifier(JavaModifier.PRIVATE);
helperJavaMethod.addModifier(JavaModifier.STATIC);
- helperJavaMethod.setMethodBody(new BaseTemplateMethodBodyStatement(renderer, templateName));
- return helperJavaMethod;
+ helperJavaMethod.setMethodBody(new TemplateStatementBase(renderer, templateName));
}
+ helperMethods.put(helperMethod, helperJavaMethod);
+ return helperJavaMethod;
}
/*
@@ -84,8 +100,7 @@
*/
@Override
public JavaMethod getHelperMethod(HelperMethod helper) {
- // TODO Auto-generated method stub
- return null;
+ return helperMethods.get(helper);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -25,7 +25,7 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class IfElseStatement extends AbstractTemplateMethodBodyStatementsContainer {
+public class IfElseStatement extends TemplateStatementsContainerBase {
public IfElseStatement() {
super("if-else");
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -21,28 +21,19 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
* @since 4.0
*/
-public class StartElementStatement extends BaseTemplateMethodBodyStatement {
+public class StartElementStatement extends ElementStatement {
- private String elementName;
-
- public StartElementStatement(String elementName) {
- this("start-element", elementName);
+ @Inject
+ public StartElementStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"start-element");
}
- protected StartElementStatement(String templateName, String elementName) {
- super(templateName);
- this.elementName = elementName;
- }
-
- /**
- * @return the elementName
- */
- public String getElementName() {
- return elementName;
- }
-
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -40,30 +40,33 @@
*/
public class StatementsContainer implements TemplateStatement, Variables {
- private static final Function<TemplateStatement, Iterable<JavaImport>> IMPORTS_TRANSFORM = new Function<TemplateStatement, Iterable<JavaImport>>() {
-
- @Override
- public Iterable<JavaImport> apply(TemplateStatement from) {
- return from.getRequiredImports();
- }
- };
+ private static final Function<TemplateStatement, Iterable<JavaImport>> IMPORTS_TRANSFORM =
+ new Function<TemplateStatement, Iterable<JavaImport>>() {
- private static final Function<TemplateStatement, Iterable<JavaField>> FIELDS_TRANSFORM = new Function<TemplateStatement, Iterable<JavaField>>() {
-
- @Override
- public Iterable<JavaField> apply(TemplateStatement from) {
- return from.getRequiredFields();
- }
- };
+ @Override
+ public Iterable<JavaImport> apply(TemplateStatement from) {
+ return from.getRequiredImports();
+ }
+ };
- private static final Function<TemplateStatement, Iterable<HelperMethod>> HELPER_METHODS_TRANSFORM = new Function<TemplateStatement, Iterable<HelperMethod>>() {
-
- @Override
- public Iterable<HelperMethod> apply(TemplateStatement from) {
- return from.getRequiredMethods();
- }
- };
+ private static final Function<TemplateStatement, Iterable<JavaField>> FIELDS_TRANSFORM =
+ new Function<TemplateStatement, Iterable<JavaField>>() {
+ @Override
+ public Iterable<JavaField> apply(TemplateStatement from) {
+ return from.getRequiredFields();
+ }
+ };
+
+ private static final Function<TemplateStatement, Iterable<HelperMethod>> HELPER_METHODS_TRANSFORM =
+ new Function<TemplateStatement, Iterable<HelperMethod>>() {
+
+ @Override
+ public Iterable<HelperMethod> apply(TemplateStatement from) {
+ return from.getRequiredMethods();
+ }
+ };
+
private List<TemplateStatement> statements = new ArrayList<TemplateStatement>();
private StatementsContainer parent;
@@ -75,22 +78,15 @@
}
public void addStatement(TemplateStatement statement) {
- setParent(statement);
+ statement.setParent(this);
statements.add(statement);
}
public void addStatement(int index, TemplateStatement statement) {
- setParent(statement);
+ statement.setParent(this);
statements.add(index, statement);
}
- private void setParent(TemplateStatement statement) {
- if (statement instanceof StatementsContainer) {
- StatementsContainer container = (StatementsContainer) statement;
- container.setParent(this);
- }
- }
-
/**
* <p class="changed_added_4_0">
* </p>
@@ -176,7 +172,7 @@
public Iterable<HelperMethod> getRequiredMethods() {
return concatStatements(HELPER_METHODS_TRANSFORM);
}
-
+
@Override
public String toString() {
return getCode();
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -17,5 +17,7 @@
Iterable<JavaField> getRequiredFields();
Iterable<HelperMethod> getRequiredMethods();
+
+ void setParent(StatementsContainer parent);
}
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java (from rev 17680, root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -0,0 +1,78 @@
+/*
+ * 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.statements;
+
+import java.util.Collections;
+import java.util.EnumSet;
+
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TemplateStatementBase implements TemplateStatement {
+
+ protected StatementsContainer parent;
+ private final String templateName;
+ private final FreeMarkerRenderer renderer;
+ private final EnumSet<HelperMethod> requiredMethods = EnumSet.noneOf(HelperMethod.class);
+
+ protected TemplateStatementBase(FreeMarkerRenderer renderer, String templateName) {
+ super();
+ this.renderer = renderer;
+ this.templateName = templateName;
+ }
+
+ @Override
+ public void setParent(StatementsContainer parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public String getCode() {
+ return renderer.renderSnippet(templateName, this);
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return requiredMethods;
+ }
+
+ protected void addRequiredMethods(HelperMethod... methods) {
+ for (HelperMethod helperMethod : methods) {
+ requiredMethods.add(helperMethod);
+ }
+ }
+}
\ No newline at end of file
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java (from rev 17680, root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AbstractTemplateMethodBodyStatementsContainer.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -0,0 +1,46 @@
+/*
+ * 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.statements;
+
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
+
+/**
+ * @author Nick Belaevski
+ */
+public class TemplateStatementsContainerBase extends StatementsContainer {
+
+ private final String templateName;
+ private final FreeMarkerRenderer renderer;
+
+ protected TemplateStatementsContainerBase(FreeMarkerRenderer renderer,String templateName) {
+ super();
+ this.renderer = renderer;
+ this.templateName = templateName;
+ }
+
+ @Override
+ public String getCode() {
+ return renderer.renderSnippet(templateName, this);
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -34,4 +34,6 @@
ELType getExpressionType();
+ boolean isLiteral();
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -21,26 +21,36 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
-public class WriteAttributeStatement extends BaseTemplateMethodBodyStatement {
+public class WriteAttributeStatement extends TemplateStatementBase {
- private String attributeName;
+ private String name;
- private String valueExpression;
+ private TypedTemplateStatement valueExpression;
- public WriteAttributeStatement(String attributeName, String valueExpression) {
- super("write-attribute");
- this.attributeName = attributeName;
- this.valueExpression = valueExpression;
+
+ @Inject
+ public WriteAttributeStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"write-attribute");
}
+
+ public void setAttribute(String name,TypedTemplateStatement expression) {
+ this.name = name;
+ this.valueExpression = expression;
+ addRequiredMethods(HelperMethod.WRITE_ATTRIBUTE);
+ }
- public String getAttributeName() {
- return attributeName;
+ public String getName() {
+ return name;
}
- public String getValueExpression() {
+ public TypedTemplateStatement getValue() {
return valueExpression;
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -25,7 +25,7 @@
/**
* @author Nick Belaevski
*/
-public class WriteAttributesSetStatement extends BaseTemplateMethodBodyStatement {
+public class WriteAttributesSetStatement extends TemplateStatementBase {
private String passThroughFieldName;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -24,7 +24,7 @@
/**
* @author Nick Belaevski
*/
-public class WriteTextStatement extends BaseTemplateMethodBodyStatement {
+public class WriteTextStatement extends TemplateStatementBase {
private String textExpression;
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-29 22:50:34 UTC (rev 17681)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-30 00:47:26 UTC (rev 17682)
@@ -658,4 +658,14 @@
public void testWrongExpression2() throws Exception {
parseExpression("#{action.property}", "action.getProperty()", Object.class);
}
+
+ @Test
+ public void testLiteralExpression() throws Exception {
+ controller.replay();
+ TypedTemplateStatement parseExpression = parseExpression("Literal", Object.class);
+ controller.verify();
+ assertTrue(parseExpression.isLiteral());
+ assertEquals("\"Literal\"",parseExpression.getCode());
+ assertEquals(String.class.getName(), parseExpression.getExpressionType().getRawName());
+ }
}
14 years, 6 months
JBoss Rich Faces SVN: r17681 - in root/build/resources/trunk/faces-shade-transformers/src: test/jars and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-29 18:50:34 -0400 (Tue, 29 Jun 2010)
New Revision: 17681
Added:
root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/NamespacesTracker.java
Modified:
root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/BaseFacesResourceTransformer.java
root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/FacesConfigXmlResourceTransformer.java
root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/TaglibXmlResourceTransformer.java
root/build/resources/trunk/faces-shade-transformers/src/test/jars/functions-ui-4.0.0-SNAPSHOT.jar
Log:
https://jira.jboss.org/browse/RF-8769
Modified: root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/BaseFacesResourceTransformer.java
===================================================================
--- root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/BaseFacesResourceTransformer.java 2010-06-29 10:16:16 UTC (rev 17680)
+++ root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/BaseFacesResourceTransformer.java 2010-06-29 22:50:34 UTC (rev 17681)
@@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.StringReader;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@@ -51,25 +52,32 @@
protected static final String META_INF_PATH = "META-INF/";
- protected static final String JAVAEE_URI = "http://java.sun.com/xml/ns/javaee";
-
protected static final String JAVAEE_PREFIX = "javaee";
- protected static final Namespace JAVAEE_NAMESPACE = Namespace.getNamespace(JAVAEE_PREFIX, JAVAEE_URI);
+ protected static final String JAVAEE_URI = "http://java.sun.com/xml/ns/javaee";
- protected static final Namespace XSI_NAMESPACE = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
-
+ private static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
+
+ private static final String XSI_PREFIX = "xsi";
+
+ protected NamespacesTracker namespacesFactory = new NamespacesTracker();
+
protected static XPath createXPath(String path) throws JDOMException {
XPath xPath = XPath.newInstance(path);
- xPath.addNamespace(JAVAEE_NAMESPACE);
- xPath.addNamespace(XSI_NAMESPACE);
+ xPath.addNamespace(Namespace.getNamespace(JAVAEE_PREFIX, JAVAEE_URI));
+ xPath.addNamespace(Namespace.getNamespace(XSI_PREFIX, XSI_URI));
return xPath;
}
+ protected Namespace getJavaEENamespace() {
+ return namespacesFactory.getNamespace(JAVAEE_URI, null);
+ }
+
protected void addSchemaLocation(Element element, String schemaLocation) {
if (schemaLocation != null && schemaLocation.length() != 0) {
- element.setAttribute("schemaLocation", JAVAEE_URI + " " + schemaLocation, XSI_NAMESPACE);
+ Namespace xsiNamespace = namespacesFactory.getNamespace(XSI_URI, XSI_PREFIX);
+ element.setAttribute("schemaLocation", JAVAEE_URI + " " + schemaLocation, xsiNamespace);
}
}
@@ -77,15 +85,15 @@
if (object instanceof Element) {
Element element = (Element) object;
- if (JAVAEE_URI.equals(element.getNamespaceURI())) {
- element.setNamespace(JAVAEE_NAMESPACE);
- }
+ element.setNamespace(namespacesFactory.getNamespace(element.getNamespace()));
for (Object attributeObject : element.getAttributes()) {
Attribute attribute = (Attribute) attributeObject;
- if (JAVAEE_URI.equals(attribute.getNamespaceURI())) {
- attribute.setNamespace(JAVAEE_NAMESPACE);
+ if (!Namespace.NO_NAMESPACE.equals(attribute.getNamespace())) {
+ attribute.setNamespace(namespacesFactory.getNamespace(attribute.getNamespace()));
+ } else {
+ attribute.setNamespace(element.getNamespace());
}
}
@@ -97,7 +105,7 @@
protected boolean isJavaEEOrDefaultNamespace(Element element) {
String namespaceURI = element.getNamespaceURI();
- if (namespaceURI == null || namespaceURI.length() == 0) {
+ if (namespaceURI == null || namespaceURI.trim().length() == 0) {
return true;
}
@@ -123,11 +131,26 @@
jos.putNextEntry(new JarEntry(resourceName));
Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setIndent(" ");
+
+ Element rootElement = document.getRootElement();
+ Collection<Namespace> namespaces = namespacesFactory.getNamespaces();
+ for (Namespace namespace : namespaces) {
+ if (namespace.getPrefix().length() == 0) {
+ continue;
+ }
+
+ rootElement.addNamespaceDeclaration(namespace);
+ }
+
new XMLOutputter(prettyFormat).output(document, jos);
}
protected abstract void processDocument(String resource, Document document, List relocators) throws JDOMException;
+ protected void resetTransformer() {
+ namespacesFactory = new NamespacesTracker();
+ }
+
protected String getMetaInfResourceName(String resource) {
if (!resource.startsWith(META_INF_PATH)) {
return null;
Modified: root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/FacesConfigXmlResourceTransformer.java
===================================================================
--- root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/FacesConfigXmlResourceTransformer.java 2010-06-29 10:16:16 UTC (rev 17680)
+++ root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/FacesConfigXmlResourceTransformer.java 2010-06-29 22:50:34 UTC (rev 17681)
@@ -37,6 +37,7 @@
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.jdom.Namespace;
import org.jdom.filter.ElementFilter;
import org.jdom.filter.Filter;
import org.jdom.xpath.XPath;
@@ -158,7 +159,7 @@
}
}
- Filter renderkitIdFilter = new ElementFilter().and(new ElementFilter(RENDER_KIT_ID, JAVAEE_NAMESPACE).negate());
+ Filter renderkitIdFilter = new ElementFilter().and(new ElementFilter(RENDER_KIT_ID, getJavaEENamespace()).negate());
XPath renderKitIdXPath = createXPath(RENDER_KIT_ID_EXPRESSION);
List<Element> children = checkedList(rootElement.getChildren(), Element.class);
for (Element child : children) {
@@ -225,7 +226,8 @@
}
Document document = new Document();
- Element rootElement = new Element(FACES_CONFIG, JAVAEE_NAMESPACE);
+ Namespace javaEENamespace = getJavaEENamespace();
+ Element rootElement = new Element(FACES_CONFIG, javaEENamespace);
rootElement.setAttribute(VERSION, CURRENT_VERSION);
if (metadataComplete != ThreeState.UNDEFINED) {
@@ -241,7 +243,7 @@
String elementName = entry.getKey();
List<Element> aggregatorElementChildren = entry.getValue();
- Element aggregatorElement = new Element(elementName, JAVAEE_NAMESPACE);
+ Element aggregatorElement = new Element(elementName, javaEENamespace);
rootElementChildren.add(aggregatorElement);
Collections.sort(aggregatorElementChildren, comparator);
@@ -252,11 +254,11 @@
String renderkitId = entry.getKey();
List<Element> renderkitElementChildren = entry.getValue();
- Element renderkitElement = new Element(RENDER_KIT, JAVAEE_NAMESPACE);
+ Element renderkitElement = new Element(RENDER_KIT, javaEENamespace);
rootElementChildren.add(renderkitElement);
if (renderkitId.length() != 0) {
- Element renderkitIdElement = new Element(RENDER_KIT_ID, JAVAEE_NAMESPACE);
+ Element renderkitIdElement = new Element(RENDER_KIT_ID, javaEENamespace);
renderkitIdElement.setText(renderkitId);
renderkitElementChildren.add(renderkitIdElement);
}
@@ -271,13 +273,19 @@
appendToStream(FACES_CONFIG_FILE_PATH, document, os);
} finally {
- hasProcessedConfigFiles = false;
- metadataComplete = ThreeState.UNDEFINED;
-
- simpleElements.clear();
- aggregatorElements.clear();
- renderkitElements.clear();
+ resetTransformer();
}
}
+ @Override
+ protected void resetTransformer() {
+ super.resetTransformer();
+
+ hasProcessedConfigFiles = false;
+ metadataComplete = ThreeState.UNDEFINED;
+
+ simpleElements.clear();
+ aggregatorElements.clear();
+ renderkitElements.clear();
+ }
}
Added: root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/NamespacesTracker.java
===================================================================
--- root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/NamespacesTracker.java (rev 0)
+++ root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/NamespacesTracker.java 2010-06-29 22:50:34 UTC (rev 17681)
@@ -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.build.shade.resource;
+
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jdom.Namespace;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class NamespacesTracker {
+
+ //see MessageFormat class for format of this string
+ private static final String GENERATED_NS_PREFIX_FORMAT = "x{0}";
+
+ private Set<String> usedPrefixes = new HashSet<String>();
+
+ private Map<String, Namespace> namespaces = new HashMap<String, Namespace>();
+
+ private int prefixGeneratorCounter = 0;
+
+ private String maskEmptyString(String s) {
+ if (s == null || s.trim().length() == 0) {
+ return "";
+ }
+
+ return s;
+ }
+
+ private Namespace createNamespace(String uri, String prefix) {
+ String maskedPrefix = maskEmptyString(prefix);
+
+ while (usedPrefixes.contains(maskedPrefix)) {
+ //generate next prefix using counter & format string
+ maskedPrefix = MessageFormat.format(GENERATED_NS_PREFIX_FORMAT, prefixGeneratorCounter++);
+ }
+
+ return Namespace.getNamespace(maskedPrefix, uri);
+ }
+
+ public Namespace getNamespace(String nsUri, String nsPrefix) {
+ String maskedUri = maskEmptyString(nsUri);
+
+ Namespace namespace = namespaces.get(maskedUri);
+
+ if (namespace == null) {
+ namespace = createNamespace(maskedUri, nsPrefix);
+
+ usedPrefixes.add(namespace.getPrefix());
+ namespaces.put(maskedUri, namespace);
+ }
+
+ return namespace;
+ }
+
+ public Namespace getNamespace(Namespace namespace) {
+ return getNamespace(namespace.getURI(), namespace.getPrefix());
+ }
+
+ public Collection<Namespace> getNamespaces() {
+ return Collections.unmodifiableCollection(namespaces.values());
+ }
+
+}
Modified: root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/TaglibXmlResourceTransformer.java
===================================================================
--- root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/TaglibXmlResourceTransformer.java 2010-06-29 10:16:16 UTC (rev 17680)
+++ root/build/resources/trunk/faces-shade-transformers/src/main/java/org/richfaces/build/shade/resource/TaglibXmlResourceTransformer.java 2010-06-29 22:50:34 UTC (rev 17681)
@@ -35,6 +35,7 @@
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.jdom.Namespace;
import org.jdom.filter.ElementFilter;
import org.jdom.filter.Filter;
import org.jdom.xpath.XPath;
@@ -65,7 +66,7 @@
private Map<String, Document> passThroughLibraries = new HashMap<String, Document>();
private Taglib[] taglibs = new Taglib[0];
-
+
private Comparator<Element> createElementsComparator() throws JDOMException {
List<String> elements = Arrays.asList("description", "display-name", "icon",
"library-class", NAMESPACE, "composite-library-name", TAG, FUNCTION, "taglib-extension");
@@ -73,13 +74,13 @@
Map<String, XPath> elementNameExpressions = new HashMap<String, XPath>();
String tagPathExpr = MessageFormat.format("./{0}:{1}|./{1}", JAVAEE_PREFIX, TAG_NAME);
elementNameExpressions.put(TAG, createXPath(tagPathExpr));
-
+
String fnPathExpr = MessageFormat.format("./{0}:{1}|./{1}", JAVAEE_PREFIX, FUNCTION_NAME);
elementNameExpressions.put(FUNCTION, createXPath(fnPathExpr));
-
+
return new ElementsComparator(JAVAEE_URI, elements, elementNameExpressions);
}
-
+
private String getShortName(String namespaceUri) {
int idx = namespaceUri.lastIndexOf('/');
if (idx < 0) {
@@ -89,12 +90,6 @@
}
}
- private Element createNamespaceElement(String namespaceUri) {
- Element nsElement = new Element(NAMESPACE, JAVAEE_NAMESPACE);
- nsElement.setText(namespaceUri);
- return nsElement;
- }
-
private String getFileName(String shortName) {
return META_INF_PATH + shortName + TAGLIB_XML_FILE_EXTENSION;
}
@@ -113,7 +108,7 @@
throw new IllegalArgumentException("Root element namespace: " + element.getNamespaceURI());
}
}
-
+
public boolean hasTransformedResource() {
return !tagLibraries.isEmpty() || !passThroughLibraries.isEmpty();
}
@@ -126,21 +121,18 @@
appendToStream(resourceName, document, os);
}
- } finally {
- passThroughLibraries.clear();
- }
- if (!tagLibraries.isEmpty()) {
- Comparator<Element> elementsComparator;
- try {
- elementsComparator = createElementsComparator();
- } catch (JDOMException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
+ if (!tagLibraries.isEmpty()) {
+ Comparator<Element> elementsComparator;
+ try {
+ elementsComparator = createElementsComparator();
+ } catch (JDOMException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
- Filter filter = new ElementFilter().and(new ElementFilter(NAMESPACE, JAVAEE_NAMESPACE).negate());
-
- try {
+ Namespace javaEENamespace = getJavaEENamespace();
+ Filter filter = new ElementFilter().and(new ElementFilter(NAMESPACE, javaEENamespace).negate());
+
for (Map.Entry<String, List<Document>> entry : tagLibraries.entrySet()) {
String namespaceUri = entry.getKey();
String shortName = getShortName(namespaceUri);
@@ -148,40 +140,50 @@
Document document = new org.jdom.Document();
- Element rootElement = new Element(FACELET_TAGLIB, JAVAEE_NAMESPACE);
+ Element rootElement = new Element(FACELET_TAGLIB, javaEENamespace);
rootElement.setAttribute(VERSION, CURRENT_VERSION);
addSchemaLocation(rootElement, "http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd");
rootElement.setAttribute(ID, shortName);
-
+
document.addContent(rootElement);
List<Element> elements = new ArrayList<Element>();
- elements.add(createNamespaceElement(namespaceUri));
-
+
+ Element nsElement = new Element(NAMESPACE, javaEENamespace);
+ nsElement.setText(namespaceUri);
+ elements.add(nsElement);
+
for (Document sourceDocument : sourceDocuments) {
Element sourceRootElement = sourceDocument.getRootElement();
checkRootElement(sourceRootElement);
-
+
List<Element> tagsContent = checkedList(sourceRootElement.getContent(filter), Element.class);
for (Element tagElement: tagsContent) {
Element clonedElement = cloneAndImportElement(tagElement);
elements.add(clonedElement);
}
}
-
+
Collections.sort(elements, elementsComparator);
rootElement.addContent(elements);
-
+
String fileName = getFileName(shortName);
appendToStream(fileName, document, os);
}
- } finally {
- tagLibraries.clear();
}
+ } finally {
+ resetTransformer();
}
}
@Override
+ protected void resetTransformer() {
+ super.resetTransformer();
+ passThroughLibraries.clear();
+ tagLibraries.clear();
+ }
+
+ @Override
protected void processDocument(String resource, Document document, List relocators) throws JDOMException {
String namespaceUri = (String) createXPath(NAMESPACE_EXPRESSION).valueOf(document);
if (namespaceUri == null || namespaceUri.length() == 0) {
@@ -193,7 +195,7 @@
break;
}
}
-
+
List<Document> documents = tagLibraries.get(namespaceUri);
if (documents == null) {
documents = new ArrayList<Document>();
Modified: root/build/resources/trunk/faces-shade-transformers/src/test/jars/functions-ui-4.0.0-SNAPSHOT.jar
===================================================================
(Binary files differ)
14 years, 6 months
JBoss Rich Faces SVN: r17680 - root/core/trunk/impl/src/main/java/org/richfaces/jsr330.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-29 06:16:16 -0400 (Tue, 29 Jun 2010)
New Revision: 17680
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
Log:
Small fixes & generics refactoring in BinderImpl
Modified: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-28 23:35:15 UTC (rev 17679)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-29 10:16:16 UTC (rev 17680)
@@ -28,6 +28,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.inject.Provider;
@@ -55,8 +56,12 @@
public T get() {
if (!instantiated) {
- value = getProvider().get();
- instantiated = true;
+ synchronized (this) {
+ if (!instantiated) {
+ value = getProvider().get();
+ instantiated = true;
+ }
+ }
}
return value;
}
@@ -77,7 +82,7 @@
T value;
FacesContext facesContext = FacesContext.getCurrentInstance();
if (null != facesContext) {
- Map map = getMap(facesContext);
+ Map<? super String, Object> map = getMap(facesContext);
String key = target.toKey();
value = (T) map.get(key);
if (null == value) {
@@ -90,8 +95,7 @@
return value;
}
- @SuppressWarnings("unchecked")
- protected abstract Map getMap(FacesContext facesContext);
+ protected abstract Map<? super String, Object> getMap(FacesContext facesContext);
}
/**
@@ -121,8 +125,12 @@
rwLock.readLock().unlock();
rwLock.writeLock().lock();
try {
- value = getProvider().get();
- map.put(key, value);
+ //re-check the value
+ value = (T) map.get(key);
+ if (null == value) {
+ value = getProvider().get();
+ map.put(key, value);
+ }
} finally {
rwLock.readLock().lock();
rwLock.writeLock().unlock();
@@ -164,15 +172,14 @@
};
private final Scope<T> componentScope = new FacesScope() {
- @SuppressWarnings("unchecked")
@Override
protected Map<String, Object> getMap(FacesContext facesContext) {
- Map<String, Object> map =
- (Map<String, Object>) facesContext.getAttributes().get(UIComponent.CURRENT_COMPONENT);
- if (null == map) {
+ UIComponent currentComponent = UIComponentBase.getCurrentComponent(facesContext);
+ if (currentComponent == null) {
throw new DependencyException("Current component is not set for dependency target " + target.toString());
}
- return map;
+
+ return currentComponent.getAttributes();
}
};
private final Scope<T> applicationScope = new ThreadSafeFacesScope() {
@@ -184,9 +191,9 @@
private final Target target;
- private Provider<T> provider;
+ private Provider<? extends T> provider;
- private Provider<Provider<T>> providerOfProvider;
+ private Provider<Provider<? extends T>> providerOfProvider;
private Scope<T> scope;
@@ -249,10 +256,9 @@
*
* @see org.richfaces.jsr330.Binder#toProvider(java.lang.Class)
*/
- @SuppressWarnings("unchecked")
public Binder<T> toProvider(Class<? extends Provider<T>> providerImplementation) {
checkNotInitialized();
- this.providerOfProvider = new DynamicProvider(providerImplementation);
+ this.providerOfProvider = new DynamicProvider<Provider<? extends T>>(providerImplementation);
return this;
}
@@ -361,7 +367,7 @@
this.initialized = false;
}
- Provider<T> getProvider() {
+ Provider<? extends T> getProvider() {
return null == this.provider ? this.providerOfProvider.get() : this.provider;
}
14 years, 6 months
JBoss Rich Faces SVN: r17679 - in root/cdk/branches/RF8755/plugins/generator/src: main/java/org/richfaces/cdk/templatecompiler/builder/model and 5 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-28 19:35:15 -0400 (Mon, 28 Jun 2010)
New Revision: 17679
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/DummyPropertyDescriptor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELPropertyDescriptor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java
Removed:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/HelperMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstDeferredOrDynamicExpressionTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticIntegerOperationTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticOperationTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanOperationTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanResultOperationTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ITreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java
Log:
Finish EL parser refactor, started template renderer
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -2,8 +2,8 @@
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
public interface ELParser {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -59,9 +59,8 @@
import org.richfaces.cdk.templatecompiler.builder.model.StatementImpl;
import org.richfaces.cdk.templatecompiler.el.ELParserUtils;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
-import org.richfaces.cdk.templatecompiler.el.HelperMethod;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
import org.richfaces.cdk.templatecompiler.model.AnyElement;
@@ -86,6 +85,7 @@
import org.richfaces.cdk.templatecompiler.statements.EndElementStatement;
import org.richfaces.cdk.templatecompiler.statements.EqualsCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ForEachStatement;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.IfElseStatement;
@@ -149,8 +149,8 @@
private static final Set<String> DEFAULT_NAMESPACES = ImmutableSet.of(Template.XHTML_EL_NAMESPACE,
Template.XHTML_NAMESPACE);
- private static final EnumMap<HelperMethod, HelperMethodBodyStatement> HELPER_METHOD_BODIES = new EnumMap<HelperMethod, HelperMethodBodyStatement>(
- HelperMethod.class);
+ private static final EnumMap<HelperMethod, HelperMethodBodyStatement> HELPER_METHOD_BODIES =
+ new EnumMap<HelperMethod, HelperMethodBodyStatement>(HelperMethod.class);
static {
HELPER_METHOD_BODIES.put(HelperMethod.EMPTINESS_CHECK, new EmptinessCheckingMethodBodyStatement());
@@ -190,8 +190,9 @@
private void initializeJavaClass() {
this.generatedClass = new JavaClass(compositeInterface.getJavaClass());
this.generatedClass.addModifier(JavaModifier.PUBLIC);
- this.generatedClass.setSuperClass(new JavaClass(compositeInterface.getBaseClass()));
-
+ if (null != compositeInterface.getBaseClass()) {
+ this.generatedClass.setSuperClass(compositeInterface.getBaseClass());
+ }
this.generatedClass.addImport(FacesContext.class);
this.generatedClass.addImport(ResponseWriter.class);
this.generatedClass.addImport(UIComponent.class);
@@ -210,27 +211,7 @@
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);
-
- helperJavaMethod.setMethodBody(methodBodyStatement);
-
+ JavaMethod helperJavaMethod = helperMethodFactory.getHelperMethod(helperMethod);
generatedClass.addMethod(helperJavaMethod);
}
}
@@ -317,8 +298,8 @@
if (eventNames != null && !eventNames.isEmpty()) {
sb.append(".setEventNames(");
sb.append("new String[] {");
- Collection<String> eventNamesStrings = Collections2.transform(eventNames,
- new Function<EventName, String>() {
+ Collection<String> eventNamesStrings =
+ Collections2.transform(eventNames, new Function<EventName, String>() {
@Override
public String apply(EventName from) {
return from.getName();
@@ -417,7 +398,7 @@
for (HelperMethod helper : currentStatement.getRequiredMethods()) {
addHelperMethod(helper);
}
- for(JavaField field : currentStatement.getRequiredFields()){
+ for (JavaField field : currentStatement.getRequiredFields()) {
generatedClass.addField(field);
}
}
@@ -548,8 +529,8 @@
Element attributesElement = attributesSchema.getElements().get(elementName.getLocalPart());
if (attributesElement != null) {
// make a copy of original set
- TreeMap<String, Attribute> actualAttributesMap = new TreeMap<String, Attribute>(
- attributesElement.getAttributes());
+ TreeMap<String, Attribute> actualAttributesMap =
+ new TreeMap<String, Attribute>(attributesElement.getAttributes());
if (passThroughExclusions != null) {
for (String passThroughExclusion : passThroughExclusions) {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,8 +21,7 @@
package org.richfaces.cdk.templatecompiler.builder.model;
-import org.richfaces.cdk.templatecompiler.el.ELType;
-import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* Representation of method argument
@@ -56,7 +55,7 @@
@Override
- public Iterable<ELType> getRequiredImports() {
+ public Iterable<JavaImport> getRequiredImports() {
return type.getRequiredImports();
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -35,4 +35,14 @@
public String getName() {
return clazz.getName();
}
+
+ @Override
+ public boolean isDefault() {
+ if(clazz.isPrimitive()){
+ return true;
+ } else if("java.lang".equals(clazz.getPackage().getName())){
+ return true;
+ }
+ return false;
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -25,8 +25,7 @@
import java.util.Arrays;
import java.util.List;
-import org.richfaces.cdk.templatecompiler.el.ELType;
-import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* Wrapper for '@annotations
@@ -54,7 +53,7 @@
return arguments;
}
- public Iterable<ELType> getRequiredImports() {
+ public Iterable<JavaImport> getRequiredImports() {
return type.getRequiredImports();
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -27,18 +27,17 @@
import java.util.Set;
import java.util.TreeSet;
+import javax.faces.render.Renderer;
+
import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.templatecompiler.el.ELType;
-import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
- * Java Class model.
- * Intended for building java classes.
- *
+ * Java Class model. Intended for building java classes.
+ *
* @author Maksim Kaszynski
*/
public class JavaClass extends JavaLanguageElement {
- private static final ELType DEFAULT_SUPERCLASS = TypesFactory.OBJECT_TYPE;
+ private static final ClassName DEFAULT_SUPERCLASS = ClassName.get(Renderer.class);
private List<JavaField> fields = new ArrayList<JavaField>();
private List<JavaMethod> methods = new ArrayList<JavaMethod>();
private Set<JavaImport> imports = new TreeSet<JavaImport>(new Comparator<JavaImport>() {
@@ -46,24 +45,12 @@
return o1.getName().compareTo(o2.getName());
}
});
- private ELType superClass = DEFAULT_SUPERCLASS;
-
- private JavaPackage pakg;
+ private ClassName superClass = DEFAULT_SUPERCLASS;
- private String simpleName;
-
- public JavaClass() {
- super();
- }
+ private final JavaPackage pakg;
- public JavaClass(Class<?> clazz) {
- this(clazz.getSimpleName(), new JavaPackage(clazz.getPackage()));
- }
+ private final String simpleName;
- public JavaClass(String name) {
- this(getSimpleName(name), createPackage(name));
- }
-
public JavaClass(String simpleName, JavaPackage pakg) {
super(getFullName(pakg, simpleName));
this.pakg = pakg;
@@ -86,35 +73,14 @@
return fullName.toString();
}
-
- private static JavaPackage createPackage(String name) {
- int lastDotIdx = name.lastIndexOf('.');
- if (lastDotIdx != -1) {
- return new JavaPackage(name.substring(0, lastDotIdx));
- } else {
- return new JavaPackage("");
- }
- }
-
- private static String getSimpleName(String name) {
- int lastDotIdx = name.lastIndexOf('.');
- if (lastDotIdx != -1) {
- return name.substring(lastDotIdx + 1);
- } else {
- return name;
- }
- }
-
public void addImport(String name) {
- if (shouldAddToImports(name)) {
- imports.add(new RuntimeImport(name));
- }
+ addImport(new RuntimeImport(name));
}
- public void addImport(ELType javaClass) {
- addImport(javaClass.getRawName());
+ public void addImport(JavaImport javaImport) {
+ imports.add(javaImport);
}
public void addImport(Class<?> claz) {
@@ -123,12 +89,12 @@
}
}
- public void addImports(Iterable<ELType> imports) {
- for (ELType elType : imports) {
+ public void addImports(Iterable<JavaImport> imports) {
+ for (JavaImport elType : imports) {
addImport(elType);
}
}
-
+
@Override
public void addAnnotation(JavaAnnotation annotation) {
super.addAnnotation(annotation);
@@ -150,18 +116,15 @@
return pakg;
}
- public ELType getSuperClass() {
+ public ClassName getSuperClass() {
return superClass;
}
- public void setSuperClass(ELType superClass) {
+ public void setSuperClass(ClassName superClass) {
this.superClass = superClass;
- addImport(superClass.getRawName());
+ addImport(superClass.getName());
}
- public void setPackage(JavaPackage s) {
- pakg = s;
- }
public JavaPackage getPackage() {
return pakg;
@@ -182,21 +145,21 @@
public String getSimpleName() {
return simpleName;
}
-
+
private boolean shouldAddToImports(String className) {
if (className == null || className.length() == 0) {
return false;
}
-
- //default package & primitive types
+
+ // default package & primitive types
if (className.indexOf('.') == -1) {
return false;
}
-
+
if (className.matches("^java\\.lang\\.[^\\.]+$")) {
return false;
}
-
+
return true;
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,7 +21,7 @@
package org.richfaces.cdk.templatecompiler.builder.model;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import com.google.common.collect.Iterables;
@@ -61,8 +61,8 @@
}
@Override
- public Iterable<ELType> getRequiredImports() {
- Iterable<ELType> imports = super.getRequiredImports();
+ public Iterable<JavaImport> getRequiredImports() {
+ Iterable<JavaImport> imports = super.getRequiredImports();
return Iterables.concat(getType().getRequiredImports(),imports);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -26,4 +26,5 @@
*/
public interface JavaImport {
public String getName();
+ public boolean isDefault();
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -26,9 +26,6 @@
import java.util.Set;
import java.util.TreeSet;
-import org.richfaces.cdk.templatecompiler.el.ELType;
-import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
-
import com.google.common.collect.Iterables;
/**
@@ -104,8 +101,8 @@
* @see org.richfaces.cdk.templatecompiler.builder.model.RequireImports#getRequiredImports()
*/
@Override
- public Iterable<ELType> getRequiredImports(){
- Iterable<ELType> imports = Iterables.concat(Iterables.transform(getAnnotations(), RequireImports.IMPORTS_TRANSFORM));
+ public Iterable<JavaImport> getRequiredImports(){
+ Iterable<JavaImport> imports = Iterables.concat(Iterables.transform(getAnnotations(), RequireImports.IMPORTS_TRANSFORM));
return imports;
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -24,8 +24,7 @@
import java.util.Arrays;
import java.util.List;
-import org.richfaces.cdk.templatecompiler.el.ELType;
-import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import com.google.common.collect.Iterables;
@@ -47,13 +46,13 @@
public JavaMethod(String name, Argument... arguments) {
this(name);
- this.arguments = Arrays.asList(arguments);
+ this.arguments.addAll(Arrays.asList(arguments));
}
public JavaMethod(String name, ELType returnType, Argument... arguments) {
this(name);
this.returnType = returnType;
- this.arguments = Arrays.asList(arguments);
+ this.arguments.addAll(Arrays.asList(arguments));
}
public List<ELType> getExceptions() {
@@ -78,10 +77,10 @@
}
@Override
- public Iterable<ELType> getRequiredImports() {
- Iterable<ELType> exceptionsImports = Iterables.concat(Iterables.transform(getExceptions(), RequireImports.IMPORTS_TRANSFORM));
- Iterable<ELType> argumentsImports = Iterables.concat(Iterables.transform(getArguments(), RequireImports.IMPORTS_TRANSFORM));
- Iterable<ELType> imports = Iterables.concat(getReturnType().getRequiredImports(),getMethodBody().getRequiredImports(),exceptionsImports,argumentsImports);
+ public Iterable<JavaImport> getRequiredImports() {
+ Iterable<JavaImport> exceptionsImports = Iterables.concat(Iterables.transform(getExceptions(), RequireImports.IMPORTS_TRANSFORM));
+ Iterable<JavaImport> argumentsImports = Iterables.concat(Iterables.transform(getArguments(), RequireImports.IMPORTS_TRANSFORM));
+ Iterable<JavaImport> imports = Iterables.concat(getReturnType().getRequiredImports(),getMethodBody().getRequiredImports(),exceptionsImports,argumentsImports);
return imports;
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,7 +21,6 @@
*/
package org.richfaces.cdk.templatecompiler.builder.model;
-import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
/**
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java (from rev 17678, root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -0,0 +1,17 @@
+package org.richfaces.cdk.templatecompiler.builder.model;
+
+
+import com.google.common.base.Function;
+
+public interface RequireImports {
+ public static final Function<RequireImports, Iterable<JavaImport>> IMPORTS_TRANSFORM = new Function<RequireImports, Iterable<JavaImport>>() {
+
+ @Override
+ public Iterable<JavaImport> apply(RequireImports from) {
+ return from.getRequiredImports();
+ }
+ };
+
+ public Iterable<JavaImport> getRequiredImports();
+
+}
\ No newline at end of file
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -38,4 +38,18 @@
public String getName() {
return name;
}
+
+ @Override
+ public boolean isDefault() {
+ // default package & primitive types
+ if (name.indexOf('.') == -1) {
+ return true;
+ }
+
+ if (name.matches("^java\\.lang\\.[^\\.]+$")) {
+ return true;
+ }
+
+ return false;
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,7 +23,6 @@
import java.util.Collections;
-import org.richfaces.cdk.templatecompiler.el.ELType;
/**
@@ -49,7 +48,7 @@
}
@Override
- public Iterable<ELType> getRequiredImports() {
+ public Iterable<JavaImport> getRequiredImports() {
return Collections.emptySet();
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -1,7 +1,7 @@
package org.richfaces.cdk.templatecompiler.builder.model;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
public interface Variables {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -7,6 +7,7 @@
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.templatecompiler.ELParser;
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
@@ -20,12 +21,10 @@
private final TypesFactory typesFactory;
private final Logger log;
- private final ELParserUtils utils;
@Inject
- public ELParserImpl(TypesFactory typesFactory, ELParserUtils utils, Logger log) {
+ public ELParserImpl(TypesFactory typesFactory, Logger log) {
this.typesFactory = typesFactory;
- this.utils = utils;
this.log = log;
}
@@ -34,7 +33,7 @@
*/
@Override
public TypedTemplateStatement parse(String expression, Variables variables, ELType expectedType) throws ParsingException {
- ELVisitor visitor = new ELVisitor(log,typesFactory,utils);
+ ELVisitor visitor = new ELVisitor(log,typesFactory);
visitor.parse(expression, variables, expectedType);
return visitor;
}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -1,474 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.templatecompiler.el;
-
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
-
-import org.jboss.el.parser.AstAnd;
-import org.jboss.el.parser.AstBracketSuffix;
-import org.jboss.el.parser.AstChoice;
-import org.jboss.el.parser.AstDeferredExpression;
-import org.jboss.el.parser.AstDiv;
-import org.jboss.el.parser.AstDynamicExpression;
-import org.jboss.el.parser.AstEmpty;
-import org.jboss.el.parser.AstEqual;
-import org.jboss.el.parser.AstFalse;
-import org.jboss.el.parser.AstFloatingPoint;
-import org.jboss.el.parser.AstFunction;
-import org.jboss.el.parser.AstGreaterThan;
-import org.jboss.el.parser.AstGreaterThanEqual;
-import org.jboss.el.parser.AstIdentifier;
-import org.jboss.el.parser.AstInteger;
-import org.jboss.el.parser.AstLessThan;
-import org.jboss.el.parser.AstLessThanEqual;
-import org.jboss.el.parser.AstLiteralExpression;
-import org.jboss.el.parser.AstMethodSuffix;
-import org.jboss.el.parser.AstMinus;
-import org.jboss.el.parser.AstMod;
-import org.jboss.el.parser.AstMult;
-import org.jboss.el.parser.AstNegative;
-import org.jboss.el.parser.AstNot;
-import org.jboss.el.parser.AstNotEqual;
-import org.jboss.el.parser.AstNull;
-import org.jboss.el.parser.AstOr;
-import org.jboss.el.parser.AstPlus;
-import org.jboss.el.parser.AstPropertySuffix;
-import org.jboss.el.parser.AstString;
-import org.jboss.el.parser.AstTrue;
-import org.jboss.el.parser.AstValue;
-import org.jboss.el.parser.Node;
-import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.templatecompiler.el.node.AstBracketSuffixTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstChoiceTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstDeferredOrDynamicExpressionTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstEmptyTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstFloatingPointTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstFunctionTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstIdentifierTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstIntegerTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstLiteralTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstMethodSuffixTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstNegativeTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstNotTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstPropertySuffixTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstStringTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.AstValueTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.BinaryArithmeticIntegerOperationTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.BinaryArithmeticOperationTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.BinaryBooleanOperationTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.BinaryBooleanResultOperationTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.ConstantValueTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.EqualityTestTreeNode;
-import org.richfaces.cdk.templatecompiler.el.node.ITreeNode;
-import org.richfaces.cdk.templatecompiler.el.types.PlainClassType;
-import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
-
-import com.google.inject.Inject;
-import com.google.inject.internal.Maps;
-
-/**
- * Class, that encapsulate all functionality, related to Reflection calls, such as loading classes, get property
- * descriptors etc...
- *
- * @author amarkhel
- *
- */
-public final class ELParserUtils {
-
- private static final class ClassDataHolder implements ClassVisitor {
-
- private Map<String, PropertyDescriptor> resolvedProperties;
-
- private List<Method> resolvedMethods;
-
- public ClassDataHolder() {
- super();
-
- this.resolvedProperties = new HashMap<String, PropertyDescriptor>();
- this.resolvedMethods = new ArrayList<Method>();
- }
-
- public Map<String, PropertyDescriptor> getResolvedProperties() {
- return resolvedProperties;
- }
-
- public List<Method> getResolvedMethods() {
- return resolvedMethods;
- }
-
- @Override
- public void visit(Class<?> clazz) throws ParsingException {
- PropertyDescriptor[] pds;
- Method[] declaredMethods;
-
- try {
- pds = getPropertyDescriptors(clazz);
- declaredMethods = clazz.getDeclaredMethods();
- } catch (LinkageError e) {
- throw new ParsingException(e.getMessage(), e);
- }
-
- for (PropertyDescriptor descriptor : pds) {
- String descriptorName = descriptor.getName();
- if (resolvedProperties.get(descriptorName) == null) {
- resolvedProperties.put(descriptorName, descriptor);
- }
- }
-
- for (Method declaredMethod : declaredMethods) {
- resolvedMethods.add(declaredMethod);
- }
- }
- }
-
- private final Map<Class<?>, ClassDataHolder> classDataCache = Maps.newHashMap();
-
- private final TypesFactory typesFactory;
- private final Logger log;
-
- @Inject
- public ELParserUtils(Logger log, TypesFactory typesFactory) {
- this.log = log;
- this.typesFactory = typesFactory;
- }
-
- private ClassDataHolder resolveClassPropertiesAndMethods(Class<?> clazz) throws ParsingException {
- ClassDataHolder classDataHolder = classDataCache.get(clazz);
- if (classDataHolder == null) {
- classDataHolder = new ClassDataHolder();
- new ClassWalkingLogic(clazz).walk(classDataHolder);
- classDataCache.put(clazz, classDataHolder);
- }
-
- return classDataHolder;
- }
-
- /**
- * This method determine type of parsed node and create wrapper for them, that extends AbstractTreeNode. If node
- * type is not recognized - throws ParsingException.
- *
- * @param child
- * - parsed node
- * @throws ParsingException
- * - if node type is not recognized.
- * @return wrapper for parsed node(if node type is recognized), that implement ITreeNode interface.
- */
- public static ITreeNode determineNodeType(Node child) throws ParsingException {
- ITreeNode treeNode = null;
-
- if (child instanceof AstIdentifier) {
- treeNode = new AstIdentifierTreeNode(child);
- } else if (child instanceof AstValue) {
- treeNode = new AstValueTreeNode(child);
- } else if (child instanceof AstInteger) {
- treeNode = new AstIntegerTreeNode(child);
- } else if (child instanceof AstString) {
- treeNode = new AstStringTreeNode(child);
- } else if (child instanceof AstFunction) {
- treeNode = new AstFunctionTreeNode(child);
- } else if (child instanceof AstDeferredExpression || child instanceof AstDynamicExpression) {
- treeNode = new AstDeferredOrDynamicExpressionTreeNode(child);
- } else if (child instanceof AstNot) {
- treeNode = new AstNotTreeNode(child);
- } else if (child instanceof AstChoice) {
- treeNode = new AstChoiceTreeNode(child);
- } else if (child instanceof AstEmpty) {
- treeNode = new AstEmptyTreeNode(child);
- } else if (child instanceof AstLiteralExpression) {
- treeNode = new AstLiteralTreeNode(child);
- } else if (child instanceof AstFalse) {
- treeNode = ConstantValueTreeNode.FALSE_NODE;
- } else if (child instanceof AstTrue) {
- treeNode = ConstantValueTreeNode.TRUE_NODE;
- } else if (child instanceof AstNull) {
- treeNode = ConstantValueTreeNode.NULL_NODE;
- } else if (child instanceof AstAnd) {
- treeNode = new BinaryBooleanOperationTreeNode(child, ELNodeConstants.AND_OPERATOR);
- } else if (child instanceof AstEqual) {
- treeNode = new EqualityTestTreeNode(child);
- } else if (child instanceof AstGreaterThan) {
- treeNode = new BinaryBooleanResultOperationTreeNode(child, ELNodeConstants.GREATER_THEN_OPERATOR);
- } else if (child instanceof AstGreaterThanEqual) {
- treeNode = new BinaryBooleanResultOperationTreeNode(child, ELNodeConstants.GREATER_THEN_OR_EQUALITY_OPERATOR);
- } else if (child instanceof AstLessThan) {
- treeNode = new BinaryBooleanResultOperationTreeNode(child, ELNodeConstants.LESS_THEN_OPERATOR);
- } else if (child instanceof AstLessThanEqual) {
- 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) {
- treeNode = new BinaryBooleanOperationTreeNode(child, ELNodeConstants.OR_OPERATOR);
- } else if (child instanceof AstDiv) {
- treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.DIV_OPERATOR);
- } else if (child instanceof AstMult) {
- treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.MULT_OPERATOR);
- } else if (child instanceof AstMod) {
- treeNode = new BinaryArithmeticIntegerOperationTreeNode(child, ELNodeConstants.MOD_OPERATOR);
- } else if (child instanceof AstPlus) {
- treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.PLUS_OPERATOR);
- } else if (child instanceof AstMinus) {
- treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.MINUS_OPERATOR);
- } else if (child instanceof AstBracketSuffix) {
- treeNode = new AstBracketSuffixTreeNode(child);
- } else if (child instanceof AstNegative) {
- treeNode = new AstNegativeTreeNode(child);
- } else if (child instanceof AstFloatingPoint) {
- treeNode = new AstFloatingPointTreeNode(child);
- } else if (child instanceof AstMethodSuffix) {
- treeNode = new AstMethodSuffixTreeNode(child);
- } else if (child instanceof AstPropertySuffix) {
- treeNode = new AstPropertySuffixTreeNode(child);
- } else {
- throw new ParsingException("Node " + child.getClass().getSimpleName() + "[" + child.getImage()
- + "] is not recognized;");
- }
-
- return treeNode;
- }
-
- /**
- * This method return PropertyDescriptor by specified propertyName and clazz.
- *
- * @param elType
- * - class to search
- * @param propertyName
- * - propertyName to search
- * @return property descriptor if found.
- * @throws ParsingException
- * if error occured.
- */
- public PropertyDescriptor getPropertyDescriptor(ELType elType, String propertyName) throws ParsingException {
-
- if (elType == null) {
- return null;
- }
-
- ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(getClassFromType(elType));
- return classDataHolder.getResolvedProperties().get(propertyName);
- }
-
- /**
- * <p>
- * Retrieve the property descriptors for the specified class, introspecting and caching them the first time a
- * particular bean class is encountered.
- * </p>
- *
- * <p>
- * <strong>FIXME</strong> - Does not work with DynaBeans.
- * </p>
- *
- * @param beanClass
- * Bean class for which property descriptors are requested
- * @return the property descriptors
- * @throws ParsingException
- * if error occured.
- *
- * @exception IllegalArgumentException
- * if <code>beanClass</code> is null
- */
- private static PropertyDescriptor[] getPropertyDescriptors(Class<?> beanClass) throws ParsingException {
- if (beanClass == null) {
- throw new IllegalArgumentException("No bean class specified");
- }
-
- // Look up any cached descriptors for this bean class
- PropertyDescriptor[] descriptors = null;
-
- // Introspect the bean and cache the generated descriptors
- BeanInfo beanInfo = null;
-
- try {
- beanInfo = Introspector.getBeanInfo(beanClass);
- descriptors = beanInfo.getPropertyDescriptors();
- } catch (IntrospectionException e) {
- return new PropertyDescriptor[0];
- }
-
- if (descriptors == null) {
- descriptors = new PropertyDescriptor[0];
- }
-
- return descriptors;
- }
-
- private static boolean isMethodVisible(Method method) {
- return !Modifier.isPrivate(method.getModifiers());
- }
-
-
- private Class<?> getClassFromType(ELType elType) {
- if (elType == null && !(elType instanceof PlainClassType)) {
- return Object.class;
- }
-
- Class<?> clazz = ((PlainClassType) elType).getPlainJavaClass();
- return clazz;
- }
- /**
- * <p>
- * Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean
- * that every method parameter is assignable from the given parameters. In other words, it finds a method with the
- * given name that will take the parameters given.
- * <p>
- *
- * <p>
- * This method is slightly undeterminstic since it loops through methods names and return the first matching method.
- * </p>
- *
- * <p>
- * This method is used by {@link #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}.
- *
- * <p>
- * This method can match primitive parameter by passing in wrapper classes. For example, a <code>Boolean</code> will
- * match a primitive <code>boolean</code> parameter.
- *
- * @param elType
- * find method in this class
- * @param methodName
- * find method with this name
- * @param parameterTypes
- * find method with compatible parameters
- * @return The accessible method
- * @throws ParsingException
- * if error occured.
- */
- public ELType getMatchingVisibleMethodReturnType(ELType elType, final String methodName, ELType[] parameterTypes)
- throws ParsingException {
-
- ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(getClassFromType(elType));
- List<Method> resolvedMethods = classDataHolder.getResolvedMethods();
-
- // search through all methods
- int paramSize = parameterTypes.length;
- Method bestMatch = null;
-
- for (Method resolvedMethod : resolvedMethods) {
- if (!isMethodVisible(resolvedMethod)) {
- continue;
- }
-
- if (!resolvedMethod.getName().equals(methodName)) {
- continue;
- }
-
- // compare parameters
- ELType[] methodsParams = typesFactory.getTypesArray(resolvedMethod.getParameterTypes());
- int methodParamSize = methodsParams.length;
-
- if (methodParamSize == paramSize) {
- boolean match = true;
-
- for (int n = 0; n < methodParamSize; n++) {
- if (!methodsParams[n].isAssignableFrom(parameterTypes[n])) {
- match = false;
-
- break;
- }
- }
-
- if (match) {
- if (bestMatch == null) {
- bestMatch = resolvedMethod;
- } else {
- throw new ParsingException(
- "Detected two methods with the alike signature, not able to select the appropriate one: "
- + resolvedMethod.toString() + " " + bestMatch.toString());
- }
- }
- }
- }
-
- if (bestMatch != null) {
- return typesFactory.getType(bestMatch.getGenericReturnType());
- } else {
- return TypesFactory.OBJECT_TYPE;
- }
- }
-
- interface ClassVisitor {
- public void visit(Class<?> clazz) throws ParsingException;
- }
-
- static class ClassWalkingLogic {
-
- private Queue<Class<?>> classesList = new LinkedList<Class<?>>();
-
- private Set<Class<?>> visitedClasses = new HashSet<Class<?>>();
-
- public ClassWalkingLogic(Class<?> clazz) {
- super();
- this.classesList.add(clazz);
- }
-
- public void walk(ClassVisitor visitor) throws ParsingException {
- // BFS algorithm
- while (!classesList.isEmpty()) {
- Class<?> clazz = classesList.remove();
-
- if (visitedClasses.add(clazz)) {
- visitor.visit(clazz);
-
- Class<?> superclass = clazz.getSuperclass();
- if (superclass != null) {
- if (!visitedClasses.contains(superclass)) {
- classesList.add(superclass);
- }
- }
-
- Class<?>[] interfaces = clazz.getInterfaces();
- if (interfaces != null) {
- for (Class<?> iface : interfaces) {
- if (!visitedClasses.contains(iface)) {
- classesList.add(iface);
- }
- }
- }
- }
- }
-
- // While interfaces do not have Object.class in their hierarchy directly,
- // implementations of interface are always inherited from Object.
- // As methods in this class are primarily designed to work with implementations (beans),
- // we are adding Object.class explicitly if it hasn't been visited yet.
- if (visitedClasses.add(Object.class)) {
- visitor.visit(Object.class);
- }
-
- visitedClasses.clear();
- }
- }
-
-
-}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -1,51 +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.el;
-
-import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
-
-/**
- * This class represents abstraction from concrete Java classes, used by EL compiler or template generator.
- * @author Nick Belaevski
- *
- */
-//TODO unit-test thoroughly all implementations of this interface
-public interface ELType extends RequireImports {
-
- public String getCode();
-
- public String getRawName();
-
- public boolean isNullType();
-
- public boolean isArray();
-
- public ELType getRawType();
-
- public ELType getContainerType();
-
- public ELType[] getTypeArguments();
-
- public boolean isAssignableFrom(ELType anotherType);
-
- public boolean isPrimitive();
-}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,24 +21,79 @@
package org.richfaces.cdk.templatecompiler.el;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.*;
+import static org.richfaces.cdk.templatecompiler.statements.HelperMethod.*;
import static org.richfaces.cdk.util.JavaUtils.*;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Type;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
+import org.jboss.el.parser.AstAnd;
+import org.jboss.el.parser.AstBracketSuffix;
+import org.jboss.el.parser.AstChoice;
import org.jboss.el.parser.AstCompositeExpression;
+import org.jboss.el.parser.AstDeferredExpression;
+import org.jboss.el.parser.AstDiv;
+import org.jboss.el.parser.AstDynamicExpression;
+import org.jboss.el.parser.AstEmpty;
+import org.jboss.el.parser.AstEqual;
+import org.jboss.el.parser.AstFalse;
+import org.jboss.el.parser.AstFloatingPoint;
+import org.jboss.el.parser.AstFunction;
+import org.jboss.el.parser.AstGreaterThan;
+import org.jboss.el.parser.AstGreaterThanEqual;
+import org.jboss.el.parser.AstIdentifier;
+import org.jboss.el.parser.AstInteger;
+import org.jboss.el.parser.AstLessThan;
+import org.jboss.el.parser.AstLessThanEqual;
+import org.jboss.el.parser.AstLiteralExpression;
+import org.jboss.el.parser.AstMethodSuffix;
+import org.jboss.el.parser.AstMinus;
+import org.jboss.el.parser.AstMod;
+import org.jboss.el.parser.AstMult;
+import org.jboss.el.parser.AstNegative;
+import org.jboss.el.parser.AstNot;
+import org.jboss.el.parser.AstNotEqual;
+import org.jboss.el.parser.AstNull;
+import org.jboss.el.parser.AstOr;
+import org.jboss.el.parser.AstPlus;
+import org.jboss.el.parser.AstPropertySuffix;
+import org.jboss.el.parser.AstString;
+import org.jboss.el.parser.AstTrue;
+import org.jboss.el.parser.AstValue;
import org.jboss.el.parser.ELParser;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
+import org.richfaces.cdk.templatecompiler.el.node.AstBracketSuffixTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstChoiceTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstDeferredOrDynamicExpressionTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstEmptyTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstFloatingPointTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstFunctionTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstIdentifierTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstIntegerTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstLiteralTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstMethodSuffixTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstNegativeTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstNotTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstPropertySuffixTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstStringTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.AstValueTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.BinaryArithmeticIntegerOperationTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.BinaryArithmeticOperationTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.BinaryBooleanOperationTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.BinaryBooleanResultOperationTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.ConstantValueTreeNode;
+import org.richfaces.cdk.templatecompiler.el.node.EqualityTestTreeNode;
import org.richfaces.cdk.templatecompiler.el.node.ITreeNode;
+import org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
/**
* Entry point for parsing EL expressions. @see parse() method.
@@ -59,15 +114,12 @@
private final TypesFactory typesFactory;
- private final ELParserUtils utils;
-
private boolean mixedExpression;
- public ELVisitor(Logger log, TypesFactory typesFactory, ELParserUtils utils) {
+ public ELVisitor(Logger log, TypesFactory typesFactory) {
this.log = log;
this.typesFactory = typesFactory;
- this.utils = utils;
}
@@ -150,7 +202,7 @@
for (int i = 0; i < numChildren; i++) {
Node child = node.jjtGetChild(i);
- ITreeNode treeNode = ELParserUtils.determineNodeType(child);
+ ITreeNode treeNode = determineNodeType(child);
treeNode.visit(sb, this);
@@ -175,8 +227,8 @@
}
@Override
- public Iterable<ELType> getRequiredImports() {
- return Collections.singleton(getExpressionType());
+ public Iterable<JavaImport> getRequiredImports() {
+ return getExpressionType().getRequiredImports();
}
@Override
@@ -192,22 +244,101 @@
public ELType getMatchingVisibleMethodReturnType(String methodName, ELType[] parameterTypes) throws ParsingException {
- return utils.getMatchingVisibleMethodReturnType(getExpressionType().getRawType(), methodName, parameterTypes);
+ return typesFactory.getMatchingVisibleMethodReturnType(getExpressionType(), methodName, parameterTypes);
}
- public PropertyDescriptor getPropertyDescriptor(String propertyName) throws ParsingException {
- return utils.getPropertyDescriptor(getExpressionType().getRawType(), propertyName);
+ public ELPropertyDescriptor getPropertyDescriptor(String propertyName) throws ParsingException {
+ return typesFactory.getPropertyDescriptor(getExpressionType(), propertyName);
}
- public ELType getType(Type genericReturnType) {
- return typesFactory.getType(genericReturnType);
+ public void addHelperMethods(HelperMethod helper) {
+ usedHelperMethods.add(helper);
}
- public void addHelperMethods(HelperMethod helper) {
- usedHelperMethods.add(helper);
+ /**
+ * This method determine type of parsed node and create wrapper for them, that extends AbstractTreeNode. If node
+ * type is not recognized - throws ParsingException.
+ *
+ * @param child
+ * - parsed node
+ * @throws ParsingException
+ * - if node type is not recognized.
+ * @return wrapper for parsed node(if node type is recognized), that implement ITreeNode interface.
+ */
+ public ITreeNode determineNodeType(Node child) throws ParsingException {
+ ITreeNode treeNode = null;
+
+ if (child instanceof AstIdentifier) {
+ treeNode = new AstIdentifierTreeNode(child);
+ } else if (child instanceof AstValue) {
+ treeNode = new AstValueTreeNode(child);
+ } else if (child instanceof AstInteger) {
+ treeNode = new AstIntegerTreeNode(child);
+ } else if (child instanceof AstString) {
+ treeNode = new AstStringTreeNode(child);
+ } else if (child instanceof AstFunction) {
+ treeNode = new AstFunctionTreeNode(child);
+ } else if (child instanceof AstDeferredExpression || child instanceof AstDynamicExpression) {
+ treeNode = new AstDeferredOrDynamicExpressionTreeNode(child);
+ } else if (child instanceof AstNot) {
+ treeNode = new AstNotTreeNode(child);
+ } else if (child instanceof AstChoice) {
+ treeNode = new AstChoiceTreeNode(child);
+ } else if (child instanceof AstEmpty) {
+ treeNode = new AstEmptyTreeNode(child);
+ } else if (child instanceof AstLiteralExpression) {
+ treeNode = new AstLiteralTreeNode(child);
+ } else if (child instanceof AstFalse) {
+ treeNode = ConstantValueTreeNode.FALSE_NODE;
+ } else if (child instanceof AstTrue) {
+ treeNode = ConstantValueTreeNode.TRUE_NODE;
+ } else if (child instanceof AstNull) {
+ treeNode = ConstantValueTreeNode.NULL_NODE;
+ } else if (child instanceof AstAnd) {
+ treeNode = new BinaryBooleanOperationTreeNode(child, ELNodeConstants.AND_OPERATOR);
+ } else if (child instanceof AstEqual) {
+ treeNode = new EqualityTestTreeNode(child);
+ } else if (child instanceof AstGreaterThan) {
+ treeNode = new BinaryBooleanResultOperationTreeNode(child, ELNodeConstants.GREATER_THEN_OPERATOR);
+ } else if (child instanceof AstGreaterThanEqual) {
+ treeNode = new BinaryBooleanResultOperationTreeNode(child, ELNodeConstants.GREATER_THEN_OR_EQUALITY_OPERATOR);
+ } else if (child instanceof AstLessThan) {
+ treeNode = new BinaryBooleanResultOperationTreeNode(child, ELNodeConstants.LESS_THEN_OPERATOR);
+ } else if (child instanceof AstLessThanEqual) {
+ 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) {
+ treeNode = new BinaryBooleanOperationTreeNode(child, ELNodeConstants.OR_OPERATOR);
+ } else if (child instanceof AstDiv) {
+ treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.DIV_OPERATOR);
+ } else if (child instanceof AstMult) {
+ treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.MULT_OPERATOR);
+ } else if (child instanceof AstMod) {
+ treeNode = new BinaryArithmeticIntegerOperationTreeNode(child, ELNodeConstants.MOD_OPERATOR);
+ } else if (child instanceof AstPlus) {
+ treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.PLUS_OPERATOR);
+ } else if (child instanceof AstMinus) {
+ treeNode = new BinaryArithmeticOperationTreeNode(child, ELNodeConstants.MINUS_OPERATOR);
+ } else if (child instanceof AstBracketSuffix) {
+ treeNode = new AstBracketSuffixTreeNode(child);
+ } else if (child instanceof AstNegative) {
+ treeNode = new AstNegativeTreeNode(child);
+ } else if (child instanceof AstFloatingPoint) {
+ treeNode = new AstFloatingPointTreeNode(child);
+ } else if (child instanceof AstMethodSuffix) {
+ treeNode = new AstMethodSuffixTreeNode(child);
+ } else if (child instanceof AstPropertySuffix) {
+ treeNode = new AstPropertySuffixTreeNode(child);
+ } else {
+ throw new ParsingException("Node " + child.getClass().getSimpleName() + "[" + child.getImage()
+ + "] is not recognized;");
+ }
+
+ return treeNode;
}
}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/HelperMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/HelperMethod.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/HelperMethod.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -1,69 +0,0 @@
-/*
- * 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.el;
-
-import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.*;
-
-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/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -25,7 +25,7 @@
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* <p>
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -26,9 +26,9 @@
import org.jboss.el.parser.Node;
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -22,7 +22,6 @@
package org.richfaces.cdk.templatecompiler.el.node;
import org.jboss.el.parser.Node;
-import org.richfaces.cdk.templatecompiler.el.ELParserUtils;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
@@ -54,7 +53,7 @@
throws ParsingException {
StringBuilder sb = new StringBuilder();
- getChild(childIndex).visit(sb, visitor);
+ getChild(childIndex, visitor).visit(sb, visitor);
return sb.toString();
}
@@ -75,23 +74,23 @@
/**
* 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
+ *
* @throws ParsingException
* - if error occurred during parsing process.
* @return instance of org.jboss.el.parser.Node
*
*/
- public ITreeNode getChild(int index) throws ParsingException {
+ public ITreeNode getChild(int index, ELVisitor visitor) throws ParsingException {
Node childNode = getNode().jjtGetChild(index);
if (null != childNode) {
- ITreeNode treeNode = ELParserUtils.determineNodeType(childNode);
+ ITreeNode treeNode = visitor.determineNodeType(childNode);
return treeNode;
} else {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -24,9 +24,9 @@
import org.jboss.el.parser.Node;
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -28,7 +28,7 @@
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* This class extend AbstractTreeNode and wrap AstChoice node.
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstDeferredOrDynamicExpressionTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstDeferredOrDynamicExpressionTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstDeferredOrDynamicExpressionTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -48,7 +48,7 @@
sb.append(ELNodeConstants.LEFT_BRACKET);
}
- ITreeNode treeNode = getChild(i);
+ ITreeNode treeNode = getChild(i, visitor);
treeNode.visit(sb, visitor);
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstEmptyTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,7 +23,7 @@
package org.richfaces.cdk.templatecompiler.el.node;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.EMPTINESS_CHECK;
+import static org.richfaces.cdk.templatecompiler.statements.HelperMethod.*;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -27,7 +27,7 @@
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.util.Strings;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstIdentifierTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -25,7 +25,7 @@
import org.jboss.el.parser.Node;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* This class extend AbstractTreeNode and wrap AstIdentifier node.
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstPropertySuffixTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,19 +21,16 @@
package org.richfaces.cdk.templatecompiler.el.node;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-
import org.jboss.el.parser.Node;
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* This class extend AbstractTreeNode and wrap AstPropertySuffix node.
- *
+ *
* @author amarkhel
*/
public class AstPropertySuffixTreeNode extends AbstractTreeNode {
@@ -42,43 +39,16 @@
super(node);
}
- private String capitalize(String propertyName) {
- char[] chars = propertyName.toCharArray();
- chars[0] = Character.toUpperCase(chars[0]);
- return new String(chars);
- }
-
- private Method getReadMethod(ELVisitor visitor, String propertyName) {
- PropertyDescriptor propertyDescriptor = null;
- try {
- propertyDescriptor = visitor.getPropertyDescriptor(propertyName);
- } catch (ParsingException e) {
- // TODO: handle exception
- }
-
- if (propertyDescriptor == null) {
- return null;
- }
-
- return propertyDescriptor.getReadMethod();
- }
-
@Override
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
String propertyName = getNode().getImage();
String readMethodName;
ELType readMethodReturnType;
+ ELPropertyDescriptor propertyDescriptor = visitor.getPropertyDescriptor(propertyName);
+ readMethodName = propertyDescriptor.getReadMethodName();
+ readMethodReturnType = propertyDescriptor.getType();
- Method readMethod = getReadMethod(visitor, propertyName);
- if (readMethod != null) {
- readMethodName = readMethod.getName();
- readMethodReturnType = visitor.getType(readMethod.getGenericReturnType());
- } else {
- readMethodName = ELNodeConstants.GETTER_PREFIX + capitalize(propertyName);
- readMethodReturnType = TypesFactory.OBJECT_TYPE;
- }
-
visitor.setExpressionType(readMethodReturnType);
sb.append(ELNodeConstants.DOT);
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticIntegerOperationTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticIntegerOperationTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticIntegerOperationTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,9 +23,9 @@
import org.jboss.el.parser.Node;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticOperationTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticOperationTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryArithmeticOperationTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -22,9 +22,9 @@
package org.richfaces.cdk.templatecompiler.el.node;
import org.jboss.el.parser.Node;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanOperationTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanOperationTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanOperationTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -22,9 +22,9 @@
package org.richfaces.cdk.templatecompiler.el.node;
import org.jboss.el.parser.Node;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanResultOperationTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanResultOperationTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/BinaryBooleanResultOperationTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -22,9 +22,9 @@
package org.richfaces.cdk.templatecompiler.el.node;
import org.jboss.el.parser.Node;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ConstantValueTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,9 +23,9 @@
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.NullType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,13 +21,13 @@
*/
package org.richfaces.cdk.templatecompiler.el.node;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.EQUALS_CHECK;
+import static org.richfaces.cdk.templatecompiler.statements.HelperMethod.*;
import org.jboss.el.parser.Node;
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ITreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ITreeNode.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/ITreeNode.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -54,10 +54,11 @@
* Return child of wrapped node by specified index
*
* @param index - index of child.
+ * @param visitor TODO
* @return wrapper for child
* @throws ParsingException - if error occurred(child not found).
*/
- ITreeNode getChild(int index) throws ParsingException;
+ ITreeNode getChild(int index, ELVisitor visitor) throws ParsingException;
/**
* Returns count of children for this node
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -24,7 +24,8 @@
import java.util.Arrays;
import java.util.Set;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.RequireImports;
import org.richfaces.cdk.util.ArrayUtils;
import com.google.common.collect.Iterables;
@@ -56,9 +57,9 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsList()
*/
@Override
- public Iterable<ELType> getRequiredImports() {
- Iterable<ELType> imports = Iterables.concat(Iterables.transform(Arrays.asList(typeArguments), RequireImports.IMPORTS_TRANSFORM));
- Set<ELType> result = Sets.newLinkedHashSet(Iterables.concat(clearComponentType.getRequiredImports(),imports));
+ public Iterable<JavaImport> getRequiredImports() {
+ Iterable<JavaImport> imports = Iterables.concat(Iterables.transform(Arrays.asList(typeArguments), RequireImports.IMPORTS_TRANSFORM));
+ Set<JavaImport> result = Sets.newLinkedHashSet(Iterables.concat(clearComponentType.getRequiredImports(),imports));
return result;
}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/DummyPropertyDescriptor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/DummyPropertyDescriptor.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/DummyPropertyDescriptor.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -0,0 +1,94 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.el.types;
+
+import org.richfaces.cdk.util.Strings;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class DummyPropertyDescriptor implements ELPropertyDescriptor {
+
+ private final String propertyName;
+ private final String getterName;
+ private final String setterName;
+
+ public DummyPropertyDescriptor(String propertyName) {
+ this.propertyName = propertyName;
+ String firstToUpperCase = Strings.firstToUpperCase(propertyName);
+ this.getterName = "get"+firstToUpperCase;
+ this.setterName = "set"+firstToUpperCase;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor#getName()
+ */
+ @Override
+ public String getName() {
+ return propertyName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor#getType()
+ */
+ @Override
+ public ELType getType() {
+ return TypesFactory.OBJECT_TYPE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor#isReadable()
+ */
+ @Override
+ public boolean isReadable() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor#isWritable()
+ */
+ @Override
+ public boolean isWritable() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor#getReadMethodName()
+ */
+ @Override
+ public String getReadMethodName() {
+ return getterName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor#getWriteMethosName()
+ */
+ @Override
+ public String getWriteMethosName() {
+ return setterName;
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/DummyPropertyDescriptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELPropertyDescriptor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELPropertyDescriptor.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELPropertyDescriptor.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -0,0 +1,46 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.el.types;
+
+
+/**
+ * <p class="changed_added_4_0">Simplified version of JavaBean property descriptor, used by EL-parser.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface ELPropertyDescriptor {
+
+ String getName();
+
+ ELType getType();
+
+ boolean isReadable();
+
+ boolean isWritable();
+
+ String getReadMethodName();
+
+ String getWriteMethosName();
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELPropertyDescriptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELType.java (from rev 17678, root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELType.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELType.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -0,0 +1,51 @@
+/*
+ * 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.el.types;
+
+import org.richfaces.cdk.templatecompiler.builder.model.RequireImports;
+
+/**
+ * This class represents abstraction from concrete Java classes, used by EL compiler or template generator.
+ * @author Nick Belaevski
+ *
+ */
+//TODO unit-test thoroughly all implementations of this interface
+public interface ELType extends RequireImports {
+
+ public String getCode();
+
+ public String getRawName();
+
+ public boolean isNullType();
+
+ public boolean isArray();
+
+ public ELType getRawType();
+
+ public ELType getContainerType();
+
+ public ELType[] getTypeArguments();
+
+ public boolean isAssignableFrom(ELType anotherType);
+
+ public boolean isPrimitive();
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ELType.java
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,10 +21,9 @@
*/
package org.richfaces.cdk.templatecompiler.el.types;
-import java.util.Collection;
import java.util.Collections;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
/**
* @author Nick Belaevski
@@ -53,7 +52,7 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsIterator()
*/
@Override
- public Collection<ELType> getRequiredImports() {
+ public Iterable<JavaImport> getRequiredImports() {
return Collections.emptyList();
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -22,10 +22,11 @@
package org.richfaces.cdk.templatecompiler.el.types;
import java.text.MessageFormat;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Set;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.builder.model.ClassImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
/**
* @author Nick Belaevski
@@ -37,6 +38,8 @@
private final Class<?> clazz;
+ private final Set<JavaImport> imports;
+
public PlainClassType(Class<?> clazz) {
super();
@@ -45,6 +48,7 @@
}
this.clazz = clazz;
+ this.imports = Collections.<JavaImport>singleton(new ClassImport(clazz));
}
public Class<?> getPlainJavaClass(){
@@ -68,8 +72,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsIterator()
*/
@Override
- public Collection<ELType> getRequiredImports() {
- return Collections.<ELType>singleton(this);
+ public Iterable<JavaImport> getRequiredImports() {
+ return imports;
}
/* (non-Javadoc)
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -22,10 +22,9 @@
package org.richfaces.cdk.templatecompiler.el.types;
import java.text.MessageFormat;
-import java.util.Collection;
import java.util.Collections;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
/**
* @author Nick Belaevski
@@ -57,7 +56,7 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsList()
*/
@Override
- public Collection<ELType> getRequiredImports() {
+ public Iterable<JavaImport> getRequiredImports() {
return Collections.emptyList();
}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -1,18 +0,0 @@
-package org.richfaces.cdk.templatecompiler.el.types;
-
-import org.richfaces.cdk.templatecompiler.el.ELType;
-
-import com.google.common.base.Function;
-
-public interface RequireImports {
- public static final Function<RequireImports, Iterable<ELType>> IMPORTS_TRANSFORM = new Function<RequireImports, Iterable<ELType>>() {
-
- @Override
- public Iterable<ELType> apply(RequireImports from) {
- return from.getRequiredImports();
- }
- };
-
- public Iterable<ELType> getRequiredImports();
-
-}
\ No newline at end of file
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.el.types;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
/**
* @author Nick Belaevski
@@ -38,10 +38,62 @@
ELType INT_TYPE = new PlainClassType(Integer.TYPE);
ELType VOID_TYPE = new PlainClassType(Void.TYPE);
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param typeString
+ * @return
+ */
ELType getType(String typeString);
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param reflectionType
+ * @return
+ */
ELType getType(java.lang.reflect.Type reflectionType);
- ELType[] getTypesArray(java.lang.reflect.Type[] reflectionTypes);
-
+ /**
+ * <p>
+ * Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean
+ * that every method parameter is assignable from the given parameters. In other words, it finds a method with the
+ * given name that will take the parameters given.
+ * <p>
+ *
+ * <p>
+ * This method is slightly undeterminstic since it loops through methods names and return the first matching method.
+ * </p>
+ *
+ * <p>
+ * This method is used by {@link #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}.
+ *
+ * <p>
+ * This method can match primitive parameter by passing in wrapper classes. For example, a <code>Boolean</code> will
+ * match a primitive <code>boolean</code> parameter.
+ *
+ * @param elType
+ * find method in this class
+ * @param methodName
+ * find method with this name
+ * @param parameterTypes
+ * find method with compatible parameters
+ * @return The accessible method
+ * @throws ParsingException
+ * if error occured.
+ */
+ ELType getMatchingVisibleMethodReturnType(ELType elType, final String methodName, ELType...parameterTypes )
+ throws ParsingException ;
+
+ /**
+ * This method return PropertyDescriptor by specified propertyName and clazz.
+ *
+ * @param elType
+ * - class to search
+ * @param propertyName
+ * - propertyName to search
+ * @return property descriptor if found.
+ * @throws ParsingException
+ * if error occured.
+ */
+ ELPropertyDescriptor getPropertyDescriptor(ELType type, String name) throws ParsingException;
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,11 +21,24 @@
*/
package org.richfaces.cdk.templatecompiler.el.types;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.text.MessageFormat;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -42,7 +55,7 @@
import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.util.ArrayUtils;
import com.google.common.base.Function;
@@ -51,6 +64,8 @@
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.google.inject.Inject;
/**
@@ -59,6 +74,8 @@
*/
public final class TypesFactoryImpl implements TypesFactory {
+ static final PropertyDescriptor[] EMPTY_PROPERTY_DESCRIPTORS = new PropertyDescriptor[0];
+
static final ImmutableMap<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_CLASSES_MAP = ImmutableMap
.<Class<?>, Class<?>> builder().put(Boolean.TYPE, Boolean.class).put(Float.TYPE, Float.class)
.put(Long.TYPE, Long.class).put(Integer.TYPE, Integer.class).put(Short.TYPE, Short.class)
@@ -99,17 +116,19 @@
private static final ImmutableCollection<String> GUESS_PACKAGES = ImmutableSet.<String> copyOf(Iterables.transform(
ImmutableSet.<Class<?>> of(UIComponent.class, Behavior.class, Converter.class, Validator.class,
FacesContext.class, Application.class, FacesEvent.class, DataModel.class, Renderer.class, Collection.class,
- Object.class), PACKAGE_NAME_FUNCTION
- ));
+ Object.class), PACKAGE_NAME_FUNCTION));
private final ClassLoader classLoader;
private final Logger log;
- private final Map<java.lang.reflect.Type, ELType> reflectionTypesCache = new ConcurrentHashMap<java.lang.reflect.Type, ELType>();
+ private final Map<java.lang.reflect.Type, ELType> reflectionTypesCache =
+ new ConcurrentHashMap<java.lang.reflect.Type, ELType>();
private final Map<String, ELType> refferencedTypesCache = new ConcurrentHashMap<String, ELType>();
+ private final Map<Class<?>, ClassDataHolder> classDataCache = Maps.newHashMap();
+
@Inject
public TypesFactoryImpl(Logger log, CdkClassLoader classLoader) {
this.log = log;
@@ -165,8 +184,8 @@
// initialize = false here for the same reason as already mentioned for the previous load block
result = Class.forName(className, false, classLoader);
} catch (LinkageError e) {
- String errorMessage = MessageFormat.format("Class {0} couldn''t be loaded because of: {1}", className,
- e.getMessage());
+ String errorMessage =
+ MessageFormat.format("Class {0} couldn''t be loaded because of: {1}", className, e.getMessage());
if (log.isInfoEnabled()) {
log.info(errorMessage);
}
@@ -179,7 +198,7 @@
ELType[] parseTypeArgumentsString(String typeArguments) {
if (typeArguments == null) {
- return null;
+ return PlainClassType.NO_TYPES;
}
String[] typeArgumentsSplit = typeArguments.trim().split(",");
@@ -263,7 +282,7 @@
rawType = rawType.getComponentType();
}
- ELType[] typeArguments = null;
+ ELType[] typeArguments = PlainClassType.NO_TYPES;
if (!ArrayUtils.isEmpty(actualTypeArguments)) {
typeArguments = getTypesArray(actualTypeArguments);
}
@@ -296,13 +315,7 @@
return result;
}
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.cdk.templatecompiler.el.types.TypesFactory#getTypesArray(java.lang.reflect.Type[])
- */
- @Override
- public ELType[] getTypesArray(java.lang.reflect.Type[] reflectionTypes) {
+ private ELType[] getTypesArray(java.lang.reflect.Type[] reflectionTypes) {
ELType[] types = new ELType[reflectionTypes.length];
for (int i = 0; i < reflectionTypes.length; i++) {
types[i] = getType(reflectionTypes[i]);
@@ -325,4 +338,330 @@
}
}
+ private static final class JavaELPropertyDescriptor implements ELPropertyDescriptor {
+
+ private final PropertyDescriptor descriptor;
+ private final String descriptorName;
+ private final ELType propertyType;
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param descriptor
+ * @param propertyType
+ * @param descriptorName
+ */
+ public JavaELPropertyDescriptor(PropertyDescriptor descriptor, ELType propertyType) {
+ this.descriptor = descriptor;
+ this.propertyType = propertyType;
+ this.descriptorName = descriptor.getName();
+ }
+
+ @Override
+ public boolean isWritable() {
+ return null != descriptor.getWriteMethod();
+ }
+
+ @Override
+ public boolean isReadable() {
+ return null != descriptor.getReadMethod();
+ }
+
+ @Override
+ public String getWriteMethosName() {
+ return descriptor.getWriteMethod().getName();
+ }
+
+ @Override
+ public ELType getType() {
+ return propertyType;
+ }
+
+ @Override
+ public String getReadMethodName() {
+ return descriptor.getReadMethod().getName();
+ }
+
+ @Override
+ public String getName() {
+ return descriptorName;
+ }
+ }
+
+ private static final class ClassDataHolder implements ClassVisitor {
+
+ private Map<String, ELPropertyDescriptor> resolvedProperties;
+
+ private List<Method> resolvedMethods;
+
+ private final TypesFactory typesFactory;
+
+ public ClassDataHolder(TypesFactory typesFactory) {
+ super();
+ this.typesFactory = typesFactory;
+
+ this.resolvedProperties = Maps.newHashMap();
+ this.resolvedMethods = Lists.newArrayList();
+ }
+
+ public Map<String, ELPropertyDescriptor> getResolvedProperties() {
+ return resolvedProperties;
+ }
+
+ public List<Method> getResolvedMethods() {
+ return resolvedMethods;
+ }
+
+ @Override
+ public void visit(Class<?> clazz) throws ParsingException {
+ PropertyDescriptor[] pds;
+ Method[] declaredMethods;
+
+ try {
+ pds = getPropertyDescriptors(clazz);
+ declaredMethods = clazz.getDeclaredMethods();
+ } catch (LinkageError e) {
+ throw new ParsingException(e.getMessage(), e);
+ }
+
+ for (PropertyDescriptor descriptor : pds) {
+ String descriptorName = descriptor.getName();
+ if (resolvedProperties.get(descriptorName) == null) {
+
+ Type reflectionType;
+ if(null != descriptor.getReadMethod()){
+ reflectionType = descriptor.getReadMethod().getGenericReturnType();
+ } else if (null != descriptor.getWriteMethod()) {
+ reflectionType = descriptor.getWriteMethod().getGenericParameterTypes()[0];
+ } else {
+ reflectionType = descriptor.getPropertyType();
+ }
+ ELType propertyType = typesFactory.getType(reflectionType);
+ ELPropertyDescriptor elDescriptor = new JavaELPropertyDescriptor(descriptor, propertyType);
+ resolvedProperties.put(descriptorName, elDescriptor);
+ }
+ }
+
+ resolvedMethods.addAll(Arrays.asList(declaredMethods));
+ }
+ }
+
+ interface ClassVisitor {
+ void visit(Class<?> clazz) throws ParsingException;
+ }
+
+ static class ClassWalkingLogic {
+
+ private Queue<Class<?>> classesList = new LinkedList<Class<?>>();
+
+ private Set<Class<?>> visitedClasses = new HashSet<Class<?>>();
+
+ public ClassWalkingLogic(Class<?> clazz) {
+ super();
+ this.classesList.add(clazz);
+ }
+
+ public void walk(ClassVisitor visitor) throws ParsingException {
+ // BFS algorithm
+ while (!classesList.isEmpty()) {
+ Class<?> clazz = classesList.remove();
+
+ if (visitedClasses.add(clazz)) {
+ visitor.visit(clazz);
+
+ Class<?> superclass = clazz.getSuperclass();
+ if (superclass != null) {
+ if (!visitedClasses.contains(superclass)) {
+ classesList.add(superclass);
+ }
+ }
+
+ Class<?>[] interfaces = clazz.getInterfaces();
+ if (interfaces != null) {
+ for (Class<?> iface : interfaces) {
+ if (!visitedClasses.contains(iface)) {
+ classesList.add(iface);
+ }
+ }
+ }
+ }
+ }
+
+ // While interfaces do not have Object.class in their hierarchy directly,
+ // implementations of interface are always inherited from Object.
+ // As methods in this class are primarily designed to work with implementations (beans),
+ // we are adding Object.class explicitly if it hasn't been visited yet.
+ if (visitedClasses.add(Object.class)) {
+ visitor.visit(Object.class);
+ }
+
+ visitedClasses.clear();
+ }
+ }
+
+ private ClassDataHolder resolveClassPropertiesAndMethods(Class<?> clazz) throws ParsingException {
+ ClassDataHolder classDataHolder = classDataCache.get(clazz);
+ if (classDataHolder == null) {
+ classDataHolder = new ClassDataHolder(this);
+ new ClassWalkingLogic(clazz).walk(classDataHolder);
+ classDataCache.put(clazz, classDataHolder);
+ }
+
+ return classDataHolder;
+ }
+
+ /**
+ * This method return PropertyDescriptor by specified propertyName and clazz.
+ *
+ * @param elType
+ * - class to search
+ * @param propertyName
+ * - propertyName to search
+ * @return property descriptor if found.
+ * @throws ParsingException
+ * if error occured.
+ */
+ public ELPropertyDescriptor getPropertyDescriptor(ELType elType, String propertyName) throws ParsingException {
+ ELPropertyDescriptor propertyDescriptor;
+
+ if (elType == null) {
+ propertyDescriptor = new DummyPropertyDescriptor(propertyName);
+ } else {
+ ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(getClassFromType(elType));
+ Map<String, ELPropertyDescriptor> resolvedProperties = classDataHolder.getResolvedProperties();
+ if (resolvedProperties.containsKey(propertyName)) {
+ propertyDescriptor = resolvedProperties.get(propertyName);
+ } else {
+ propertyDescriptor = new DummyPropertyDescriptor(propertyName);
+ }
+ }
+ return propertyDescriptor;
+ }
+
+ /**
+ * <p>
+ * Retrieve the property descriptors for the specified class, introspecting and caching them the first time a
+ * particular bean class is encountered.
+ * </p>
+ *
+ * <p>
+ * <strong>FIXME</strong> - Does not work with DynaBeans.
+ * </p>
+ *
+ * @param beanClass
+ * Bean class for which property descriptors are requested
+ * @return the property descriptors
+ * @throws ParsingException
+ * if error occured.
+ *
+ * @exception IllegalArgumentException
+ * if <code>beanClass</code> is null
+ */
+ private static PropertyDescriptor[] getPropertyDescriptors(Class<?> beanClass) throws ParsingException {
+ if (beanClass == null) {
+ throw new IllegalArgumentException("No bean class specified");
+ }
+
+ // Look up any cached descriptors for this bean class
+ PropertyDescriptor[] descriptors = null;
+
+ // Introspect the bean and cache the generated descriptors
+ BeanInfo beanInfo = null;
+
+ try {
+ beanInfo = Introspector.getBeanInfo(beanClass);
+ descriptors = beanInfo.getPropertyDescriptors();
+ } catch (IntrospectionException e) {
+ return EMPTY_PROPERTY_DESCRIPTORS;
+ }
+
+ if (descriptors == null) {
+ descriptors = EMPTY_PROPERTY_DESCRIPTORS;
+ }
+
+ return descriptors;
+ }
+
+ private static boolean isMethodVisible(Method method) {
+ return !Modifier.isPrivate(method.getModifiers());
+ }
+
+ private static Class<?> getClassFromType(ELType elType) {
+ if (elType == null) {
+ return Object.class;
+ } else if (elType instanceof PlainClassType) {
+ Class<?> clazz = ((PlainClassType) elType).getPlainJavaClass();
+ return clazz;
+ } else if (elType instanceof ComplexType) {
+ return getClassFromType(elType.getRawType());
+ }
+ return Object.class;
+ }
+
+ /**
+ * <p>
+ * Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean
+ * that every method parameter is assignable from the given parameters. In other words, it finds a method with the
+ * given name that will take the parameters given.
+ * <p>
+ *
+ * <p>
+ * This method is slightly undeterminstic since it loops through methods names and return the first matching method.
+ * </p>
+ *
+ * <p>
+ * This method is used by {@link #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}.
+ *
+ * <p>
+ * This method can match primitive parameter by passing in wrapper classes. For example, a <code>Boolean</code> will
+ * match a primitive <code>boolean</code> parameter.
+ *
+ * @param elType
+ * find method in this class
+ * @param methodName
+ * find method with this name
+ * @param parameterTypes
+ * find method with compatible parameters
+ * @return The accessible method
+ * @throws ParsingException
+ * if error occured.
+ */
+ public ELType getMatchingVisibleMethodReturnType(ELType elType, final String methodName, ELType... parameterTypes)
+ throws ParsingException {
+
+ ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(getClassFromType(elType));
+ List<Method> resolvedMethods = classDataHolder.getResolvedMethods();
+
+ // search through all methods
+ int paramSize = parameterTypes.length;
+ Method bestMatch = null;
+
+ for (Method resolvedMethod : resolvedMethods) {
+ if (isMethodVisible(resolvedMethod) && resolvedMethod.getName().equals(methodName)) {
+ // compare parameters
+ ELType[] methodsParams = getTypesArray(resolvedMethod.getParameterTypes());
+ int methodParamSize = methodsParams.length;
+ if (methodParamSize == paramSize) {
+ boolean match = true;
+ for (int n = 0; n < methodParamSize; n++) {
+ if (!methodsParams[n].isAssignableFrom(parameterTypes[n])) {
+ match = false;
+ break;
+ }
+ }
+ if (match) {
+ bestMatch = resolvedMethod;
+ }
+ }
+ }
+ }
+
+ if (bestMatch != null) {
+ return getType(bestMatch.getGenericReturnType());
+ } else {
+ return TypesFactory.OBJECT_TYPE;
+ }
+ }
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/BaseTemplateMethodBodyStatement.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,20 +23,22 @@
import java.util.Collections;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
-import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
-import org.richfaces.cdk.templatecompiler.el.HelperMethod;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
/**
* @author Nick Belaevski
+ *
*/
public class BaseTemplateMethodBodyStatement implements TemplateStatement {
- private String templateName;
+ private final String templateName;
+ private final FreeMarkerRenderer renderer;
- protected BaseTemplateMethodBodyStatement(String templateName) {
+ protected BaseTemplateMethodBodyStatement(FreeMarkerRenderer renderer,String templateName) {
super();
+ this.renderer = renderer;
this.templateName = templateName;
}
@@ -46,7 +48,7 @@
}
@Override
- public Iterable<ELType> getRequiredImports() {
+ public Iterable<JavaImport> getRequiredImports() {
return Collections.emptySet();
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* @author Nick Belaevski
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -0,0 +1,35 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class HelperJavaMethod extends JavaMethod {
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperJavaMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java (from rev 17678, root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/HelperMethod.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -0,0 +1,86 @@
+/*
+ * 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.statements;
+
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.*;
+
+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 boolean utilsMethod = false;
+
+ private HelperMethod(String name, Class<?> returnType, Class<?>... argumentTypes) {
+ this.name = name;
+ this.returnType = returnType;
+ this.argumentTypes = argumentTypes;
+ }
+
+ private HelperMethod(String name, Class<?> returnType, boolean utils, Class<?>... argumentTypes) {
+ this.name = name;
+ this.returnType = returnType;
+ this.argumentTypes = argumentTypes;
+ this.utilsMethod=utils;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the utilsMethod
+ */
+ public boolean isUtilsMethod() {
+ return this.utilsMethod;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class<?> getReturnType() {
+ return returnType;
+ }
+
+ public Class<?>[] getArgumentTypes() {
+ return argumentTypes;
+ }
+
+ public static Set<HelperMethod> getConversionMethods() {
+ return CONVERSION_METHODS;
+ }
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -24,7 +24,6 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
-import org.richfaces.cdk.templatecompiler.el.HelperMethod;
/**
* <p class="changed_added_4_0"></p>
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,18 +23,64 @@
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.Generator;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
-import org.richfaces.cdk.templatecompiler.el.HelperMethod;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import com.google.inject.Inject;
+import com.google.inject.internal.Nullable;
+import com.google.inject.name.Named;
+
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
public class HelperMethodFactoryImpl implements HelperMethodFactory {
- /* (non-Javadoc)
- * @see org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory#getHelperMethod(org.richfaces.cdk.templatecompiler.el.HelperMethod)
+ private final FreeMarkerRenderer renderer;
+ private final TypesFactory typesFactory;
+ private final String rendererUtilsClass;
+
+ @Inject
+ public HelperMethodFactoryImpl(FreeMarkerRenderer renderer, TypesFactory typesFactory,
+ @Named(Generator.RENDERER_UTILS_CLASS) @Nullable String rendererUtilsClass) {
+ this.renderer = renderer;
+ this.typesFactory = typesFactory;
+ this.rendererUtilsClass = rendererUtilsClass;
+ }
+
+ private JavaMethod buildHelperMethod(HelperMethod helperMethod, String templateName, String... argumentNames) {
+ if (helperMethod.isUtilsMethod() && null != rendererUtilsClass) {
+ return new RendererUtilsMethod(helperMethod, rendererUtilsClass);
+ } else {
+ Class<?>[] argumentTypes = helperMethod.getArgumentTypes();
+ Argument[] arguments = new Argument[argumentTypes.length];
+ for (int i = 0; i < arguments.length; i++) {
+ String argumentName = i < argumentNames.length ? argumentNames[i] : "arg" + i;
+ arguments[i] = new Argument(argumentName, typesFactory.getType(argumentTypes[i]));
+ }
+ ELType returnType = typesFactory.getType(helperMethod.getReturnType());
+ JavaMethod helperJavaMethod = new JavaMethod(helperMethod.getName(), returnType, arguments);
+ helperJavaMethod.addModifier(JavaModifier.PRIVATE);
+ helperJavaMethod.addModifier(JavaModifier.STATIC);
+ helperJavaMethod.setMethodBody(new BaseTemplateMethodBodyStatement(renderer, templateName));
+ return helperJavaMethod;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory#getHelperMethod(org.richfaces.cdk.templatecompiler
+ * .el.HelperMethod)
*/
@Override
public JavaMethod getHelperMethod(HelperMethod helper) {
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -1,39 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.templatecompiler.statements;
-
-import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class JavaHelperMethod extends JavaMethod {
-
- public JavaHelperMethod(String name) {
- super(name);
- }
-
-}
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java (from rev 17678, root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -0,0 +1,55 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import java.util.Collections;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class RendererUtilsMethod extends JavaMethod {
+
+ private Iterable<JavaImport> runtimeImport;
+
+ public RendererUtilsMethod(HelperMethod helper,String rendererUtilsClassName) {
+ super(helper.getName());
+ this.runtimeImport = Collections.<JavaImport>singleton(new RuntimeImport(rendererUtilsClassName));
+ }
+
+ @Override
+ public boolean isHidden() {
+ return true;
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return runtimeImport;
+ }
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -26,9 +26,9 @@
import java.util.Map;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
-import org.richfaces.cdk.templatecompiler.el.HelperMethod;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@@ -40,10 +40,10 @@
*/
public class StatementsContainer implements TemplateStatement, Variables {
- private static final Function<TemplateStatement, Iterable<ELType>> IMPORTS_TRANSFORM = new Function<TemplateStatement, Iterable<ELType>>() {
+ private static final Function<TemplateStatement, Iterable<JavaImport>> IMPORTS_TRANSFORM = new Function<TemplateStatement, Iterable<JavaImport>>() {
@Override
- public Iterable<ELType> apply(TemplateStatement from) {
+ public Iterable<JavaImport> apply(TemplateStatement from) {
return from.getRequiredImports();
}
};
@@ -163,7 +163,7 @@
}
@Override
- public Iterable<ELType> getRequiredImports() {
+ public Iterable<JavaImport> getRequiredImports() {
return concatStatements(IMPORTS_TRANSFORM);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -5,8 +5,7 @@
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
-import org.richfaces.cdk.templatecompiler.el.HelperMethod;
-import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+import org.richfaces.cdk.templatecompiler.builder.model.RequireImports;
/**
* @author asmirnov
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,7 +23,7 @@
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
/**
* <p class="changed_added_4_0"></p>
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/Bean.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -26,6 +26,8 @@
import java.util.List;
import java.util.Map;
+import javax.faces.context.FacesContext;
+
public class Bean {
private UIComponent[] array = new UIComponent[] { new UIComponent() };
private List<UIComponent> components;
@@ -77,6 +79,10 @@
return readOnly;
}
+ public FacesContext getContext(){
+ return null;
+ }
+
public void setArray(UIComponent[] array) {
this.array = array;
}
@@ -103,4 +109,9 @@
public void test(UIComponent comp, boolean test) {
}
+
+ @Override
+ public String toString() {
+ return super.toString();
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -23,7 +23,7 @@
import static org.junit.Assert.*;
import static org.easymock.EasyMock.*;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.*;
+import static org.richfaces.cdk.templatecompiler.statements.HelperMethod.*;
import java.util.HashMap;
import java.util.List;
@@ -41,11 +41,11 @@
import org.richfaces.cdk.templatecompiler.ELParser;
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
import org.richfaces.cdk.templatecompiler.el.ELParserImpl;
-import org.richfaces.cdk.templatecompiler.el.ELType;
-import org.richfaces.cdk.templatecompiler.el.HelperMethod;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
import com.google.common.collect.ImmutableSet;
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java 2010-06-28 12:56:43 UTC (rev 17678)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java 2010-06-28 23:35:15 UTC (rev 17679)
@@ -21,23 +21,21 @@
*/
package org.richfaces.cdk.templatecompiler.parser.el.test;
-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.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.io.Writer;
import java.util.List;
import java.util.Map;
+import javax.faces.context.FacesContext;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.CdkTestBase;
import org.richfaces.cdk.CdkTestRunner;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.ELPropertyDescriptor;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
import com.google.inject.Binder;
@@ -52,13 +50,13 @@
@Inject
TypesFactoryImpl typesFactory;
-
+
@Override
public void configure(Binder binder) {
super.configure(binder);
binder.bind(CdkClassLoader.class).toInstance(createClassLoader());
}
-
+
private static final class ParameterizedTypesHolder {
@SuppressWarnings("unused")
@@ -110,58 +108,56 @@
}
-
@Test
public void testGetTypeFromReflectionType() throws Exception {
ELType integerType = typesFactory.getType(Integer.TYPE);
assertNotNull(integerType);
- assertEquals(Integer.TYPE, integerType.getRawType());
- assertNull(integerType.getTypeArguments());
+ assertEquals(Integer.TYPE.getName(), integerType.getRawName());
assertFalse(integerType.isArray());
assertFalse(integerType.isNullType());
ELType stringType = typesFactory.getType(String.class);
assertNotNull(stringType);
- assertEquals(String.class, stringType.getRawType());
- assertNull(stringType.getTypeArguments());
+ assertEquals(String.class.getName(), stringType.getRawName());
+ assertEquals(0, stringType.getTypeArguments().length);
assertFalse(stringType.isArray());
assertFalse(stringType.isNullType());
ELType arrayType = typesFactory.getType(String[].class);
assertNotNull(arrayType);
- assertNull(arrayType.getTypeArguments());
+ assertEquals(0, arrayType.getTypeArguments().length);
assertTrue(arrayType.isArray());
- assertEquals(String.class, arrayType.getContainerType().getRawType());
+ assertEquals(String.class.getName(), arrayType.getContainerType().getRawName());
assertFalse(arrayType.isNullType());
ELType multiDimArrayType = typesFactory.getType(String[][][].class);
assertNotNull(multiDimArrayType);
- assertNull(multiDimArrayType.getTypeArguments());
+ assertEquals(0, multiDimArrayType.getTypeArguments().length);
assertTrue(multiDimArrayType.isArray());
- assertEquals(String[][].class, multiDimArrayType.getContainerType().getRawType());
+ // assertEquals(String[][].class, multiDimArrayType.getContainerType().getRawName());
assertFalse(multiDimArrayType.isNullType());
ELType parameterizedMapType = typesFactory.getType(getParameterizedMapType());
assertNotNull(parameterizedMapType);
assertFalse(parameterizedMapType.isArray());
- assertEquals(Map.class, parameterizedMapType.getRawType());
+ assertEquals(Map.class.getName(), parameterizedMapType.getRawName());
ELType[] parameterizedMapTypeArguments = parameterizedMapType.getTypeArguments();
assertNotNull(parameterizedMapTypeArguments);
assertEquals(2, parameterizedMapTypeArguments.length);
- assertEquals(String.class, parameterizedMapTypeArguments[0].getRawType());
- assertEquals(Object.class, parameterizedMapTypeArguments[1].getRawType());
+ assertEquals(String.class.getName(), parameterizedMapTypeArguments[0].getRawName());
+ assertEquals(Object.class.getName(), parameterizedMapTypeArguments[1].getRawName());
ELType parameterizedArrayType = typesFactory.getType(getParameterizedArrayType());
assertNotNull(parameterizedArrayType);
assertTrue(parameterizedArrayType.isArray());
- assertEquals(List[].class, parameterizedArrayType.getRawType());
+ // assertEquals(List[].class, parameterizedArrayType.getRawName());
ELType[] parameterizedArrayTypeArguments = parameterizedArrayType.getTypeArguments();
assertNotNull(parameterizedArrayTypeArguments);
assertEquals(1, parameterizedArrayTypeArguments.length);
ELType parameterizedArrayTypeArgument = parameterizedArrayTypeArguments[0];
- assertEquals(String.class, parameterizedArrayTypeArgument.getRawType());
+ assertEquals(String.class.getName(), parameterizedArrayTypeArgument.getRawName());
assertFalse(parameterizedArrayTypeArgument.isArray());
ELType typeVariableType = typesFactory.getType(getTypeVariableType());
@@ -171,7 +167,7 @@
ELType wildcardTypeHolder = typesFactory.getType(getWildcardType());
assertNotNull(wildcardTypeHolder);
- assertEquals(List.class, wildcardTypeHolder.getRawType());
+ assertEquals(List.class.getName(), wildcardTypeHolder.getRawName());
ELType[] wildcardTypeHolderArguments = wildcardTypeHolder.getTypeArguments();
assertNotNull(wildcardTypeHolderArguments);
@@ -185,49 +181,48 @@
ELType primitiveIntType = typesFactory.getType("int");
assertNotNull(primitiveIntType);
- assertEquals(Integer.TYPE, primitiveIntType.getRawType());
+ assertEquals(Integer.TYPE.getName(), primitiveIntType.getRawName());
ELType guessedMapType = typesFactory.getType("Map");
assertNotNull(guessedMapType);
- assertEquals(Map.class, guessedMapType.getRawType());
- assertNull(guessedMapType.getTypeArguments());
+ assertEquals(Map.class.getName(), guessedMapType.getRawName());
ELType writerType = typesFactory.getType(java.io.Writer.class.getName());
assertNotNull(writerType);
- assertEquals(Writer.class, writerType.getRawType());
- assertNull(writerType.getTypeArguments());
+ assertEquals(Writer.class.getName(), writerType.getRawName());
+ assertEquals(0, writerType.getTypeArguments().length);
ELType genericMapType = typesFactory.getType("Map<String, Object>");
assertNotNull(genericMapType);
- assertEquals(Map.class, genericMapType.getRawType());
+ assertEquals(Map.class.getName(), genericMapType.getRawName());
ELType[] genericMapTypeArguments = genericMapType.getTypeArguments();
assertNotNull(genericMapTypeArguments);
assertFalse(genericMapType.isArray());
assertEquals(2, genericMapTypeArguments.length);
ELType genericMapTypeKeyArgument = genericMapTypeArguments[0];
- assertEquals(String.class, genericMapTypeKeyArgument.getRawType());
+ assertEquals(String.class.getName(), genericMapTypeKeyArgument.getRawName());
ELType genericMapTypeValueArgument = genericMapTypeArguments[1];
- assertEquals(Object.class, genericMapTypeValueArgument.getRawType());
+ assertEquals(Object.class.getName(), genericMapTypeValueArgument.getRawName());
ELType arrayType = typesFactory.getType("String[]");
assertNotNull(arrayType);
assertTrue(arrayType.isArray());
- assertEquals(String[].class, arrayType.getRawType());
+ // assertEquals(String[].class, arrayType.getRawName());
ELType genericArrayType = typesFactory.getType("List<String>[]");
assertNotNull(genericArrayType);
assertTrue(genericArrayType.isArray());
- assertEquals(List[].class, genericArrayType.getRawType());
+ // assertEquals(List[].class, genericArrayType.getRawName());
ELType[] genericArrayTypeArguments = genericArrayType.getTypeArguments();
assertNotNull(genericArrayTypeArguments);
assertEquals(1, genericArrayTypeArguments.length);
ELType genericArrayTypeArgument = genericArrayTypeArguments[0];
- assertEquals(String.class, genericArrayTypeArgument.getRawType());
+ assertEquals(String.class.getName(), genericArrayTypeArgument.getRawName());
}
@Test
@@ -253,6 +248,89 @@
assertNotNull(genericTypeArguments);
assertEquals(1, genericTypeArguments.length);
ELType genericTypeArgument = genericTypeArguments[0];
- assertEquals(String.class, genericTypeArgument.getRawType());
+ assertEquals(String.class.getName(), genericTypeArgument.getRawName());
}
+
+ public ELPropertyDescriptor getAndCheckPropertyDescriptor(Class<?> clazz, String propertyName,
+ String getMethodName, Class<?> expectedType, boolean readable, boolean writable) throws Exception {
+ ELPropertyDescriptor checkPropertyDescriptor =
+ getAndCheckPropertyDescriptor(clazz, propertyName, getMethodName, expectedType);
+ assertEquals(writable, checkPropertyDescriptor.isWritable());
+ assertEquals(readable, checkPropertyDescriptor.isReadable());
+ return checkPropertyDescriptor;
+ }
+
+ public ELPropertyDescriptor getAndCheckPropertyDescriptor(Class<?> clazz, String propertyName,
+ String getMethodName, Class<?> expectedType) throws Exception {
+ ELType beanType = typesFactory.getType(clazz);
+ ELPropertyDescriptor propertyDescriptor = typesFactory.getPropertyDescriptor(beanType, propertyName);
+ assertNotNull(propertyDescriptor);
+ assertEquals(getMethodName, propertyDescriptor.getReadMethodName());
+ assertEquals(expectedType.getName(), propertyDescriptor.getType().getRawName());
+ return propertyDescriptor;
+ }
+
+ @Test
+ public void testGetStringProperty() throws Exception {
+ ELPropertyDescriptor propertyDescriptor =
+ getAndCheckPropertyDescriptor(Bean2.class, "string", "getString", String.class, true, true);
+ }
+
+ @Test
+ public void testGetRawMapProperty() throws Exception {
+ ELPropertyDescriptor propertyDescriptor =
+ getAndCheckPropertyDescriptor(Bean.class, "rawMap", "getRawMap", Map.class, true, true);
+ }
+
+ @Test
+ public void testGetBooleanProperty() throws Exception {
+ ELPropertyDescriptor propertyDescriptor =
+ getAndCheckPropertyDescriptor(Bean.class, "readOnly", "isReadOnly", Boolean.TYPE, true, true);
+ }
+
+ @Test
+ public void testGetContextProperty() throws Exception {
+ ELPropertyDescriptor propertyDescriptor =
+ getAndCheckPropertyDescriptor(Bean.class, "context", "getContext", FacesContext.class, true, false);
+ }
+
+ @Test
+ public void testGetDummyProperty() throws Exception {
+ ELPropertyDescriptor propertyDescriptor =
+ getAndCheckPropertyDescriptor(Bean.class, "nonExistedProperty", "getNonExistedProperty", Object.class,
+ false, false);
+ }
+
+ public ELType findAndCheckMethod(Class<?> clazz, String methodName, Class<?> expectedType, Class<?>... arguments)
+ throws Exception {
+ ELType beanType = typesFactory.getType(clazz);
+ ELType[] parameters = new ELType[arguments.length];
+ for (int i = 0; i < arguments.length; i++) {
+ parameters[i] = typesFactory.getType(arguments[i]);
+ }
+ ELType returnType = typesFactory.getMatchingVisibleMethodReturnType(beanType, methodName, parameters);
+ assertNotNull(returnType);
+ assertEquals(expectedType.getName(), returnType.getRawName());
+ return returnType;
+ }
+
+ @Test
+ public void testFindCountMethod() throws Exception {
+ findAndCheckMethod(Bean.class, "count", Integer.class, Integer.TYPE);
+ }
+ @Test
+ public void testFindCountMethodWithWrongParameter() throws Exception {
+ findAndCheckMethod(Bean.class, "count", Object.class, String.class);
+ }
+
+ @Test
+ public void testFindToStringMethod() throws Exception {
+ findAndCheckMethod(Bean.class, "toString", String.class);
+ }
+
+ @Test
+ public void testFindCollectionMethod() throws Exception {
+ ELType type = findAndCheckMethod(Bean.class, "getComponents", List.class);
+ assertEquals(UIComponent.class.getName(), type.getContainerType().getRawName());
+ }
}
14 years, 6 months
JBoss Rich Faces SVN: r17678 - root/ui-sandbox/panels/trunk/docs.
by richfaces-svn-commits@lists.jboss.org
Author: Alex.Kolonitsky
Date: 2010-06-28 08:56:43 -0400 (Mon, 28 Jun 2010)
New Revision: 17678
Added:
root/ui-sandbox/panels/trunk/docs/client_side_api-dev.png
root/ui-sandbox/panels/trunk/docs/client_side_api.png
root/ui-sandbox/panels/trunk/docs/taglib-dev.png
root/ui-sandbox/panels/trunk/docs/taglib.png
Removed:
root/ui-sandbox/panels/trunk/docs/client_side_api 1.2.2.png
root/ui-sandbox/panels/trunk/docs/client_side_api-dev 1.2.2.png
root/ui-sandbox/panels/trunk/docs/panels-classes 1.1.png
root/ui-sandbox/panels/trunk/docs/panels-taglib 1.2.1.png
root/ui-sandbox/panels/trunk/docs/panels-taglib 1.2.2.png
root/ui-sandbox/panels/trunk/docs/panels-taglib 1.2.png
root/ui-sandbox/panels/trunk/docs/renderkit 1.1.png
root/ui-sandbox/panels/trunk/docs/richfaces 4.0.eap
root/ui-sandbox/panels/trunk/docs/taglib-dev 1.2.2.png
root/ui-sandbox/panels/trunk/docs/taglib-toggle 1.2.png
Log:
clean up diagrams
Deleted: root/ui-sandbox/panels/trunk/docs/client_side_api 1.2.2.png
===================================================================
(Binary files differ)
Deleted: root/ui-sandbox/panels/trunk/docs/client_side_api-dev 1.2.2.png
===================================================================
(Binary files differ)
Added: root/ui-sandbox/panels/trunk/docs/client_side_api-dev.png
===================================================================
(Binary files differ)
Property changes on: root/ui-sandbox/panels/trunk/docs/client_side_api-dev.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: root/ui-sandbox/panels/trunk/docs/client_side_api.png
===================================================================
(Binary files differ)
Property changes on: root/ui-sandbox/panels/trunk/docs/client_side_api.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: root/ui-sandbox/panels/trunk/docs/panels-classes 1.1.png
===================================================================
(Binary files differ)
Deleted: root/ui-sandbox/panels/trunk/docs/panels-taglib 1.2.1.png
===================================================================
(Binary files differ)
Deleted: root/ui-sandbox/panels/trunk/docs/panels-taglib 1.2.2.png
===================================================================
(Binary files differ)
Deleted: root/ui-sandbox/panels/trunk/docs/panels-taglib 1.2.png
===================================================================
(Binary files differ)
Deleted: root/ui-sandbox/panels/trunk/docs/renderkit 1.1.png
===================================================================
(Binary files differ)
Deleted: root/ui-sandbox/panels/trunk/docs/richfaces 4.0.eap
===================================================================
(Binary files differ)
Deleted: root/ui-sandbox/panels/trunk/docs/taglib-dev 1.2.2.png
===================================================================
(Binary files differ)
Added: root/ui-sandbox/panels/trunk/docs/taglib-dev.png
===================================================================
(Binary files differ)
Property changes on: root/ui-sandbox/panels/trunk/docs/taglib-dev.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: root/ui-sandbox/panels/trunk/docs/taglib-toggle 1.2.png
===================================================================
(Binary files differ)
Added: root/ui-sandbox/panels/trunk/docs/taglib.png
===================================================================
(Binary files differ)
Property changes on: root/ui-sandbox/panels/trunk/docs/taglib.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
14 years, 6 months
JBoss Rich Faces SVN: r17677 - root/cdk/branches/RF8755/bom.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-25 20:56:48 -0400 (Fri, 25 Jun 2010)
New Revision: 17677
Modified:
root/cdk/branches/RF8755/bom/pom.xml
Log:
svitch to the new google collections project
Modified: root/cdk/branches/RF8755/bom/pom.xml
===================================================================
--- root/cdk/branches/RF8755/bom/pom.xml 2010-06-26 00:56:03 UTC (rev 17676)
+++ root/cdk/branches/RF8755/bom/pom.xml 2010-06-26 00:56:48 UTC (rev 17677)
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <groupId>org.richfaces</groupId>
- <artifactId>richfaces-parent</artifactId>
- <version>7</version>
+ <groupId>org.richfaces</groupId>
+ <artifactId>richfaces-parent</artifactId>
+ <version>7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -16,9 +17,9 @@
<packaging>pom</packaging>
<name>JSF Components Development Kit (CDK) bill of materials.</name>
<description>This module defines all versions of CDK projects and their dependencies.</description>
- <properties>
- <org.richfaces.commons.version>4.0.0-SNAPSHOT</org.richfaces.commons.version>
- </properties>
+ <properties>
+ <org.richfaces.commons.version>4.0.0-SNAPSHOT</org.richfaces.commons.version>
+ </properties>
<scm>
<connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/root/cdk/trunk/bom</connection>
<developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root/cdk/trunk/bom</developerConnection>
@@ -38,17 +39,18 @@
</build>
<dependencyManagement>
<dependencies>
- <!-- Import richfaces-common-bom -->
- <dependency>
- <groupId>org.richfaces.commons</groupId>
- <artifactId>richfaces-commons-bom</artifactId>
- <version>${org.richfaces.commons.version}</version>
- <scope>import</scope>
- <type>pom</type>
- </dependency>
-
- <!-- TODO remove duplicates from these dependences already defined in project BOM -->
+ <!-- Import richfaces-common-bom -->
<dependency>
+ <groupId>org.richfaces.commons</groupId>
+ <artifactId>richfaces-commons-bom</artifactId>
+ <version>${org.richfaces.commons.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- TODO remove duplicates from these dependences already defined in
+ project BOM -->
+ <dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
@@ -80,6 +82,22 @@
<version>1.0</version>
</dependency>
<dependency>
+ <groupId>com.googlecode.functional-collections</groupId>
+ <artifactId>functional-collections</artifactId>
+ <version>1.1.7</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.google.collections</groupId>
+ <artifactId>google-collections</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>r05</version>
+ </dependency>
+ <dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
14 years, 6 months
JBoss Rich Faces SVN: r17676 - in root/cdk/branches/RF8755/plugins/generator: src/main/java/org/richfaces/cdk/templatecompiler and 6 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-25 20:56:03 -0400 (Fri, 25 Jun 2010)
New Revision: 17676
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
Removed:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java
Modified:
root/cdk/branches/RF8755/plugins/generator/pom.xml
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
Log:
template compiler refactor
Modified: root/cdk/branches/RF8755/plugins/generator/pom.xml
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/pom.xml 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/pom.xml 2010-06-26 00:56:03 UTC (rev 17676)
@@ -149,9 +149,7 @@
<artifactId>xercesImpl</artifactId>
</dependency>
<!--
- <dependency> <groupId>com.google.collections</groupId>
- <artifactId>google-collections</artifactId>
- <version>1.0-rc2</version> </dependency> <dependency>
+ <dependency>
<groupId>org.w3c.css</groupId> <artifactId>sac</artifactId>
<version>1.3</version> </dependency>
-->
@@ -159,11 +157,11 @@
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
<dependency>
- <groupId>com.google.collections</groupId>
- <artifactId>google-collections</artifactId>
- </dependency>
- <dependency>
<groupId>com.sun.xsom</groupId>
<artifactId>xsom</artifactId>
</dependency>
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -87,6 +87,7 @@
import org.richfaces.cdk.templatecompiler.statements.EqualsCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ForEachStatement;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodBodyStatement;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.IfElseStatement;
import org.richfaces.cdk.templatecompiler.statements.IfStatement;
import org.richfaces.cdk.templatecompiler.statements.StartElementStatement;
@@ -174,14 +175,16 @@
private final Collection<PropertyBase> attributes;
private final Injector injector;
+ private final HelperMethodFactory helperMethodFactory;
public RendererClassVisitor(CompositeInterface compositeInterface, Collection<PropertyBase> attributes, Logger log,
- Injector injector, ELParser parser) {
+ Injector injector, ELParser parser, HelperMethodFactory helperFactory) {
this.compositeInterface = compositeInterface;
this.attributes = attributes;
this.injector = injector;
this.parser = parser;
this.log = log;
+ this.helperMethodFactory = helperFactory;
}
private void initializeJavaClass() {
@@ -407,7 +410,7 @@
Iterable<ELType> importsList = currentStatement.getRequiredImports();
for (ELType importedClass : importsList) {
generatedClass.addImport(importedClass.getRawType());
- for (Class<?> classToImport : importedClass.getImportsList()) {
+ for (Class<?> classToImport : importedClass.getRequiredImports()) {
generatedClass.addImport(classToImport);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -30,6 +30,8 @@
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
import org.richfaces.cdk.templatecompiler.model.Template;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactoryImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
@@ -56,6 +58,7 @@
bind(FreeMarkerRenderer.class).to(JavaClassConfiguration.class);
bind(TypesFactory.class).to(TypesFactoryImpl.class);
bind(ELParser.class).to(ELParserImpl.class);
+ bind(HelperMethodFactory.class).to(HelperMethodFactoryImpl.class).in(Singleton.class);
bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE)).toProvider(XhtmlElSchemaProvider.class).in(Singleton.class);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -28,6 +28,7 @@
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -42,6 +43,7 @@
final ELParser parser;
final Logger log;
final Injector injector;
+ private final HelperMethodFactory helpersFactory;
/**
* <p class="changed_added_4_0"></p>
@@ -50,10 +52,11 @@
* @param log
*/
@Inject
- public VisitorFactoryImpl(ELParser parser, Logger log, Injector injector) {
+ public VisitorFactoryImpl(ELParser parser, Logger log, Injector injector,HelperMethodFactory helpersFactory) {
this.parser = parser;
this.log = log;
this.injector = injector;
+ this.helpersFactory = helpersFactory;
}
/* (non-Javadoc)
@@ -61,7 +64,7 @@
*/
@Override
public RendererClassVisitor createVisitor(CompositeInterface composite, Collection<PropertyBase> attributes) {
- return new RendererClassVisitor(composite, attributes, log,injector,parser);
+ return new RendererClassVisitor(composite, attributes, log,injector,parser,helpersFactory);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -21,38 +21,42 @@
package org.richfaces.cdk.templatecompiler.builder.model;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
/**
* Representation of method argument
*
* @author Maksim Kaszynski
*/
-public class Argument {
+public class Argument implements RequireImports {
private String name;
- private JavaClass type;
+ private ELType type;
- public Argument(String name, Class<?> type) {
+ public Argument(String name, ELType type) {
super();
this.name = name;
- this.type = new JavaClass(type);
+ this.type = type;
}
- public Argument(String name, String type) {
- super();
- this.name = name;
- this.type = new JavaClass(type);
- }
- public static Argument arg(String name, Class<?> type) {
+ public static Argument arg(String name, ELType type) {
return new Argument(name, type);
}
- public JavaClass getType() {
+ public ELType getType() {
return type;
}
public String getName() {
return name;
}
+
+
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ return type.getRequiredImports();
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -25,30 +25,36 @@
import java.util.Arrays;
import java.util.List;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
/**
* Wrapper for '@annotations
*
* @author Maksim Kaszynski
*/
-public class JavaAnnotation {
+public class JavaAnnotation implements RequireImports {
private List<String> arguments = new ArrayList<String>();
- private JavaClass type;
+ private ELType type;
- public JavaAnnotation(JavaClass type) {
- super();
+ public JavaAnnotation(ELType type) {
this.type = type;
}
- public JavaAnnotation(JavaClass type, String... parameters) {
+ public JavaAnnotation(ELType type, String... parameters) {
this(type);
this.arguments = Arrays.asList(parameters);
}
- public JavaClass getType() {
+ public ELType getType() {
return type;
}
public List<String> getArguments() {
return arguments;
}
+
+ public Iterable<ELType> getRequiredImports() {
+ return type.getRequiredImports();
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -28,6 +28,8 @@
import java.util.TreeSet;
import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
* Java Class model.
@@ -36,7 +38,7 @@
* @author Maksim Kaszynski
*/
public class JavaClass extends JavaLanguageElement {
- private static final JavaClass DEFAULT_SUPERCLASS = new JavaClass(Object.class);
+ private static final ELType DEFAULT_SUPERCLASS = TypesFactory.OBJECT_TYPE;
private List<JavaField> fields = new ArrayList<JavaField>();
private List<JavaMethod> methods = new ArrayList<JavaMethod>();
private Set<JavaImport> imports = new TreeSet<JavaImport>(new Comparator<JavaImport>() {
@@ -44,7 +46,8 @@
return o1.getName().compareTo(o2.getName());
}
});
- private JavaClass superClass = DEFAULT_SUPERCLASS;
+ private ELType superClass = DEFAULT_SUPERCLASS;
+
private JavaPackage pakg;
private String simpleName;
@@ -67,11 +70,6 @@
this.simpleName = simpleName;
}
- public JavaClass(String simpleName, JavaPackage pakg, Class<?> superClass) {
- this(simpleName, pakg);
- setSuperClass(new JavaClass(superClass));
- }
-
public JavaClass(ClassName javaClass) {
this(javaClass.getSimpleName(), new JavaPackage(javaClass.getPackage()));
}
@@ -115,8 +113,8 @@
}
}
- public void addImport(JavaClass javaClass) {
- addImport(javaClass.getName());
+ public void addImport(ELType javaClass) {
+ addImport(javaClass.getRawName());
}
public void addImport(Class<?> claz) {
@@ -125,64 +123,40 @@
}
}
+ public void addImports(Iterable<ELType> imports) {
+ for (ELType elType : imports) {
+ addImport(elType);
+ }
+ }
+
@Override
public void addAnnotation(JavaAnnotation annotation) {
super.addAnnotation(annotation);
- addImport(annotation.getType());
+ addImports(annotation.getRequiredImports());
}
public void addField(JavaField field) {
fields.add(field);
- addImport(field.getType());
-
- List<JavaAnnotation> annotations2 = field.getAnnotations();
-
- if (annotations2 != null) {
- for (JavaAnnotation javaAnnotation : annotations2) {
- addImport(javaAnnotation.getType());
- }
- }
+ addImports(field.getRequiredImports());
}
public void addMethod(JavaMethod method) {
methods.add(method);
- addImport(method.getReturnType());
+ addImports(method.getRequiredImports());
- List<Class<? extends Throwable>> exceptions = method.getExceptions();
-
- for (Class<? extends Throwable> exception : exceptions) {
- addImport(exception);
- }
-
- List<Argument> arguments = method.getArguments();
-
- if (arguments != null) {
- for (Argument argument : arguments) {
- addImport(argument.getType());
- }
- }
-
- List<JavaAnnotation> annotations2 = method.getAnnotations();
-
- if (annotations2 != null) {
- for (JavaAnnotation javaAnnotation : annotations2) {
- addImport(javaAnnotation.getType());
- }
- }
-
}
public JavaPackage getPakg() {
return pakg;
}
- public JavaClass getSuperClass() {
+ public ELType getSuperClass() {
return superClass;
}
- public void setSuperClass(JavaClass superClass) {
+ public void setSuperClass(ELType superClass) {
this.superClass = superClass;
- addImport(superClass.getName());
+ addImport(superClass.getRawName());
}
public void setPackage(JavaPackage s) {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -21,38 +21,34 @@
package org.richfaces.cdk.templatecompiler.builder.model;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import com.google.common.collect.Iterables;
+
+
/**
* Class field abstraction
*
* @author Maksim Kaszynski
*/
public class JavaField extends JavaLanguageElement {
- private JavaClass type;
+ private ELType type;
+
private JavaStatement value;
- private JavaClass[] genericArguments;
-
- public JavaField(Class<?> type, String name) {
- this(new JavaClass(type), name, null);
- }
-
- public JavaField(JavaClass type, String name) {
+ public JavaField(ELType type, String name) {
this(type, name, null);
}
- public JavaField(Class<?> type, String name, JavaStatement value) {
- this(new JavaClass(type), name, value);
- }
- public JavaField(JavaClass type, String name, JavaStatement value) {
+ public JavaField(ELType type, String name, JavaStatement value) {
super(name);
this.type = type;
this.value = value;
}
- public JavaClass getType() {
+ public ELType getType() {
return type;
}
@@ -64,39 +60,10 @@
this.value = value;
}
- /**
- * @return the genericArguments
- */
- public JavaClass[] getGenericArguments() {
- return genericArguments;
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ Iterable<ELType> imports = super.getRequiredImports();
+ return Iterables.concat(getType().getRequiredImports(),imports);
}
- /**
- * @param genericArguments the genericArguments to set
- */
- public void setGenericArguments(JavaClass[] genericArguments) {
- this.genericArguments = genericArguments;
- }
-
- public String getGenericSignature() {
- StringBuilder result = new StringBuilder();
-
- if (genericArguments != null) {
- for (JavaClass genericArgument : genericArguments) {
- if (result.length() == 0) {
- result.append('<');
- } else {
- result.append(", ");
- }
-
- result.append(genericArgument.getName());
- }
- }
-
- if (result.length() != 0) {
- result.append('>');
- }
-
- return result.toString();
- }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -26,10 +26,18 @@
import java.util.Set;
import java.util.TreeSet;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
+import com.google.common.collect.Iterables;
+
/**
* @author Maksim Kaszynski
*/
-public class JavaLanguageElement {
+public class JavaLanguageElement implements RequireImports {
+
+ private boolean hidden = false;
+
private Set<JavaModifier> modifiers = new TreeSet<JavaModifier>();
private List<JavaComment> comments = new ArrayList<JavaComment>();
private List<JavaAnnotation> annotations = new ArrayList<JavaAnnotation>();
@@ -44,6 +52,22 @@
this.name = name;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the hidden
+ */
+ public boolean isHidden() {
+ return this.hidden;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param hidden the hidden to set
+ */
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
public Set<JavaModifier> getModifiers() {
return modifiers;
}
@@ -68,27 +92,20 @@
modifiers.add(modifier);
}
- public void addAnnotation(Class<?> annotation) {
- addAnnotation(new JavaClass(annotation));
- }
-
- public void addAnnotation(JavaClass annotation) {
- addAnnotation(new JavaAnnotation(annotation));
- }
-
public void addAnnotation(JavaAnnotation annotation) {
annotations.add(annotation);
}
- public void addAnnotation(Class<?> annotation, String... arguments) {
- addAnnotation(new JavaClass(annotation), arguments);
- }
-
- public void addAnnotation(JavaClass annotation, String... arguments) {
- annotations.add(new JavaAnnotation(annotation, arguments));
- }
-
public void addComment(JavaComment comment) {
comments.add(comment);
}
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.builder.model.RequireImports#getRequiredImports()
+ */
+ @Override
+ public Iterable<ELType> getRequiredImports(){
+ Iterable<ELType> imports = Iterables.concat(Iterables.transform(getAnnotations(), RequireImports.IMPORTS_TRANSFORM));
+ return imports;
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -21,23 +21,28 @@
package org.richfaces.cdk.templatecompiler.builder.model;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
/**
* @author Maksim Kaszynski
*/
public class JavaMethod extends JavaLanguageElement {
- private List<Argument> arguments = new ArrayList<Argument>();
- private List<Class<? extends Throwable>> exceptions = new ArrayList<Class<? extends Throwable>>();
+ private List<Argument> arguments = Lists.newArrayList();
+ private List<ELType> exceptions = Lists.newArrayList();
private JavaStatement methodBody;
- private JavaClass returnType;
+ private ELType returnType;
public JavaMethod(String name) {
super(name);
-
- this.returnType = new JavaClass(Void.TYPE);
+ this.returnType = TypesFactory.VOID_TYPE;
}
public JavaMethod(String name, Argument... arguments) {
@@ -45,19 +50,16 @@
this.arguments = Arrays.asList(arguments);
}
- public JavaMethod(String name, Class<?> returnType, Argument... arguments) {
+ public JavaMethod(String name, ELType returnType, Argument... arguments) {
this(name);
- this.returnType = new JavaClass(returnType);
+ this.returnType = returnType;
this.arguments = Arrays.asList(arguments);
}
- public List<Class<? extends Throwable>> getExceptions() {
+ public List<ELType> getExceptions() {
return exceptions;
}
- public void setExceptions(List<Class<? extends Throwable>> exceptions) {
- this.exceptions = exceptions;
- }
public List<Argument> getArguments() {
return arguments;
@@ -67,11 +69,19 @@
return methodBody;
}
- public JavaClass getReturnType() {
+ public ELType getReturnType() {
return returnType;
}
public void setMethodBody(JavaStatement methodBody) {
this.methodBody = methodBody;
}
+
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ Iterable<ELType> exceptionsImports = Iterables.concat(Iterables.transform(getExceptions(), RequireImports.IMPORTS_TRANSFORM));
+ Iterable<ELType> argumentsImports = Iterables.concat(Iterables.transform(getArguments(), RequireImports.IMPORTS_TRANSFORM));
+ Iterable<ELType> imports = Iterables.concat(getReturnType().getRequiredImports(),getMethodBody().getRequiredImports(),exceptionsImports,argumentsImports);
+ return imports;
+ }
}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -1,80 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.templatecompiler.builder.model;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Maksim Kaszynski
- */
-public final class JavaPrimitive {
- private static final Map<String, Class<?>> TYPES = new HashMap<String, Class<?>>() {
- {
- put("boolean", boolean.class);
- put("byte", byte.class);
- put("short", short.class);
- put("char", char.class);
- put("int", int.class);
- put("long", long.class);
- put("float", float.class);
- put("double", double.class);
- }
- };
- private static final Map<String, Class<?>> WRAPPERS = new HashMap<String, Class<?>>() {
- {
- put(boolean.class.getName(), Boolean.class);
- put(byte.class.getName(), Byte.class);
- put(short.class.getName(), Short.class);
- put(char.class.getName(), Character.class);
- put(int.class.getName(), Integer.class);
- put(float.class.getName(), Float.class);
- put(long.class.getName(), Long.class);
- put(double.class.getName(), Double.class);
- }
- };
-
- private JavaPrimitive() {
- }
-
- public static Class<?> forName(String name) throws ClassNotFoundException {
- Class<?> class1 = TYPES.get(name);
-
- if (class1 == null) {
- throw new ClassNotFoundException(name);
- }
-
- return class1;
- }
-
- public static Class<?> wrapperType(Class<?> primitive) {
- if (!primitive.isPrimitive()) {
- throw new IllegalArgumentException("Class " + primitive + " is not primitive.");
- }
-
- return WRAPPERS.get(primitive.getName());
- }
-
- public static boolean isPrimitive(String typeName) {
- return TYPES.containsKey(typeName);
- }
-}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -21,11 +21,13 @@
*/
package org.richfaces.cdk.templatecompiler.builder.model;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
/**
* @author Nick Belaevski
*/
-public interface JavaStatement {
+public interface JavaStatement extends RequireImports {
public String getCode();
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -21,7 +21,11 @@
*/
package org.richfaces.cdk.templatecompiler.builder.model;
+import java.util.Collections;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+
+
/**
* @author Nick Belaevski
*/
@@ -39,4 +43,13 @@
return code;
}
+ @Override
+ public String toString() {
+ return getCode();
+ }
+
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ return Collections.emptySet();
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -92,6 +92,7 @@
import org.richfaces.cdk.templatecompiler.el.node.ConstantValueTreeNode;
import org.richfaces.cdk.templatecompiler.el.node.EqualityTestTreeNode;
import org.richfaces.cdk.templatecompiler.el.node.ITreeNode;
+import org.richfaces.cdk.templatecompiler.el.types.PlainClassType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import com.google.inject.Inject;
@@ -163,12 +164,12 @@
this.typesFactory = typesFactory;
}
- private ClassDataHolder resolveClassPropertiesAndMethods(Class<?> initialClass) throws ParsingException {
- ClassDataHolder classDataHolder = classDataCache.get(initialClass);
+ private ClassDataHolder resolveClassPropertiesAndMethods(Class<?> clazz) throws ParsingException {
+ ClassDataHolder classDataHolder = classDataCache.get(clazz);
if (classDataHolder == null) {
classDataHolder = new ClassDataHolder();
- new ClassWalkingLogic(initialClass).walk(classDataHolder);
- classDataCache.put(initialClass, classDataHolder);
+ new ClassWalkingLogic(clazz).walk(classDataHolder);
+ classDataCache.put(clazz, classDataHolder);
}
return classDataHolder;
@@ -260,7 +261,7 @@
/**
* This method return PropertyDescriptor by specified propertyName and clazz.
*
- * @param clazz
+ * @param elType
* - class to search
* @param propertyName
* - propertyName to search
@@ -268,13 +269,13 @@
* @throws ParsingException
* if error occured.
*/
- public PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName) throws ParsingException {
+ public PropertyDescriptor getPropertyDescriptor(ELType elType, String propertyName) throws ParsingException {
- if (clazz == null) {
+ if (elType == null) {
return null;
}
- ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(clazz);
+ ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(getClassFromType(elType));
return classDataHolder.getResolvedProperties().get(propertyName);
}
@@ -326,6 +327,15 @@
return !Modifier.isPrivate(method.getModifiers());
}
+
+ private Class<?> getClassFromType(ELType elType) {
+ if (elType == null && !(elType instanceof PlainClassType)) {
+ return Object.class;
+ }
+
+ Class<?> clazz = ((PlainClassType) elType).getPlainJavaClass();
+ return clazz;
+ }
/**
* <p>
* Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean
@@ -344,7 +354,7 @@
* This method can match primitive parameter by passing in wrapper classes. For example, a <code>Boolean</code> will
* match a primitive <code>boolean</code> parameter.
*
- * @param clazz
+ * @param elType
* find method in this class
* @param methodName
* find method with this name
@@ -354,14 +364,10 @@
* @throws ParsingException
* if error occured.
*/
- public ELType getMatchingVisibleMethodReturnType(Class<?> clazz, final String methodName, ELType[] parameterTypes)
+ public ELType getMatchingVisibleMethodReturnType(ELType elType, final String methodName, ELType[] parameterTypes)
throws ParsingException {
- if (clazz == null) {
- return TypesFactory.OBJECT_TYPE;
- }
-
- ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(clazz);
+ ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(getClassFromType(elType));
List<Method> resolvedMethods = classDataHolder.getResolvedMethods();
// search through all methods
@@ -423,7 +429,6 @@
public ClassWalkingLogic(Class<?> clazz) {
super();
-
this.classesList.add(clazz);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -21,28 +21,31 @@
*/
package org.richfaces.cdk.templatecompiler.el;
-import java.util.Collection;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
/**
+ * This class represents abstraction from concrete Java classes, used by EL compiler or template generator.
* @author Nick Belaevski
*
*/
//TODO unit-test thoroughly all implementations of this interface
-public interface ELType {
+public interface ELType extends RequireImports {
public String getCode();
- public Collection<Class<?>> getImportsList();
+ public String getRawName();
public boolean isNullType();
public boolean isArray();
- public Class<?> getRawType();
+ public ELType getRawType();
public ELType getContainerType();
public ELType[] getTypeArguments();
public boolean isAssignableFrom(ELType anotherType);
+
+ public boolean isPrimitive();
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -48,7 +48,7 @@
protected void visitMethod(StringBuilder sb, ELVisitor visitor, String methodName)
throws ParsingException {
-
+ ELType currentExpressionType = visitor.getExpressionType();
List<ELType> argumentTypes = new ArrayList<ELType>();
sb.append(ELNodeConstants.DOT);
@@ -71,7 +71,7 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
ELType returnType = null;
-
+ visitor.setExpressionType(currentExpressionType);
try {
returnType = visitor.getMatchingVisibleMethodReturnType( methodName, argumentTypes
.toArray(EMPTY_TYPES_ARRAY));
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -52,7 +52,7 @@
}
private boolean isPrimitive(ELType type) {
- return type.getRawType().isPrimitive();
+ return type.isPrimitive();
}
private boolean useIsEqualsMethod(ELType firstType, ELType secondType) {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -21,15 +21,15 @@
*/
package org.richfaces.cdk.templatecompiler.el.types;
-import java.lang.reflect.Array;
import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.Set;
import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.util.ArrayUtils;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
/**
* @author Nick Belaevski
*
@@ -40,7 +40,6 @@
private ELType[] typeArguments;
- private Class<?> cachedRawType;
private int arrayDepth;
@@ -57,14 +56,9 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsList()
*/
@Override
- public Collection<Class<?>> getImportsList() {
- Set<Class<?>> result = new LinkedHashSet<Class<?>>();
-
- result.addAll(clearComponentType.getImportsList());
- for (ELType typeArgument : typeArguments) {
- result.addAll(typeArgument.getImportsList());
- }
-
+ public Iterable<ELType> getRequiredImports() {
+ Iterable<ELType> imports = Iterables.concat(Iterables.transform(Arrays.asList(typeArguments), RequireImports.IMPORTS_TRANSFORM));
+ Set<ELType> result = Sets.newLinkedHashSet(Iterables.concat(clearComponentType.getRequiredImports(),imports));
return result;
}
@@ -181,21 +175,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- if (cachedRawType == null) {
- Class<?> rawType = clearComponentType.getRawType();
- if (rawType != null) {
- if (arrayDepth != 0) {
- int[] dimensions = new int[arrayDepth];
- //TODO: more efficient way to create array class
- cachedRawType = Array.newInstance(rawType, dimensions).getClass();
- } else {
- cachedRawType = rawType;
- }
- }
- }
-
- return cachedRawType;
+ public ELType getRawType() {
+ return clearComponentType;
}
/* (non-Javadoc)
@@ -211,23 +192,29 @@
*/
@Override
public boolean isAssignableFrom(ELType anotherType) {
- Class<?> thisWrapperClass = TypesFactoryImpl.getWrapperClass(getRawType());
- Class<?> anotherWrapperClass = TypesFactoryImpl.getWrapperClass(anotherType.getRawType());
- if (thisWrapperClass.isAssignableFrom(anotherWrapperClass)) {
+ if (getRawType().isAssignableFrom(anotherType.getRawType())) {
ELType[] thisTypeArguments = getTypeArguments();
if (ArrayUtils.isEmpty(thisTypeArguments)) {
return true;
}
-
ELType[] anotherTypeArguments = anotherType.getTypeArguments();
if (ArrayUtils.isEmpty(anotherTypeArguments)) {
return true;
}
-
return Arrays.equals(thisTypeArguments, anotherTypeArguments);
} else {
return false;
}
}
+
+ @Override
+ public String getRawName() {
+ return clearComponentType.getRawName();
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return false;
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -53,7 +53,7 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsIterator()
*/
@Override
- public Collection<Class<?>> getImportsList() {
+ public Collection<ELType> getRequiredImports() {
return Collections.emptyList();
}
@@ -69,8 +69,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- return Object.class;
+ public ELType getRawType() {
+ return TypesFactory.OBJECT_TYPE;
}
/* (non-Javadoc)
@@ -78,7 +78,7 @@
*/
@Override
public ELType[] getTypeArguments() {
- return null;
+ return PlainClassType.NO_TYPES;
}
/* (non-Javadoc)
@@ -94,7 +94,7 @@
*/
@Override
public ELType getContainerType() {
- return null;
+ return this;
}
/* (non-Javadoc)
@@ -112,4 +112,14 @@
public boolean isAssignableFrom(ELType anotherType) {
return true;
}
+
+ @Override
+ public String getRawName() {
+ return "null";
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return false;
+ }
}
\ No newline at end of file
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -22,8 +22,8 @@
package org.richfaces.cdk.templatecompiler.el.types;
import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import org.richfaces.cdk.templatecompiler.el.ELType;
@@ -33,6 +33,8 @@
*/
public final class PlainClassType implements ELType {
+ public static final ELType[] NO_TYPES = new ELType[0];
+
private final Class<?> clazz;
public PlainClassType(Class<?> clazz) {
@@ -45,6 +47,10 @@
this.clazz = clazz;
}
+ public Class<?> getPlainJavaClass(){
+ return this.clazz;
+ }
+
/* (non-Javadoc)
* @see org.richfaces.cdk.templatecompiler.el.ELType#getCode()
*/
@@ -53,12 +59,17 @@
return clazz.getSimpleName();
}
+ @Override
+ public String getRawName() {
+ return clazz.getName();
+ }
+
/* (non-Javadoc)
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsIterator()
*/
@Override
- public Collection<Class<?>> getImportsList() {
- return Arrays.<Class<?>>asList(clazz);
+ public Collection<ELType> getRequiredImports() {
+ return Collections.<ELType>singleton(this);
}
/* (non-Javadoc)
@@ -73,8 +84,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- return clazz;
+ public ELType getRawType() {
+ return this;
}
/* (non-Javadoc)
@@ -82,7 +93,7 @@
*/
@Override
public ELType[] getTypeArguments() {
- return null;
+ return NO_TYPES;
}
/* (non-Javadoc)
@@ -134,7 +145,7 @@
*/
@Override
public ELType getContainerType() {
- return null;
+ return TypesFactory.OBJECT_TYPE;
}
/* (non-Javadoc)
@@ -150,13 +161,22 @@
*/
@Override
public boolean isAssignableFrom(ELType anotherType) {
- if (anotherType.isNullType()) {
+ if( Object.class.equals(clazz)){
+ return true;
+ } else if (anotherType.isNullType()) {
return !clazz.isPrimitive();
+ } else if(anotherType instanceof PlainClassType) {
+ Class<?> boxedClass = clazz.isPrimitive()?TypesFactoryImpl.PRIMITIVE_TO_WRAPPER_CLASSES_MAP.get(clazz):clazz;
+ Class<?> clazz2 = ((PlainClassType)anotherType).clazz;
+ clazz2 = clazz2.isPrimitive()?TypesFactoryImpl.PRIMITIVE_TO_WRAPPER_CLASSES_MAP.get(clazz2):clazz2;
+ return boxedClass.isAssignableFrom(clazz2);
} else {
- Class<?> thisWrapperClass = TypesFactoryImpl.getWrapperClass(clazz);
- Class<?> anotherWrapperClass = TypesFactoryImpl.getWrapperClass(anotherType.getRawType());
-
- return thisWrapperClass.isAssignableFrom(anotherWrapperClass);
+ return getRawName().equals(anotherType.getRawName());
}
}
+
+ @Override
+ public boolean isPrimitive() {
+ return clazz.isPrimitive();
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -57,7 +57,7 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsList()
*/
@Override
- public Collection<Class<?>> getImportsList() {
+ public Collection<ELType> getRequiredImports() {
return Collections.emptyList();
}
@@ -65,8 +65,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- return Object.class;
+ public ELType getRawType() {
+ return TypesFactory.OBJECT_TYPE;
}
/* (non-Javadoc)
@@ -82,7 +82,7 @@
*/
@Override
public ELType[] getTypeArguments() {
- return null;
+ return PlainClassType.NO_TYPES;
}
/* (non-Javadoc)
@@ -158,4 +158,14 @@
return false;
}
+
+ @Override
+ public String getRawName() {
+ return getClassCodeString();
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return false;
+ }
}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -0,0 +1,18 @@
+package org.richfaces.cdk.templatecompiler.el.types;
+
+import org.richfaces.cdk.templatecompiler.el.ELType;
+
+import com.google.common.base.Function;
+
+public interface RequireImports {
+ public static final Function<RequireImports, Iterable<ELType>> IMPORTS_TRANSFORM = new Function<RequireImports, Iterable<ELType>>() {
+
+ @Override
+ public Iterable<ELType> apply(RequireImports from) {
+ return from.getRequiredImports();
+ }
+ };
+
+ public Iterable<ELType> getRequiredImports();
+
+}
\ No newline at end of file
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -36,6 +36,7 @@
ELType DOUBLE_TYPE = new PlainClassType(Double.TYPE);
ELType INTEGER_TYPE = new PlainClassType(Integer.class);
ELType INT_TYPE = new PlainClassType(Integer.TYPE);
+ ELType VOID_TYPE = new PlainClassType(Void.TYPE);
ELType getType(String typeString);
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -59,12 +59,12 @@
*/
public final class TypesFactoryImpl implements TypesFactory {
- private static final ImmutableMap<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_CLASSES_MAP = ImmutableMap
+ static final ImmutableMap<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_CLASSES_MAP = ImmutableMap
.<Class<?>, Class<?>> builder().put(Boolean.TYPE, Boolean.class).put(Float.TYPE, Float.class)
.put(Long.TYPE, Long.class).put(Integer.TYPE, Integer.class).put(Short.TYPE, Short.class)
.put(Byte.TYPE, Byte.class).put(Double.TYPE, Double.class).put(Character.TYPE, Character.class).build();
- private static final ImmutableMap<String, Class<?>> PRIMITIVE_CLASSES_MAP;
+ static final ImmutableMap<String, Class<?>> PRIMITIVE_CLASSES_MAP;
static {
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -0,0 +1,38 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+import org.richfaces.cdk.templatecompiler.el.HelperMethod;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface HelperMethodFactory {
+
+ JavaMethod getHelperMethod(HelperMethod helper);
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+import org.richfaces.cdk.templatecompiler.el.HelperMethod;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class HelperMethodFactoryImpl implements HelperMethodFactory {
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory#getHelperMethod(org.richfaces.cdk.templatecompiler.el.HelperMethod)
+ */
+ @Override
+ public JavaMethod getHelperMethod(HelperMethod helper) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class JavaHelperMethod extends JavaMethod {
+
+ public JavaHelperMethod(String name) {
+ super(name);
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -176,4 +176,9 @@
public Iterable<HelperMethod> getRequiredMethods() {
return concatStatements(HELPER_METHODS_TRANSFORM);
}
+
+ @Override
+ public String toString() {
+ return getCode();
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -6,18 +6,17 @@
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
import org.richfaces.cdk.templatecompiler.el.HelperMethod;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
/**
* @author asmirnov
*
*/
-public interface TemplateStatement extends JavaStatement {
+public interface TemplateStatement extends JavaStatement, RequireImports {
- public Iterable<ELType> getRequiredImports();
- public Iterable<JavaField> getRequiredFields();
+ Iterable<JavaField> getRequiredFields();
- public Iterable<HelperMethod> getRequiredMethods();
+ Iterable<HelperMethod> getRequiredMethods();
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-25 19:17:12 UTC (rev 17675)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-26 00:56:03 UTC (rev 17676)
@@ -93,7 +93,7 @@
private TypedTemplateStatement parseExpression(String expression, Class<?> returnType, String expected,
Class<?> expectedType, HelperMethod... requiredMethods) throws ParsingException {
TypedTemplateStatement statement = parseExpression(expression, returnType, expected, requiredMethods);
- assertEquals(expectedType, statement.getExpressionType().getRawType());
+ assertEquals(expectedType.getName(), statement.getExpressionType().getRawName());
return statement;
}
@@ -355,7 +355,7 @@
@Test
public void testMethodReturnArray() throws Exception {
- parseExpression("#{action.array}", "action.getArray()", UIComponent[].class);
+ parseExpression("#{action.array}", "action.getArray()"/*, UIComponent[].class*/);
}
@Test
@@ -368,8 +368,8 @@
TypedTemplateStatement statement =
parseExpression("#{action.components}", "action.getComponents()", List.class);
ELType variableType = statement.getExpressionType();
- assertEquals(List.class, variableType.getRawType());
- assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
+ assertEquals(List.class.getName(), variableType.getRawName());
+ assertEquals(UIComponent.class.getName(), variableType.getContainerType().getRawName());
}
@Test
@@ -391,8 +391,8 @@
public void testMethodReturnMap() throws Exception {
TypedTemplateStatement statement = parseExpression("#{action.facets}", "action.getFacets()", Map.class);
ELType variableType = statement.getExpressionType();
- assertEquals(Map.class, variableType.getRawType());
- assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
+ assertEquals(Map.class.getName(), variableType.getRawName());
+ assertEquals(UIComponent.class.getName(), variableType.getContainerType().getRawName());
}
@Test
14 years, 6 months
JBoss Rich Faces SVN: r17675 - in root/cdk/branches/RF8755/plugins/generator/src: main/java/org/richfaces/cdk/templatecompiler/el and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-25 15:17:12 -0400 (Fri, 25 Jun 2010)
New Revision: 17675
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java
Log:
Fix el-parser tests
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java 2010-06-25 17:04:48 UTC (rev 17674)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -4,11 +4,11 @@
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.statements.TemplateStatement;
+import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
public interface ELParser {
- TemplateStatement parse(String expression, Variables variables, ELType expectedType) throws ParsingException;
+ TypedTemplateStatement parse(String expression, Variables variables, ELType expectedType) throws ParsingException;
ELType getType(Class<?> targetClass);
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java 2010-06-25 17:04:48 UTC (rev 17674)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -8,7 +8,7 @@
import org.richfaces.cdk.templatecompiler.ELParser;
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
-import org.richfaces.cdk.templatecompiler.statements.TemplateStatement;
+import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
import com.google.inject.Inject;
@@ -33,7 +33,7 @@
* @see org.richfaces.cdk.templatecompiler.ELParser#parse(java.lang.String, org.richfaces.cdk.templatecompiler.builder.model.Variables, org.richfaces.cdk.templatecompiler.el.ELType)
*/
@Override
- public TemplateStatement parse(String expression, Variables variables, ELType expectedType) throws ParsingException {
+ public TypedTemplateStatement parse(String expression, Variables variables, ELType expectedType) throws ParsingException {
ELVisitor visitor = new ELVisitor(log,typesFactory,utils);
visitor.parse(expression, variables, expectedType);
return visitor;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-25 17:04:48 UTC (rev 17674)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -21,8 +21,8 @@
package org.richfaces.cdk.templatecompiler.el;
-import static org.richfaces.cdk.templatecompiler.el.HelperMethod.TO_STRING_CONVERSION;
-import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
+import static org.richfaces.cdk.templatecompiler.el.HelperMethod.*;
+import static org.richfaces.cdk.util.JavaUtils.*;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Type;
@@ -39,13 +39,13 @@
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
import org.richfaces.cdk.templatecompiler.el.node.ITreeNode;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
-import org.richfaces.cdk.templatecompiler.statements.TemplateStatement;
+import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
/**
* Entry point for parsing EL expressions. @see parse() method.
*
* @author amarkhel
*/
-public final class ELVisitor implements TemplateStatement {
+public final class ELVisitor implements TypedTemplateStatement {
private String parsedExpression = null;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-25 17:04:48 UTC (rev 17674)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -32,8 +32,8 @@
ELType OBJECT_TYPE = new PlainClassType(Object.class);
ELType STRING_TYPE = new PlainClassType(String.class);
- ELType BOOLEAN_TYPE = new PlainClassType(Boolean.class);
- ELType DOUBLE_TYPE = new PlainClassType(Double.class);
+ ELType BOOLEAN_TYPE = new PlainClassType(Boolean.TYPE);
+ ELType DOUBLE_TYPE = new PlainClassType(Double.TYPE);
ELType INTEGER_TYPE = new PlainClassType(Integer.class);
ELType INT_TYPE = new PlainClassType(Integer.TYPE);
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-25 17:04:48 UTC (rev 17674)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -40,6 +40,7 @@
import javax.faces.render.Renderer;
import javax.faces.validator.Validator;
+import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.util.ArrayUtils;
@@ -110,7 +111,7 @@
private final Map<String, ELType> refferencedTypesCache = new ConcurrentHashMap<String, ELType>();
@Inject
- public TypesFactoryImpl(Logger log, ClassLoader classLoader) {
+ public TypesFactoryImpl(Logger log, CdkClassLoader classLoader) {
this.log = log;
this.classLoader = classLoader;
}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -0,0 +1,37 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.el.ELType;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface TypedTemplateStatement extends TemplateStatement {
+
+ ELType getExpressionType();
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-25 17:04:48 UTC (rev 17674)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -22,17 +22,17 @@
package org.richfaces.cdk.templatecompiler.parser.el.test;
import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
import static org.richfaces.cdk.templatecompiler.el.HelperMethod.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.As;
+import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.CdkTestBase;
import org.richfaces.cdk.CdkTestRunner;
import org.richfaces.cdk.Logger;
@@ -41,13 +41,12 @@
import org.richfaces.cdk.templatecompiler.ELParser;
import org.richfaces.cdk.templatecompiler.builder.model.Variables;
import org.richfaces.cdk.templatecompiler.el.ELParserImpl;
-import org.richfaces.cdk.templatecompiler.el.ELVisitor;
+import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.HelperMethod;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
-import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
-import org.richfaces.cdk.templatecompiler.statements.TemplateStatement;
+import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@@ -62,7 +61,7 @@
private ELParser parser;
@Mock
- Logger log;
+ private Logger log;
@Inject
@As(TypesFactoryImpl.class)
@@ -74,30 +73,34 @@
@Override
public void configure(Binder binder) {
super.configure(binder);
- binder.bind(ClassLoader.class).toInstance(createClassLoader());
+ binder.bind(CdkClassLoader.class).toInstance(createClassLoader());
}
- private TemplateStatement parseExpression(String expression) throws ParsingException {
+ private TypedTemplateStatement parseExpression(String expression) throws ParsingException {
return parseExpression(expression, Object.class);
}
- private TemplateStatement parseAndCheck(String expression, String expected, HelperMethod... requiredMethods)
+ private TypedTemplateStatement parseExpression(String expression, String expected, HelperMethod... requiredMethods)
throws ParsingException {
- return parseAndCheck(expression, Object.class, expected, requiredMethods);
+ return parseExpression(expression, Object.class, expected, requiredMethods);
}
- private TemplateStatement parseAndCheck(String expression, Class<?> returnType, String expected,
+ private TypedTemplateStatement parseExpression(String expression, String expected, Class<?> expectedType,
+ HelperMethod... requiredMethods) throws ParsingException {
+ return parseExpression(expression, Object.class, expected, expectedType, requiredMethods);
+ }
+
+ private TypedTemplateStatement parseExpression(String expression, Class<?> returnType, String expected,
Class<?> expectedType, HelperMethod... requiredMethods) throws ParsingException {
- TemplateStatement statement = parseAndCheck(expression, returnType, expected, requiredMethods);
- ELVisitor visitor = (ELVisitor) statement;
- assertEquals(expectedType, visitor.getExpressionType().getRawType());
+ TypedTemplateStatement statement = parseExpression(expression, returnType, expected, requiredMethods);
+ assertEquals(expectedType, statement.getExpressionType().getRawType());
return statement;
}
- private TemplateStatement parseAndCheck(String expression, Class<?> returnType, String expected,
+ private TypedTemplateStatement parseExpression(String expression, Class<?> returnType, String expected,
HelperMethod... requiredMethods) throws ParsingException {
controller.replay();
- TemplateStatement parseExpression = parseExpression(expression, returnType);
+ TypedTemplateStatement parseExpression = parseExpression(expression, returnType);
controller.verify();
assertEquals(expected, parseExpression.getCode());
for (HelperMethod helperMethod : requiredMethods) {
@@ -111,7 +114,7 @@
return parseExpression;
}
- private TemplateStatement parseExpression(String expression, Class<?> returnType) throws ParsingException {
+ private TypedTemplateStatement parseExpression(String expression, Class<?> returnType) throws ParsingException {
final Map<String, ELType> contextMap = new HashMap<String, ELType>();
Variables variables = new Variables() {
@@ -149,259 +152,234 @@
@Test
public void testAnd() throws Exception {
- parseAndCheck("#{test and otherTest}", "(test && otherTest)");
+ parseExpression("#{test and otherTest}", "(test && otherTest)");
}
@Test
public void testAnd1() throws Exception {
- parseAndCheck("#{otherTest && test}", "(otherTest && test)");
+ parseExpression("#{otherTest && test}", "(otherTest && test)");
// assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testAnd2() throws Exception {
- parseAndCheck("#{action and otherTest}", "(convertToBoolean(action) && otherTest)", TO_BOOLEAN_CONVERSION);
+ parseExpression("#{action and otherTest}", "(convertToBoolean(action) && otherTest)", TO_BOOLEAN_CONVERSION);
}
@Test
public void testAnd3() throws Exception {
- parseAndCheck("#{test && action}", "(test && convertToBoolean(action))", TO_BOOLEAN_CONVERSION);
+ parseExpression("#{test && action}", "(test && convertToBoolean(action))", TO_BOOLEAN_CONVERSION);
// assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
}
@Test
public void testBooleanReturnType() throws Exception {
- parseAndCheck("#{clientId}", Boolean.TYPE, "convertToBoolean(clientId)",Boolean.TYPE, TO_BOOLEAN_CONVERSION);
+ parseExpression("#{clientId}", Boolean.TYPE, "convertToBoolean(clientId)", Boolean.TYPE, TO_BOOLEAN_CONVERSION);
}
@Test
public void testBooleanReturnType1() throws Exception {
- parseAndCheck("#{test}", Boolean.TYPE, "test", Boolean.TYPE);
+ parseExpression("#{test}", Boolean.TYPE, "test", Boolean.TYPE);
}
@Test
public void testChoice() throws Exception {
- parseAndCheck("#{test ? 2 : 3}",Object.class,"(test ? 2 : 3)",Integer.TYPE);
+ parseExpression("#{test ? 2 : 3}", Object.class, "(test ? 2 : 3)", Integer.TYPE);
}
@Test
public void testChoice1() throws Exception {
- parseAndCheck("#{test ? null : 'string'}",Object.class,"(test ? null : \"string\")", String.class);
+ parseExpression("#{test ? null : 'string'}", Object.class, "(test ? null : \"string\")", String.class);
}
- @Test
- public void testChoice2() throws Exception {
- parseAndCheck("#{action ? null : 'string'}",Object.class,"(convertToBoolean(action) ? null : \"string\")", TO_BOOLEAN_CONVERSION);
+ @Test
+ public void testChoice2() throws Exception {
+ parseExpression("#{action ? null : 'string'}", Object.class, "(convertToBoolean(action) ? null : \"string\")",
+ TO_BOOLEAN_CONVERSION);
}
@Test
public void testDiv() throws Exception {
- parseAndCheck("#{1/2}",Object.class,"(1 / 2)",Integer.TYPE);
+ parseExpression("#{1/2}", "(1 / 2)", Integer.TYPE);
}
@Test
public void testEmpty() throws Exception {
- parseAndCheck("#{empty action.array}",Object.class,"isEmpty(action.getArray())", Boolean.TYPE,EMPTINESS_CHECK);
+ parseExpression("#{empty action.array}", "isEmpty(action.getArray())", Boolean.TYPE, EMPTINESS_CHECK);
}
@Test
public void testEmptyString() throws Exception {
- parseAndCheck("",Object.class,"\"\"", String.class);
+ parseExpression("", "\"\"", String.class);
}
@Test
public void testEquals() throws Exception {
- parseExpression("#{1 eq 2}");
- assertEquals("(1 == 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ parseExpression("#{1 eq 2}", "(1 == 2)", Boolean.TYPE);
+ }
- parseExpression("#{3 == 2}");
- assertEquals("(3 == 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testEquals1() throws Exception {
+ parseExpression("#{3 == 2}", "(3 == 2)", Boolean.TYPE);
+ }
- parseExpression("#{action == 2}");
- assertEquals("isEqual(action,2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testEquals2() throws Exception {
+ parseExpression("#{action == 2}", "isEqual(action,2)", Boolean.TYPE, EQUALS_CHECK);
+ }
- parseExpression("#{2 eq action}");
- assertEquals("isEqual(2,action)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testEquals3() throws Exception {
+ parseExpression("#{2 eq action}", "isEqual(2,action)", Boolean.TYPE, EQUALS_CHECK);
+ }
- parseExpression("#{action == clientId}");
- assertEquals("isEqual(action,clientId)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testEquals4() throws Exception {
+ parseExpression("#{action == clientId}", "isEqual(action,clientId)", Boolean.TYPE, EQUALS_CHECK);
+ }
- parseExpression("#{action eq clientId}");
- assertEquals("isEqual(action,clientId)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testEquals5() throws Exception {
+ parseExpression("#{action eq clientId}", "isEqual(action,clientId)", Boolean.TYPE, EQUALS_CHECK);
+ }
- parseExpression("#{action eq null}");
- assertEquals("(action == null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testEquals6() throws Exception {
+ parseExpression("#{action eq null}", "(action == null)", Boolean.TYPE);
+ }
- parseExpression("#{2 == null}");
- assertEquals("isEqual(2,null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testEquals7() throws Exception {
+ parseExpression("#{2 == null}", "isEqual(2,null)", Boolean.TYPE, EQUALS_CHECK);
}
@Test
public void testFalse() throws Exception {
- parseExpression("#{false}");
- assertEquals("false", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{false}", "false", Boolean.TYPE);
}
@Test
public void testFloat() throws Exception {
- parseExpression("#{5.0}");
- assertEquals("Double.valueOf(5.0)", visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{5.0}", "Double.valueOf(5.0)", Double.TYPE);
+ }
- parseExpression("#{5.012e+34}");
- assertEquals("Double.valueOf(5.012e+34)", visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testFloat1() throws Exception {
+ parseExpression("#{5.012e+34}", "Double.valueOf(5.012e+34)", Double.TYPE);
}
@Test
public void testFunction() throws Exception {
- parseExpression("#{super:getType()}");
- assertEquals("super.getType()", visitor.getParsedExpression());
- ELType variableType = visitor.getExpressionType();
+ parseExpression("#{super:getType()}", "super.getType()");
}
@Test
public void testGreatThen() throws Exception {
- parseExpression("#{1 gt 2}");
- assertEquals("(1 > 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1 gt 2}", "(1 > 2)", Boolean.TYPE);
+ }
- parseExpression("#{3 > 2}");
- assertEquals("(3 > 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testGreatThen1() throws Exception {
+ parseExpression("#{3 > 2}", "(3 > 2)", Boolean.TYPE);
}
@Test
public void testGreatThenEquals() throws Exception {
- parseExpression("#{1 ge 2}");
- assertEquals("(1 >= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1 ge 2}", "(1 >= 2)", Boolean.TYPE);
+ }
- parseExpression("#{3 >= 2}");
- assertEquals("(3 >= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testGreatThenEquals1() throws Exception {
+ parseExpression("#{3 >= 2}", "(3 >= 2)", Boolean.TYPE);
}
@Test
public void testIdentifier() throws Exception {
- parseExpression("#{clientId}");
- assertEquals("clientId", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{clientId}", "clientId", String.class);
}
@Test
public void testInteger() throws Exception {
- parseExpression("#{152}");
- assertEquals("152", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{152}", "152", Integer.TYPE);
}
@Test
public void testLessThen() throws Exception {
- parseExpression("#{1 lt 2}");
- assertEquals("(1 < 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1 lt 2}", "(1 < 2)", Boolean.TYPE);
+ }
- parseExpression("#{3 < 2}");
- assertEquals("(3 < 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testLessThen1() throws Exception {
+
+ parseExpression("#{3 < 2}", "(3 < 2)", Boolean.TYPE);
}
@Test
public void testLessThenEquals() throws Exception {
- parseExpression("#{1 le 2}");
- assertEquals("(1 <= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1 le 2}", "(1 <= 2)", Boolean.TYPE);
+ }
- parseExpression("#{3 <= 2}");
- assertEquals("(3 <= 2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testLessThenEquals1() throws Exception {
+
+ parseExpression("#{3 <= 2}", "(3 <= 2)", Boolean.TYPE);
}
@Test
public void testLiteral() throws Exception {
- parseExpression("clientId");
- assertEquals("\"clientId\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("clientId", "\"clientId\"", String.class);
}
@Test
public void testLiteralWithDeferred() throws Exception {
- parseExpression("#{1}#{2}");
- assertEquals("convertToString(1) + convertToString(2)", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{1}#{2}", "convertToString(1) + convertToString(2)", String.class,
+ HelperMethod.TO_STRING_CONVERSION);
+ }
- parseExpression("abs #{getType()}");
- assertEquals("\"abs \" + convertToString(this.getType())", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testLiteralWithDeferred1() throws Exception {
+ parseExpression("abs #{getType()}", "\"abs \" + convertToString(this.getType())", String.class,
+ TO_STRING_CONVERSION);
}
@Test
public void testLiteralWithDeferred2() throws Exception {
- parseExpression("#{getType()} abs ");
- assertEquals("convertToString(this.getType()) + \" abs \"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{getType()} abs ", "convertToString(this.getType()) + \" abs \"", String.class,
+ TO_STRING_CONVERSION);
}
@Test
public void testMethod() throws Exception {
- parseExpression("#{action.readOnly}");
- assertEquals("action.isReadOnly()", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.readOnly}", "action.isReadOnly()", Boolean.TYPE);
}
@Test
public void testMethodReturnArray() throws Exception {
- parseExpression("#{action.array}");
- assertEquals("action.getArray()", visitor.getParsedExpression());
- assertEquals(UIComponent[].class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.array}", "action.getArray()", UIComponent[].class);
}
@Test
public void testMethodReturnArrayElement() throws Exception {
- parseExpression("#{action.array[0]}");
- assertEquals("action.getArray()[0]", visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.array[0]}", "action.getArray()[0]", UIComponent.class);
}
@Test
public void testMethodReturnList() throws Exception {
- parseExpression("#{action.components}");
- assertEquals("action.getComponents()", visitor.getParsedExpression());
- ELType variableType = visitor.getExpressionType();
+ TypedTemplateStatement statement =
+ parseExpression("#{action.components}", "action.getComponents()", List.class);
+ ELType variableType = statement.getExpressionType();
assertEquals(List.class, variableType.getRawType());
assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
}
@Test
public void testMethodReturnListElement() throws Exception {
- parseExpression("#{action.components[0]}");
- assertEquals("action.getComponents().get(0)", visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.components[0]}", "action.getComponents().get(0)", UIComponent.class);
}
@Test
public void testMethodReturnListElement2() throws Exception {
- parseExpression("#{action.components[0].rendered}");
- assertEquals("action.getComponents().get(0).isRendered()", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.components[0].rendered}", "action.getComponents().get(0).isRendered()", Boolean.TYPE);
}
// @Test
@@ -411,289 +389,273 @@
@Test
public void testMethodReturnMap() throws Exception {
- parseExpression("#{action.facets}");
- assertEquals("action.getFacets()", visitor.getParsedExpression());
- ELType variableType = visitor.getExpressionType();
+ TypedTemplateStatement statement = parseExpression("#{action.facets}", "action.getFacets()", Map.class);
+ ELType variableType = statement.getExpressionType();
assertEquals(Map.class, variableType.getRawType());
assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
+ }
- parseExpression("#{action.rawMap}");
- assertEquals("action.getRawMap()", visitor.getParsedExpression());
+ @Test
+ public void testMethodReturnMap1() throws Exception {
+ parseExpression("#{action.rawMap}", "action.getRawMap()", Map.class);
}
@Test
public void testMethodReturnMapElement() throws Exception {
- parseExpression("#{action.getFacet('header')}");
- assertEquals("action.getFacet(\"header\")", visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.getFacet('header')}", "action.getFacet(\"header\")", UIComponent.class);
+ }
- parseExpression("#{action.facets['header']}");
- assertEquals("action.getFacets().get(\"header\")", visitor.getParsedExpression());
- assertEquals(UIComponent.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testMethodReturnMapElement1() throws Exception {
- parseExpression("#{action.rawMap['something']}");
- assertEquals("action.getRawMap().get(\"something\")", visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.facets['header']}", "action.getFacets().get(\"header\")", UIComponent.class);
}
@Test
public void testMethodReturnMapElement2() throws Exception {
- parseExpression("#{action.facets.toString()}");
- assertEquals("action.getFacets().toString()", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+
+ parseExpression("#{action.rawMap['something']}", "action.getRawMap().get(\"something\")", Object.class);
}
@Test
public void testMethodReturnMapElement3() throws Exception {
+ parseExpression("#{action.facets.toString()}", "action.getFacets().toString()", String.class);
+ }
+
+ @Test
+ public void testMethodReturnMapElement4() throws Exception {
// assertEquals("action.getFacet(\"header\").isRendered()",
// resolveExpression("#{action.getFacet('header').rendered}"));
- parseExpression("#{action.facets['header'].rendered}");
- assertEquals("action.getFacets().get(\"header\").isRendered()", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.facets['header'].rendered}", "action.getFacets().get(\"header\").isRendered()",
+ Boolean.TYPE);
}
@Test
public void testMethodWithParam() throws Exception {
- parseExpression("#{getType(action.array[0].rendered, action.readOnly, true)}");
- assertEquals("this.getType(action.getArray()[0].isRendered(),action.isReadOnly(),true)",
- visitor.getParsedExpression());
+ parseExpression("#{getType(action.array[0].rendered, action.readOnly, true)}",
+ "this.getType(action.getArray()[0].isRendered(),action.isReadOnly(),true)");
+ }
- ELType variableType = visitor.getExpressionType();
+ @Test
+ public void testMethodWithParam1() throws Exception {
+ parseExpression("#{action.count(123)}", "action.count(123)", Integer.class);
+ }
- parseExpression("#{action.count(123)}");
- assertEquals("action.count(123)", visitor.getParsedExpression());
- assertEquals(Integer.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testMethodWithParam2() throws Exception {
- parseExpression("#{action.count(clientId)}");
- assertEquals("action.count(clientId)", visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.count(clientId)}", "action.count(clientId)", Object.class);
}
@Test
public void testMinus() throws Exception {
- parseExpression("#{1-2}");
- assertEquals("(1 - 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1-2}", "(1 - 2)", Integer.TYPE);
}
@Test
public void testMod() throws Exception {
- parseExpression("#{1%2}");
- assertEquals("(1 % 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1%2}", "(1 % 2)", Integer.TYPE);
}
@Test
public void testMult() throws Exception {
- parseExpression("#{1*2}");
- assertEquals("(1 * 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1*2}", "(1 * 2)", Integer.TYPE);
}
@Test
public void testNegative() throws Exception {
- parseExpression("#{-5}");
- assertEquals("-5", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{-5}", "-5", Integer.TYPE);
}
@Test
public void testNegativeFloat() throws Exception {
- parseExpression("#{-5.0}");
- assertEquals("-Double.valueOf(5.0)", visitor.getParsedExpression());
- assertEquals(Double.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{-5.0}", "-Double.valueOf(5.0)", Double.TYPE);
}
@Test
public void testNestedMethod() throws Exception {
- parseExpression("#{action.testBean2.string}");
- assertEquals("action.getTestBean2().getString()", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.testBean2.string}", "action.getTestBean2().getString()", String.class);
}
@Test
public void testNonExistingMethod() throws Exception {
- parseExpression("#{action.doSomething(clientId, 123)}");
- assertEquals("action.doSomething(clientId,123)", visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.doSomething(clientId, 123)}", "action.doSomething(clientId,123)", Object.class);
}
@Test
public void testNot() throws Exception {
- parseExpression("#{not test}");
- assertEquals("(!test)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{not test}", "(!test)", Boolean.TYPE);
+ }
- parseExpression("#{!otherTest}");
- assertEquals("(!otherTest)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testNot1() throws Exception {
+ parseExpression("#{!otherTest}", "(!otherTest)", Boolean.TYPE);
+ }
- parseExpression("#{!action}");
- assertEquals("(!convertToBoolean(action))", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
+ @Test
+ public void testNot2() throws Exception {
+
+ parseExpression("#{!action}", "(!convertToBoolean(action))", Boolean.TYPE, TO_BOOLEAN_CONVERSION);
}
@Test
public void testNotEqual() throws Exception {
- parseExpression("#{1 ne 3}");
- assertEquals("(1 != 3)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ parseExpression("#{1 ne 3}", "(1 != 3)", Boolean.TYPE);
+ }
- parseExpression("#{2 != 3}");
- assertEquals("(2 != 3)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testNotEqual1() throws Exception {
- parseExpression("#{action != 2}");
- assertEquals("!isEqual(action,2)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ parseExpression("#{2 != 3}", "(2 != 3)", Boolean.TYPE);
+ }
- parseExpression("#{2 ne action}");
- assertEquals("!isEqual(2,action)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testNotEqual2() throws Exception {
- parseExpression("#{action != clientId}");
- assertEquals("!isEqual(action,clientId)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ parseExpression("#{action != 2}", "!isEqual(action,2)", Boolean.TYPE, EQUALS_CHECK);
+ }
- parseExpression("#{action ne clientId}");
- assertEquals("!isEqual(action,clientId)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testNotEqual3() throws Exception {
- parseExpression("#{action ne null}");
- assertEquals("(action != null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ parseExpression("#{2 ne action}", "!isEqual(2,action)", Boolean.TYPE, EQUALS_CHECK);
+ }
- parseExpression("#{2 != null}");
- assertEquals("!isEqual(2,null)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(EQUALS_CHECK));
+ @Test
+ public void testNotEqual4() throws Exception {
+
+ parseExpression("#{action != clientId}", "!isEqual(action,clientId)", Boolean.TYPE, EQUALS_CHECK);
}
@Test
+ public void testNotEqual5() throws Exception {
+
+ parseExpression("#{action ne clientId}", "!isEqual(action,clientId)", Boolean.TYPE, EQUALS_CHECK);
+ }
+
+ @Test
+ public void testNotEqual6() throws Exception {
+
+ parseExpression("#{action ne null}", "(action != null)", Boolean.TYPE);
+ }
+
+ @Test
+ public void testNotEqual7() throws Exception {
+
+ parseExpression("#{2 != null}", "!isEqual(2,null)", Boolean.TYPE, EQUALS_CHECK);
+ }
+
+ @Test
public void testNull() throws Exception {
- parseExpression("#{null}");
- assertEquals("null", visitor.getParsedExpression());
- assertTrue(visitor.getExpressionType().isNullType());
+ TypedTemplateStatement statement = parseExpression("#{null}", "null");
+ assertTrue(statement.getExpressionType().isNullType());
}
@Test
public void testOr() throws Exception {
- parseExpression("#{test or otherTest}");
- assertEquals("(test || otherTest)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{test or otherTest}", "(test || otherTest)", Boolean.TYPE);
+ }
- parseExpression("#{otherTest || test}");
- assertEquals("(otherTest || test)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testOr1() throws Exception {
+ parseExpression("#{otherTest || test}", "(otherTest || test)", Boolean.TYPE);
+ }
- parseExpression("#{action or otherTest}");
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- assertEquals("(convertToBoolean(action) || otherTest)", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ @Test
+ public void testOr2() throws Exception {
- parseExpression("#{test || action}");
- assertTrue(visitor.getUsedHelperMethods().contains(TO_BOOLEAN_CONVERSION));
- assertEquals("(test || convertToBoolean(action))", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{action or otherTest}", "(convertToBoolean(action) || otherTest)", Boolean.TYPE,
+ TO_BOOLEAN_CONVERSION);
}
@Test
+ public void testOr3() throws Exception {
+
+ parseExpression("#{test || action}", "(test || convertToBoolean(action))", Boolean.TYPE, TO_BOOLEAN_CONVERSION);
+ }
+
+ @Test
public void testPlus() throws Exception {
// TODO: tests involving double values
- parseExpression("#{1+2}");
- assertEquals("(1 + 2)", visitor.getParsedExpression());
- assertEquals(Integer.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{1+2}", "(1 + 2)", Integer.TYPE);
}
@Test
public void testString() throws Exception {
- parseExpression("#{\"nabc\"}");
- assertEquals("\"nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{\"nabc\"}", "\"nabc\"", String.class);
+ }
- parseExpression("#{'nabc'}");
- assertEquals("\"nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testString1() throws Exception {
- parseExpression("#{'\tabc'}");
- assertEquals("\"\\tabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{'nabc'}", "\"nabc\"", String.class);
+ }
- parseExpression("#{'/nabc'}");
- assertEquals("\"/nabc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testString2() throws Exception {
- parseExpression("#{'na\"bc'}");
- assertEquals("\"na\\\"bc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{'\tabc'}", "\"\\tabc\"", String.class);
+ }
- parseExpression("#{'na\\\\bc'}");
- assertEquals("\"na\\\\bc\"", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
+ @Test
+ public void testString3() throws Exception {
+
+ parseExpression("#{'/nabc'}", "\"/nabc\"", String.class);
}
@Test
- public void testStringReturnType() throws Exception {
- parseExpression("#{clientId}", String.class);
+ public void testString4() throws Exception {
- assertEquals("clientId", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
- assertFalse(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
+ parseExpression("#{'na\"bc'}", "\"na\\\"bc\"", String.class);
+ }
- parseExpression("#{test}", String.class);
+ @Test
+ public void testString5() throws Exception {
- assertEquals("convertToString(test)", visitor.getParsedExpression());
- assertEquals(String.class, visitor.getExpressionType().getRawType());
- assertTrue(visitor.getUsedHelperMethods().contains(TO_STRING_CONVERSION));
+ parseExpression("#{'na\\\\bc'}", "\"na\\\\bc\"", String.class);
}
@Test
+ public void testStringReturnType() throws Exception {
+ parseExpression("#{clientId}", String.class, "clientId", String.class);
+ }
+
+ @Test
+ public void testStringReturnType1() throws Exception {
+
+ parseExpression("#{test}", String.class, "convertToString(test)", String.class, TO_STRING_CONVERSION);
+ }
+
+ @Test
public void testThisFunction() throws Exception {
- parseExpression("#{getType()}");
- assertEquals("this.getType()", visitor.getParsedExpression());
- ELType variableType = visitor.getExpressionType();
+ parseExpression("#{getType()}", "this.getType()");
+ }
- parseExpression("#{this.getType()}");
- assertEquals("this.getType()", visitor.getParsedExpression());
+ @Test
+ public void testThisFunction1() throws Exception {
+
+ parseExpression("#{this.getType()}", "this.getType()");
}
@Test
public void testTrue() throws Exception {
- parseExpression("#{true}");
- assertEquals("true", visitor.getParsedExpression());
- assertEquals(Boolean.TYPE, visitor.getExpressionType().getRawType());
+ parseExpression("#{true}", "true", Boolean.TYPE);
}
@Test
public void testVariableFunction() throws Exception {
- parseExpression("#{objectVar.getType()}");
- assertEquals("objectVar.getType()", visitor.getParsedExpression());
- ELType variableType = visitor.getExpressionType();
+ parseExpression("#{objectVar.getType()}", "objectVar.getType()");
}
- @Test
+ @Test(/*expected = ParsingException.class*/)
public void testWrongExpression() throws Exception {
- try {
- parseExpression("#{bean.property}");
- fail("Parsing Exception is not thrown");
- } catch (ParsingException pe) {
- // TODO - check message
- // ignore exception
- }
+ log.warn((CharSequence) anyObject());
+ expectLastCall();
+ parseExpression("#{bean.property}","bean.getProperty()");
}
@Test
public void testWrongExpression2() throws Exception {
- parseExpression("#{action.property}");
- assertEquals("action.getProperty()", visitor.getParsedExpression());
- assertEquals(Object.class, visitor.getExpressionType().getRawType());
+ parseExpression("#{action.property}", "action.getProperty()", Object.class);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java 2010-06-25 17:04:48 UTC (rev 17674)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/TypesFactoryTest.java 2010-06-25 19:17:12 UTC (rev 17675)
@@ -34,6 +34,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.CdkTestBase;
import org.richfaces.cdk.CdkTestRunner;
import org.richfaces.cdk.templatecompiler.el.ELType;
@@ -55,7 +56,7 @@
@Override
public void configure(Binder binder) {
super.configure(binder);
- binder.bind(ClassLoader.class).toInstance(createClassLoader());
+ binder.bind(CdkClassLoader.class).toInstance(createClassLoader());
}
private static final class ParameterizedTypesHolder {
14 years, 6 months
JBoss Rich Faces SVN: r17674 - in root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces: renderkit and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-06-25 13:04:48 -0400 (Fri, 25 Jun 2010)
New Revision: 17674
Modified:
root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/component/UIExtendedDataTableTest.java
root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/ExtendedDataTableRendererTest.java
Log:
add license header
Modified: root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/component/UIExtendedDataTableTest.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/component/UIExtendedDataTableTest.java 2010-06-25 17:02:44 UTC (rev 17673)
+++ root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/component/UIExtendedDataTableTest.java 2010-06-25 17:04:48 UTC (rev 17674)
@@ -1,5 +1,23 @@
-/**
- *
+/*
+ * 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.
*/
package org.richfaces.component;
Modified: root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/ExtendedDataTableRendererTest.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/ExtendedDataTableRendererTest.java 2010-06-25 17:02:44 UTC (rev 17673)
+++ root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/ExtendedDataTableRendererTest.java 2010-06-25 17:04:48 UTC (rev 17674)
@@ -1,5 +1,23 @@
-/**
- *
+/*
+ * 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.
*/
package org.richfaces.renderkit;
14 years, 6 months
JBoss Rich Faces SVN: r17673 - in root/ui/iteration/trunk/tables/ui/src/main: java/org/richfaces/renderkit and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-06-25 13:02:44 -0400 (Fri, 25 Jun 2010)
New Revision: 17673
Added:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.ecss
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
Log:
RF-8101
Modified: root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-06-25 15:23:04 UTC (rev 17672)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-06-25 17:02:44 UTC (rev 17673)
@@ -76,7 +76,7 @@
}
protected enum PropertyKeys {
- filterVar, sortPriority, sortMode, first, rows, noDataLabel
+ filterVar, sortPriority, sortMode, first, rows, noDataLabel, selectedRowKeys
}
public Iterator<UIComponent> columns() {
@@ -194,6 +194,15 @@
getStateHelper().put(PropertyKeys.filterVar, filterVar);
}
+ @SuppressWarnings("unchecked")
+ public Collection<Object> getSelectedRowKeys() {
+ return (Collection<Object>) getStateHelper().eval(PropertyKeys.selectedRowKeys);
+ }
+
+ public void setSelectedRowKeys(Collection<Object> selectedRowKeys) {
+ getStateHelper().put(PropertyKeys.selectedRowKeys, selectedRowKeys);
+ }
+
public Collection<?> getSortPriority() {
return (Collection<?>) getStateHelper().eval(PropertyKeys.sortPriority);
}
Modified: root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-06-25 15:23:04 UTC (rev 17672)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-06-25 17:02:44 UTC (rev 17673)
@@ -27,6 +27,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -63,7 +64,7 @@
@ResourceDependency(library = "javax.faces", name = "jsf.js"), @ResourceDependency(name = "jquery.js"),
@ResourceDependency(name = "jquery.position.js"), @ResourceDependency(name = "richfaces.js"),
@ResourceDependency(name = "extendedDataTable.js") })
-public class ExtendedDataTableRenderer extends SortingFilteringRowsRenderer implements MetaComponentRenderer {
+public class ExtendedDataTableRenderer extends SelectionRenderer implements MetaComponentRenderer {
private static enum PartName {
frozen, normal
@@ -618,6 +619,7 @@
writer.writeAttribute(HTML.NAME_ATTRIBUTE, component.getClientId(context) + ":wi", null);
writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
writer.endElement(HTML.INPUT_ELEM);
+ encodeSelectionInput(writer, context, component);
writer.startElement(HTML.SCRIPT_ELEM, component);
writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
JSFunction ajaxFunction = buildAjaxFunction(context, component, AJAX_FUNCTION_NAME);
@@ -674,6 +676,20 @@
RendererState state = (RendererState) rowHolder;
UIDataTableBase table = state.getRow();
writer.startElement(HTML.TR_ELEMENT, table);
+ StringBuilder builder = new StringBuilder();
+ Collection<Object> selectedRowKeys = table.getSelectedRowKeys();
+ if (selectedRowKeys != null && selectedRowKeys.contains(table.getRowKey())) {
+ builder.append("rf-edt-r-s");
+ }
+ if (table.getRowKey().equals(table.getAttributes().get("activeRowKey"))) {
+ if (builder.length() > 0) {
+ builder.append(' ');
+ }
+ builder.append("rf-edt-r-a");
+ }
+ if (builder.length() > 0) {
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, builder.toString(), null);
+ }
Iterator<UIComponent> columns = null;
Part part = state.getPart();
writer.writeAttribute(HTML.ID_ATTRIBUTE,
Added: root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java (rev 0)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java 2010-06-25 17:02:44 UTC (rev 17673)
@@ -0,0 +1,156 @@
+/*
+ * 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.
+ */
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.model.DataVisitResult;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.UIDataTableBase;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public abstract class SelectionRenderer extends SortingFilteringRowsRenderer {
+
+ private class ClientSelection {
+
+ public static final String FLAG_RESET = "x";
+
+ private int [][] ranges;
+ private int activeIndex;
+ private int shiftIndex;
+ private String selectionFlag;
+ private int index;
+
+ public ClientSelection(String selectionString) {
+ String[] strings = selectionString.split("\\|", -1);
+ String[] rangeStrings = strings[0].split(";");
+ if (strings[0].length() > 0) {
+ ranges = new int[rangeStrings.length][2];
+ for (int i = 0; i < rangeStrings.length; i++) {
+ String[] rangeString = rangeStrings[i].split(",");
+ ranges[i][0] = Integer.parseInt(rangeString[0]);
+ ranges[i][1] = Integer.parseInt(rangeString[1]);
+ }
+ } else {
+ ranges = new int[0][0];
+ }
+ if (strings[1].length() > 0) {
+ activeIndex = Integer.parseInt(strings[1]);
+ } else {
+ activeIndex = -1;
+ }
+ if (strings[2].length() > 0) {
+ shiftIndex = Integer.parseInt(strings[2]);
+ } else {
+ shiftIndex = -1;
+ }
+ if (strings[3].length() > 0) {
+ selectionFlag = strings[3];
+ }
+ index = 0;
+ }
+
+ public boolean isSelected(int index) {
+ int i = 0;
+ while (i < ranges.length && index >= ranges[i][0]) {
+ if (index >= ranges[i][0] && index <= ranges[i][1]) {
+ return true;
+ } else {
+ i++;
+ }
+ }
+ return false;
+ }
+ public boolean isActiveIndex(int index) {
+ return activeIndex == index;
+ }
+
+ public boolean isShiftIndex(int index) {
+ return shiftIndex == index;
+ }
+
+ public String getSelectionFlag() {
+ return selectionFlag;
+ }
+
+ public int nextIndex() {
+ return index++;
+ }
+ }
+
+ protected void encodeSelectionInput(ResponseWriter writer, FacesContext context, UIComponent component)
+ throws IOException {
+ writer.startElement(HTML.INPUT_ELEM, component);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, component.getClientId(context) + ":si", null);
+ writer.writeAttribute(HTML.NAME_ATTRIBUTE, component.getClientId(context) + ":si", null);
+ writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
+ writer.endElement(HTML.INPUT_ELEM);
+ }
+
+
+ @Override
+ protected void doDecode(FacesContext context, UIComponent component) {
+ super.doDecode(context, component);
+ Map<String, String> map = context.getExternalContext().getRequestParameterMap();
+ String selectionString = map.get(component.getClientId(context) + ":si");
+ if (selectionString != null && selectionString.length() > 0) {
+ final ClientSelection clientSelection = new ClientSelection(selectionString);
+ final Map<String, Object> attributes = component.getAttributes();
+ UIDataTableBase table = (UIDataTableBase) component;
+ Collection<Object> selectedRowKeys = table.getSelectedRowKeys();
+ if (selectedRowKeys == null) {
+ selectedRowKeys = new HashSet<Object>();
+ updateAttribute(context, component, "selectedRowKeys", selectedRowKeys);
+ }
+ if (ClientSelection.FLAG_RESET.equals(clientSelection.getSelectionFlag())) {
+ selectedRowKeys.clear();
+ }
+ final Collection<Object> rowKeys = selectedRowKeys;
+ table.walk(context, new DataVisitor() {
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ int index = clientSelection.nextIndex();
+ if (clientSelection.isSelected(index)) {
+ rowKeys.add(rowKey);
+ }
+ if (clientSelection.isActiveIndex(index)) {
+ attributes.put("activeRowKey", rowKey);
+ }
+ if (clientSelection.isShiftIndex(index)) {
+ attributes.put("shiftRowKey", rowKey);
+ }
+ return DataVisitResult.CONTINUE;
+ }
+ }, null);
+ }
+ }
+}
Modified: root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.ecss
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.ecss 2010-06-25 15:23:04 UTC (rev 17672)
+++ root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.ecss 2010-06-25 17:02:44 UTC (rev 17673)
@@ -152,4 +152,8 @@
.rf-edt-r-s {
background-color: '#{richSkin.additionalBackgroundColor}'; /*TODO Probably use other skin property.*/
+}
+
+.rf-edt-r-a {
+ font-weight: bold; /*TODO Probably use other property.*/
}
\ No newline at end of file
Modified: root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js 2010-06-25 15:23:04 UTC (rev 17672)
+++ root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js 2010-06-25 17:02:44 UTC (rev 17673)
@@ -122,7 +122,7 @@
this.ranges = [];
},
- isSelected: function(index) {
+ contains: function(index) {
var i = 0;
while(i < this.ranges.length && index >= this.ranges[i][0]) {
if(index >= this.ranges[i][0] && index <= this.ranges[i][1]) {
@@ -149,11 +149,13 @@
var ranges = new richfaces.utils.Ranges();
var element = document.getElementById(id);
- var bodyElement, contentElement, spacerElement, dataTableElement, rows, rowHeight, parts, tbodies, shiftIndex, activeIndex;
+ var bodyElement, contentElement, spacerElement, dataTableElement, rows, rowHeight, parts, tbodies, shiftIndex,
+ activeIndex, selectionFlag;
var dragElement = document.getElementById(id + ":d");
var reorderElement = document.getElementById(id + ":r");
var reorderMarkerElement = document.getElementById(id + ":rm");
var widthInput = document.getElementById(id + ":wi");
+ var selectionInput = document.getElementById(id + ":si");
var normalPartStyle = richfaces.utils.getCSSRule(".rf-edt-pw").style;
var header = jQuery(element).children(".rf-edt-h");
var resizerHolders = header.find(".rf-edt-rsh");
@@ -259,7 +261,7 @@
adjustResizers();
};
- var initializeLayout = function() {
+ var initialize = function() {
bodyElement = document.getElementById(id + ":b");
contentElement = jQuery(bodyElement).children("div:first")[0];
if (contentElement) {
@@ -273,6 +275,7 @@
}
jQuery(bodyElement).bind("scroll", bodyScrollListener)
tbodies.bind("click", selectionClickListener);
+ initializeSelection();
} else {
spacerElement = null;
dataTableElement = null;
@@ -397,7 +400,7 @@
var selectRow = function (index) {
ranges.add(index);
for ( var i = 0; i < tbodies.length; i++) {
- tbodies[i].rows[index].className = "rf-edt-r-s";
+ jQuery(tbodies[i].rows[index]).addClass("rf-edt-r-s");
}
}
@@ -406,11 +409,53 @@
ranges.remove(index);
}
for ( var i = 0; i < tbodies.length; i++) {
- tbodies[i].rows[index].className = "";
+ jQuery(tbodies[i].rows[index]).removeClass("rf-edt-r-s");
}
}
+ var setActiveRow = function (index) {
+ if(activeIndex != null) {
+ for ( var i = 0; i < tbodies.length; i++) {
+ jQuery(tbodies[i].rows[activeIndex]).removeClass("rf-edt-r-a");
+ }
+
+ }
+ activeIndex = index;
+ for ( var i = 0; i < tbodies.length; i++) {
+ jQuery(tbodies[i].rows[activeIndex]).addClass("rf-edt-r-a");
+ }
+ }
+
+ var initializeSelection = function() {
+ ranges.clear();
+ activeIndex = null;
+ shiftIndex = null;
+ selectionFlag = null;
+ var rows = tbodies[0].rows;
+ for (var i = 0; i < rows.length; i++) {
+ var row = jQuery(rows[i]);
+ if (row.hasClass("rf-edt-r-s")) {
+ ranges.add(row[0].rowIndex)
+ }
+ if (row.hasClass("rf-edt-r-a")) {
+ activeIndex = row[0].rowIndex;
+ }
+ }
+ wtiteSelection();
+ }
+
+ var wtiteSelection = function() {
+ selectionInput.value = [ranges, activeIndex, shiftIndex, selectionFlag].join("|");
+ }
var selectionClickListener = function (event) {
+ if (event.shiftKey || event.ctrlKey) {
+ if (window.getSelection) {
+ window.getSelection().removeAllRanges(); //TODO
+ } else if (document.selection) {
+ document.selection.empty();
+ }
+ }
+
var tr = event.target;
while (tbodies.index(tr.parentNode) == -1) {
tr = tr.parentNode;
@@ -419,16 +464,10 @@
if(!event.shiftKey) {
shiftIndex = null;
- } else {
- if (window.getSelection) {
- window.getSelection().removeAllRanges(); //TODO
- } else if (document.selection) {
- document.selection.empty();
- }
}
if (event.shiftKey && !event.ctrlKey) {
- if(!shiftIndex) {//TODO
- shiftIndex = activeIndex;
+ if(shiftIndex == null) {
+ shiftIndex = activeIndex != null ? activeIndex : index;
}
var range;
if (index >= shiftIndex) {
@@ -438,22 +477,23 @@
}
var i = 0;
for (; i < range[0]; i++) {
- if (ranges.isSelected(i)) {
+ if (ranges.contains(i)) {
deselectRow(i);
}
}
for (; i <= range[1]; i++) {
- if (!ranges.isSelected(i)) {
+ if (!ranges.contains(i)) {
selectRow(i);
}
}
for (; i < rows; i++) {
- if (ranges.isSelected(i)) {
+ if (ranges.contains(i)) {
deselectRow(i);
}
}
+ selectionFlag = "x";
} else if (!event.shiftKey && event.ctrlKey) {
- if (ranges.isSelected(index)) {
+ if (ranges.contains(index)) {
deselectRow(index);
} else {
selectRow(index);
@@ -467,8 +507,10 @@
deselectRow(i, true);
}
}
+ selectionFlag = "x";
}
- activeIndex = index;
+ setActiveRow(index);
+ wtiteSelection();
}
var ajaxComplete = function (event, data) {
@@ -477,7 +519,9 @@
} else {
if (data.reinitializeBody) {
rowCount = data.rowCount;
- initializeLayout();
+ initialize();
+ } else {
+ initializeSelection();
}
if (spacerElement) {
spacerElement.style.height = (data.first * rowHeight) + "px";
@@ -485,7 +529,7 @@
}
};
- jQuery(document).ready(initializeLayout);
+ jQuery(document).ready(initialize);
jQuery(window).bind("resize", updateLayout);
jQuery(scrollElement).bind("scroll", updateScrollPosition);
var bindHeaderHandlers = function () {
14 years, 6 months