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());
+ }
}