Author: Alex.Kolonitsky
Date: 2010-03-17 16:40:27 -0400 (Wed, 17 Mar 2010)
New Revision: 16590
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/_attributes_import.ftl
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedComponent.java
Log:
RF-8232 Tags support
some fixes for integration tests
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java 2010-03-17
20:35:18 UTC (rev 16589)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java 2010-03-17
20:40:27 UTC (rev 16590)
@@ -32,6 +32,7 @@
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
+import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.Property;
@@ -40,6 +41,7 @@
import java.util.Collection;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.TreeSet;
/**
* <p class="changed_added_4_0">
@@ -74,11 +76,38 @@
return eventNames();
} else if ("defaultEvent".equals(key)) {
return defaultEvent();
+ } else if ("importClasses".equals(key)) {
+ return getImportClasses();
}
return super.get(key);
}
+
+ public TemplateModel getImportClasses() throws TemplateModelException {
+ Set<String> result = new TreeSet<String>();
+ for (Property entry : model.getAttributes()) {
+ if (entry.isGenerate() && !isPredefined(entry)) {
+ result.add(entry.getType().getName());
+// System.out.println(entry.getType().getTypeParameters());
+ }
+ }
+
+ Collection<String> list = new ArrayList<String>(result.size());
+ for (String imp : result) {
+ list.add(imp);
+ }
+ return this.wrapper.wrap(list);
+ }
+
+ public boolean isPredefined(Property property) {
+ return property.isPrimitive() || isFromJavaLang(property.getType());
+ }
+
+ public boolean isFromJavaLang(ClassName type) {
+ return "java.lang".equals(type.getPackage());
+ }
+
private TemplateModel eventNames() throws TemplateModelException {
return wrapper.wrap(getEventNames());
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java 2010-03-17
20:35:18 UTC (rev 16589)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java 2010-03-17
20:40:27 UTC (rev 16590)
@@ -43,7 +43,6 @@
/**
* <p class="changed_added_4_0"></p>
- * @param name
* @param object
* @param wrapper
*/
@@ -88,6 +87,8 @@
value = isBingingAttribute();
} else if ("isBinging".equals(key)) {
value = isBinging();
+ } else if ("type".equals(key)) {
+ value = this.property.getType().getName();
} else {
return super.get(key);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/_attributes_import.ftl
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/_attributes_import.ftl 2010-03-17
20:35:18 UTC (rev 16589)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/_attributes_import.ftl 2010-03-17
20:40:27 UTC (rev 16590)
@@ -1,2 +1,2 @@
-<#list generatedAttributes as attribute><#if (!attribute.isPredefined)
>import ${attribute.type};
-</#if></#list>
\ No newline at end of file
+<#list importClasses as imp>import ${imp};
+</#list>
\ No newline at end of file
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java 2010-03-17
20:35:18 UTC (rev 16589)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java 2010-03-17
20:40:27 UTC (rev 16590)
@@ -24,25 +24,21 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Arrays;
import javax.el.ELContext;
import javax.faces.component.UIComponent;
-import org.richfaces.cdk.CdkClassLoader;
-import org.richfaces.cdk.CdkTestBase;
-import org.richfaces.cdk.FileManager;
-import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.Mock;
-import org.richfaces.cdk.Source;
-import org.richfaces.cdk.SourceFileManager;
-import org.richfaces.cdk.SourceImpl;
-import org.richfaces.cdk.Sources;
+import org.richfaces.cdk.*;
import org.richfaces.cdk.annotations.Family;
import org.richfaces.cdk.model.ComponentModel;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.apache.maven.plugin.MojoExecutionException;
import com.google.common.collect.ImmutableList;
import com.google.inject.Binder;
import com.google.inject.Inject;
+import com.google.inject.Injector;
/**
* @author akolonitsky
@@ -57,6 +53,21 @@
@Mock
protected Logger log;
+ @Inject
+ private Injector injector;
+
+ protected void process(String javaFilePath) throws Exception {
+ Generator generator = new Generator();
+ generator.setLoader(createClassLoader());
+ generator.addSources(Sources.JAVA_SOURCES,
ImmutableList.of(getJavaFile(javaFilePath)), null);
+
+ generator.init();
+ injector.injectMembers(new ComponentProcessor());
+
+ LibraryBuilder builder = injector.getInstance(LibraryBuilder.class);
+ builder.build();
+ }
+
@Override
public void configure(Binder binder) {
super.configure(binder);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-03-17
20:35:18 UTC (rev 16589)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-03-17
20:40:27 UTC (rev 16590)
@@ -42,6 +42,7 @@
import javax.faces.component.UIOutput;
import javax.faces.el.MethodBinding;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Set;
/**
@@ -111,6 +112,18 @@
attribute.setType(new ClassName(String.class));
attribute.setGenerate(false);
+ attribute = component.getOrCreateAttribute("listStrings");
+ attribute.setType(new ClassName(new ArrayList<String>().getClass()));
+ attribute.setGenerate(true);
+
+ attribute = component.getOrCreateAttribute("listInteger");
+ attribute.setType(new ClassName(new ArrayList<Integer>().getClass()));
+ attribute.setGenerate(true);
+
+ attribute = component.getOrCreateAttribute("list");
+ attribute.setType(new ClassName(ArrayList.class));
+ attribute.setGenerate(true);
+
Set<EventName> eventNames = attribute.getEventNames();
eventNames.add(getEvent("id", false));
eventNames.add(getEvent("action", true));
Modified:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedComponent.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedComponent.java 2010-03-17
20:35:18 UTC (rev 16589)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedComponent.java 2010-03-17
20:40:27 UTC (rev 16590)
@@ -36,8 +36,9 @@
import javax.faces.component.StateHelper;
import org.richfaces.PartialStateHolderHelper;
import javax.faces.component.UIOutput;
+import java.util.ArrayList;
+import javax.el.MethodExpression;
import javax.faces.el.MethodBinding;
-import javax.el.MethodExpression;
/**
*
@@ -64,7 +65,10 @@
testValue,
testFlag,
testBinding,
- testExpr
+ testExpr,
+ listStrings,
+ listInteger,
+ list
}
@@ -99,4 +103,28 @@
public void setTestExpr(MethodExpression testExpr) {
getStateHelper().put(Properties.testExpr, testExpr);
}
+
+ public ArrayList getListStrings() {
+ return (ArrayList) getStateHelper().eval(Properties.listStrings);
+ }
+
+ public void setListStrings(ArrayList listStrings) {
+ getStateHelper().put(Properties.listStrings, listStrings);
+ }
+
+ public ArrayList getListInteger() {
+ return (ArrayList) getStateHelper().eval(Properties.listInteger);
+ }
+
+ public void setListInteger(ArrayList listInteger) {
+ getStateHelper().put(Properties.listInteger, listInteger);
+ }
+
+ public ArrayList getList() {
+ return (ArrayList) getStateHelper().eval(Properties.list);
+ }
+
+ public void setList(ArrayList list) {
+ getStateHelper().put(Properties.list, list);
+ }
}
\ No newline at end of file
Show replies by date