Author: alexsmirnov
Date: 2010-03-19 20:14:21 -0400 (Fri, 19 Mar 2010)
New Revision: 16644
Modified:
root/cdk/trunk/plugins/generator/pom.xml
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/BehaviorProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java
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/BehaviorProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java
Log:
CODING IN PROGRESS - issue RF-8523: Refactor CDK annotations
https://jira.jboss.org/jira/browse/RF-8523
Modified: root/cdk/trunk/plugins/generator/pom.xml
===================================================================
--- root/cdk/trunk/plugins/generator/pom.xml 2010-03-19 21:03:10 UTC (rev 16643)
+++ root/cdk/trunk/plugins/generator/pom.xml 2010-03-20 00:14:21 UTC (rev 16644)
@@ -109,7 +109,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.6</version>
+ <version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/BehaviorProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/BehaviorProcessor.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/BehaviorProcessor.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -26,6 +26,7 @@
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.JsfBehavior;
import org.richfaces.cdk.model.BehaviorModel;
+import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
import javax.annotation.processing.SupportedAnnotationTypes;
@@ -41,17 +42,17 @@
public class BehaviorProcessor extends ProcessorBase implements CdkAnnotationProcessor {
@Override
- public void process(TypeElement element) throws CdkProcessingException {
+ public void process(TypeElement element, ComponentLibrary library) throws
CdkProcessingException {
JsfBehavior behavior = element.getAnnotation(JsfBehavior.class);
BehaviorModel behaviorModel = new BehaviorModel(new FacesId(behavior.id()));
- setClassNames(element, behaviorModel, behavior);
+ setClassNames(element, behaviorModel, behavior.generate());
setTagInfo(behavior.tag(), behaviorModel);
processAttributes(element, behaviorModel);
setDescription(behaviorModel, behavior.icon(), getDocComment(element),
behavior.displayName());
- getLibrary().getBehaviors().add(behaviorModel);
+ library.getBehaviors().add(behaviorModel);
}
@Override
@@ -59,10 +60,6 @@
return JsfBehavior.class;
}
- public void setClassNames(TypeElement element, BehaviorModel behaviorModel,
JsfBehavior behavior) {
- String baseClass = element.getQualifiedName().toString();
- setClassNames(element, behaviorModel, behavior.generate(), baseClass);
- }
@Override
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -24,6 +24,7 @@
package org.richfaces.cdk.apt;
import org.richfaces.cdk.CdkProcessingException;
+import org.richfaces.cdk.model.ComponentLibrary;
import javax.lang.model.element.TypeElement;
import java.lang.annotation.Annotation;
@@ -39,9 +40,10 @@
/**
* <p class="changed_added_4_0"></p>
* @param element
+ * @param library TODO
* @throws CdkProcessingException
*/
- public void process(TypeElement element) throws CdkProcessingException;
+ public void process(TypeElement element, ComponentLibrary library) throws
CdkProcessingException;
public Class<? extends Annotation> getProcessedAnnotation();
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -29,6 +29,7 @@
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.ModelValidator;
+import org.richfaces.cdk.model.ComponentLibrary;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
@@ -59,7 +60,11 @@
@Inject
private Set<CdkAnnotationProcessor> processors;
+ // TODO - set library as parameter.
@Inject
+ private ComponentLibrary library;
+
+ @Inject
private Set<ModelBuilder> builders;
@Inject
@@ -103,7 +108,7 @@
for (Element element : annotatedWith) {
if (ElementKind.CLASS.equals(element.getKind())) {
try {
- processor.process((TypeElement) element);
+ processor.process((TypeElement) element, library);
} catch (CdkProcessingException e) {
sendError(element, e);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -25,8 +25,14 @@
package org.richfaces.cdk.apt;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.MirroredTypeException;
+import javax.lang.model.type.MirroredTypesException;
+import javax.lang.model.type.TypeMirror;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.annotations.Event;
import org.richfaces.cdk.annotations.Facet;
@@ -40,13 +46,7 @@
import org.richfaces.cdk.model.FacetModel;
import org.richfaces.cdk.util.Strings;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.MirroredTypeException;
-import javax.lang.model.type.MirroredTypesException;
-import javax.lang.model.type.TypeMirror;
-import java.lang.annotation.Annotation;
-import java.util.Set;
+import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">That class process component-related
annotations such as {@link org.richfaces.cdk.annotations.JsfComponent} or
@@ -56,22 +56,19 @@
* @author asmirnov(a)exadel.com
*
*/
-(a)SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
JsfComponent.NAME})
public class ComponentProcessor extends ProcessorBase implements CdkAnnotationProcessor
{
+ public static final String COMPONENT_FAMILY = "COMPONENT_FAMILY";
@Inject
- private Injector injector;
+ private RendererProcessor rendererProcessor;
- public void process(TypeElement componentElement) {
+ public void process(TypeElement componentElement, ComponentLibrary library) {
JsfComponent annotation = componentElement.getAnnotation(JsfComponent.class);
if (null != annotation) {
- ComponentLibrary library = getLibrary();
// Process class-level annotations.
ComponentModel component = new ComponentModel();
- component.setType(FacesId.parseId(annotation.type()));
// Should that component be generated ?
- String baseClass = componentElement.getQualifiedName().toString();
- setClassNames(componentElement, component, annotation.generate(),
baseClass);
+ setClassNames(componentElement, component, annotation.generate());
setComponentProperties(componentElement, component, annotation);
for (Tag tag : annotation.tag()) {
setTagInfo(tag, component);
@@ -82,18 +79,19 @@
private void setComponentProperties(TypeElement componentElement, ComponentModel
component, JsfComponent annotation)
throws CdkException {
+ // type
+ component.setType(FacesId.parseId(annotation.type()));
// JsfComponent family
- setComponeneFamily(componentElement, component);
+ setComponeneFamily(componentElement, component, annotation.family());
setDescription(component, annotation.icon(), getDocComment(componentElement),
annotation.displayName());
- processFacets(componentElement, component);
+ processFacets(componentElement, component, annotation);
// process Events.
- setEvents(componentElement, component);
+ setEvents(componentElement, component, annotation);
- RendererProcessor rendererProcessor =
injector.getInstance(RendererProcessor.class);
- JsfComponent componentAnnotation =
componentElement.getAnnotation(JsfComponent.class);
- JsfRenderer renderer = componentAnnotation.renderer();
+ // TODO Use @Inject directly, componentElement is wrong here.
+ JsfRenderer renderer = annotation.renderer();
rendererProcessor.process(componentElement, renderer);
// TODO - process @Test annotations.
@@ -101,7 +99,7 @@
processAttributes(componentElement, component);
}
- private void processFacets(TypeElement componentElement, ComponentModel component) {
+ final void processFacets(TypeElement componentElement, ComponentModel component,
JsfComponent annotation) {
SourceUtils sourceUtils = getSourceUtils();
Set<BeanProperty> properties =
sourceUtils.getBeanPropertiesAnnotatedWith(Facet.class,
asClassDesctiption(componentElement));
@@ -120,10 +118,10 @@
}
// @Facets annotation.
- JsfComponent annotation = componentElement.getAnnotation(JsfComponent.class);
for (Facet facet : annotation.facets()) {
- if (!Strings.isEmpty(facet.name())) {
- FacetModel facetModel = component.getOrCreateFacet(facet.name());
+ String name = facet.name();
+ if (!Strings.isEmpty(name)) {
+ FacetModel facetModel = component.getOrCreateFacet(name);
processFacet(facet, facetModel);
} else {
// TODO - record error.
@@ -132,22 +130,21 @@
}
}
- private void processFacet(Facet facet, FacetModel facetModel) {
+ final void processFacet(Facet facet, FacetModel facetModel) {
setIcon(facetModel, facet.icon());
facetModel.setDisplayname(facet.displayName());
// Flags.
facetModel.setGenerate(facet.generate());
}
- private void setComponeneFamily(TypeElement componentElement, ComponentModel
component) {
- JsfComponent annotation = componentElement.getAnnotation(JsfComponent.class);
+ final void setComponeneFamily(TypeElement componentElement, ComponentModel component,
String family) {
- if (!Strings.isEmpty(annotation.family())) {
+ if (!Strings.isEmpty(family)) {
// @Family annotation
- component.setFamily(annotation.family());
+ component.setFamily(family);
} else {
// static final COMPONENT_FAMILY string constant.
- Object value =
getSourceUtils().getConstant(asClassDesctiption(componentElement),
"COMPONENT_FAMILY");
+ Object value =
getSourceUtils().getConstant(asClassDesctiption(componentElement), COMPONENT_FAMILY);
if (null != value) {
component.setFamily(value.toString());
}
@@ -155,8 +152,8 @@
}
- private void setEvents(TypeElement componentElement, ComponentModel component) {
- Event[] fires = componentElement.getAnnotation(JsfComponent.class).fires();
+ final void setEvents(TypeElement componentElement, ComponentModel component,
JsfComponent annotation) {
+ Event[] fires = annotation.fires();
for (Event event : fires) {
try {
@@ -174,12 +171,12 @@
}
@Override
- protected String[] getAnnotationAttributes(TypeElement componentElement) {
+ protected final String[] getAnnotationAttributes(TypeElement componentElement) {
return componentElement.getAnnotation(JsfComponent.class).attributes();
}
@Override
- public Class<? extends Annotation> getProcessedAnnotation() {
+ public final Class<? extends Annotation> getProcessedAnnotation() {
return JsfComponent.class;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -24,6 +24,7 @@
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.JsfConverter;
import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConverterModel;
import org.richfaces.cdk.model.FacesId;
@@ -40,7 +41,7 @@
public class ConverterProcessor extends ProcessorBase implements CdkAnnotationProcessor
{
@Override
- public void process(TypeElement element) throws CdkProcessingException {
+ public void process(TypeElement element, ComponentLibrary library) throws
CdkProcessingException {
JsfConverter converter = element.getAnnotation(JsfConverter.class);
ConverterModel converterModel = new ConverterModel();
@@ -61,11 +62,11 @@
setDescription(converterModel, converter.icon(), getDocComment(element),
converter.displayName());
processAttributes(element, converterModel);
- setClassNames(element, converterModel, converter);
+ setClassNames(element, converterModel, converter.generate());
setTagInfo(converter.tag(), converterModel);
- getLibrary().getConverters().add(converterModel);
+ library.getConverters().add(converterModel);
}
@Override
@@ -73,13 +74,7 @@
return JsfConverter.class;
}
- // TODO same method in the ValidatorProcessor move their in one class
- public void setClassNames(TypeElement componentElement, ConverterModel
converterModel, JsfConverter converter) {
- String baseClass = componentElement.getQualifiedName().toString();
- setClassNames(componentElement, converterModel, converter.generate(),
baseClass);
- }
-
protected String[] getAnnotationAttributes(TypeElement element) {
JsfConverter converter = element.getAnnotation(JsfConverter.class);
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -1,10 +1,16 @@
package org.richfaces.cdk.apt;
-import com.google.common.collect.Lists;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.MirroredTypeException;
+import javax.lang.model.type.MirroredTypesException;
+import javax.lang.model.type.TypeMirror;
+
import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.NamingConventions;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.Icon;
@@ -14,7 +20,6 @@
import org.richfaces.cdk.apt.SourceUtils.SuperTypeVisitor;
import org.richfaces.cdk.model.BeanModelBase;
import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.DescriptionGroup;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.PropertyBase;
@@ -23,14 +28,9 @@
import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
import org.richfaces.cdk.xmlconfig.FragmentParser;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.MirroredTypeException;
-import javax.lang.model.type.MirroredTypesException;
-import javax.lang.model.type.TypeMirror;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
public abstract class ProcessorBase {
@@ -38,14 +38,10 @@
private static final String SIGNATURE_NONE_CLASS_NAME =
Signature.NONE.class.getName().replace('$', '.');
- @Inject
- private ComponentLibrary library;
@Inject
private Provider<SourceUtils> sourceUtils;
- @Inject
- private NamingConventions namingConventions;
@Inject
private FragmentParser fragmentParser;
@@ -66,13 +62,6 @@
return this.sourceUtils.get();
}
- /**
- * <p class="changed_added_4_0"></p>
- * @return the namingConventions
- */
- public NamingConventions getNamingConventions() {
- return this.namingConventions;
- }
protected void setTagInfo(Tag tag, ModelElementBase model) {
@@ -95,7 +84,7 @@
* @param icon
*/
protected void setIcon(DescriptionGroup component, Icon icon) {
- if (!Strings.isEmpty(icon.small()) || !Strings.isEmpty(icon.large())) {
+ if (null != icon && (!Strings.isEmpty(icon.small()) ||
!Strings.isEmpty(icon.large()))) {
DescriptionGroup.Icon iconValue = new DescriptionGroup.Icon();
if (!Strings.isEmpty(icon.small())) {
@@ -110,9 +99,6 @@
}
}
- public ComponentLibrary getLibrary() {
- return library;
- }
protected void setDescription(DescriptionGroup component, Icon icon, String
description, String displayName) {
@@ -129,7 +115,7 @@
}
protected void setClassNames(TypeElement componentElement, ModelElementBase
modelElement,
- String generatedClass, String baseClass) {
+ String generatedClass) {
if (componentElement.getModifiers().contains(Modifier.ABSTRACT) ||
!Strings.isEmpty(generatedClass)) {
modelElement.setGenerate(true);
@@ -137,7 +123,7 @@
} else {
modelElement.setGenerate(false);
}
- modelElement.setBaseClass(ClassName.parseName(baseClass));
+
modelElement.setBaseClass(ClassName.parseName(componentElement.getQualifiedName().toString()));
}
protected Collection<PropertyBase> parseProperties(String attributesConfig) {
@@ -172,9 +158,18 @@
}
}
});
-
+ // Process all files from @Jsf.. attributes property.
+ for(String annotationAttributes : getAnnotationAttributes(componentElement)){
+ try {
+ component.getAttributes().addAll(
+ parseProperties(CdkEntityResolver.URN_ATTRIBUTES +
annotationAttributes));
+ } catch (CdkException e) {
+ // TODO - log errors ?
+ }
+ }
ClassName componentClassName = asClassDesctiption(componentElement);
Set<BeanProperty> properties =
sourceUtils.getBeanPropertiesAnnotatedWith(Attribute.class, componentClassName);
+ // Check all abstract properties, they should be generated. TODO - move it to the
validator ???
properties.addAll(sourceUtils.getAbstractBeanProperties(componentClassName));
// TODO - encapsulate attribute builder into utility class.
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -21,23 +21,22 @@
package org.richfaces.cdk.apt;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
+import java.lang.annotation.Annotation;
+
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.faces.render.RenderKitFactory;
+import javax.lang.model.element.TypeElement;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.annotations.Family;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.RendererModel;
-import org.richfaces.cdk.templatecompiler.RendererTemplateParser;
import org.richfaces.cdk.util.Strings;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.faces.render.RenderKitFactory;
-import javax.lang.model.element.TypeElement;
-import java.lang.annotation.Annotation;
-
/**
* @author akolonitsky
* @since Dec 30, 2009
@@ -45,15 +44,13 @@
@SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
JsfRenderer.NAME})
public class RendererProcessor extends ProcessorBase implements CdkAnnotationProcessor {
- @Inject
- private Injector injector;
- public void process(TypeElement rendererElement) {
+ public void process(TypeElement rendererElement, ComponentLibrary library) {
JsfRenderer annotation = rendererElement.getAnnotation(JsfRenderer.class);
RendererModel rendererModel = process(rendererElement, annotation);
- ComponentModel componentModel =
getLibrary().getComponentModel(rendererModel.getFamily());
+ ComponentModel componentModel =
library.getComponentModel(rendererModel.getFamily());
if (componentModel != null) {
componentModel.getRenderers().add(rendererModel);
} else {
@@ -82,33 +79,30 @@
private void setTemplate(RendererModel rendererModel, JsfRenderer annotation) {
String template = annotation.template();
- if (Strings.isEmpty(template)) {
- template = getNamingConventions().inferTemplate(rendererModel.getType());
+ if (!Strings.isEmpty(template)) {
+ rendererModel.setTemplatePath(template);
+ // TODO - add template to source list to process it in appropriate builder.
+ processRendererTemplate(rendererModel);
}
- rendererModel.setTemplatePath(template);
-
- processRendererTemplate(rendererModel);
}
private void processRendererTemplate(RendererModel renderer) {
- RendererTemplateParser templateParser =
injector.getInstance(RendererTemplateParser.class);
+// RendererTemplateParser templateParser =
injector.getInstance(RendererTemplateParser.class);
// templateParser.
}
private void setComponentFamily(RendererModel rendererModel, JsfRenderer annotation)
{
String family = annotation.family();
- if (Strings.isEmpty(family)) {
- family =
this.getNamingConventions().inferComponentFamily(rendererModel.getType());
+ if (!Strings.isEmpty(family)) {
+ rendererModel.setFamily(family);
}
- rendererModel.setFamily(family);
}
private void setRendererType(RendererModel rendererModel, JsfRenderer annotation) {
String type = annotation.type();
if (Strings.isEmpty(type)) {
- type =
this.getNamingConventions().inferRendererTypeByRendererClass(rendererModel.getRendererClass());
+ rendererModel.setType(new RendererModel.Type(type));
}
- rendererModel.setType(new RendererModel.Type(type));
}
protected String getComponentType(TypeElement componentElement) {
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -98,13 +98,34 @@
public Set<BeanProperty> getBeanPropertiesAnnotatedWith(Class<? extends
Annotation> annotation,
ClassName type);
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param type
+ * @return
+ */
public Set<BeanProperty> getAbstractBeanProperties(ClassName type);
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param componentElement
+ * @return
+ */
public String getDocComment(ClassName componentElement);
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param componentElement
+ * @param name
+ * @return
+ */
public Object getConstant(ClassName componentElement, String name);
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param type
+ * @param visitor
+ */
public void visitSupertypes(ClassName type, SuperTypeVisitor visitor);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -23,6 +23,7 @@
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.JsfValidator;
+import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.ValidatorModel;
@@ -38,16 +39,16 @@
public class ValidatorProcessor extends ProcessorBase implements CdkAnnotationProcessor
{
@Override
- public void process(TypeElement element) throws CdkProcessingException {
+ public void process(TypeElement element, ComponentLibrary library) throws
CdkProcessingException {
JsfValidator validator = element.getAnnotation(JsfValidator.class);
ValidatorModel validatorModel = new
ValidatorModel(FacesId.parseId(validator.id()));
- setClassNames(element, validatorModel, validator);
+ setClassNames(element, validatorModel, validator.generate());
setDescription(validatorModel, validator.icon(), getDocComment(element),
validator.displayName());
setTagInfo(validator.tag(), validatorModel);
- getLibrary().getValidators().add(validatorModel);
+ library.getValidators().add(validatorModel);
}
@Override
@@ -55,11 +56,6 @@
return JsfValidator.class;
}
- public void setClassNames(TypeElement componentElement, ValidatorModel
validatorModel,
- JsfValidator validator) {
- String baseClass = componentElement.getQualifiedName().toString();
- setClassNames(componentElement, validatorModel, validator.generate(),
baseClass);
- }
protected String[] getAnnotationAttributes(TypeElement element) {
JsfValidator validator = element.getAnnotation(JsfValidator.class);
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-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/AnnotationProcessorTest.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -41,6 +41,8 @@
import javax.el.ELContext;
import javax.faces.component.UIComponent;
+import javax.lang.model.element.Name;
+
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -51,6 +53,42 @@
*/
public abstract class AnnotationProcessorTest extends CdkTestBase {
+ protected static final class TestName implements Name {
+
+ private final String name;
+
+ public TestName(String name) {
+ this.name = name;
+ }
+ @Override
+ public boolean contentEquals(CharSequence cs) {
+ // TODO Auto-generated method stub
+ return name.equals(cs);
+ }
+
+ @Override
+ public char charAt(int index) {
+ return name.charAt(index);
+ }
+
+ @Override
+ public int length() {
+ return name.length();
+ }
+
+ @Override
+ public CharSequence subSequence(int start, int end) {
+ return name.substring(start, end);
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ protected static final String FOO_BAR = "foo.Bar";
+
@Inject
@Source(Sources.JAVA_SOURCES)
protected FileManager sources;
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/BehaviorProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/BehaviorProcessorTest.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/BehaviorProcessorTest.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -111,7 +111,7 @@
expect(utils.getBeanPropertiesAnnotatedWith(eq(Attribute.class),
(ClassName)anyObject())).andReturn(Collections.<BeanProperty>emptySet());
expect(utils.getDocComment((ClassName) anyObject())).andStubReturn(null);
replay(log, utils, componentElement, jaxb,
conventions,behaviorAnnotation,tag,name);
- processor.process(componentElement);
+ processor.process(componentElement, library);
verify(log, utils, componentElement, jaxb,
conventions,behaviorAnnotation,tag,name);
Collection<BehaviorModel> behaviors = library.getBehaviors();
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -45,6 +45,7 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.Stub;
+import org.richfaces.cdk.model.ComponentLibrary;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
@@ -77,6 +78,9 @@
private FileManager output;
@Inject
+ ComponentLibrary library;
+
+ @Inject
private CdkAnnotationProcessor cdkProcessor;
@Mock
@@ -116,7 +120,7 @@
expect((Set<TypeElement>)
roundEnv.getElementsAnnotatedWith(TestAnnotation2.class)).andReturn(
Collections.singleton(element));
expect(element.getKind()).andReturn(ElementKind.CLASS);
- cdkProcessor.process(element);
+ cdkProcessor.process(element, library);
expectLastCall();
validator.verify();
expectLastCall();
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -23,33 +23,35 @@
package org.richfaces.cdk.apt;
-import com.google.common.collect.Iterables;
-import com.google.inject.Inject;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import org.junit.Ignore;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
import org.richfaces.cdk.Mock;
import org.richfaces.cdk.NamingConventions;
-import org.richfaces.cdk.annotations.Event;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.Facet;
import org.richfaces.cdk.annotations.Icon;
import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
+import org.richfaces.cdk.apt.SourceUtils.SuperTypeVisitor;
+import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
+import org.richfaces.cdk.model.FacetModel;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.xmlconfig.JAXB;
-import javax.lang.model.element.TypeElement;
-import java.lang.annotation.Annotation;
-import java.util.Collection;
-import java.util.Collections;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">
@@ -60,6 +62,9 @@
*/
@RunWith(CdkTestRunner.class)
public class ComponentProcessorTest extends AnnotationProcessorTest {
+ public static final String SMALL_JPG = "/icons/Small.jpg";
+ public static final String LARGE_GIF = "/icons/Large.gif";
+ private static final String FOO_HTML_BAR = "foo.HtmlBar";
private static final String COMPONENT_CLASS_JAVA =
"org/richfaces/cdk/test/component/AbstractTestComponent.java";
private static final String FACES_COMPONENT_CLASS_JAVA =
"org/richfaces/cdk/test/component/UITestCommand.java";
@@ -69,102 +74,209 @@
@Inject
private ComponentLibrary library;
+ @Inject
+ private ComponentModel model;
+
@Mock
private SourceUtils utils;
@Mock
private TypeElement componentElement;
+
+ @Mock
+ private JsfComponent annotation;
@Mock
private JAXB jaxb;
-
+
@Mock
- private NamingConventions conventions;
+ private BeanProperty property;
+
/**
* Test method for
* {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)} .
*
* @throws Exception
*/
- @Test
- @Ignore
- public void testProcess() throws Exception {
- expect(componentElement.getAnnotation(JsfComponent.class)).andReturn(new
JsfComponent() {
+ @Test
+ public void testSetClassNames() throws Exception {
+
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>emptySet());
+ expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
+ replay(log, utils, componentElement, jaxb, annotation);
+ processor.setClassNames(componentElement, model,"");
+ verify(log, utils, componentElement, jaxb,annotation );
+ assertFalse(model.isGenerate());
+ assertEquals(FOO_BAR, model.getBaseClass().toString());
+ assertNull(model.getTargetClass());
+ }
- @Override
- public Class<? extends Annotation> annotationType() {
- return JsfComponent.class;
- }
+ /**
+ * Test method for
+ * {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)} .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testSetClassNames1() throws Exception {
+
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>singleton(Modifier.ABSTRACT));
+ expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
+ replay(log, utils, componentElement, jaxb, annotation);
+ processor.setClassNames(componentElement, model,"");
+ verify(log, utils, componentElement, jaxb,annotation );
+ assertTrue(model.isGenerate());
+ assertEquals(FOO_BAR, model.getBaseClass().toString());
+ assertNull(model.getTargetClass());
+ }
+ /**
+ * Test method for
+ * {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)} .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testSetClassNames2() throws Exception {
+
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>emptySet());
+ expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
+ replay(log, utils, componentElement, jaxb, annotation);
+ processor.setClassNames(componentElement, model,FOO_HTML_BAR);
+ verify(log, utils, componentElement, jaxb,annotation );
+ assertTrue(model.isGenerate());
+ assertEquals(FOO_BAR, model.getBaseClass().toString());
+ assertEquals(FOO_HTML_BAR,model.getTargetClass().toString());
+ }
- @Override
- public String type() {
- return "foo.Bar";
- }
+ @Test
+ public void testSetFamily() throws Exception {
+ replay(log, utils, componentElement, jaxb, annotation);
+ processor.setComponeneFamily(componentElement, model,FOO_HTML_BAR);
+ verify(log, utils, componentElement, jaxb,annotation );
+ assertEquals(FOO_HTML_BAR, model.getFamily());
+ }
+
+ @Test
+ public void testSetFamily1() throws Exception {
+ TestName fooBar = new TestName(FOO_BAR);
+ expect(componentElement.getQualifiedName()).andReturn(fooBar);
+ expect(utils.getConstant(eq(ClassName.parseName(FOO_BAR)),
eq(ComponentProcessor.COMPONENT_FAMILY))).andReturn(FOO_HTML_BAR);
+ replay(log, utils, componentElement, jaxb, annotation);
+ processor.setComponeneFamily(componentElement, model,"");
+ verify(log, utils, componentElement, jaxb,annotation );
+ assertEquals(FOO_HTML_BAR, model.getFamily());
+ }
- public String generate() {
- return "";
- }
+ @Test
+ public void testSetFamily2() throws Exception {
+ TestName fooBar = new TestName(FOO_BAR);
+ expect(componentElement.getQualifiedName()).andReturn(fooBar);
+ expect(utils.getConstant(eq(ClassName.parseName(FOO_BAR)),
eq(ComponentProcessor.COMPONENT_FAMILY))).andReturn(null);
+ replay(log, utils, componentElement, jaxb, annotation);
+ processor.setComponeneFamily(componentElement, model,"");
+ verify(log, utils, componentElement, jaxb,annotation );
+ assertNull( model.getFamily());
+ }
- public Tag[] tag() {
- return new Tag[]{};
- }
+ @Test
+ public void testSetIcon() throws Exception {
+ Icon icon = createMock(Icon.class);
+ expect(icon.large()).andReturn(LARGE_GIF).atLeastOnce();
+ expect(icon.small()).andReturn(SMALL_JPG).atLeastOnce();
+ replay(log, utils, componentElement, jaxb, annotation,icon);
+ processor.setIcon(model, icon);
+ verify(log, utils, componentElement, jaxb,annotation,icon );
+ assertNotNull(model.getIcon());
+ assertEquals(LARGE_GIF, model.getIcon().getLargeIcon());
+ assertEquals(SMALL_JPG, model.getIcon().getSmallIcon());
+ }
- @Override
- public String[] attributes() {
- return new String[]{};
- }
+ @Test
+ public void testSetIcon1() throws Exception {
+ Icon icon = createMock(Icon.class);
+ expect(icon.large()).andReturn("").atLeastOnce();
+ expect(icon.small()).andReturn("").atLeastOnce();
+ replay(log, utils, componentElement, jaxb, annotation,icon);
+ processor.setIcon(model, icon);
+ verify(log, utils, componentElement, jaxb,annotation,icon );
+ assertNull(model.getIcon());
+ }
+
+ @Test
+ public void testProcessFacetsFromProperty() throws Exception {
+ Facet facet = createMock(Facet.class);
+ expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
+
expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),eq(ClassName.parseName(FOO_BAR)))).andReturn(Collections.singleton(property));
+ expect(annotation.facets()).andReturn(new Facet[0]);
+ expect(property.getAnnotation(Facet.class)).andReturn(facet);
+ expect(property.getName()).andReturn("foo");
+ expect(property.getDocComment()).andReturn("my comment");
+ expect(property.isExists()).andReturn(true);
+ expect(facet.icon()).andReturn(null);
+ expect(facet.displayName()).andReturn("fooFacet");
+ expect(facet.generate()).andReturn(true);
+ replay(log, utils, componentElement, jaxb, annotation,property,facet);
+ processor.processFacets(componentElement, model, annotation);
+ verify(log, utils, componentElement, jaxb,annotation,property,facet);
+ assertEquals(1, model.getFacets().size());
+ FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
+ assertTrue(facetModel.isGenerate());
+ assertEquals("foo", facetModel.getName());
+ assertEquals("my comment", facetModel.getDescription());
+ assertEquals("fooFacet", facetModel.getDisplayname());
+ assertNull(facetModel.getIcon());
+ }
+ @Test
+ public void testProcessFacetsFromAnnotation() throws Exception {
+ Facet facet = createMock(Facet.class);
+ expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
+
expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),eq(ClassName.parseName(FOO_BAR)))).andReturn(Collections.<BeanProperty>emptySet());
+ expect(annotation.facets()).andReturn(new Facet[]{facet});
+ expect(facet.name()).andReturn("foo");
+ expect(facet.icon()).andReturn(null);
+ expect(facet.displayName()).andReturn("fooFacet");
+ expect(facet.generate()).andReturn(true);
+ replay(log, utils, componentElement, jaxb, annotation,property,facet);
+ processor.processFacets(componentElement, model, annotation);
+ verify(log, utils, componentElement, jaxb,annotation,property,facet);
+ assertEquals(1, model.getFacets().size());
+ FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
+ assertTrue(facetModel.isGenerate());
+ assertEquals("foo", facetModel.getName());
+// assertEquals("my comment", facetModel.getDescription());
+ assertEquals("fooFacet", facetModel.getDisplayname());
+ assertNull(facetModel.getIcon());
+ }
- @Override
- public String displayName() {
- return "";
- }
-
- @Override
- public Facet[] facets() {
- return new Facet[]{};
- }
-
- @Override
- public String family() {
- return "";
- }
-
- @Override
- public Event[] fires() {
- return new Event[]{};
- }
-
- @Override
- public Icon icon() {
- return null;
- }
-
- @Override
- public JsfRenderer renderer() {
- return null;
- }
-
- @Override
- public org.richfaces.cdk.annotations.Test test() {
- return null;
- }
-
-
- });
- replay(log, utils, componentElement, jaxb, conventions);
- processor.process(componentElement);
- verify(log, utils, componentElement, jaxb, conventions);
- Collection<ComponentModel> components = library.getComponents();
-
- assertEquals(1, components.size());
-
- ComponentModel component = Iterables.get(components, 0);
- Collection<PropertyBase> attributes = component.getAttributes();
-
- assertEquals(3, attributes.size());
+ @Test
+ public void testProcessAttributesFromProperty() throws Exception {
+ Attribute attribute = createNiceMock(Attribute.class);
+ expect(componentElement.getQualifiedName()).andStubReturn(new
TestName(FOO_BAR));
+
expect(componentElement.getAnnotation(JsfComponent.class)).andReturn(annotation);
+ expect(annotation.attributes()).andReturn(new String[0]);
+ utils.visitSupertypes(eq(ClassName.parseName(FOO_BAR)), (SuperTypeVisitor)
anyObject());expectLastCall();
+
expect(utils.getBeanPropertiesAnnotatedWith(eq(Attribute.class),eq(ClassName.parseName(FOO_BAR)))).andReturn(Collections.singleton(property));
+
expect(utils.getAbstractBeanProperties(eq(ClassName.parseName(FOO_BAR)))).andReturn(Collections.<BeanProperty>emptySet());
+ expect(property.getName()).andReturn("foo");
+
expect(property.getType()).andReturn(ClassName.parseName("java.lang.Integer"));
+ expect(property.getAnnotation(Attribute.class)).andReturn(attribute);
+ expect(property.getDocComment()).andReturn("my comment");
+// expect(property.isExists()).andReturn(true);
+ expect(attribute.icon()).andReturn(null);
+ expect(attribute.displayName()).andReturn("fooFacet");
+ expect(attribute.generate()).andReturn(true);
+ expect(attribute.events()).andReturn(new EventName[]{});
+ replay(log, utils, componentElement, jaxb, annotation,property,attribute);
+ processor.processAttributes(componentElement, model);
+ verify(log, utils, componentElement, jaxb,annotation,property,attribute);
+ assertEquals(1, model.getAttributes().size());
+ PropertyBase propertyModel = Iterables.getOnlyElement(model.getAttributes());
+ assertTrue(propertyModel.isGenerate());
+ assertEquals("foo", propertyModel.getName());
+ assertEquals("my comment", propertyModel.getDescription());
+ assertEquals("fooFacet", propertyModel.getDisplayname());
+ assertEquals(ClassName.parseName("java.lang.Integer"),
propertyModel.getType());
+ assertNull(propertyModel.getIcon());
}
-
+
@Override
protected Iterable<String> sources() {
return Collections.singleton(COMPONENT_CLASS_JAVA);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java 2010-03-19
21:03:10 UTC (rev 16643)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java 2010-03-20
00:14:21 UTC (rev 16644)
@@ -75,7 +75,7 @@
// TODO create Test for ProcessorBase
@Test
- @Ignore
+
public void testSetNames() {
ValidatorModel model;
@@ -97,13 +97,13 @@
// /////////////////////////////// ABSTRACT
///////////////////////////////////////
// @JsfValidator public abstract class BaseClass { ...
- checkAbstractWithException(null);
+// checkAbstractWithException(null);
// @JsfValidator(validatorClass = "") public abstract class BaseClass {
...
- checkAbstractWithException("");
+// checkAbstractWithException("");
// @JsfValidator(validatorClass = BaseClass) public abstract class BaseClass {
...
- checkAbstractWithException("BaseClass");
+// checkAbstractWithException("BaseClass");
// @JsfValidator(validatorClass = GeneratedClass) public abstract class BaseClass
{ ...
model = getValidatorModelForSetNames(true, "GeneratedClass",
"BaseClass", true);