Author: alexsmirnov
Date: 2011-01-10 17:35:38 -0500 (Mon, 10 Jan 2011)
New Revision: 20938
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ViewElement.java
Removed:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java
Modified:
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/Event.java
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfComponent.java
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfRenderer.java
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfValidator.java
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/RendererSpecificComponent.java
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/TagType.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/ReflectionUtils.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/EventProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ValidatorProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/LibraryModelWrapper.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ModelElementBaseTemplateModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroup.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroupBase.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/EventModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/DescriptionGroupBean.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsAnnotationsTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java
trunk/ui/core/ui/src/main/java/org/richfaces/component/UIRepeat.java
Log:
RESOLVED - issue RF-10093:
https://issues.jboss.org/browse/RF-10093
Modified: trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/Event.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/Event.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/Event.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -23,6 +23,8 @@
package org.richfaces.cdk.annotations;
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
@@ -50,13 +52,18 @@
public static final String NAME = "org.richfaces.cdk.annotations.Event";
/**
+ * <p class="changed_added_4_0">Used in the {@link JsfComponent}
only, to define event type.</p>
+ * @return
+ */
+ public Class<? extends FacesEvent> value() default DEFAULT.class;
+ /**
* <p class="changed_added_4_0">
- * The listener interface class that process annotated event. This is mandatory
parameter.
+ * The listener interface class that process annotated event.
* </p>
*
* @return name of listener interface
*/
- public Class<? extends FacesListener> listener();
+ public Class<? extends FacesListener> listener() default
DEFAULT_LISTENER.class;
/**
* <p class="changed_added_4_0">Name for the listener interface
method that process annotated event type.</p>
@@ -82,4 +89,24 @@
*/
public Tag[] tag() default {};
+ @SuppressWarnings("serial")
+ static final class DEFAULT extends FacesEvent {
+
+ public DEFAULT(UIComponent component) {
+ super(component);
+ }
+
+ @Override
+ public boolean isAppropriateListener(FacesListener listener) {
+ return false;
+ }
+
+ @Override
+ public void processListener(FacesListener listener) {
+ }
+ }
+
+ static final class DEFAULT_LISTENER implements FacesListener {
+
+ }
}
Modified:
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -52,7 +52,7 @@
public String generate() default "";
- public Tag tag() default @Tag;
+ public Tag[] tag() default {};
public JsfBehaviorRenderer renderer() default @JsfBehaviorRenderer();
/**
@@ -77,4 +77,13 @@
* @return
*/
public String[] attributes() default {};
+
+ /**
+ * <p class="changed_added_4_0">
+ * Interfaces that should be implemented in the generated class. CDK processes all
{@link Attribute} annotations in these interfaces
+ * </p>
+ *
+ * @return
+ */
+ public Class<?>[] interfaces() default {};
}
Modified:
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfComponent.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfComponent.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfComponent.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -134,7 +134,7 @@
*
* @return
*/
- public Class<? extends FacesEvent>[] fires() default {};
+ public Event[] fires() default {};
/**
* <p class="changed_added_4_0">
Modified:
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -56,7 +56,7 @@
*/
public Description description() default @Description();
- public Tag tag() default @Tag;
+ public Tag[] tag() default {};
public static final class NONE {}
@@ -72,5 +72,13 @@
* @return
*/
public String[] attributes() default {};
+ /**
+ * <p class="changed_added_4_0">
+ * Interfaces that should be implemented in the generated class. CDK processes all
{@link Attribute} annotations in these interfaces
+ * </p>
+ *
+ * @return
+ */
+ public Class<?>[] interfaces() default {};
}
Modified:
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfRenderer.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfRenderer.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfRenderer.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -58,6 +58,13 @@
* @return
*/
public String family() default "";
+
+
+ /**
+ * <p class="changed_added_4_0">Name of generated renderer
class.</p>
+ * @return
+ */
+ public String generate() default "";
/**
* <p class="changed_added_4_0">RenderKit for which this renderer is
belong to</p>
Modified:
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfValidator.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfValidator.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/JsfValidator.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -19,7 +19,7 @@
public String generate() default "";
- public Tag tag() default @Tag;
+ public Tag[] tag() default {};
/**
* <p class="changed_added_4_0">
* Description used by IDE.
@@ -41,4 +41,13 @@
* @return
*/
public String[] attributes() default {};
+ /**
+ * <p class="changed_added_4_0">
+ * Interfaces that should be implemented in the generated class. CDK processes all
{@link Attribute} annotations in these interfaces
+ * </p>
+ *
+ * @return
+ */
+ public Class<?>[] interfaces() default {};
+
}
Modified:
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/RendererSpecificComponent.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/RendererSpecificComponent.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/RendererSpecificComponent.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -129,5 +129,13 @@
* @return
*/
public Class<?>[] interfaces() default {};
+ /**
+ * <p class="changed_added_4_0">
+ * Events fired by the component.
+ * </p>
+ *
+ * @return
+ */
+ public Event[] fires() default {};
}
Modified: trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/TagType.java
===================================================================
---
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/TagType.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/annotations/src/main/java/org/richfaces/cdk/annotations/TagType.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -28,16 +28,19 @@
*/
public enum TagType {
/**
- * <p class="changed_added_4_0">Do not generate any tags, this is
default value for {@link Tag#type()} annotation.</p>
- */
- None, /**
- * <p class="changed_added_4_0">Defines JSP tag.</p>
- */
+ * <p class="changed_added_4_0">
+ * Defines JSP tag.
+ * </p>
+ */
Jsp, /**
- * <p class="changed_added_4_0">Defines Facelets tag.</p>
- */
+ * <p class="changed_added_4_0">
+ * Defines Facelets tag.
+ * </p>
+ */
Facelets, /**
- * <p class="changed_added_4_0">Enforces tag annotation to generate
all known tag types</p>
- */
+ * <p class="changed_added_4_0">
+ * Enforces tag annotation to generate all known tag types
+ * </p>
+ */
All
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java 2011-01-10
22:19:53 UTC (rev 20937)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -25,6 +25,7 @@
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.util.PropertyUtils;
import com.google.common.base.Predicate;
@@ -160,7 +161,7 @@
AptBeanProperty beanProperty = result.get(propertyName);
checkPropertyType(type, propertyName, propertyType, beanProperty);
if (null != (setter?beanProperty.setter:beanProperty.getter)) {
- log.warn("Two " + (setter ? "setter" :
"getter") + " methods for the same bean property "
+ log.debug("Two " + (setter ? "setter" :
"getter") + " methods for the same bean property "
+ propertyName + " in the class " +
type.getQualifiedName());
if(!method.getModifiers().contains(Modifier.ABSTRACT)){
beanProperty.setAccessMethod(method, setter);
@@ -278,8 +279,11 @@
VariableElement variable = (VariableElement) annotationValue.getValue();
return (T) Enum.valueOf((Class<? extends Enum>) expectedType,
variable.getSimpleName().toString());
} else if (ClassName.class.equals(expectedType)) {
- TypeMirror value = (TypeMirror) annotationValue.getValue();
+ Object value = annotationValue.getValue();
return (T) ClassName.get(value.toString());
+ } else if (FacesId.class.equals(expectedType)) {
+ String value = (String) annotationValue.getValue();
+ return (T) FacesId.parseId(value);
} else if (AnnotationMirror.class.isAssignableFrom(expectedType)) {
AnnotationMirror value = (AnnotationMirror) annotationValue.getValue();
return (T) value;
@@ -290,7 +294,7 @@
@SuppressWarnings("unchecked")
@Override
- public <T> List<T> getAnnotationValues(AnnotationMirror annotation,
String propertyName, Class<T> expectedType) {
+ public <T> Iterable<T> getAnnotationValues(AnnotationMirror annotation,
String propertyName, Class<T> expectedType) {
Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>
attributeEntry =
findAnnotationProperty(annotation, propertyName);
List<? extends AnnotationValue> annotationValues =
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/ReflectionUtils.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/ReflectionUtils.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/ReflectionUtils.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -24,7 +24,6 @@
package org.richfaces.cdk.apt;
import java.lang.annotation.Annotation;
-import java.util.List;
import java.util.Set;
import javax.lang.model.element.AnnotationMirror;
@@ -113,7 +112,7 @@
}
@Override
- public <T> List<T> getAnnotationValues(AnnotationMirror annotation,
String propertyName, Class<T> expectedType) {
+ public <T> Iterable<T> getAnnotationValues(AnnotationMirror annotation,
String propertyName, Class<T> expectedType) {
// TODO Auto-generated method stub
return null;
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java 2011-01-10
22:19:53 UTC (rev 20937)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -24,7 +24,6 @@
package org.richfaces.cdk.apt;
import java.lang.annotation.Annotation;
-import java.util.List;
import java.util.Set;
import javax.lang.model.element.AnnotationMirror;
@@ -200,7 +199,7 @@
* @param propertyName
* @return
*/
- <T> List<T> getAnnotationValues(AnnotationMirror annotation, String
propertyName, Class<T> expectedType);
+ <T> Iterable<T> getAnnotationValues(AnnotationMirror annotation, String
propertyName, Class<T> expectedType);
/**
* <p class="changed_added_4_0"></p>
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -23,6 +23,7 @@
import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
import org.richfaces.cdk.xmlconfig.FragmentParser;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -83,19 +84,20 @@
}
} else {
SourceUtils utils = utilsProvider.get();
- utils.setModelProperty(attribute, attributeAnnotarion, "hidden");
- utils.setModelProperty(attribute, attributeAnnotarion,
"literal");
- utils.setModelProperty(attribute, attributeAnnotarion,
"passThrough");
- utils.setModelProperty(attribute, attributeAnnotarion,
"required");
- utils.setModelProperty(attribute, attributeAnnotarion,
"readOnly");
+ utils.setModelProperty(attribute, attributeAnnotarion, "hidden");
+ utils.setModelProperty(attribute, attributeAnnotarion, "literal");
+ utils.setModelProperty(attribute, attributeAnnotarion,
"passThrough");
+ utils.setModelProperty(attribute, attributeAnnotarion,
"required");
+ utils.setModelProperty(attribute, attributeAnnotarion,
"readOnly");
if (!utils.isDefaultValue(attributeAnnotarion, "generate")) {
attribute.setGenerate(utils.getAnnotationValue(attributeAnnotarion,
"generate", boolean.class));
} else {
attribute.setGenerate(!beanProperty.isExists());
}
- descriptionProcessor.processDescription(attribute,
beanProperty.getAnnotation(Attribute.class).description(), beanProperty
- .getDocComment());
+ descriptionProcessor.processDescription(attribute,
+ utils.getAnnotationValue(attributeAnnotarion, "description",
AnnotationMirror.class),
+ beanProperty.getDocComment());
setDefaultValue(attribute, attributeAnnotarion);
@@ -104,13 +106,13 @@
// MethodExpression call signature.
attribute.setSignature(getSignature(attributeAnnotarion));
- for (AnnotationMirror event : utils.getAnnotationValues(attributeAnnotarion,
"events", AnnotationMirror.class)){
+ for (AnnotationMirror event : utils.getAnnotationValues(attributeAnnotarion,
"events",
+ AnnotationMirror.class)) {
setBehaviorEvent(attribute, event);
}
}
}
-
private void setDefaultValue(PropertyBase attribute, AnnotationMirror
attributeAnnotarion) {
SourceUtils utils = utilsProvider.get();
String defaultValue;
@@ -165,8 +167,8 @@
if (!SIGNATURE_NONE_CLASS_NAME.equals(returnType)) {
MethodSignature methodSignature = new MethodSignature();
-
methodSignature.setParameters(utils.getAnnotationValues(signatureAnnotation,
"parameters",
- ClassName.class));
+
methodSignature.setParameters(Lists.newArrayList(utils.getAnnotationValues(signatureAnnotation,
"parameters",
+ ClassName.class)));
methodSignature.setReturnType(returnType);
return methodSignature;
}
@@ -174,7 +176,6 @@
return null;
}
-
private void setBehaviorEvent(PropertyBase attribute, AnnotationMirror eventMirror)
{
if (null != eventMirror) {
SourceUtils utils = utilsProvider.get();
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -26,14 +26,15 @@
import java.lang.annotation.Annotation;
import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.JsfBehavior;
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.BehaviorModel;
import org.richfaces.cdk.model.ComponentLibrary;
-import org.richfaces.cdk.model.FacesId;
/**
* <p class="changed_added_4_0"></p>
@@ -45,17 +46,17 @@
@Override
public void process(Element element, ComponentLibrary library) throws
CdkProcessingException {
- JsfBehavior behavior = element.getAnnotation(JsfBehavior.class);
+ SourceUtils sourceUtils = getSourceUtils();
+ AnnotationMirror behavior = sourceUtils.getAnnotationMirror(element,
JsfBehavior.class);
- BehaviorModel behaviorModel = new BehaviorModel(new FacesId(behavior.id()));
- setClassNames((TypeElement) element, behaviorModel, behavior.generate());
+ BehaviorModel behaviorModel = new BehaviorModel();
+
+ sourceUtils.setModelProperty(behaviorModel, behavior, "id");
+ setClassNames((TypeElement) element, behaviorModel, behavior);
- setTagInfo(behavior.tag(), behaviorModel);
- AttributesProcessor attributesProcessor = getAttributeProcessor();
- attributesProcessor.processXmlFragment(behaviorModel, behavior.attributes());
- attributesProcessor.processType(behaviorModel, (TypeElement) element);
- setDescription(behaviorModel, behavior.description(), getDocComment(element));
-
+ setTagInfo(behavior, behaviorModel);
+ processAttributes((TypeElement) element, behaviorModel, behavior);
+ setDescription(behaviorModel, behavior, getDocComment(element));
library.getBehaviors().add(behaviorModel);
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -24,36 +24,24 @@
package org.richfaces.cdk.apt.processors;
import java.lang.annotation.Annotation;
-import java.util.Collection;
-import java.util.List;
import java.util.Set;
-import javax.faces.event.FacesEvent;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.MirroredTypeException;
-import javax.lang.model.type.MirroredTypesException;
-import javax.lang.model.type.TypeKind;
-import javax.lang.model.type.TypeMirror;
import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.Logger;
import org.richfaces.cdk.annotations.Facet;
import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.RendererSpecificComponent;
-import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
+import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.FacetModel;
-import org.richfaces.cdk.util.Strings;
-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
@@ -69,32 +57,32 @@
public static final String COMPONENT_TYPE = "COMPONENT_TYPE";
- @Inject
- private Logger log;
-
public void process(Element componentElement, ComponentLibrary library) {
- final JsfComponent annotation =
componentElement.getAnnotation(JsfComponent.class);
- if (annotation == null) {
- return;
- }
+ SourceUtils sourceUtils = getSourceUtils();
+ if (sourceUtils.isAnnotationPresent(componentElement, JsfComponent.class)) {
+ AnnotationMirror annotation =
sourceUtils.getAnnotationMirror(componentElement, JsfComponent.class);
+ // Process class-level annotations.
+ ComponentModel component = new ComponentModel();
- // Process class-level annotations.
- ComponentModel component = new ComponentModel();
+ // Should that component be generated ?
+ setClassNames((TypeElement) componentElement, component, annotation);
+ setComponentProperties((TypeElement) componentElement, component,
annotation);
- // Should that component be generated ?
- setClassNames((TypeElement) componentElement, component, annotation.generate());
- setComponentProperties((TypeElement) componentElement, component, annotation);
- library.getComponents().add(component);
+ library.getComponents().add(component);
- // Process the second level annotations.
- for (final RendererSpecificComponent subcomponent : annotation.components()) {
- JsfComponent subAnnotation = new JsfSubComponent(subcomponent, annotation);
- ComponentModel subcomponentModel = new ComponentModel();
- subcomponentModel.setBaseClass(component.getTargetClass());
-
subcomponentModel.setTargetClass(ClassName.parseName(subcomponent.generate()));
- subcomponentModel.setGenerate(!Strings.isEmpty(subcomponent.generate()));
- setComponentProperties(null, subcomponentModel, subAnnotation);
- library.getComponents().add(subcomponentModel);
+ // Process the second level annotations.
+ for (AnnotationMirror subcomponent :
sourceUtils.getAnnotationValues(annotation, "components",
+ AnnotationMirror.class)) {
+ ComponentModel subcomponentModel = new ComponentModel();
+ subcomponentModel.setBaseClass(component.getTargetClass());
+ if (!sourceUtils.isDefaultValue(subcomponent, "generate")) {
+
subcomponentModel.setTargetClass(sourceUtils.getAnnotationValue(subcomponent,
"generate",
+ ClassName.class));
+ subcomponentModel.setGenerate(true);
+ }
+ setComponentProperties(null, subcomponentModel, subcomponent);
+ library.getComponents().add(subcomponentModel);
+ }
}
}
@@ -108,91 +96,48 @@
* @param annotation
* @throws CdkException
*/
- void setComponentProperties(TypeElement componentElement, ComponentModel component,
JsfComponent annotation)
+ void setComponentProperties(TypeElement componentElement, ComponentModel component,
AnnotationMirror annotation)
throws CdkException {
+ SourceUtils sourceUtils = getSourceUtils();
- setComponentType(componentElement, component, annotation.type());
- setComponeneFamily(componentElement, component, annotation.family());
- setDescription(component, annotation.description(),
getDocComment(componentElement));
- setRendererType(component, annotation.renderer());
-
+ setComponentType(componentElement, component, annotation);
+ setComponeneFamily(componentElement, component, annotation);
+ setDescription(component, annotation, getDocComment(componentElement));
+ if (!sourceUtils.isDefaultValue(annotation, "renderer")) {
+ setRendererType(component, sourceUtils.getAnnotationValue(annotation,
"renderer", AnnotationMirror.class));
+ }
processFacets(componentElement, component, annotation);
processAttributes(componentElement, component, annotation);
processEvents(componentElement, component, annotation);
- for (Tag tag : annotation.tag()) {
- setTagInfo(tag, component);
- }
+ setTagInfo(annotation, component);
// TODO - process @Test annotations.
}
- private void setRendererType(ComponentModel component, JsfRenderer jsfRenderer) {
- if(!Strings.isEmpty(jsfRenderer.type())){
- component.setRendererType(FacesId.parseId(jsfRenderer.type()));
+ private void setRendererType(ComponentModel component, AnnotationMirror annotation)
{
+ SourceUtils sourceUtils = getSourceUtils();
+ if (!sourceUtils.isDefaultValue(annotation, "type")) {
+ component.setRendererType(sourceUtils.getAnnotationValue(annotation,
"type", FacesId.class));
}
- if(!Strings.isEmpty(jsfRenderer.template())){
- component.setRendererTemplate(jsfRenderer.template());
+ if (!sourceUtils.isDefaultValue(annotation, "template")) {
+ component.setRendererTemplate(sourceUtils.getAnnotationValue(annotation,
"template", String.class));
}
}
- private void processAttributes(TypeElement componentElement, ComponentModel
component, JsfComponent annotation) {
- AttributesProcessor attributesProcessor = getAttributeProcessor();
- attributesProcessor.processXmlFragment(component, annotation.attributes());
-
- if (componentElement != null) {
- attributesProcessor.processType(component, componentElement);
- }
-
- Collection<ClassName> interfaceNames = component.getInterfaces();
- try {
- Class<?>[] interfaces = annotation.interfaces();
- for (Class<?> clazz : interfaces) {
- interfaceNames.add(new ClassName(clazz));
- }
- } catch (MirroredTypesException e) {
- List<? extends TypeMirror> typeMirrors = e.getTypeMirrors();
- for (TypeMirror mirror : typeMirrors) {
- processInterface(component, attributesProcessor, mirror);
- }
- } catch (MirroredTypeException e) {
- processInterface(component, attributesProcessor, e.getTypeMirror());
- }
+ void setComponentType(TypeElement componentElement, ComponentModel component,
AnnotationMirror annotation) {
+ component.setId(FacesId.parseId(getAnnotationPropertyOrConstant(componentElement,
annotation,"type",COMPONENT_TYPE)));
}
- private void processInterface(ComponentModel component, AttributesProcessor
attributesProcessor, TypeMirror mirror) {
- component.getInterfaces().add(ClassName.parseName(mirror.toString()));
- if (TypeKind.DECLARED.equals(mirror.getKind())) {
- attributesProcessor.processType(component,
getSourceUtils().asTypeElement(mirror));
- } else {
- // TODO - record warning.
- }
- }
-
- void setComponentType(TypeElement componentElement, ComponentModel component, String
type) {
- if (!Strings.isEmpty(type)) {
- component.setId(FacesId.parseId(type));
- } else if (null != componentElement) {
-
- // static final String COMPONENT_FAMILY = "...";
- Object value = getSourceUtils().getConstant(componentElement,
COMPONENT_TYPE);
- if (value != null) {
- component.setId(FacesId.parseId(value.toString()));
- }
- }
- }
-
- final void processFacets(TypeElement componentElement, ComponentModel component,
JsfComponent annotation) {
+ final void processFacets(TypeElement componentElement, ComponentModel component,
AnnotationMirror annotation) {
+ SourceUtils sourceUtils = getSourceUtils();
if (null != componentElement) {
- SourceUtils sourceUtils = getSourceUtils();
Set<BeanProperty> properties =
sourceUtils.getBeanPropertiesAnnotatedWith(Facet.class, componentElement);
// TODO - encapsulate attribute builder into utility class.
for (BeanProperty beanProperty : properties) {
- Facet facet = beanProperty.getAnnotation(Facet.class);
+ AnnotationMirror facet = beanProperty.getAnnotationMirror(Facet.class);
FacetModel facetModel =
component.getOrCreateFacet(beanProperty.getName());
-
facetModel.setDescription(beanProperty.getDocComment());
-
processFacet(facet, facetModel, beanProperty.getDocComment());
if (!beanProperty.isExists()) {
facetModel.setGenerate(true);
@@ -200,57 +145,42 @@
}
}
- for (Facet facet : annotation.facets()) {
- String name = facet.name();
- if (!Strings.isEmpty(name)) {
+ for (AnnotationMirror facet : sourceUtils.getAnnotationValues(annotation,
"facets", AnnotationMirror.class)) {
+ if (!sourceUtils.isDefaultValue(facet, "name")) {
+ String name = sourceUtils.getAnnotationValue(facet, "name",
String.class);
FacetModel facetModel = component.getOrCreateFacet(name);
processFacet(facet, facetModel, null);
} else {
- // TODO - record error.
throw new CdkException("Facet name should be set");
}
}
}
- final void processFacet(Facet facet, FacetModel facetModel, String docComment) {
- setDescription(facetModel, facet.description(), docComment);
- facetModel.setGenerate(facet.generate());
+ final void processFacet(AnnotationMirror facet, FacetModel facetModel, String
docComment) {
+ SourceUtils sourceUtils = getSourceUtils();
+ if (!sourceUtils.isDefaultValue(facet, "description")) {
+ setDescription(facetModel, facet, docComment);
+ }
+ if (!sourceUtils.isDefaultValue(facet, "generate")) {
+ facetModel.setGenerate(sourceUtils.getAnnotationValue(facet,
"generate", Boolean.class));
+ }
}
- final void setComponeneFamily(TypeElement componentElement, ComponentModel component,
String family) {
- if (!Strings.isEmpty(family)) {
- component.setFamily(FacesId.parseId(family));
- } else if (null != componentElement) {
- // static final String COMPONENT_FAMILY = "...";
- Object value = getSourceUtils().getConstant(componentElement,
COMPONENT_FAMILY);
- if (null != value) {
- component.setFamily(FacesId.parseId(value.toString()));
- }
+ final void setComponeneFamily(TypeElement componentElement, ComponentModel component,
AnnotationMirror annotation) {
+ if(null != componentElement){
+
component.setFamily(FacesId.parseId(getAnnotationPropertyOrConstant(componentElement,
annotation,"family",COMPONENT_FAMILY)));
}
}
- final void processEvents(TypeElement componentElement, ComponentModel component,
JsfComponent annotation) {
- try {
- Class<? extends FacesEvent>[] fires = annotation.fires();
-
- for (Class<? extends FacesEvent> event : fires) {
- try {
- component.addEvent(event.getName());
- } catch (MirroredTypesException mirror) {
- for (TypeMirror eventType : mirror.getTypeMirrors()) {
- component.addEvent(eventType.toString());
- }
- } catch (MirroredTypeException mirror) {
- component.addEvent(mirror.getTypeMirror().toString());
- }
-
- }
- } catch (MirroredTypesException mirror) {
- for (TypeMirror eventType : mirror.getTypeMirrors()) {
- component.addEvent(eventType.toString());
- }
- } catch (MirroredTypeException mirror) {
- component.addEvent(mirror.getTypeMirror().toString());
+ final void processEvents(TypeElement componentElement, ComponentModel component,
AnnotationMirror annotation) {
+ SourceUtils sourceUtils = getSourceUtils();
+ for (AnnotationMirror event : sourceUtils.getAnnotationValues(annotation,
"fires", AnnotationMirror.class)) {
+ EventModel model = new EventModel();
+ sourceUtils.setModelProperty(model, event, "type",
"value");
+ sourceUtils.setModelProperty(model, event, "listenerInterface",
"listener");
+ sourceUtils.setModelProperty(model, event, "listenerMethod");
+ sourceUtils.setModelProperty(model, event, "sourceInterface",
"source");
+ component.getEvents().add(model);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -24,16 +24,14 @@
import java.lang.annotation.Annotation;
import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.MirroredTypeException;
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.JsfConverter;
-import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConverterModel;
-import org.richfaces.cdk.model.FacesId;
/**
* @author akolonitsky
@@ -44,32 +42,16 @@
@Override
public void process(Element element, ComponentLibrary library) throws
CdkProcessingException {
- JsfConverter converter = element.getAnnotation(JsfConverter.class);
+ SourceUtils sourceUtils = getSourceUtils();
+ AnnotationMirror converter = sourceUtils.getAnnotationMirror(element,
JsfConverter.class);
ConverterModel converterModel = new ConverterModel();
- converterModel.setId(FacesId.parseId(converter.id()));
+ sourceUtils.setModelProperty(converterModel, converter, "id");
+ sourceUtils.setModelProperty(converterModel, converter,
"converterForClass","forClass");
- try {
- Class<?> forClass = converter.forClass();
- if (!JsfConverter.NONE.class.equals(forClass)) {
- converterModel.setConverterForClass(new ClassName(forClass.getName()));
- }
- } catch (MirroredTypeException e) {
- String name = e.getTypeMirror().toString();
- if (!JsfConverter.NONE.class.getName().equals(name)) {
- converterModel.setConverterForClass(new ClassName(name));
- }
- }
-
- setDescription(converterModel, converter.description(), getDocComment(element));
-
- AttributesProcessor attributesProcessor = getAttributeProcessor();
- attributesProcessor.processXmlFragment(converterModel, converter.attributes());
- attributesProcessor.processType(converterModel, (TypeElement) element);
- setClassNames((TypeElement) element, converterModel, converter.generate());
-
- setTagInfo(converter.tag(), converterModel);
-
+ setDescription(converterModel, converter, getDocComment(element));
+ processAttributes(element, converterModel, converter);
+ setTagInfo(converter, converterModel);
library.getConverters().add(converterModel);
}
@@ -77,11 +59,4 @@
public Class<? extends Annotation> getProcessedAnnotation() {
return JsfConverter.class;
}
-
-
- protected String[] getAnnotationAttributes(TypeElement element) {
- JsfConverter converter = element.getAnnotation(JsfConverter.class);
-
- return converter.attributes();
- }
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -23,7 +23,8 @@
package org.richfaces.cdk.apt.processors;
-import org.richfaces.cdk.annotations.Description;
+import javax.lang.model.element.AnnotationMirror;
+
import org.richfaces.cdk.model.DescriptionGroup;
/**
@@ -36,15 +37,15 @@
/**
* <p class="changed_added_4_0">process {@link Description}
annotation and set information from it into model. Optional string from the JavaDoc
comment has precedence over {@link Desription#value()} attribute.</p>
* @param model
- * @param description
+ * @param annotation
* @param docComment JavaDoc comment associated with described element.
*/
- public void processDescription(DescriptionGroup model, Description description,
String docComment);
+ public void processDescription(DescriptionGroup model, AnnotationMirror annotation,
String docComment);
/**
* <p class="changed_added_4_0">process {@link Description}
annotation and set information from it into model.</p>
* @param model
* @param description
*/
- public void processDescription(DescriptionGroup model, Description description);
+ public void processDescription(DescriptionGroup model, AnnotationMirror
description);
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -23,51 +23,56 @@
package org.richfaces.cdk.apt.processors;
-import org.richfaces.cdk.annotations.Description;
+import javax.lang.model.element.AnnotationMirror;
+
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.DescriptionGroup;
import org.richfaces.cdk.util.Strings;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
*/
public class DescriptionProcessorImpl implements DescriptionProcessor {
+ private final Provider<SourceUtils> utilsProvider;
+
+ @Inject
+ public DescriptionProcessorImpl(Provider<SourceUtils> utilsProvider) {
+ this.utilsProvider = utilsProvider;
+ }
+
@Override
- public void processDescription(DescriptionGroup model, Description description,
String docComment) {
+ public void processDescription(DescriptionGroup model, AnnotationMirror description,
String docComment) {
if (!Strings.isEmpty(docComment)) {
model.setDescription(docComment);
}
if (description != null) {
+ SourceUtils utils = utilsProvider.get();
setIcon(model, description);
- if (!Strings.isEmpty(description.displayName())) {
- model.setDisplayname(description.displayName());
- }
- if (!Strings.isEmpty(description.value())) {
- model.setDescription(description.value());
- }
+ utils.setModelProperty(model, description, "displayName");
+ utils.setModelProperty(model, description,
"description","value");
}
}
@Override
- public void processDescription(DescriptionGroup model, Description description) {
+ public void processDescription(DescriptionGroup model, AnnotationMirror description)
{
processDescription(model, description, null);
}
- protected void setIcon(DescriptionGroup component, Description icon) {
- if (null != icon && (!Strings.isEmpty(icon.smallIcon()) ||
!Strings.isEmpty(icon.largeIcon()))) {
+ protected void setIcon(DescriptionGroup component, AnnotationMirror description) {
+ SourceUtils utils = utilsProvider.get();
+ if (null != description
+ && (!utils.isDefaultValue(description, "smallIcon") ||
!utils.isDefaultValue(description, "largeIcon"))) {
DescriptionGroup.Icon iconValue = new DescriptionGroup.Icon();
-
- if (!Strings.isEmpty(icon.smallIcon())) {
- iconValue.setSmallIcon(icon.smallIcon());
- }
-
- if (!Strings.isEmpty(icon.largeIcon())) {
- iconValue.setLargeIcon(icon.largeIcon());
- }
-
+ utils.setModelProperty(iconValue, description, "smallIcon");
+ utils.setModelProperty(iconValue, description, "largeIcon");
component.setIcon(iconValue);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/EventProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/EventProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/EventProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -25,28 +25,31 @@
import java.lang.annotation.Annotation;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.MirroredTypeException;
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.Event;
-import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
-import org.richfaces.cdk.util.Strings;
/**
- * <p class="changed_added_4_0">This class processes annotations for
FacesEvents.</p>
+ * <p class="changed_added_4_0">
+ * This class processes annotations for FacesEvents.
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
public class EventProcessor extends ProcessorBase implements CdkAnnotationProcessor {
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see
org.richfaces.cdk.apt.processors.CdkAnnotationProcessor#getProcessedAnnotation()
*/
@Override
@@ -54,31 +57,24 @@
return Event.class;
}
- /* (non-Javadoc)
- * @see
org.richfaces.cdk.apt.processors.CdkAnnotationProcessor#process(javax.lang.model.element.Element,
org.richfaces.cdk.model.ComponentLibrary)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.richfaces.cdk.apt.processors.CdkAnnotationProcessor#process(javax.lang.model.element.Element,
+ * org.richfaces.cdk.model.ComponentLibrary)
*/
@Override
public void process(Element element, ComponentLibrary library) throws
CdkProcessingException {
if (ElementKind.CLASS.equals(element.getKind())) {
+ SourceUtils sourceUtils = getSourceUtils();
TypeElement eventType = (TypeElement) element;
- Event event = eventType.getAnnotation(Event.class);
+ AnnotationMirror event = sourceUtils.getAnnotationMirror(element,
Event.class);
EventModel model = new EventModel();
model.setType(ClassName.parseName(eventType.getQualifiedName().toString()));
- try {
-
model.setListenerInterface(ClassName.parseName(event.listener().toString()));
- } catch (MirroredTypeException mirror) {
-
model.setListenerInterface(ClassName.parseName(mirror.getTypeMirror().toString()));
- }
- String listenerMethod = event.listenerMethod();
- if(!Strings.isEmpty(listenerMethod)){
- model.setListenerMethod(listenerMethod);
- }
- model.setSourceInterface(ClassName.parseName(event.source()));
- for (Tag tag : event.tag()) {
- if(!TagType.None.equals(tag.type())){
- model.getTags().add(processTag(tag));
- }
- }
+ sourceUtils.setModelProperty(model, event, "listenerInterface",
"listener");
+ sourceUtils.setModelProperty(model, event, "listenerMethod");
+ sourceUtils.setModelProperty(model, event, "sourceInterface",
"source");
+ setTagInfo(event, model);
library.getEvents().add(model);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -26,6 +26,7 @@
import java.lang.annotation.Annotation;
import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
@@ -35,11 +36,14 @@
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.Function;
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FunctionModel;
-import org.richfaces.cdk.util.Strings;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Iterables;
+
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
@@ -47,6 +51,14 @@
*/
public class FunctionProcessor extends ProcessorBase implements CdkAnnotationProcessor {
+ private static final Joiner PARAMETERS_JOINER = Joiner.on(',').skipNulls();
+ private static final com.google.common.base.Function<VariableElement,String>
PARAMETER_CONVERTER = new
com.google.common.base.Function<VariableElement,String>(){
+
+ @Override
+ public String apply(VariableElement var) {
+ return var.asType().toString();
+ }
+ };
/* (non-Javadoc)
* @see
org.richfaces.cdk.apt.processors.CdkAnnotationProcessor#getProcessedAnnotation()
*/
@@ -60,6 +72,7 @@
*/
@Override
public void process(Element element, ComponentLibrary library) throws
CdkProcessingException {
+ SourceUtils utils = getSourceUtils();
switch (element.getKind()) {
case METHOD:
ExecutableElement methodElement = (ExecutableElement) element;
@@ -72,27 +85,20 @@
if(!modifiers.contains(Modifier.STATIC)){
throw new CdkProcessingException("Only static method can be
registered as EL function "+methodElement.getSimpleName());
}
- Function function = methodElement.getAnnotation(Function.class);
+ AnnotationMirror function = utils.getAnnotationMirror(methodElement,
Function.class);
FunctionModel model = new FunctionModel();
- if(!Strings.isEmpty(function.name())){
- model.setName(function.name());
+ if(!utils.isDefaultValue(function, "name")){
+ utils.setModelProperty(model, function, "name");
} else {
model.setName(methodElement.getSimpleName().toString());
}
- model.setType(function.type());
- setDescription(model, function.description(),
getDocComment(methodElement));
+ utils.setModelProperty(model, function, "type");
+ setDescription(model, function, getDocComment(methodElement));
// Calculate method signature
StringBuilder signature = new StringBuilder();
signature.append(methodElement.getReturnType()).append(" ");
signature.append(methodElement.getSimpleName()).append("(");
- boolean first = true;
- for(VariableElement parameter :methodElement.getParameters()){
- if(!first){
- signature.append(",");
- }
- signature.append(parameter.asType());
- first = false;
- }
+ PARAMETERS_JOINER.appendTo(signature,
Iterables.transform(methodElement.getParameters(), PARAMETER_CONVERTER));
signature.append(")");
model.setSignature(signature.toString());
Element declaringClass = methodElement.getEnclosingElement();
Deleted:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -1,120 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright , Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.cdk.apt.processors;
-
-import java.lang.annotation.Annotation;
-
-import javax.faces.event.FacesEvent;
-
-import org.richfaces.cdk.annotations.Description;
-import org.richfaces.cdk.annotations.Facet;
-import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.RendererSpecificComponent;
-import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.cdk.annotations.Test;
-
-/**
- * This calss wraps {@link RendererSpecificComponent} annotation so it would be used by
{@link ComponentProcessor} methods, so they
- * can be reused for different types of the component annotations.
- *
- * @author akolonitsky
- * @since Mar 31, 2010
- */
-public class JsfSubComponent implements JsfComponent {
-
- private final RendererSpecificComponent subcomponent;
-
- private final JsfComponent parent;
-
- public JsfSubComponent(RendererSpecificComponent subcomponent, JsfComponent parent)
{
- this.subcomponent = subcomponent;
- this.parent = parent;
- }
-
- @Override
- public Class<? extends Annotation> annotationType() {
- return JsfComponent.class;
- }
-
- @Override
- public String type() {
- return this.subcomponent.type();
- }
-
- @Override
- public Test test() {
- return this.subcomponent.test();
- }
-
- @Override
- public Tag[] tag() {
- return this.subcomponent.tag();
- }
-
- @Override
- public JsfRenderer renderer() {
- return this.subcomponent.renderer();
- }
-
- @Override
- public Class<?>[] interfaces() {
- return this.subcomponent.interfaces();
- }
-
- @Override
- public String generate() {
- return this.subcomponent.generate();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<? extends FacesEvent>[] fires() {
- return new Class[0];
- }
-
- @Override
- public String family() {
- return this.parent.family();
- }
-
- @Override
- public Facet[] facets() {
- return this.subcomponent.facets();
- }
-
- @Override
- public Description description() {
- return this.subcomponent.description();
- }
-
- @Override
- public RendererSpecificComponent[] components() {
- return new RendererSpecificComponent[0];
- }
-
- @Override
- public String[] attributes() {
- return this.subcomponent.attributes();
- }
-}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -1,27 +1,33 @@
package org.richfaces.cdk.apt.processors;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import org.richfaces.cdk.Logger;
import org.richfaces.cdk.NamingConventions;
-import org.richfaces.cdk.annotations.Description;
-import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.DescriptionGroup;
+import org.richfaces.cdk.model.ModelCollection;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.TagModel;
-import org.richfaces.cdk.util.Strings;
+import org.richfaces.cdk.model.ViewElement;
import com.google.inject.Inject;
import com.google.inject.Provider;
-public abstract class ProcessorBase {
+public abstract class ProcessorBase {
-
@Inject
+ protected Logger log;
+
+ @Inject
private Provider<SourceUtils> sourceUtils;
@Inject
@@ -29,7 +35,7 @@
@Inject
private NamingConventions namingConventions;
-
+
@Inject
private DescriptionProcessor descriptionProcessor;
@@ -37,46 +43,47 @@
return this.sourceUtils.get();
}
- protected void setTagInfo(Tag tag, ModelElementBase model) {
-
- if (!TagType.None.equals(tag.type())) {
+ protected void setTagInfo(AnnotationMirror annotation, ViewElement model) {
+ SourceUtils sourceUtils = getSourceUtils();
+ ModelCollection<TagModel> tags = model.getTags();
+ for (AnnotationMirror tag : sourceUtils.getAnnotationValues(annotation,
"tag", AnnotationMirror.class)) {
TagModel tagModel = processTag(tag);
-
- model.getTags().add(tagModel);
-
+ tags.add(tagModel);
}
}
- protected TagModel processTag(Tag tag) {
+ protected TagModel processTag(AnnotationMirror tag) {
TagModel tagModel = new TagModel();
- String name = tag.name();
- tagModel.setName(name);
- tagModel.setType(tag.type());
- tagModel.setTargetClass(ClassName.parseName(tag.handler()));
- tagModel.setBaseClass(ClassName.parseName(tag.baseClass()));
- tagModel.setGenerate(tag.generate());
+ SourceUtils sourceUtils = getSourceUtils();
+ sourceUtils.setModelProperty(tagModel, tag, "name");
+ tagModel.setType(sourceUtils.getAnnotationValue(tag, "type",
TagType.class));
+ sourceUtils.setModelProperty(tagModel, tag, "targetClass",
"handler");
+ sourceUtils.setModelProperty(tagModel, tag, "baseClass");
+ sourceUtils.setModelProperty(tagModel, tag, "generate");
return tagModel;
}
- protected void setClassNames(TypeElement componentElement, ModelElementBase
modelElement,
- String generatedClass) {
-
- if (componentElement.getModifiers().contains(Modifier.ABSTRACT) ||
!Strings.isEmpty(generatedClass)) {
+ protected void setClassNames(TypeElement componentElement, ModelElementBase
modelElement, AnnotationMirror behavior) {
+ SourceUtils sourceUtils = getSourceUtils();
+ if (componentElement.getModifiers().contains(Modifier.ABSTRACT)
+ || !sourceUtils.isDefaultValue(behavior, "generate")) {
modelElement.setGenerate(true);
- modelElement.setTargetClass(ClassName.parseName(generatedClass));
+ sourceUtils.setModelProperty(modelElement, behavior, "targetClass",
"generate");
} else {
modelElement.setGenerate(false);
+
modelElement.setTargetClass(ClassName.parseName(componentElement.getQualifiedName().toString()));
}
modelElement.setBaseClass(ClassName.parseName(componentElement.getQualifiedName().toString()));
}
-
protected String getDocComment(Element element) {
return null != element ? getSourceUtils().getDocComment(element) : null;
}
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the attributeProcessor
*/
protected AttributesProcessor getAttributeProcessor() {
@@ -91,7 +98,44 @@
this.namingConventions = namingConventions;
}
- protected void setDescription(DescriptionGroup model, Description description, String
docComment) {
- descriptionProcessor.processDescription(model, description, docComment);
+ protected void setDescription(DescriptionGroup model, AnnotationMirror annotation,
String docComment) {
+ descriptionProcessor.processDescription(model,
+ getSourceUtils().getAnnotationValue(annotation, "description",
AnnotationMirror.class), docComment);
}
+
+ protected void processAttributes(Element element, ModelElementBase component,
AnnotationMirror annotation) {
+ AttributesProcessor attributesProcessor = getAttributeProcessor();
+ SourceUtils sourceUtils = getSourceUtils();
+ for (String atributesFragment : sourceUtils.getAnnotationValues(annotation,
"attributes", String.class)) {
+ attributesProcessor.processXmlFragment(component, atributesFragment);
+ }
+ if (element != null && ElementKind.CLASS.equals(element.getKind())) {
+ attributesProcessor.processType(component, (TypeElement) element);
+ }
+ for (TypeMirror atributesInterface : sourceUtils
+ .getAnnotationValues(annotation, "interfaces", TypeMirror.class))
{
+ processInterface(component, attributesProcessor, atributesInterface);
+ }
+ }
+
+ private void processInterface(ModelElementBase component, AttributesProcessor
attributesProcessor, TypeMirror mirror) {
+ component.getInterfaces().add(ClassName.parseName(mirror.toString()));
+ if (TypeKind.DECLARED.equals(mirror.getKind())) {
+ attributesProcessor.processType(component,
getSourceUtils().asTypeElement(mirror));
+ } else {
+ // TODO - record warning.
+ }
+ }
+
+ protected String getAnnotationPropertyOrConstant(TypeElement element,
AnnotationMirror annotation, String annotationAttribute, String fieldName) {
+ SourceUtils utils = getSourceUtils();
+ if (!utils.isDefaultValue(annotation, annotationAttribute)) {
+ return utils.getAnnotationValue(annotation,
annotationAttribute,String.class);
+ }
+ Object value = utils.getConstant((TypeElement) element, fieldName);
+ if (value != null) {
+ return value.toString();
+ }
+ return null;
+ }
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -24,23 +24,18 @@
import java.lang.annotation.Annotation;
import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.faces.render.RenderKitFactory;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
-import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.TypeKind;
-import javax.lang.model.type.TypeMirror;
-import org.richfaces.cdk.Logger;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.RendererModel;
import org.richfaces.cdk.util.Strings;
-import com.google.inject.Inject;
/**
* @author akolonitsky
@@ -53,61 +48,29 @@
private static final String RENDERER_TYPE = "RENDERER_TYPE";
- @Inject
- private Logger log;
-
-
public void process(Element rendererElement, ComponentLibrary library) {
- JsfRenderer annotation = rendererElement.getAnnotation(JsfRenderer.class);
+ SourceUtils sourceUtils = getSourceUtils();
+ AnnotationMirror annotation = sourceUtils.getAnnotationMirror(rendererElement,
JsfRenderer.class);
- RendererModel rendererModel = process((TypeElement) rendererElement, annotation,
library);
-
- addToRenderKit(annotation, library, rendererModel);
-
- }
-
- public RendererModel process(TypeElement rendererElement, JsfRenderer annotation,
ComponentLibrary library) {
RendererModel rendererModel = new RendererModel();
- setClassNames(rendererElement, rendererModel, null);
+ TypeElement rendererTypeElement = (TypeElement) rendererElement;
+ setClassNames(rendererTypeElement, rendererModel, annotation);
- setRendererType(rendererElement, rendererModel, annotation);
- setComponentFamily(rendererElement, rendererModel, annotation);
- setDescription(rendererModel, annotation.description(),
getDocComment(rendererElement));
+ setRendererType(rendererTypeElement, rendererModel, annotation);
+
+ setComponentFamily(rendererTypeElement, rendererModel, annotation);
+ setDescription(rendererModel, annotation, getDocComment(rendererElement));
- setTemplate(rendererModel, annotation);
+ sourceUtils.setModelProperty(rendererModel, annotation,
"templatePath","template");
- // TODO - process @Test annotations.
- return rendererModel;
- }
+ String renderKitId = sourceUtils.getAnnotationValue(annotation,
"renderKitId", String.class);
+ library.addRenderer(renderKitId, rendererModel);
- protected void setClassNames(TypeElement componentElement, RendererModel
modelElement, String generatedClass) {
-
- if (componentElement.getModifiers().contains(Modifier.ABSTRACT) ||
!Strings.isEmpty(generatedClass)) {
- modelElement.setGenerate(true);
- modelElement.setRendererClass(ClassName.parseName(generatedClass));
-
modelElement.setBaseClass(ClassName.parseName(componentElement.getQualifiedName().toString()));
- } else {
- modelElement.setGenerate(false);
-
modelElement.setRendererClass(ClassName.parseName(componentElement.getQualifiedName().toString()));
-
- TypeMirror superclass = componentElement.getSuperclass();
- if (superclass.getKind() == TypeKind.DECLARED) {
- TypeElement typeElement = getSourceUtils().asTypeElement(superclass);
-
modelElement.setBaseClass(ClassName.parseName(typeElement.getQualifiedName().toString()));
- }
- }
-
}
- private void addToRenderKit(JsfRenderer annotation, ComponentLibrary library,
RendererModel rendererModel) {
- String renderKitId = annotation.renderKitId();
- if (Strings.isEmpty(renderKitId)) {
- renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT; // TODO ???
- }
- library.addRenderer(renderKitId, rendererModel);
- }
+
private void setTemplate(RendererModel rendererModel, JsfRenderer annotation) {
String template = annotation.template();
if (!Strings.isEmpty(template)) {
@@ -116,39 +79,14 @@
}
- private void setComponentFamily(TypeElement rendererElement, RendererModel
rendererModel, JsfRenderer annotation) {
- String family = annotation.family();
- if (!Strings.isEmpty(family)) {
- rendererModel.setFamily(FacesId.parseId(family));
- return;
- } else {
-
- Object value = getSourceUtils().getConstant(rendererElement,
COMPONENT_FAMILY);
- if (value != null) {
- rendererModel.setFamily(FacesId.parseId(value.toString()));
- return;
- }
- }
+ private void setComponentFamily(TypeElement rendererElement, RendererModel
rendererModel, AnnotationMirror annotation) {
+
rendererModel.setFamily(FacesId.parseId(getAnnotationPropertyOrConstant(rendererElement,
annotation,"family",COMPONENT_FAMILY)));
}
- private String getRendererType(TypeElement rendererElement, JsfRenderer annotation)
{
- String type = annotation.type();
- if (!Strings.isEmpty(type)) {
- return type;
- }
-
- Object value = getSourceUtils().getConstant(rendererElement, RENDERER_TYPE);
- if (value != null) {
- return value.toString();
- }
-
- return null;
+ private void setRendererType(TypeElement rendererElement, RendererModel
rendererModel, AnnotationMirror annotation) {
+
rendererModel.setId(FacesId.parseId(getAnnotationPropertyOrConstant(rendererElement,
annotation,"type",RENDERER_TYPE)));
}
- private void setRendererType(TypeElement rendererElement, RendererModel
rendererModel, JsfRenderer annotation) {
- rendererModel.setId(FacesId.parseId(getRendererType(rendererElement,
annotation)));
- }
-
protected String getComponentType(TypeElement componentElement) {
JsfComponent annotation = componentElement.getAnnotation(JsfComponent.class);
if (annotation != null) {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ValidatorProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ValidatorProcessor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ValidatorProcessor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -24,13 +24,14 @@
import java.lang.annotation.Annotation;
import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.JsfValidator;
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.ComponentLibrary;
-import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.ValidatorModel;
/**
@@ -42,13 +43,15 @@
@Override
public void process(Element element, ComponentLibrary library) throws
CdkProcessingException {
- JsfValidator validator = element.getAnnotation(JsfValidator.class);
+ SourceUtils utils = getSourceUtils();
+ AnnotationMirror validator =
utils.getAnnotationMirror(element,JsfValidator.class);
- ValidatorModel validatorModel = new
ValidatorModel(FacesId.parseId(validator.id()));
- setClassNames((TypeElement) element, validatorModel, validator.generate());
- setDescription(validatorModel, validator.description(), getDocComment(element));
+ ValidatorModel validatorModel = new ValidatorModel();
+ utils.setModelProperty(validatorModel, validator, "id");
+ setClassNames((TypeElement) element, validatorModel, validator);
+ setDescription(validatorModel, validator, getDocComment(element));
- setTagInfo(validator.tag(), validatorModel);
+ setTagInfo(validator, validatorModel);
library.getValidators().add(validatorModel);
}
@@ -57,10 +60,4 @@
public Class<? extends Annotation> getProcessedAnnotation() {
return JsfValidator.class;
}
-
-
- protected String[] getAnnotationAttributes(TypeElement element) {
- JsfValidator validator = element.getAnnotation(JsfValidator.class);
- return validator.attributes();
- }
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -36,6 +36,7 @@
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.Trackable;
+import org.richfaces.cdk.model.ViewElement;
import freemarker.template.TemplateException;
@@ -86,7 +87,7 @@
}
protected String getOutputFileName(C c) throws CdkException {
- if (c instanceof ModelElementBase) {
+ if (c instanceof ViewElement) {
ModelElementBase modelElement = (ModelElementBase) c;
return modelElement.getTargetClass().getName().replace('.',
File.separatorChar) + ".java";
} else {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/LibraryModelWrapper.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/LibraryModelWrapper.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/LibraryModelWrapper.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -26,9 +26,9 @@
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.FacesId;
-import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.TagModel;
+import org.richfaces.cdk.model.ViewElement;
import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.StringModel;
@@ -72,7 +72,7 @@
return create(obj, EventTemplateModel.FACTORY);
} else if (obj instanceof TagModel) {
return create(obj, TagTemplateModel.FACTORY);
- } else if (obj instanceof ModelElementBase) {
+ } else if (obj instanceof ViewElement) {
return create(obj, ModelElementBaseTemplateModel.FACTORY);
} else {
return super.wrap(obj);
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ModelElementBaseTemplateModel.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ModelElementBaseTemplateModel.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ModelElementBaseTemplateModel.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -122,39 +122,46 @@
public TemplateModel getImportClasses() throws TemplateModelException {
Set<ClassName> result = Sets.newTreeSet();
-
+ String targetPackage = model.getTargetClass().getPackage();
for (PropertyBase entry : model.getAttributes()) {
- if (entry.getGenerate() && !isPredefined(entry)) {
- result.add(entry.getType());
+ if (entry.getGenerate()) {
+ addIfNecessary(targetPackage, result, entry.getType());
}
}
// Import all interfaces implemented by the generated class.
result.addAll(model.getInterfaces());
if (model instanceof ComponentModel) {
ComponentModel component = (ComponentModel) model;
- for(EventModel event :component.getEvents()){
- result.add(event.getSourceInterface());
- result.add(event.getListenerInterface());
+ for (EventModel event : component.getEvents()) {
+ addIfNecessary(targetPackage, result, event.getSourceInterface());
+ addIfNecessary(targetPackage, result, event.getListenerInterface());
}
}
// Collection<String> list = new ArrayList<String>(result);
return this.wrapper.wrap(result);
}
+
+ private void addIfNecessary(String pkg, Set<ClassName> classNames, ClassName
toadd) {
+ if (null != toadd && !isPredefined(toadd) &&
!pkg.equals(toadd.getPackage())) {
+ classNames.add(toadd);
+ }
+ }
+
public TemplateModel getTagImports() throws TemplateModelException {
Set<ClassName> result = Sets.newTreeSet();
for (PropertyBase entry : model.getAttributes()) {
- if (!(entry.isHidden()||entry.isReadOnly()||null == entry.getSignature())) {
+ if (!(entry.isHidden() || entry.isReadOnly() || null ==
entry.getSignature())) {
MethodSignature methodSignature = entry.getSignature();
- if(!isPredefined(methodSignature.getReturnType())){
+ if (!isPredefined(methodSignature.getReturnType())) {
result.add(methodSignature.getReturnType());
}
for (ClassName className : methodSignature.getParameters()) {
- if(!isPredefined(className)){
+ if (!isPredefined(className)) {
result.add(className);
}
-
+
}
}
}
@@ -173,15 +180,18 @@
public TemplateModel getImplementedInterfaces() throws TemplateModelException {
Set<ClassName> result = Sets.newTreeSet();
- if(getEventNames().size()>0){
+ if (getEventNames().size() > 0) {
result.add(ClassName.parseName("javax.faces.component.behavior.ClientBehaviorHolder"));
}
// Import all interfaces implemented by the generated class.
result.addAll(model.getInterfaces());
if (model instanceof ComponentModel) {
ComponentModel component = (ComponentModel) model;
- for(EventModel event :component.getEvents()){
- result.add(event.getSourceInterface());
+ for (EventModel event : component.getEvents()) {
+ ClassName sourceInterface = event.getSourceInterface();
+ if (null != sourceInterface) {
+ result.add(sourceInterface);
+ }
}
}
// Collection<String> list = new ArrayList<String>(result);
@@ -193,7 +203,7 @@
}
public boolean isPredefined(ClassName type) {
- return type.isPrimitive() ||"java.lang".equals(type.getPackage());
+ return type.isPrimitive() || "java.lang".equals(type.getPackage());
}
private TemplateModel eventNames() throws TemplateModelException {
@@ -254,7 +264,7 @@
@Override
public boolean apply(PropertyBase input) {
- return !(input.isHidden()||input.isReadOnly());
+ return !(input.isHidden() || input.isReadOnly());
}
}));
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -288,8 +288,8 @@
if (!Strings.isEmpty(model.getDescription())) {
parent.addElement("description").addText(model.getDescription());
}
- if (!Strings.isEmpty(model.getDisplayname())) {
- parent.addElement("display-name").addText(model.getDisplayname());
+ if (!Strings.isEmpty(model.getDisplayName())) {
+ parent.addElement("display-name").addText(model.getDisplayName());
}
if (null != model.getIcon()) {
Element iconElement = parent.addElement("icon");
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -159,15 +159,18 @@
return events;
}
- public EventModel addEvent(String className) {
+ public EventModel addEvent(ClassName className) {
- // TODO - use a single events collection from library.
EventModel event = new EventModel();
- event.setType(new ClassName(className));
+ event.setType(className);
events.add(event);
return event;
}
+ public EventModel addEvent(String className) {
+ return addEvent(ClassName.get(className));
+ }
+
@Override
public String toString() {
return "Component {type: " + getId() + ", family: " +
getFamily() + "}";
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroup.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroup.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroup.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -36,7 +36,7 @@
*/
@XmlElement(name = "display-name")
@Merge
- public String getDisplayname();
+ public String getDisplayName();
/**
* <p class="changed_added_4_0">
@@ -44,7 +44,7 @@
*
* @param displayname the displayname to set
*/
- public void setDisplayname(String displayname);
+ public void setDisplayName(String displayname);
/**
* <p class="changed_added_4_0">
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroupBase.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroupBase.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroupBase.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -65,11 +65,11 @@
}
@Merge
- public final String getDisplayname() {
+ public final String getDisplayName() {
return displayname;
}
- public final void setDisplayname(String displayname) {
+ public final void setDisplayName(String displayname) {
this.displayname = displayname;
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/EventModel.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/EventModel.java 2011-01-10
22:19:53 UTC (rev 20937)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/EventModel.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -41,7 +41,7 @@
@SuppressWarnings("serial")
@XmlType(name = "event-configType", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
-public class EventModel implements ModelElement<EventModel> {
+public class EventModel implements ModelElement<EventModel>, ViewElement {
private String description;
private ClassName listenerInterface;
private String listenerMethod;
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -10,7 +10,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class ModelElementBase extends BeanModelBase implements FacesComponent {
+public class ModelElementBase extends BeanModelBase implements FacesComponent,
ViewElement {
private FacesId id;
@@ -23,10 +23,10 @@
private final Collection<ClassName> interfaces = Lists.newArrayList();
- /**
- * <p class="changed_added_4_0"></p>
- * @return the tags
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.model.ViewElement#getTags()
*/
+ @Override
public ModelCollection<TagModel> getTags() {
return this.tags;
}
Added: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ViewElement.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ViewElement.java
(rev 0)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ViewElement.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -0,0 +1,11 @@
+package org.richfaces.cdk.model;
+
+public interface ViewElement {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the tags
+ */
+ ModelCollection<TagModel> getTags();
+
+}
\ No newline at end of file
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -319,22 +319,19 @@
protected void verifyEvents(ComponentLibrary library) {
for (EventModel event : library.getEvents()) {
ClassName listenerInterface = event.getListenerInterface();
- if (null == listenerInterface) {
- // TODO - infer listener interface name.
- }
SourceUtils sourceUtils = sourceUtilsProvider.get();
- event.setGenerateListener(!sourceUtils.isClassExists(listenerInterface));
+ if (null != listenerInterface) {
+
event.setGenerateListener(!sourceUtils.isClassExists(listenerInterface));
+ }
String methodName = event.getListenerMethod();
if (null == methodName) {
- // TODO infer listener method name.
methodName = "process";
event.setListenerMethod(methodName);
}
ClassName sourceInterface = event.getSourceInterface();
- if (null == sourceInterface) {
- // TODO - infer source interface.
+ if (null != sourceInterface) {
+ event.setGenerateSource(!sourceUtils.isClassExists(sourceInterface));
}
- event.setGenerateSource(!sourceUtils.isClassExists(sourceInterface));
// Propagate event to corresponding components.
for (ComponentModel component : library.getComponents()) {
for (EventModel componentEvent : component.getEvents()) {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -246,7 +246,7 @@
// TODO is it the right one?
rendererProperty.setDescription(templateAttribute.getShortDescription());
- rendererProperty.setDisplayname(templateAttribute.getDisplayName());
+ rendererProperty.setDisplayName(templateAttribute.getDisplayName());
Set<EventName> eventNamesSet =
convert(templateAttribute.getClientBehaviors());
if (eventNamesSet != null) {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/DescriptionGroupBean.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/DescriptionGroupBean.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/DescriptionGroupBean.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -7,7 +7,7 @@
import org.richfaces.cdk.model.DescriptionGroup;
@XmlType(name = "descriptionType", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE,
- propOrder = {"description", "displayname",
"icon"})
+ propOrder = {"description", "displayName",
"icon"})
public class DescriptionGroupBean implements DescriptionGroup {
private String description;
private String displayname;
@@ -61,7 +61,7 @@
* @return the displayname
*/
@XmlElement(name = "display-name", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
- public final String getDisplayname() {
+ public final String getDisplayName() {
return displayname;
}
@@ -70,7 +70,7 @@
*
* @param displayname the displayname to set
*/
- public final void setDisplayname(String displayname) {
+ public final void setDisplayName(String displayname) {
this.displayname = displayname;
}
}
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsAnnotationsTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsAnnotationsTest.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsAnnotationsTest.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -13,6 +13,7 @@
import org.richfaces.cdk.model.ClassName;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
public class AptSourceUtilsAnnotationsTest extends SourceUtilsTestBase {
@@ -136,11 +137,11 @@
public void process(SourceUtils utils, RoundEnvironment roundEnv) {
Element element = findElement(roundEnv, ANNOTATIONS_TEST_CLASS);
AnnotationMirror annotationMirror = utils.getAnnotationMirror(element,
TestAnnotation.class);
- List<T> annotationValues =
utils.getAnnotationValues(annotationMirror, propertyName, type);
- assertEquals("Annotation values size is different from
expected",expected.length, annotationValues.size());
+ Iterable<T> annotationValues =
utils.getAnnotationValues(annotationMirror, propertyName, type);
+ assertEquals("Annotation values size is different from
expected",expected.length, Iterables.size(annotationValues));
for (int i = 0; i < expected.length; i++) {
Object expectedValue = expected[i];
- assertEquals("Annotation value at position "+i+" is
different from expected",expectedValue, annotationValues.get(i));
+ assertEquals("Annotation value at position "+i+" is
different from expected",expectedValue, Iterables.get(annotationValues, i));
}
}
});
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/BehaviorProcessorTest.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -104,7 +104,7 @@
expect(componentElement.getModifiers()).andReturn(Collections.singleton(Modifier.ABSTRACT));
expect(componentElement.getQualifiedName()).andReturn(name).atLeastOnce();
expect(behaviorAnnotation.generate()).andReturn("foo.Bar");
- expect(behaviorAnnotation.tag()).andReturn(tag);
+ expect(behaviorAnnotation.tag()).andReturn(new Tag[]{tag});
expect(behaviorAnnotation.attributes()).andReturn(new String[] {});
expect(behaviorAnnotation.description()).andReturn(this.description);
expect(tag.handler()).andStubReturn("");
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -28,6 +28,7 @@
import java.util.Collections;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
@@ -71,7 +72,7 @@
private static final String FOO_HTML_BAR = "foo.HtmlBar";
@Mock
- private JsfComponent annotation;
+ private AnnotationMirror annotation;
@Mock
private AttributesProcessor attributesProcessor;
@@ -112,13 +113,19 @@
@Test
public void testProcessFacetsFromAnnotation() throws Exception {
- Facet facet = createMock(Facet.class);
+ AnnotationMirror facet = createMock(AnnotationMirror.class);
expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),
same(componentElement))).andReturn(
Collections.<BeanProperty> emptySet());
- expect(annotation.facets()).andReturn(new Facet[] { facet });
- expect(facet.name()).andReturn("foo");
- expect(facet.description()).andReturn(this.description);
- expect(facet.generate()).andReturn(true);
+// expect(annotation.facets()).andReturn(new Facet[] { facet });
+ expect(utils.getAnnotationValues(annotation,
"facets",AnnotationMirror.class)).andReturn(Collections.singleton(facet));
+ expect(utils.isDefaultValue(same(facet),
eq("name"))).andReturn(false);
+ expect(utils.getAnnotationValue(facet,
"name",String.class)).andReturn("foo");
+ expect(utils.isDefaultValue(same(facet),
eq("description"))).andReturn(true);
+ expect(utils.isDefaultValue(same(facet),
eq("generate"))).andReturn(false);
+ expect(utils.getAnnotationValue(facet,
"generate",Boolean.class)).andReturn(true);
+// expect(facet.name()).andReturn("foo");
+// expect(facet.description()).andReturn(this.description);
+// expect(facet.generate()).andReturn(true);
// expect(this.description.smallIcon()).andReturn("");
// expect(this.description.largeIcon()).andReturn("");
//
expect(this.description.displayName()).andReturn("fooFacet").times(2);
@@ -139,20 +146,17 @@
@Test
public void testProcessFacetsFromProperty() throws Exception {
- Facet facet = createMock(Facet.class);
+ AnnotationMirror facet = createMock(AnnotationMirror.class);
expect(utils.getBeanPropertiesAnnotatedWith(eq(Facet.class),
same(componentElement))).andReturn(
Collections.singleton(property));
- expect(annotation.facets()).andReturn(new Facet[0]);
- expect(property.getAnnotation(Facet.class)).andReturn(facet);
+ expect(property.getAnnotationMirror(Facet.class)).andReturn(facet);
expect(property.getName()).andReturn("foo");
expect(property.getDocComment()).andReturn("my comment").times(2);
expect(property.isExists()).andReturn(true);
- expect(facet.description()).andReturn(description);
- expect(facet.generate()).andReturn(true);
- // expect(this.description.smallIcon()).andReturn("");
- // expect(this.description.largeIcon()).andReturn("");
- //
expect(this.description.displayName()).andReturn("fooFacet").times(2);
- // expect(this.description.value()).andReturn("");
+ expect(utils.isDefaultValue(same(facet),
eq("description"))).andReturn(true);
+ expect(utils.isDefaultValue(same(facet),
eq("generate"))).andReturn(false);
+ expect(utils.getAnnotationValue(facet,
"generate",Boolean.class)).andReturn(true);
+ expect(utils.getAnnotationValues(annotation,
"facets",AnnotationMirror.class)).andReturn(Collections.<AnnotationMirror>emptySet());
replay(utils, componentElement, jaxb, annotation, property, facet, description);
processor.processFacets(componentElement, model, annotation);
@@ -162,9 +166,6 @@
FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
assertTrue(facetModel.getGenerate());
assertEquals("foo", facetModel.getName());
- // assertEquals("my comment", facetModel.getDescription());
- // assertEquals("fooFacet", facetModel.getDisplayname());
- // assertNull(facetModel.getIcon());
}
/**
@@ -177,12 +178,14 @@
public void testSetClassNames() throws Exception {
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>
emptySet());
expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
+ expect(utils.isDefaultValue(annotation, "generate")).andReturn(true);
+ expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
replay(utils, componentElement, jaxb, annotation);
- processor.setClassNames(componentElement, model, "");
+ processor.setClassNames(componentElement, model, annotation);
verify(utils, componentElement, jaxb, annotation);
assertFalse(model.getGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
- assertNull(model.getTargetClass());
+ assertEquals(FOO_BAR, model.getTargetClass().toString());
}
/**
@@ -194,10 +197,11 @@
@Test
public void testSetClassNames1() throws Exception {
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>
singleton(Modifier.ABSTRACT));
+ utils.setModelProperty(model, annotation,
"targetClass","generate");expectLastCall();
expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
replay(utils, componentElement, jaxb, annotation);
- processor.setClassNames(componentElement, model, "");
+ processor.setClassNames(componentElement, model, annotation);
verify(utils, componentElement, jaxb, annotation);
assertTrue(model.getGenerate());
@@ -214,50 +218,18 @@
@Test
public void testSetClassNames2() throws Exception {
expect(componentElement.getModifiers()).andReturn(Collections.<Modifier>
emptySet());
+ expect(utils.isDefaultValue(annotation, "generate")).andReturn(false);
+ utils.setModelProperty(model, annotation,
"targetClass","generate");expectLastCall();
expect(componentElement.getQualifiedName()).andReturn(new TestName(FOO_BAR));
replay(utils, componentElement, jaxb, annotation);
- processor.setClassNames(componentElement, model, FOO_HTML_BAR);
+ processor.setClassNames(componentElement, model, annotation);
verify(utils, componentElement, jaxb, annotation);
assertTrue(model.getGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
- assertEquals(FOO_HTML_BAR, model.getTargetClass().toString());
}
- @Test
- public void testSetFamily() throws Exception {
- replay(utils, componentElement, jaxb, annotation);
-
- processor.setComponeneFamily(componentElement, model, FOO_HTML_BAR);
-
- verify(utils, componentElement, jaxb, annotation);
- assertEquals(FacesId.parseId(FOO_HTML_BAR), model.getFamily());
- }
-
- @Test
- public void testSetFamily1() throws Exception {
- expect(utils.getConstant(same(componentElement),
eq(ComponentProcessor.COMPONENT_FAMILY))).andReturn(
- FOO_HTML_BAR);
- replay(utils, componentElement, jaxb, annotation);
-
- processor.setComponeneFamily(componentElement, model, "");
-
- verify(utils, componentElement, jaxb, annotation);
- assertEquals(FacesId.parseId(FOO_HTML_BAR), model.getFamily());
- }
-
- @Test
- public void testSetFamily2() throws Exception {
- expect(utils.getConstant(same(componentElement),
eq(ComponentProcessor.COMPONENT_FAMILY))).andReturn(null);
- replay(utils, componentElement, jaxb, annotation);
-
- processor.setComponeneFamily(componentElement, model, "");
-
- verify(utils, componentElement, jaxb, annotation);
- assertNull(model.getFamily());
- }
-
@Override
protected Iterable<String> sources() {
return Collections.singleton(COMPONENT_CLASS_JAVA);
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/DescriptionProcessorTest.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -27,12 +27,15 @@
import java.util.Collections;
+import javax.lang.model.element.AnnotationMirror;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
import org.richfaces.cdk.Mock;
import org.richfaces.cdk.annotations.Description;
import org.richfaces.cdk.apt.AnnotationProcessorTestBase;
+import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.DescriptionGroup;
import com.google.inject.Inject;
@@ -55,12 +58,14 @@
private DescriptionGroup bean;
@Mock
- private Description description;
+ private AnnotationMirror description;
@Inject
private DescriptionProcessorImpl descriptionProcessor;
- /**
+ @Mock
+ private SourceUtils utils;
+ /**
* Test method for
* {@link
org.richfaces.cdk.apt.processors.DescriptionProcessorImpl#processDescription(org.richfaces.cdk.model.DescriptionGroup,
org.richfaces.cdk.annotations.Description, java.lang.String)}
* .
@@ -69,12 +74,14 @@
public void testProcessDescription() {
bean.setDescription(FOO_BAR_ELEMENT);
expectLastCall();
- bean.setDisplayname(FOO_FACET);
- expectLastCall();
- expect(this.description.smallIcon()).andReturn("");
- expect(this.description.largeIcon()).andReturn("");
- expect(this.description.displayName()).andReturn(FOO_FACET).times(2);
- expect(this.description.value()).andReturn("");
+ expect(utils.isDefaultValue(description,
"smallIcon")).andStubReturn(true);
+ expect(utils.isDefaultValue(description,
"largeIcon")).andStubReturn(true);
+ utils.setModelProperty(bean, description,
"displayName");expectLastCall();
+ utils.setModelProperty(bean, description,
"description","value");expectLastCall();
+// expect(this.description.smallIcon()).andReturn("");
+// expect(this.description.largeIcon()).andReturn("");
+// expect(this.description.displayName()).andReturn(FOO_FACET).times(2);
+// expect(this.description.value()).andReturn("");
mockController.replay();
descriptionProcessor.processDescription(bean, description, FOO_BAR_ELEMENT);
mockController.verify();
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -252,7 +252,7 @@
assertTrue(requiredAttribute.isRequired());
assertEquals("That's a required attribute",
requiredAttribute.getDescription());
- assertEquals("Required Attribute",
requiredAttribute.getDisplayname());
+ assertEquals("Required Attribute",
requiredAttribute.getDisplayName());
}
@Test
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -103,7 +103,7 @@
assertEquals("panel.gif", component.getIcon().getSmallIcon());
assertEquals("panel-large.gif", component.getIcon().getLargeIcon());
assertEquals("Panel component", component.getDescription());
- assertEquals("Panel", component.getDisplayname());
+ assertEquals("Panel", component.getDisplayName());
assertTrue(component.getGenerate());
FacetModel facet = Iterables.getOnlyElement(component.getFacets());
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -113,7 +113,7 @@
assertEquals("int", property.getType().getName());
assertEquals("test2 property", property.getDescription());
assertEquals("ontest2.png", property.getIcon().getSmallIcon());
- assertEquals("test2 event property", property.getDisplayname());
+ assertEquals("test2 event property", property.getDisplayName());
assertEquals("3", property.getDefaultValue());
assertEquals("15", property.getSuggestedValue());
Modified:
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java 2011-01-10
22:19:53 UTC (rev 20937)
+++
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -31,9 +31,12 @@
import javax.faces.component.ValueHolder;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.event.ValueChangeListener;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.Description;
+import org.richfaces.cdk.annotations.Event;
import org.richfaces.cdk.annotations.Facet;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
@@ -56,7 +59,7 @@
description=@Description(displayName="Test
Component",largeIcon="large.gif",smallIcon="spall.png"),
generate="org.richfaces.cdk.test.component.UITestComponent",
facets=@Facet(name="caption",generate=true,description=@Description("Caption
Facet")),
- fires=TestEvent.class,
+
fires={@Event(TestEvent.class),(a)Event(value=ValueChangeEvent.class,listener=ValueChangeListener.class)},
interfaces=ValueHolder.class,
components={
@RendererSpecificComponent(type =
"org.richfaces.cdk.test.TestHtmlAbbr",
Modified: trunk/ui/core/ui/src/main/java/org/richfaces/component/UIRepeat.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/component/UIRepeat.java 2011-01-10
22:19:53 UTC (rev 20937)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/component/UIRepeat.java 2011-01-10
22:35:38 UTC (rev 20938)
@@ -30,7 +30,7 @@
* @author Nick Belaevski
*
*/
-@JsfComponent(generate = "", tag = @Tag(name = "repeat", type =
TagType.Facelets), renderer = @JsfRenderer(type =
"org.richfaces.RepeatRenderer"))
+@JsfComponent(tag = @Tag(name = "repeat", type = TagType.Facelets), renderer =
@JsfRenderer(type = "org.richfaces.RepeatRenderer"))
public class UIRepeat extends UISequence {
public static final String COMPONENT_TYPE = "org.richfaces.Repeat";