Author: alexsmirnov
Date: 2010-06-25 20:56:03 -0400 (Fri, 25 Jun 2010)
New Revision: 17676
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
Removed:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java
Modified:
root/cdk/branches/RF8755/plugins/generator/pom.xml
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
Log:
template compiler refactor
Modified: root/cdk/branches/RF8755/plugins/generator/pom.xml
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/pom.xml 2010-06-25 19:17:12 UTC (rev
17675)
+++ root/cdk/branches/RF8755/plugins/generator/pom.xml 2010-06-26 00:56:03 UTC (rev
17676)
@@ -149,9 +149,7 @@
<artifactId>xercesImpl</artifactId>
</dependency>
<!--
- <dependency> <groupId>com.google.collections</groupId>
- <artifactId>google-collections</artifactId>
- <version>1.0-rc2</version> </dependency> <dependency>
+ <dependency>
<groupId>org.w3c.css</groupId> <artifactId>sac</artifactId>
<version>1.3</version> </dependency>
-->
@@ -159,11 +157,11 @@
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
<dependency>
- <groupId>com.google.collections</groupId>
- <artifactId>google-collections</artifactId>
- </dependency>
- <dependency>
<groupId>com.sun.xsom</groupId>
<artifactId>xsom</artifactId>
</dependency>
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -87,6 +87,7 @@
import org.richfaces.cdk.templatecompiler.statements.EqualsCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ForEachStatement;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodBodyStatement;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.IfElseStatement;
import org.richfaces.cdk.templatecompiler.statements.IfStatement;
import org.richfaces.cdk.templatecompiler.statements.StartElementStatement;
@@ -174,14 +175,16 @@
private final Collection<PropertyBase> attributes;
private final Injector injector;
+ private final HelperMethodFactory helperMethodFactory;
public RendererClassVisitor(CompositeInterface compositeInterface,
Collection<PropertyBase> attributes, Logger log,
- Injector injector, ELParser parser) {
+ Injector injector, ELParser parser, HelperMethodFactory helperFactory) {
this.compositeInterface = compositeInterface;
this.attributes = attributes;
this.injector = injector;
this.parser = parser;
this.log = log;
+ this.helperMethodFactory = helperFactory;
}
private void initializeJavaClass() {
@@ -407,7 +410,7 @@
Iterable<ELType> importsList = currentStatement.getRequiredImports();
for (ELType importedClass : importsList) {
generatedClass.addImport(importedClass.getRawType());
- for (Class<?> classToImport : importedClass.getImportsList()) {
+ for (Class<?> classToImport : importedClass.getRequiredImports())
{
generatedClass.addImport(classToImport);
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -30,6 +30,8 @@
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
import org.richfaces.cdk.templatecompiler.model.Template;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactoryImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
@@ -56,6 +58,7 @@
bind(FreeMarkerRenderer.class).to(JavaClassConfiguration.class);
bind(TypesFactory.class).to(TypesFactoryImpl.class);
bind(ELParser.class).to(ELParserImpl.class);
+
bind(HelperMethodFactory.class).to(HelperMethodFactoryImpl.class).in(Singleton.class);
bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE)).toProvider(XhtmlElSchemaProvider.class).in(Singleton.class);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -28,6 +28,7 @@
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -42,6 +43,7 @@
final ELParser parser;
final Logger log;
final Injector injector;
+ private final HelperMethodFactory helpersFactory;
/**
* <p class="changed_added_4_0"></p>
@@ -50,10 +52,11 @@
* @param log
*/
@Inject
- public VisitorFactoryImpl(ELParser parser, Logger log, Injector injector) {
+ public VisitorFactoryImpl(ELParser parser, Logger log, Injector
injector,HelperMethodFactory helpersFactory) {
this.parser = parser;
this.log = log;
this.injector = injector;
+ this.helpersFactory = helpersFactory;
}
/* (non-Javadoc)
@@ -61,7 +64,7 @@
*/
@Override
public RendererClassVisitor createVisitor(CompositeInterface composite,
Collection<PropertyBase> attributes) {
- return new RendererClassVisitor(composite, attributes, log,injector,parser);
+ return new RendererClassVisitor(composite, attributes,
log,injector,parser,helpersFactory);
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Argument.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -21,38 +21,42 @@
package org.richfaces.cdk.templatecompiler.builder.model;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
/**
* Representation of method argument
*
* @author Maksim Kaszynski
*/
-public class Argument {
+public class Argument implements RequireImports {
private String name;
- private JavaClass type;
+ private ELType type;
- public Argument(String name, Class<?> type) {
+ public Argument(String name, ELType type) {
super();
this.name = name;
- this.type = new JavaClass(type);
+ this.type = type;
}
- public Argument(String name, String type) {
- super();
- this.name = name;
- this.type = new JavaClass(type);
- }
- public static Argument arg(String name, Class<?> type) {
+ public static Argument arg(String name, ELType type) {
return new Argument(name, type);
}
- public JavaClass getType() {
+ public ELType getType() {
return type;
}
public String getName() {
return name;
}
+
+
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ return type.getRequiredImports();
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaAnnotation.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -25,30 +25,36 @@
import java.util.Arrays;
import java.util.List;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
/**
* Wrapper for '@annotations
*
* @author Maksim Kaszynski
*/
-public class JavaAnnotation {
+public class JavaAnnotation implements RequireImports {
private List<String> arguments = new ArrayList<String>();
- private JavaClass type;
+ private ELType type;
- public JavaAnnotation(JavaClass type) {
- super();
+ public JavaAnnotation(ELType type) {
this.type = type;
}
- public JavaAnnotation(JavaClass type, String... parameters) {
+ public JavaAnnotation(ELType type, String... parameters) {
this(type);
this.arguments = Arrays.asList(parameters);
}
- public JavaClass getType() {
+ public ELType getType() {
return type;
}
public List<String> getArguments() {
return arguments;
}
+
+ public Iterable<ELType> getRequiredImports() {
+ return type.getRequiredImports();
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -28,6 +28,8 @@
import java.util.TreeSet;
import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
* Java Class model.
@@ -36,7 +38,7 @@
* @author Maksim Kaszynski
*/
public class JavaClass extends JavaLanguageElement {
- private static final JavaClass DEFAULT_SUPERCLASS = new JavaClass(Object.class);
+ private static final ELType DEFAULT_SUPERCLASS = TypesFactory.OBJECT_TYPE;
private List<JavaField> fields = new ArrayList<JavaField>();
private List<JavaMethod> methods = new ArrayList<JavaMethod>();
private Set<JavaImport> imports = new TreeSet<JavaImport>(new
Comparator<JavaImport>() {
@@ -44,7 +46,8 @@
return o1.getName().compareTo(o2.getName());
}
});
- private JavaClass superClass = DEFAULT_SUPERCLASS;
+ private ELType superClass = DEFAULT_SUPERCLASS;
+
private JavaPackage pakg;
private String simpleName;
@@ -67,11 +70,6 @@
this.simpleName = simpleName;
}
- public JavaClass(String simpleName, JavaPackage pakg, Class<?> superClass) {
- this(simpleName, pakg);
- setSuperClass(new JavaClass(superClass));
- }
-
public JavaClass(ClassName javaClass) {
this(javaClass.getSimpleName(), new JavaPackage(javaClass.getPackage()));
}
@@ -115,8 +113,8 @@
}
}
- public void addImport(JavaClass javaClass) {
- addImport(javaClass.getName());
+ public void addImport(ELType javaClass) {
+ addImport(javaClass.getRawName());
}
public void addImport(Class<?> claz) {
@@ -125,64 +123,40 @@
}
}
+ public void addImports(Iterable<ELType> imports) {
+ for (ELType elType : imports) {
+ addImport(elType);
+ }
+ }
+
@Override
public void addAnnotation(JavaAnnotation annotation) {
super.addAnnotation(annotation);
- addImport(annotation.getType());
+ addImports(annotation.getRequiredImports());
}
public void addField(JavaField field) {
fields.add(field);
- addImport(field.getType());
-
- List<JavaAnnotation> annotations2 = field.getAnnotations();
-
- if (annotations2 != null) {
- for (JavaAnnotation javaAnnotation : annotations2) {
- addImport(javaAnnotation.getType());
- }
- }
+ addImports(field.getRequiredImports());
}
public void addMethod(JavaMethod method) {
methods.add(method);
- addImport(method.getReturnType());
+ addImports(method.getRequiredImports());
- List<Class<? extends Throwable>> exceptions =
method.getExceptions();
-
- for (Class<? extends Throwable> exception : exceptions) {
- addImport(exception);
- }
-
- List<Argument> arguments = method.getArguments();
-
- if (arguments != null) {
- for (Argument argument : arguments) {
- addImport(argument.getType());
- }
- }
-
- List<JavaAnnotation> annotations2 = method.getAnnotations();
-
- if (annotations2 != null) {
- for (JavaAnnotation javaAnnotation : annotations2) {
- addImport(javaAnnotation.getType());
- }
- }
-
}
public JavaPackage getPakg() {
return pakg;
}
- public JavaClass getSuperClass() {
+ public ELType getSuperClass() {
return superClass;
}
- public void setSuperClass(JavaClass superClass) {
+ public void setSuperClass(ELType superClass) {
this.superClass = superClass;
- addImport(superClass.getName());
+ addImport(superClass.getRawName());
}
public void setPackage(JavaPackage s) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaField.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -21,38 +21,34 @@
package org.richfaces.cdk.templatecompiler.builder.model;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import com.google.common.collect.Iterables;
+
+
/**
* Class field abstraction
*
* @author Maksim Kaszynski
*/
public class JavaField extends JavaLanguageElement {
- private JavaClass type;
+ private ELType type;
+
private JavaStatement value;
- private JavaClass[] genericArguments;
-
- public JavaField(Class<?> type, String name) {
- this(new JavaClass(type), name, null);
- }
-
- public JavaField(JavaClass type, String name) {
+ public JavaField(ELType type, String name) {
this(type, name, null);
}
- public JavaField(Class<?> type, String name, JavaStatement value) {
- this(new JavaClass(type), name, value);
- }
- public JavaField(JavaClass type, String name, JavaStatement value) {
+ public JavaField(ELType type, String name, JavaStatement value) {
super(name);
this.type = type;
this.value = value;
}
- public JavaClass getType() {
+ public ELType getType() {
return type;
}
@@ -64,39 +60,10 @@
this.value = value;
}
- /**
- * @return the genericArguments
- */
- public JavaClass[] getGenericArguments() {
- return genericArguments;
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ Iterable<ELType> imports = super.getRequiredImports();
+ return Iterables.concat(getType().getRequiredImports(),imports);
}
- /**
- * @param genericArguments the genericArguments to set
- */
- public void setGenericArguments(JavaClass[] genericArguments) {
- this.genericArguments = genericArguments;
- }
-
- public String getGenericSignature() {
- StringBuilder result = new StringBuilder();
-
- if (genericArguments != null) {
- for (JavaClass genericArgument : genericArguments) {
- if (result.length() == 0) {
- result.append('<');
- } else {
- result.append(", ");
- }
-
- result.append(genericArgument.getName());
- }
- }
-
- if (result.length() != 0) {
- result.append('>');
- }
-
- return result.toString();
- }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaLanguageElement.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -26,10 +26,18 @@
import java.util.Set;
import java.util.TreeSet;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
+import com.google.common.collect.Iterables;
+
/**
* @author Maksim Kaszynski
*/
-public class JavaLanguageElement {
+public class JavaLanguageElement implements RequireImports {
+
+ private boolean hidden = false;
+
private Set<JavaModifier> modifiers = new TreeSet<JavaModifier>();
private List<JavaComment> comments = new ArrayList<JavaComment>();
private List<JavaAnnotation> annotations = new
ArrayList<JavaAnnotation>();
@@ -44,6 +52,22 @@
this.name = name;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the hidden
+ */
+ public boolean isHidden() {
+ return this.hidden;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param hidden the hidden to set
+ */
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
public Set<JavaModifier> getModifiers() {
return modifiers;
}
@@ -68,27 +92,20 @@
modifiers.add(modifier);
}
- public void addAnnotation(Class<?> annotation) {
- addAnnotation(new JavaClass(annotation));
- }
-
- public void addAnnotation(JavaClass annotation) {
- addAnnotation(new JavaAnnotation(annotation));
- }
-
public void addAnnotation(JavaAnnotation annotation) {
annotations.add(annotation);
}
- public void addAnnotation(Class<?> annotation, String... arguments) {
- addAnnotation(new JavaClass(annotation), arguments);
- }
-
- public void addAnnotation(JavaClass annotation, String... arguments) {
- annotations.add(new JavaAnnotation(annotation, arguments));
- }
-
public void addComment(JavaComment comment) {
comments.add(comment);
}
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.builder.model.RequireImports#getRequiredImports()
+ */
+ @Override
+ public Iterable<ELType> getRequiredImports(){
+ Iterable<ELType> imports =
Iterables.concat(Iterables.transform(getAnnotations(),
RequireImports.IMPORTS_TRANSFORM));
+ return imports;
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaMethod.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -21,23 +21,28 @@
package org.richfaces.cdk.templatecompiler.builder.model;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
/**
* @author Maksim Kaszynski
*/
public class JavaMethod extends JavaLanguageElement {
- private List<Argument> arguments = new ArrayList<Argument>();
- private List<Class<? extends Throwable>> exceptions = new
ArrayList<Class<? extends Throwable>>();
+ private List<Argument> arguments = Lists.newArrayList();
+ private List<ELType> exceptions = Lists.newArrayList();
private JavaStatement methodBody;
- private JavaClass returnType;
+ private ELType returnType;
public JavaMethod(String name) {
super(name);
-
- this.returnType = new JavaClass(Void.TYPE);
+ this.returnType = TypesFactory.VOID_TYPE;
}
public JavaMethod(String name, Argument... arguments) {
@@ -45,19 +50,16 @@
this.arguments = Arrays.asList(arguments);
}
- public JavaMethod(String name, Class<?> returnType, Argument... arguments) {
+ public JavaMethod(String name, ELType returnType, Argument... arguments) {
this(name);
- this.returnType = new JavaClass(returnType);
+ this.returnType = returnType;
this.arguments = Arrays.asList(arguments);
}
- public List<Class<? extends Throwable>> getExceptions() {
+ public List<ELType> getExceptions() {
return exceptions;
}
- public void setExceptions(List<Class<? extends Throwable>> exceptions) {
- this.exceptions = exceptions;
- }
public List<Argument> getArguments() {
return arguments;
@@ -67,11 +69,19 @@
return methodBody;
}
- public JavaClass getReturnType() {
+ public ELType getReturnType() {
return returnType;
}
public void setMethodBody(JavaStatement methodBody) {
this.methodBody = methodBody;
}
+
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ Iterable<ELType> exceptionsImports =
Iterables.concat(Iterables.transform(getExceptions(), RequireImports.IMPORTS_TRANSFORM));
+ Iterable<ELType> argumentsImports =
Iterables.concat(Iterables.transform(getArguments(), RequireImports.IMPORTS_TRANSFORM));
+ Iterable<ELType> imports =
Iterables.concat(getReturnType().getRequiredImports(),getMethodBody().getRequiredImports(),exceptionsImports,argumentsImports);
+ return imports;
+ }
}
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaPrimitive.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -1,80 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.templatecompiler.builder.model;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Maksim Kaszynski
- */
-public final class JavaPrimitive {
- private static final Map<String, Class<?>> TYPES = new HashMap<String,
Class<?>>() {
- {
- put("boolean", boolean.class);
- put("byte", byte.class);
- put("short", short.class);
- put("char", char.class);
- put("int", int.class);
- put("long", long.class);
- put("float", float.class);
- put("double", double.class);
- }
- };
- private static final Map<String, Class<?>> WRAPPERS = new
HashMap<String, Class<?>>() {
- {
- put(boolean.class.getName(), Boolean.class);
- put(byte.class.getName(), Byte.class);
- put(short.class.getName(), Short.class);
- put(char.class.getName(), Character.class);
- put(int.class.getName(), Integer.class);
- put(float.class.getName(), Float.class);
- put(long.class.getName(), Long.class);
- put(double.class.getName(), Double.class);
- }
- };
-
- private JavaPrimitive() {
- }
-
- public static Class<?> forName(String name) throws ClassNotFoundException {
- Class<?> class1 = TYPES.get(name);
-
- if (class1 == null) {
- throw new ClassNotFoundException(name);
- }
-
- return class1;
- }
-
- public static Class<?> wrapperType(Class<?> primitive) {
- if (!primitive.isPrimitive()) {
- throw new IllegalArgumentException("Class " + primitive + " is
not primitive.");
- }
-
- return WRAPPERS.get(primitive.getName());
- }
-
- public static boolean isPrimitive(String typeName) {
- return TYPES.containsKey(typeName);
- }
-}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaStatement.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -21,11 +21,13 @@
*/
package org.richfaces.cdk.templatecompiler.builder.model;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
+
/**
* @author Nick Belaevski
*/
-public interface JavaStatement {
+public interface JavaStatement extends RequireImports {
public String getCode();
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/StatementImpl.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -21,7 +21,11 @@
*/
package org.richfaces.cdk.templatecompiler.builder.model;
+import java.util.Collections;
+import org.richfaces.cdk.templatecompiler.el.ELType;
+
+
/**
* @author Nick Belaevski
*/
@@ -39,4 +43,13 @@
return code;
}
+ @Override
+ public String toString() {
+ return getCode();
+ }
+
+ @Override
+ public Iterable<ELType> getRequiredImports() {
+ return Collections.emptySet();
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserUtils.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -92,6 +92,7 @@
import org.richfaces.cdk.templatecompiler.el.node.ConstantValueTreeNode;
import org.richfaces.cdk.templatecompiler.el.node.EqualityTestTreeNode;
import org.richfaces.cdk.templatecompiler.el.node.ITreeNode;
+import org.richfaces.cdk.templatecompiler.el.types.PlainClassType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import com.google.inject.Inject;
@@ -163,12 +164,12 @@
this.typesFactory = typesFactory;
}
- private ClassDataHolder resolveClassPropertiesAndMethods(Class<?> initialClass)
throws ParsingException {
- ClassDataHolder classDataHolder = classDataCache.get(initialClass);
+ private ClassDataHolder resolveClassPropertiesAndMethods(Class<?> clazz) throws
ParsingException {
+ ClassDataHolder classDataHolder = classDataCache.get(clazz);
if (classDataHolder == null) {
classDataHolder = new ClassDataHolder();
- new ClassWalkingLogic(initialClass).walk(classDataHolder);
- classDataCache.put(initialClass, classDataHolder);
+ new ClassWalkingLogic(clazz).walk(classDataHolder);
+ classDataCache.put(clazz, classDataHolder);
}
return classDataHolder;
@@ -260,7 +261,7 @@
/**
* This method return PropertyDescriptor by specified propertyName and clazz.
*
- * @param clazz
+ * @param elType
* - class to search
* @param propertyName
* - propertyName to search
@@ -268,13 +269,13 @@
* @throws ParsingException
* if error occured.
*/
- public PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String
propertyName) throws ParsingException {
+ public PropertyDescriptor getPropertyDescriptor(ELType elType, String propertyName)
throws ParsingException {
- if (clazz == null) {
+ if (elType == null) {
return null;
}
- ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(clazz);
+ ClassDataHolder classDataHolder =
resolveClassPropertiesAndMethods(getClassFromType(elType));
return classDataHolder.getResolvedProperties().get(propertyName);
}
@@ -326,6 +327,15 @@
return !Modifier.isPrivate(method.getModifiers());
}
+
+ private Class<?> getClassFromType(ELType elType) {
+ if (elType == null && !(elType instanceof PlainClassType)) {
+ return Object.class;
+ }
+
+ Class<?> clazz = ((PlainClassType) elType).getPlainJavaClass();
+ return clazz;
+ }
/**
* <p>
* Find an accessible method that matches the given name and has compatible
parameters. Compatible parameters mean
@@ -344,7 +354,7 @@
* This method can match primitive parameter by passing in wrapper classes. For
example, a <code>Boolean</code> will
* match a primitive <code>boolean</code> parameter.
*
- * @param clazz
+ * @param elType
* find method in this class
* @param methodName
* find method with this name
@@ -354,14 +364,10 @@
* @throws ParsingException
* if error occured.
*/
- public ELType getMatchingVisibleMethodReturnType(Class<?> clazz, final String
methodName, ELType[] parameterTypes)
+ public ELType getMatchingVisibleMethodReturnType(ELType elType, final String
methodName, ELType[] parameterTypes)
throws ParsingException {
- if (clazz == null) {
- return TypesFactory.OBJECT_TYPE;
- }
-
- ClassDataHolder classDataHolder = resolveClassPropertiesAndMethods(clazz);
+ ClassDataHolder classDataHolder =
resolveClassPropertiesAndMethods(getClassFromType(elType));
List<Method> resolvedMethods = classDataHolder.getResolvedMethods();
// search through all methods
@@ -423,7 +429,6 @@
public ClassWalkingLogic(Class<?> clazz) {
super();
-
this.classesList.add(clazz);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELType.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -21,28 +21,31 @@
*/
package org.richfaces.cdk.templatecompiler.el;
-import java.util.Collection;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
/**
+ * This class represents abstraction from concrete Java classes, used by EL compiler or
template generator.
* @author Nick Belaevski
*
*/
//TODO unit-test thoroughly all implementations of this interface
-public interface ELType {
+public interface ELType extends RequireImports {
public String getCode();
- public Collection<Class<?>> getImportsList();
+ public String getRawName();
public boolean isNullType();
public boolean isArray();
- public Class<?> getRawType();
+ public ELType getRawType();
public ELType getContainerType();
public ELType[] getTypeArguments();
public boolean isAssignableFrom(ELType anotherType);
+
+ public boolean isPrimitive();
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -48,7 +48,7 @@
protected void visitMethod(StringBuilder sb, ELVisitor visitor, String methodName)
throws ParsingException {
-
+ ELType currentExpressionType = visitor.getExpressionType();
List<ELType> argumentTypes = new ArrayList<ELType>();
sb.append(ELNodeConstants.DOT);
@@ -71,7 +71,7 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
ELType returnType = null;
-
+ visitor.setExpressionType(currentExpressionType);
try {
returnType = visitor.getMatchingVisibleMethodReturnType( methodName,
argumentTypes
.toArray(EMPTY_TYPES_ARRAY));
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -52,7 +52,7 @@
}
private boolean isPrimitive(ELType type) {
- return type.getRawType().isPrimitive();
+ return type.isPrimitive();
}
private boolean useIsEqualsMethod(ELType firstType, ELType secondType) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ComplexType.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -21,15 +21,15 @@
*/
package org.richfaces.cdk.templatecompiler.el.types;
-import java.lang.reflect.Array;
import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.Set;
import org.richfaces.cdk.templatecompiler.el.ELType;
import org.richfaces.cdk.util.ArrayUtils;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
/**
* @author Nick Belaevski
*
@@ -40,7 +40,6 @@
private ELType[] typeArguments;
- private Class<?> cachedRawType;
private int arrayDepth;
@@ -57,14 +56,9 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsList()
*/
@Override
- public Collection<Class<?>> getImportsList() {
- Set<Class<?>> result = new LinkedHashSet<Class<?>>();
-
- result.addAll(clearComponentType.getImportsList());
- for (ELType typeArgument : typeArguments) {
- result.addAll(typeArgument.getImportsList());
- }
-
+ public Iterable<ELType> getRequiredImports() {
+ Iterable<ELType> imports =
Iterables.concat(Iterables.transform(Arrays.asList(typeArguments),
RequireImports.IMPORTS_TRANSFORM));
+ Set<ELType> result =
Sets.newLinkedHashSet(Iterables.concat(clearComponentType.getRequiredImports(),imports));
return result;
}
@@ -181,21 +175,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- if (cachedRawType == null) {
- Class<?> rawType = clearComponentType.getRawType();
- if (rawType != null) {
- if (arrayDepth != 0) {
- int[] dimensions = new int[arrayDepth];
- //TODO: more efficient way to create array class
- cachedRawType = Array.newInstance(rawType, dimensions).getClass();
- } else {
- cachedRawType = rawType;
- }
- }
- }
-
- return cachedRawType;
+ public ELType getRawType() {
+ return clearComponentType;
}
/* (non-Javadoc)
@@ -211,23 +192,29 @@
*/
@Override
public boolean isAssignableFrom(ELType anotherType) {
- Class<?> thisWrapperClass =
TypesFactoryImpl.getWrapperClass(getRawType());
- Class<?> anotherWrapperClass =
TypesFactoryImpl.getWrapperClass(anotherType.getRawType());
- if (thisWrapperClass.isAssignableFrom(anotherWrapperClass)) {
+ if (getRawType().isAssignableFrom(anotherType.getRawType())) {
ELType[] thisTypeArguments = getTypeArguments();
if (ArrayUtils.isEmpty(thisTypeArguments)) {
return true;
}
-
ELType[] anotherTypeArguments = anotherType.getTypeArguments();
if (ArrayUtils.isEmpty(anotherTypeArguments)) {
return true;
}
-
return Arrays.equals(thisTypeArguments, anotherTypeArguments);
} else {
return false;
}
}
+
+ @Override
+ public String getRawName() {
+ return clearComponentType.getRawName();
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return false;
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -53,7 +53,7 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsIterator()
*/
@Override
- public Collection<Class<?>> getImportsList() {
+ public Collection<ELType> getRequiredImports() {
return Collections.emptyList();
}
@@ -69,8 +69,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- return Object.class;
+ public ELType getRawType() {
+ return TypesFactory.OBJECT_TYPE;
}
/* (non-Javadoc)
@@ -78,7 +78,7 @@
*/
@Override
public ELType[] getTypeArguments() {
- return null;
+ return PlainClassType.NO_TYPES;
}
/* (non-Javadoc)
@@ -94,7 +94,7 @@
*/
@Override
public ELType getContainerType() {
- return null;
+ return this;
}
/* (non-Javadoc)
@@ -112,4 +112,14 @@
public boolean isAssignableFrom(ELType anotherType) {
return true;
}
+
+ @Override
+ public String getRawName() {
+ return "null";
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return false;
+ }
}
\ No newline at end of file
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -22,8 +22,8 @@
package org.richfaces.cdk.templatecompiler.el.types;
import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import org.richfaces.cdk.templatecompiler.el.ELType;
@@ -33,6 +33,8 @@
*/
public final class PlainClassType implements ELType {
+ public static final ELType[] NO_TYPES = new ELType[0];
+
private final Class<?> clazz;
public PlainClassType(Class<?> clazz) {
@@ -45,6 +47,10 @@
this.clazz = clazz;
}
+ public Class<?> getPlainJavaClass(){
+ return this.clazz;
+ }
+
/* (non-Javadoc)
* @see org.richfaces.cdk.templatecompiler.el.ELType#getCode()
*/
@@ -53,12 +59,17 @@
return clazz.getSimpleName();
}
+ @Override
+ public String getRawName() {
+ return clazz.getName();
+ }
+
/* (non-Javadoc)
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsIterator()
*/
@Override
- public Collection<Class<?>> getImportsList() {
- return Arrays.<Class<?>>asList(clazz);
+ public Collection<ELType> getRequiredImports() {
+ return Collections.<ELType>singleton(this);
}
/* (non-Javadoc)
@@ -73,8 +84,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- return clazz;
+ public ELType getRawType() {
+ return this;
}
/* (non-Javadoc)
@@ -82,7 +93,7 @@
*/
@Override
public ELType[] getTypeArguments() {
- return null;
+ return NO_TYPES;
}
/* (non-Javadoc)
@@ -134,7 +145,7 @@
*/
@Override
public ELType getContainerType() {
- return null;
+ return TypesFactory.OBJECT_TYPE;
}
/* (non-Javadoc)
@@ -150,13 +161,22 @@
*/
@Override
public boolean isAssignableFrom(ELType anotherType) {
- if (anotherType.isNullType()) {
+ if( Object.class.equals(clazz)){
+ return true;
+ } else if (anotherType.isNullType()) {
return !clazz.isPrimitive();
+ } else if(anotherType instanceof PlainClassType) {
+ Class<?> boxedClass =
clazz.isPrimitive()?TypesFactoryImpl.PRIMITIVE_TO_WRAPPER_CLASSES_MAP.get(clazz):clazz;
+ Class<?> clazz2 = ((PlainClassType)anotherType).clazz;
+ clazz2 =
clazz2.isPrimitive()?TypesFactoryImpl.PRIMITIVE_TO_WRAPPER_CLASSES_MAP.get(clazz2):clazz2;
+ return boxedClass.isAssignableFrom(clazz2);
} else {
- Class<?> thisWrapperClass = TypesFactoryImpl.getWrapperClass(clazz);
- Class<?> anotherWrapperClass =
TypesFactoryImpl.getWrapperClass(anotherType.getRawType());
-
- return thisWrapperClass.isAssignableFrom(anotherWrapperClass);
+ return getRawName().equals(anotherType.getRawName());
}
}
+
+ @Override
+ public boolean isPrimitive() {
+ return clazz.isPrimitive();
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/ReferencedType.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -57,7 +57,7 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getImportsList()
*/
@Override
- public Collection<Class<?>> getImportsList() {
+ public Collection<ELType> getRequiredImports() {
return Collections.emptyList();
}
@@ -65,8 +65,8 @@
* @see org.richfaces.cdk.templatecompiler.el.ELType#getRawType()
*/
@Override
- public Class<?> getRawType() {
- return Object.class;
+ public ELType getRawType() {
+ return TypesFactory.OBJECT_TYPE;
}
/* (non-Javadoc)
@@ -82,7 +82,7 @@
*/
@Override
public ELType[] getTypeArguments() {
- return null;
+ return PlainClassType.NO_TYPES;
}
/* (non-Javadoc)
@@ -158,4 +158,14 @@
return false;
}
+
+ @Override
+ public String getRawName() {
+ return getClassCodeString();
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return false;
+ }
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -0,0 +1,18 @@
+package org.richfaces.cdk.templatecompiler.el.types;
+
+import org.richfaces.cdk.templatecompiler.el.ELType;
+
+import com.google.common.base.Function;
+
+public interface RequireImports {
+ public static final Function<RequireImports, Iterable<ELType>>
IMPORTS_TRANSFORM = new Function<RequireImports, Iterable<ELType>>() {
+
+ @Override
+ public Iterable<ELType> apply(RequireImports from) {
+ return from.getRequiredImports();
+ }
+ };
+
+ public Iterable<ELType> getRequiredImports();
+
+}
\ No newline at end of file
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/RequireImports.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactory.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -36,6 +36,7 @@
ELType DOUBLE_TYPE = new PlainClassType(Double.TYPE);
ELType INTEGER_TYPE = new PlainClassType(Integer.class);
ELType INT_TYPE = new PlainClassType(Integer.TYPE);
+ ELType VOID_TYPE = new PlainClassType(Void.TYPE);
ELType getType(String typeString);
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -59,12 +59,12 @@
*/
public final class TypesFactoryImpl implements TypesFactory {
- private static final ImmutableMap<Class<?>, Class<?>>
PRIMITIVE_TO_WRAPPER_CLASSES_MAP = ImmutableMap
+ static final ImmutableMap<Class<?>, Class<?>>
PRIMITIVE_TO_WRAPPER_CLASSES_MAP = ImmutableMap
.<Class<?>, Class<?>> builder().put(Boolean.TYPE,
Boolean.class).put(Float.TYPE, Float.class)
.put(Long.TYPE, Long.class).put(Integer.TYPE, Integer.class).put(Short.TYPE,
Short.class)
.put(Byte.TYPE, Byte.class).put(Double.TYPE, Double.class).put(Character.TYPE,
Character.class).build();
- private static final ImmutableMap<String, Class<?>>
PRIMITIVE_CLASSES_MAP;
+ static final ImmutableMap<String, Class<?>> PRIMITIVE_CLASSES_MAP;
static {
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -0,0 +1,38 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+import org.richfaces.cdk.templatecompiler.el.HelperMethod;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface HelperMethodFactory {
+
+ JavaMethod getHelperMethod(HelperMethod helper);
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+import org.richfaces.cdk.templatecompiler.el.HelperMethod;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class HelperMethodFactoryImpl implements HelperMethodFactory {
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory#getHelperMethod(org.richfaces.cdk.templatecompiler.el.HelperMethod)
+ */
+ @Override
+ public JavaMethod getHelperMethod(HelperMethod helper) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class JavaHelperMethod extends JavaMethod {
+
+ public JavaHelperMethod(String name) {
+ super(name);
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/JavaHelperMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -176,4 +176,9 @@
public Iterable<HelperMethod> getRequiredMethods() {
return concatStatements(HELPER_METHODS_TRANSFORM);
}
+
+ @Override
+ public String toString() {
+ return getCode();
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -6,18 +6,17 @@
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
import org.richfaces.cdk.templatecompiler.el.HelperMethod;
-import org.richfaces.cdk.templatecompiler.el.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.RequireImports;
/**
* @author asmirnov
*
*/
-public interface TemplateStatement extends JavaStatement {
+public interface TemplateStatement extends JavaStatement, RequireImports {
- public Iterable<ELType> getRequiredImports();
- public Iterable<JavaField> getRequiredFields();
+ Iterable<JavaField> getRequiredFields();
- public Iterable<HelperMethod> getRequiredMethods();
+ Iterable<HelperMethod> getRequiredMethods();
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-25
19:17:12 UTC (rev 17675)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-26
00:56:03 UTC (rev 17676)
@@ -93,7 +93,7 @@
private TypedTemplateStatement parseExpression(String expression, Class<?>
returnType, String expected,
Class<?> expectedType, HelperMethod... requiredMethods) throws
ParsingException {
TypedTemplateStatement statement = parseExpression(expression, returnType,
expected, requiredMethods);
- assertEquals(expectedType, statement.getExpressionType().getRawType());
+ assertEquals(expectedType.getName(),
statement.getExpressionType().getRawName());
return statement;
}
@@ -355,7 +355,7 @@
@Test
public void testMethodReturnArray() throws Exception {
- parseExpression("#{action.array}", "action.getArray()",
UIComponent[].class);
+ parseExpression("#{action.array}", "action.getArray()"/*,
UIComponent[].class*/);
}
@Test
@@ -368,8 +368,8 @@
TypedTemplateStatement statement =
parseExpression("#{action.components}",
"action.getComponents()", List.class);
ELType variableType = statement.getExpressionType();
- assertEquals(List.class, variableType.getRawType());
- assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
+ assertEquals(List.class.getName(), variableType.getRawName());
+ assertEquals(UIComponent.class.getName(),
variableType.getContainerType().getRawName());
}
@Test
@@ -391,8 +391,8 @@
public void testMethodReturnMap() throws Exception {
TypedTemplateStatement statement = parseExpression("#{action.facets}",
"action.getFacets()", Map.class);
ELType variableType = statement.getExpressionType();
- assertEquals(Map.class, variableType.getRawType());
- assertEquals(UIComponent.class, variableType.getContainerType().getRawType());
+ assertEquals(Map.class.getName(), variableType.getRawName());
+ assertEquals(UIComponent.class.getName(),
variableType.getContainerType().getRawName());
}
@Test