Author: alexsmirnov
Date: 2011-01-05 19:59:41 -0500 (Wed, 05 Jan 2011)
New Revision: 20901
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsPropertiesTest.java
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestClass.java
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestInterface.java
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessorImpl.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/generate/freemarker/ModelElementBaseTemplateModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/BehaviorRendererModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroupBase.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/FacesComponent.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/RenderKitModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsAnnotationsTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/SourceUtilsTestBase.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.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/generator/src/test/resources/org/richfaces/cdk/apt/TestClass.java
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.xml
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/pom.xml
trunk/cdk/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java
Log:
RESOLVED - issue RF-10105: CDK: impossible to import configuration files from project
https://issues.jboss.org/browse/RF-10105
RESOLVED - issue RF-9323
https://issues.jboss.org/browse/RF-9323
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-05
23:40:33 UTC (rev 20900)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -2,15 +2,12 @@
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
-import java.util.Map.Entry;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
@@ -28,18 +25,39 @@
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.InvalidNameException;
import org.richfaces.cdk.util.PropertyUtils;
import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.google.inject.Inject;
+/**
+ * <p class="changed_added_4_0">
+ * Implementation to use in annotation processor.
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
public class AptSourceUtils implements SourceUtils {
- private static final Set<String> PROPERTIES =
- new HashSet<String>(Arrays.asList("getEventNames",
"getDefaultEventName", "getClientBehaviors", "getFamily"));
+ private static final String IS = "is";
+ private static final int IS_LENGTH = IS.length();
+
+ private static final String GET = "get";
+
+ private static final String SET = "set";
+
+ private static final int SET_LENGTH = SET.length();
+
+ private static final int GET_LENGTH = GET.length();
+
+ private static final ImmutableSet<String> HIDDEN_PROPERTIES =
ImmutableSet.of("eventNames", "defaultEventName",
+ "clientBehaviors", "family", "class");
+
private final ProcessingEnvironment processingEnv;
@Inject
@@ -66,153 +84,144 @@
*/
public Set<BeanProperty> getBeanPropertiesAnnotatedWith(Class<? extends
Annotation> annotation, TypeElement type) {
Set<BeanProperty> properties = new HashSet<BeanProperty>();
- List<? extends Element> members =
this.processingEnv.getElementUtils().getAllMembers(type);
-
- // Get all methods and fields annotated by annotation.
- for (Element childElement : members) {
- boolean annotated = null != childElement.getAnnotation(annotation);
- if (!annotated) {
- continue;
+ Map<String, AptBeanProperty> beanProperties = getBeanProperties(type);
+ for (BeanProperty beanProperty : beanProperties.values()) {
+ if (beanProperty.isAnnotationPresent(annotation)) {
+ properties.add(beanProperty);
}
-
- // Have an annotation, infer property name.
- if (ElementKind.METHOD.equals(childElement.getKind())) {
- processMethod(properties, childElement, annotated);
- } else if (ElementKind.FIELD.equals(childElement.getKind())) {
- processFiled(properties, childElement);
- }
-
- // TODO - merge properties with same name ?
}
-
return properties;
}
public Set<BeanProperty> getAbstractBeanProperties(TypeElement type) {
- log.debug("AptSourceUtils.getAbstractBeanProperties");
- log.debug(" - type = " + type);
-
Set<BeanProperty> properties = new HashSet<BeanProperty>();
- List<? extends Element> members =
this.processingEnv.getElementUtils().getAllMembers(type);
-
- Map<String, List<ExecutableElement>> props =
groupMethodsBySignature(members);
- removeNotAbstractGroups(props);
-
- for (List<ExecutableElement> methods : props.values()) {
- ExecutableElement method = methods.get(0);
-
- if (ElementKind.METHOD.equals(method.getKind()) &&
!PROPERTIES.contains(method.getSimpleName().toString())) {
- processMethod(properties, method, false);
+ Map<String, AptBeanProperty> beanProperties = getBeanProperties(type);
+ for (BeanProperty beanProperty : beanProperties.values()) {
+ if (!beanProperty.isExists()) {
+ properties.add(beanProperty);
}
-
- // TODO - merge properties with same name ?
}
-
return properties;
}
- private void removeNotAbstractGroups(Map<String, List<ExecutableElement>>
props) {
- List<String> removeKeys = new ArrayList<String>();
- for (Map.Entry<String, List<ExecutableElement>> entry :
props.entrySet()) {
- List<ExecutableElement> value = entry.getValue();
- for (ExecutableElement element : value) {
- if (!isAbstract(element)) {
- removeKeys.add(entry.getKey());
- }
- }
- }
+ @Override
+ public BeanProperty getBeanProperty(ClassName type, final String name) {
+ return getBeanProperty(asTypeElement(type), name);
+ }
- for (String removeKey : removeKeys) {
- props.remove(removeKey);
+ @Override
+ public BeanProperty getBeanProperty(TypeElement type, final String name) {
+ Map<String, AptBeanProperty> beanProperties = getBeanProperties(type);
+ if (beanProperties.containsKey(name)) {
+ return beanProperties.get(name);
+ } else {
+ return new PropertyImpl(name);
}
}
- private Map<String, List<ExecutableElement>>
groupMethodsBySignature(List<? extends Element> members) {
- Map<String, List<ExecutableElement>> props = new HashMap<String,
List<ExecutableElement>>();
+ /**
+ * <p class="changed_added_4_0">
+ * Utility method to get all bean properties, similar to Introspector
+ * </p>
+ *
+ * @param type
+ * @return
+ */
+ Map<String, AptBeanProperty> getBeanProperties(TypeElement type) {
+ List<? extends Element> members =
this.processingEnv.getElementUtils().getAllMembers(type);
+ // extract all getters/setters.
+ Map<String, AptBeanProperty> result = Maps.newHashMap();
for (Element element : members) {
- if (ElementKind.METHOD.equals(element.getKind())
- && !PROPERTIES.contains(element.getSimpleName().toString())) {
-
+ if (ElementKind.METHOD.equals(element.getKind())) {
ExecutableElement method = (ExecutableElement) element;
-
- String signature = getSignature(method);
-
- List<ExecutableElement> methods = props.get(signature);
- if (methods == null) {
- methods = new ArrayList<ExecutableElement>(5);
- props.put(signature, methods);
- }
-
- methods.add(method);
+ processMethod(type, result, method);
}
}
- return props;
+ return result;
}
- private String getSignature(ExecutableElement method) {
- String name = method.getSimpleName().toString();
- List<? extends VariableElement> methodParams = method.getParameters();
- StringBuilder builder = new StringBuilder(name);
- for (VariableElement methodParam : methodParams) {
- builder.append(":").append(methodParam.getKind().name());
+ private void processMethod(TypeElement type, Map<String, AptBeanProperty>
result, ExecutableElement method) {
+ if (isPublicNonStatic(method)) {
+ if (isGetter(method)) {
+ processBeanPropertyAccessor(type, result, method, false);
+ } else if (isSetter(method)) {
+ processBeanPropertyAccessor(type, result, method, true);
+ }
}
- return builder.toString();
}
- private void processFiled(Set<BeanProperty> properties, Element childElement)
{
- AptBeanProperty property = new
AptBeanProperty(childElement.getSimpleName().toString());
+ private void processBeanPropertyAccessor(TypeElement type, Map<String,
AptBeanProperty> result,
+ ExecutableElement method, boolean setter) {
+ String propertyName = getPropertyName(method);
+ if (!HIDDEN_PROPERTIES.contains(propertyName)) {
+ ClassName propertyType =
asClassDescription(setter?method.getParameters().get(0).asType():method.getReturnType());
+ if (result.containsKey(propertyName)) {
+ // Merge property with existed one.
+ 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 "
+ + propertyName + " in the class " +
type.getQualifiedName());
+ if(!method.getModifiers().contains(Modifier.ABSTRACT)){
+ beanProperty.setAccessMethod(method, setter);
+ }
+ } else {
+ beanProperty.setAccessMethod(method, setter);
+ }
+ } else {
+ AptBeanProperty beanProperty = new AptBeanProperty(propertyName);
+ beanProperty.setAccessMethod(method, setter);
+ beanProperty.type = propertyType;
+ result.put(propertyName, beanProperty);
+ }
- property.type = asClassDescription(childElement.asType());
- property.element = childElement;
+ }
+ }
- // TODO - find getter/setter, check them for abstract.
- property.exists = true;
-
- properties.add(property);
+ private String getPropertyName(ExecutableElement method) {
+ return PropertyUtils.methodToName(method.getSimpleName().toString());
}
- private void processMethod(Set<BeanProperty> properties, Element childElement,
boolean annotated) {
- ExecutableElement method = (ExecutableElement) childElement;
- boolean exists = !isAbstract(method);
- if (!annotated && exists) {
- log.debug(" - " + childElement.getSimpleName() + " :
didn't annotated and didn't abstract.");
- return;
+ private void checkPropertyType(TypeElement type, String propertyName, ClassName
propertyType,
+ AptBeanProperty beanProperty) {
+ if (!propertyType.equals(beanProperty.type)) {
+ log.warn("Unambiguious type for bean property " + propertyName +
" in the class " + type.getQualifiedName());
}
+ }
- TypeMirror propertyType = method.getReturnType();
- List<? extends VariableElement> parameters = method.getParameters();
- if (TypeKind.VOID.equals(propertyType.getKind()) && 1 ==
parameters.size()) {
+ private boolean isAbstract(ExecutableElement method) {
+ return method.getModifiers().contains(Modifier.ABSTRACT);
+ }
- // That is setter method, get type from parameter.
- propertyType = parameters.get(0).asType();
- } else if (!parameters.isEmpty()) {
- // TODO Invalid method signature for a bean property,
- // throw exception ?
- log.debug(" - " + childElement.getSimpleName() + " :
Invalid method signature for a bean property.");
- return;
- }
+ private boolean isPublicNonStatic(ExecutableElement method) {
+ Set<Modifier> modifiers = method.getModifiers();
+ return modifiers.contains(Modifier.PUBLIC) &&
!modifiers.contains(Modifier.STATIC);
+ }
- try {
- String name =
PropertyUtils.methodToName(childElement.getSimpleName().toString());
- AptBeanProperty property = new AptBeanProperty(name);
+ private boolean isGetter(ExecutableElement e) {
+ String methodName = e.getSimpleName().toString();
+ return (isGetterName(methodName) || isBooleanGetterName(methodName)) && 0
== e.getParameters().size();
+ }
- property.type = asClassDescription(propertyType);
- property.element = childElement;
- property.exists = exists;
+ private boolean isGetterName(String methodName) {
+ return methodName.startsWith(GET) && methodName.length() > GET_LENGTH
+ && Character.isUpperCase(methodName.charAt(GET_LENGTH));
+ }
- properties.add(property);
- log.debug(" - " + childElement.getSimpleName() + " : was
added.");
+ private boolean isBooleanGetterName(String methodName) {
+ return methodName.startsWith(IS) && methodName.length() > IS_LENGTH
+ && Character.isUpperCase(methodName.charAt(IS_LENGTH));
+ }
- } catch (InvalidNameException e) {
- log.debug(" - " + childElement.getSimpleName() + " :
Invalid method name for a bean property, throw.");
-
- // TODO Invalid method name for a bean property, throw
- // exception ?
- }
+ private boolean isSetter(ExecutableElement e) {
+ String methodName = e.getSimpleName().toString();
+ return isSetterName(methodName) && 1 == e.getParameters().size()
&& !e.isVarArgs()
+ && TypeKind.VOID.equals(e.getReturnType().getKind());
}
- private boolean isAbstract(ExecutableElement method) {
- return method.getModifiers().contains(Modifier.ABSTRACT);
+ private boolean isSetterName(String methodName) {
+ return methodName.startsWith(SET) && methodName.length() > SET_LENGTH
+ && Character.isUpperCase(methodName.charAt(SET_LENGTH));
}
private ClassName asClassDescription(TypeMirror type) {
@@ -242,12 +251,12 @@
return null != element.getAnnotation(annotationType);
}
-
@Override
- public boolean isAnnotationPropertyPresent(AnnotationMirror annotation, final String
propertyName){
- return Iterables.any(getAnnotationValuesMap(annotation).entrySet(), new
AnnotationAttributePredicate(propertyName));
+ public boolean isAnnotationPropertyPresent(AnnotationMirror annotation, final String
propertyName) {
+ return Iterables.any(getAnnotationValuesMap(annotation).entrySet(), new
AnnotationAttributePredicate(
+ propertyName));
}
-
+
@Override
public boolean isDefaultValue(AnnotationMirror annotation, String propertyName) {
Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>
attributeEntry =
@@ -255,7 +264,6 @@
return !annotation.getElementValues().containsKey(attributeEntry.getKey());
}
- @SuppressWarnings("unchecked")
@Override
public <T> T getAnnotationValue(AnnotationMirror annotation, String
propertyName, Class<T> expectedType) {
Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>
attributeEntry =
@@ -264,6 +272,7 @@
return convertAnnotationValue(expectedType, annotationValue);
}
+ @SuppressWarnings("unchecked")
private <T> T convertAnnotationValue(Class<T> expectedType,
AnnotationValue annotationValue) {
if (Enum.class.isAssignableFrom(expectedType)) {
VariableElement variable = (VariableElement) annotationValue.getValue();
@@ -275,7 +284,6 @@
AnnotationMirror value = (AnnotationMirror) annotationValue.getValue();
return (T) value;
} else {
- // TODO - check value for expected type.
return (T) annotationValue.getValue();
}
}
@@ -285,7 +293,8 @@
public <T> List<T> getAnnotationValues(AnnotationMirror annotation,
String propertyName, Class<T> expectedType) {
Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>
attributeEntry =
findAnnotationProperty(annotation, propertyName);
- List<? extends AnnotationValue>annotationValues = (List<? extends
AnnotationValue>) attributeEntry.getValue().getValue();
+ List<? extends AnnotationValue> annotationValues =
+ (List<? extends AnnotationValue>)
attributeEntry.getValue().getValue();
List<T> values = Lists.newArrayList();
for (AnnotationValue annotationValue : annotationValues) {
values.add(convertAnnotationValue(expectedType, annotationValue));
@@ -296,43 +305,57 @@
private Entry<? extends ExecutableElement, ? extends AnnotationValue>
findAnnotationProperty(
AnnotationMirror annotation, final String propertyName) {
try {
- return Iterables.find(getAnnotationValuesMap(annotation).entrySet(),
- new AnnotationAttributePredicate(propertyName));
+ return Iterables.find(getAnnotationValuesMap(annotation).entrySet(), new
AnnotationAttributePredicate(
+ propertyName));
} catch (NoSuchElementException e) {
throw new CdkException("Attribute " + propertyName + " not
found for annotation "
+ annotation.getAnnotationType().toString());
}
}
- private Map<? extends ExecutableElement, ? extends AnnotationValue>
getAnnotationValuesMap(AnnotationMirror annotation) {
+ private Map<? extends ExecutableElement, ? extends AnnotationValue>
getAnnotationValuesMap(
+ AnnotationMirror annotation) {
return processingEnv.getElementUtils().getElementValuesWithDefaults(annotation);
}
/**
- * <p class="changed_added_4_0">Set model property to the
corresponding annotation attribute, if annotation attribute set to non-default
value.</p>
- * @param model Model object.
- * @param annotation annotation to copy property from.
- * @param modelProperty bean attribute name in the model and annotation.
+ * <p class="changed_added_4_0">
+ * Set model property to the corresponding annotation attribute, if annotation
attribute set to non-default value.
+ * </p>
+ *
+ * @param model
+ * Model object.
+ * @param annotation
+ * annotation to copy property from.
+ * @param modelProperty
+ * bean attribute name in the model and annotation.
*/
@Override
public void setModelProperty(Object model, AnnotationMirror annotation, String
modelProperty) {
- setModelProperty(model, annotation, modelProperty, modelProperty);
+ setModelProperty(model, annotation, modelProperty, modelProperty);
}
/**
- * <p class="changed_added_4_0">Set model property to the
corresponding annotation attribute, if annotation attribute set to non-default
value.</p>
- * @param model Model object.
- * @param annotation annotation to copy property from.
- * @param modelProperty bean attribute name in model.
- * @param annotationAttribute annotation attribute name.
+ * <p class="changed_added_4_0">
+ * Set model property to the corresponding annotation attribute, if annotation
attribute set to non-default value.
+ * </p>
+ *
+ * @param model
+ * Model object.
+ * @param annotation
+ * annotation to copy property from.
+ * @param modelProperty
+ * bean attribute name in model.
+ * @param annotationAttribute
+ * annotation attribute name.
*/
@Override
- public void setModelProperty(Object model, AnnotationMirror annotation,
- String modelProperty, String annotationAttribute) {
+ public void setModelProperty(Object model, AnnotationMirror annotation, String
modelProperty,
+ String annotationAttribute) {
if (!isDefaultValue(annotation, annotationAttribute)) {
PropertyDescriptor propertyDescriptor =
PropertyUtils.getPropertyDescriptor(model, modelProperty);
- PropertyUtils.setPropertyValue(model, modelProperty,
getAnnotationValue(annotation,
- annotationAttribute, propertyDescriptor.getPropertyType()));
+ PropertyUtils.setPropertyValue(model, modelProperty,
+ getAnnotationValue(annotation, annotationAttribute,
propertyDescriptor.getPropertyType()));
}
}
@@ -364,11 +387,14 @@
visitor.visit(type);
}
- @Override
- public TypeElement asTypeElement(ClassName type) {
+ private TypeElement asTypeElement(ClassName type) {
return processingEnv.getElementUtils().getTypeElement(type.toString());
}
+ public boolean isClassExists(ClassName type){
+ return null != asTypeElement(type);
+ }
+
@Override
public TypeElement asTypeElement(TypeMirror mirror) {
if (TypeKind.DECLARED.equals(mirror.getKind())) {
@@ -378,6 +404,13 @@
}
}
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
private static final class AnnotationAttributePredicate implements
Predicate<Map.Entry<? extends ExecutableElement, ? extends
AnnotationValue>> {
private final String propertyName;
@@ -401,8 +434,8 @@
*
*/
protected final class AptBeanProperty implements BeanProperty {
- private Element element;
- private boolean exists;
+ private ExecutableElement getter;
+ private ExecutableElement setter;
private final String name;
private ClassName type;
@@ -416,6 +449,103 @@
this.name = name;
}
+ void setAccessMethod(ExecutableElement method, boolean setter) {
+ if (setter) {
+ this.setter = method;
+ } else {
+ this.getter = method;
+ }
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Get JavaDoc comment of appropriate bean property element.
+ * </p>
+ *
+ * @return
+ */
+ public String getDocComment() {
+ String comment = getMethodComment(getter);
+ if (null == comment) {
+ comment = getMethodComment(setter);
+ }
+ return comment;
+ }
+
+ private String getMethodComment(ExecutableElement method) {
+ if (null != method) {
+ return processingEnv.getElementUtils().getDocComment(method);
+ } else {
+ return null;
+ }
+ }
+
+ public ClassName getType() {
+ return type;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the exists
+ */
+ public boolean isExists() {
+ return !(isAbstract(getter) || isAbstract(setter));
+ }
+
+ private boolean isAbstract(ExecutableElement method) {
+ return null != method &&
method.getModifiers().contains(Modifier.ABSTRACT);
+ }
+
+ public AnnotationMirror getAnnotationMirror(Class<? extends Annotation>
annotationType) {
+ if (isAnnotationPresent(getter, annotationType)) {
+ return AptSourceUtils.this.getAnnotationMirror(getter, annotationType);
+ } else if (isAnnotationPresent(setter, annotationType)) {
+ return AptSourceUtils.this.getAnnotationMirror(setter, annotationType);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isAnnotationPresent(Class<? extends Annotation>
annotationType) {
+ return isAnnotationPresent(getter, annotationType) ||
isAnnotationPresent(setter, annotationType);
+ }
+
+ @Override
+ public <T extends Annotation> T getAnnotation(Class<T>
annotationType) {
+ if (isAnnotationPresent(getter, annotationType)) {
+ return getter.getAnnotation(annotationType);
+ } else if (isAnnotationPresent(setter, annotationType)) {
+ return setter.getAnnotation(annotationType);
+ }
+ return null;
+ }
+
+ private <T extends Annotation> boolean
isAnnotationPresent(ExecutableElement method, Class<T> annotationType) {
+ return null != method && null !=
method.getAnnotation(annotationType);
+ }
+
+ @Override
+ public ACCESS_TYPE getAccessType() {
+ if (null != getter && null != setter) {
+ return ACCESS_TYPE.readWrite;
+ } else if (null == setter) {
+ return ACCESS_TYPE.readOnly;
+ }
+ return ACCESS_TYPE.writeOnly;
+ }
+
/*
* (non-Javadoc)
*
@@ -463,48 +593,10 @@
return true;
}
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the name
- */
- public String getName() {
- return name;
+ @Override
+ public String toString() {
+ return name + "[" + getType() + "]";
}
-
- /**
- * <p class="changed_added_4_0">
- * Get JavaDoc comment of appropriate bean property element.
- * </p>
- *
- * @return
- */
- public String getDocComment() {
- return processingEnv.getElementUtils().getDocComment(element);
- }
-
- public ClassName getType() {
- return type;
- }
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the exists
- */
- public boolean isExists() {
- return exists;
- }
-
- public AnnotationMirror getAnnotationMirror(Class<? extends Annotation>
annotationType) {
- return AptSourceUtils.this.getAnnotationMirror(element, annotationType);
- }
-
- public <T extends Annotation> T getAnnotation(Class<T>
annotationType) {
- return element.getAnnotation(annotationType);
- }
}
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessorImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessorImpl.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessorImpl.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -36,8 +36,8 @@
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
-import javax.tools.Diagnostic.Kind;
+import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.LibraryBuilder;
import org.richfaces.cdk.Logger;
@@ -96,52 +96,65 @@
for (CdkAnnotationProcessor process : processors) {
processAnnotation(process, roundEnv);
}
- } else {
+ } else {
// parse non-java sources
processNonJavaSources();
+ verify();
+ if (0 == log.getErrorCount()) {
+ generate();
+ }
}
return false;
}
- /* (non-Javadoc)
+ private void generate() {
+ log.debug("Generate output files");
+ builder.generate(library);
+ }
+
+ private void verify() {
+ try {
+ log.debug("Validate model");
+ validator.verify(library);
+
+ } catch (CdkException e) {
+ sendError(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.richfaces.cdk.apt.CdkProcessor#processNonJavaSources()
*/
public void processNonJavaSources() {
for (ModelBuilder builder : builders) {
- log.debug("Run builder "+builder.getClass().getName());
- builder.build();
+ log.debug("Run builder " + builder.getClass().getName());
+ try {
+ builder.build();
+
+ } catch (CdkException e) {
+ sendError(e);
+ }
}
- // validator should be called even if previvous phases finish with errors, to
collect all possible problems.
- log.debug("Validate model");
- validator.verify(library);
- if(0 == log.getErrorCount()) {
- // processing over, generate files.
- log.debug("Generate output files");
- builder.generate(library);
- }
}
protected void processAnnotation(CdkAnnotationProcessor processor, RoundEnvironment
environment) {
Class<? extends Annotation> processedAnnotation =
processor.getProcessedAnnotation();
- log.debug("Process all elements annotated with
"+processedAnnotation.getName());
+ log.debug("Process all elements annotated with " +
processedAnnotation.getName());
Target target = processedAnnotation.getAnnotation(Target.class);
- try {
- Set<? extends Element> rootElements = environment.getRootElements();
- for (Element element : rootElements) {
- if (isAppropriateTarget(element, target)){
- processElement(processor, processedAnnotation, element);
- } else {
- for (Element enclosedElement : element.getEnclosedElements()) {
- if (isAppropriateTarget(enclosedElement, target)){
- processElement(processor, processedAnnotation,
enclosedElement);
- }
+ Set<? extends Element> rootElements = environment.getRootElements();
+ for (Element element : rootElements) {
+ if (isAppropriateTarget(element, target)) {
+ processElement(processor, processedAnnotation, element);
+ } else {
+ for (Element enclosedElement : element.getEnclosedElements()) {
+ if (isAppropriateTarget(enclosedElement, target)) {
+ processElement(processor, processedAnnotation, enclosedElement);
}
}
}
- } catch (Exception e) {
- processingEnv.getMessager().printMessage(Kind.ERROR,
- "Errorr processing annotation " + processedAnnotation + ":
" + e);
}
}
@@ -149,22 +162,23 @@
Element element) {
if (null != element.getAnnotation(processedAnnotation)) {
try {
- log.debug("Process "+element.getSimpleName()+" annotated
with "+processedAnnotation.getName());
+ log.debug("Process " + element.getSimpleName() + "
annotated with " + processedAnnotation.getName());
processor.process(element, library);
} catch (CdkProcessingException e) {
sendError(element, e);
}
}
}
-
- private boolean isAppropriateTarget(Element element,Target target){
+
+ private boolean isAppropriateTarget(Element element, Target target) {
boolean match = false;
ElementKind kind = element.getKind();
- if(null != target){
- for(ElementType targetType : target.value()){
+ if (null != target) {
+ for (ElementType targetType : target.value()) {
switch (targetType) {
case TYPE:
- match |=
ElementKind.CLASS.equals(kind)||ElementKind.INTERFACE.equals(kind)||ElementKind.ENUM.equals(kind);
+ match |= ElementKind.CLASS.equals(kind) ||
ElementKind.INTERFACE.equals(kind)
+ || ElementKind.ENUM.equals(kind);
break;
case PACKAGE:
match |= ElementKind.PACKAGE.equals(kind);
@@ -181,19 +195,22 @@
}
} else {
// Annotation without @Target match any element.
- match =
- ElementKind.CLASS.equals(kind) || ElementKind.INTERFACE.equals(kind) ||
ElementKind.ENUM.equals(kind)
- || ElementKind.PACKAGE.equals(kind) ||
ElementKind.METHOD.equals(kind)
- || ElementKind.FIELD.equals(kind);
+ match = ElementKind.CLASS.equals(kind) || ElementKind.INTERFACE.equals(kind)
+ || ElementKind.ENUM.equals(kind) || ElementKind.PACKAGE.equals(kind) ||
ElementKind.METHOD.equals(kind)
+ || ElementKind.FIELD.equals(kind);
}
return match;
}
- protected void sendError(Element componentElement, CdkProcessingException e) {
+ protected void sendError(Element componentElement, Exception e) {
// rise error and continue.
processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.ERROR,
e.getMessage(), componentElement);
}
+ protected void sendError(CdkException e) {
+ processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.ERROR,
e.getMessage());
+ }
+
@Override
public Set<String> getSupportedAnnotationTypes() {
return PROCESSED_ANNOTATION;
Added: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java
(rev 0)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -0,0 +1,57 @@
+package org.richfaces.cdk.apt;
+
+import java.lang.annotation.Annotation;
+
+import javax.lang.model.element.AnnotationMirror;
+
+import org.richfaces.cdk.apt.SourceUtils.ACCESS_TYPE;
+import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
+import org.richfaces.cdk.model.ClassName;
+
+public final class PropertyImpl implements BeanProperty {
+ private final String name;
+
+ public PropertyImpl(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean isExists() {
+ return false;
+ }
+
+ @Override
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
+ return false;
+ }
+
+ @Override
+ public ClassName getType() {
+ return ClassName.get(Object.class);
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ public String getDocComment() {
+ return null;
+ }
+
+ @Override
+ public AnnotationMirror getAnnotationMirror(Class<? extends Annotation>
annotationType) {
+ return null;
+ }
+
+ @Override
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
+ return null;
+ }
+
+ @Override
+ public ACCESS_TYPE getAccessType() {
+ return ACCESS_TYPE.readWrite;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/ReflectionUtils.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -49,9 +49,8 @@
}
@Override
- public TypeElement asTypeElement(ClassName type) {
- // TODO Auto-generated method stub
- return null;
+ public boolean isClassExists(ClassName type) {
+ return true;
}
@Override
@@ -67,6 +66,17 @@
}
@Override
+ public BeanProperty getBeanProperty(TypeElement type, String name) {
+ return getBeanProperty(type, name);
+ }
+
+ @Override
+ public BeanProperty getBeanProperty(ClassName type, String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
public Object getConstant(TypeElement element, String name) {
// 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-05
23:40:33 UTC (rev 20900)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -59,6 +59,11 @@
void visit(TypeMirror type);
}
+ enum ACCESS_TYPE {
+ readOnly,
+ writeOnly,
+ readWrite
+ }
/**
* <p class="changed_added_4_0">
* </p>
@@ -85,19 +90,28 @@
*/
String getDocComment();
+ /**
+ * <p class="changed_added_4_0">Bean property type</p>
+ * @return
+ */
ClassName getType();
/**
- * <p class="changed_added_4_0">
+ * <p class="changed_added_4_0">Is this property implementted by
component
* </p>
*
* @return the exists
*/
boolean isExists();
+
+ boolean isAnnotationPresent(Class<? extends Annotation> annotationType);
AnnotationMirror getAnnotationMirror(Class<? extends Annotation>
annotationType);
<T extends Annotation> T getAnnotation(Class<T> annotationType);
+
+ ACCESS_TYPE getAccessType();
+
}
/**
@@ -119,8 +133,25 @@
* @return
*/
Set<BeanProperty> getAbstractBeanProperties(TypeElement type);
+
+
+ /**
+ * <p class="changed_added_4_0">Get bean property descriptor for
particular type.</p>
+ * @param type
+ * @param name
+ * @return
+ */
+ BeanProperty getBeanProperty(TypeElement type, String name);
/**
+ * <p class="changed_added_4_0">Get bean property descriptor for
particular type.</p>
+ * @param type
+ * @param name
+ * @return
+ */
+ BeanProperty getBeanProperty(ClassName type, String name);
+
+ /**
* <p class="changed_added_4_0">
* Get JavaDoc comments associated with given element.
* </p>
@@ -172,6 +203,14 @@
<T> List<T> getAnnotationValues(AnnotationMirror annotation, String
propertyName, Class<T> expectedType);
/**
+ * <p class="changed_added_4_0"></p>
+ * @param annotation
+ * @param propertyName
+ * @return
+ */
+ public abstract boolean isAnnotationPropertyPresent(AnnotationMirror annotation,
final String propertyName);
+
+ /**
* <p class="changed_added_4_0">Check annotation proprrty for default
value.</p>
* @param annotation
* @param propertyName
@@ -179,6 +218,23 @@
*/
boolean isDefaultValue(AnnotationMirror annotation, String propertyName);
/**
+ * <p class="changed_added_4_0"></p>
+ * @param model
+ * @param annotation
+ * @param modelProperty
+ * @param annotationAttribute
+ */
+ public abstract void setModelProperty(Object model, AnnotationMirror annotation,
String modelProperty, String annotationAttribute);
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param model
+ * @param annotation
+ * @param modelProperty
+ */
+ public abstract void setModelProperty(Object model, AnnotationMirror annotation,
String modelProperty);
+
+ /**
* <p class="changed_added_4_0">
* </p>
*
@@ -203,7 +259,7 @@
* </p>
*
* @param mirror
- * @return
+ * @return The Element for given type
*/
TypeElement asTypeElement(TypeMirror mirror);
@@ -212,14 +268,8 @@
* </p>
*
* @param type
- * @return
+ * @return true if class already exist in project source or dependent libraries.
*/
- TypeElement asTypeElement(ClassName type);
+ boolean isClassExists(ClassName type);
- public abstract boolean isAnnotationPropertyPresent(AnnotationMirror annotation,
final String propertyName);
-
- public abstract void setModelProperty(Object model, AnnotationMirror annotation,
String modelProperty, String annotationAttribute);
-
- public abstract void setModelProperty(Object model, AnnotationMirror annotation,
String modelProperty);
-
}
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ModelElementBaseTemplateModel.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -124,7 +124,7 @@
Set<ClassName> result = Sets.newTreeSet();
for (PropertyBase entry : model.getAttributes()) {
- if (entry.isGenerate() && !isPredefined(entry)) {
+ if (entry.getGenerate() && !isPredefined(entry)) {
result.add(entry.getType());
}
}
@@ -244,7 +244,7 @@
@Override
public boolean apply(PropertyBase input) {
- return input.isGenerate();
+ return input.getGenerate();
}
}));
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -52,7 +52,7 @@
public void render(ComponentLibrary library) throws CdkException {
Collection<BehaviorModel> models = library.getBehaviors();
for (BehaviorModel model : models) {
- if (model.isGenerate()) {
+ if (model.getGenerate()) {
this.generate(library, model);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -55,7 +55,7 @@
public void render(ComponentLibrary library) throws CdkException {
Collection<ComponentModel> models = library.getComponents();
for (ComponentModel model : models) {
- if (model.isGenerate()) {
+ if (model.getGenerate()) {
this.generate(library, model);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -52,7 +52,7 @@
public void render(ComponentLibrary library) throws CdkException {
Collection<ConverterModel> models = library.getConverters();
for (ConverterModel model : models) {
- if (model.isGenerate()) {
+ if (model.getGenerate()) {
this.generate(library, model);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -51,7 +51,7 @@
public void render(ComponentLibrary library) throws CdkException {
Collection<ValidatorModel> models = library.getValidators();
for (ValidatorModel model : models) {
- if (model.isGenerate()) {
+ if (model.getGenerate()) {
this.generate(library, model);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/BehaviorRendererModel.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/BehaviorRendererModel.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/BehaviorRendererModel.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -99,7 +99,7 @@
* <p class="changed_added_4_0"></p>
* @return the generate
*/
- public boolean isGenerate() {
+ public Boolean getGenerate() {
return this.generate;
}
@@ -107,7 +107,7 @@
* <p class="changed_added_4_0"></p>
* @param generate the generate to set
*/
- public void setGenerate(boolean generate) {
+ public void setGenerate(Boolean generate) {
this.generate = generate;
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2011-01-05
23:40:33 UTC (rev 20900)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -52,6 +52,18 @@
.put(double.class.getName(), Double.class.getName())
.build();
+ private static final ImmutableMap<String, String> DEFAULT_VALUES =
+ ImmutableMap.<String, String>builder()
+ .put(boolean.class.getName(), "Boolean.FALSE")
+ .put(byte.class.getName(), "Byte.MIN_VALUE")
+ .put(char.class.getName(), "Character.MIN_VALUE")
+ .put(short.class.getName(), "Short.MIN_VALUE")
+ .put(int.class.getName(), "Integer.MIN_VALUE")
+ .put(long.class.getName(), "Long.MIN_VALUE")
+ .put(float.class.getName(), "Float.MIN_VALUE")
+ .put(double.class.getName(), "Double.MIN_VALUE")
+ .build();
+
private final String boxingClassName;
private final String fullName;
@@ -196,6 +208,9 @@
return primitive;
}
+ public String getDefaultValue(){
+ return DEFAULT_VALUES.get(name);
+ }
/**
* <p class="changed_added_4_0">
* </p>
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -61,7 +61,6 @@
ComponentLibrary.merge(getFacets(), otherComponent.getFacets());
ComponentLibrary.merge(getEvents(), otherComponent.getEvents());
ComponentLibrary.merge(this, otherComponent);
- this.setGenerate(this.isGenerate() || otherComponent.isGenerate());
}
@Override
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/DescriptionGroupBase.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -31,7 +31,7 @@
/**
* <p class="changed_added_4_0">Is that bean property generate in
the class or should be generated ?</p>
*/
- private boolean generate = false;
+ private Boolean generate ;
/**
* <p class="changed_added_4_0">
@@ -83,11 +83,11 @@
}
@Merge
- public boolean isGenerate() {
+ public Boolean getGenerate() {
return generate;
}
- public void setGenerate(boolean generate) {
+ public void setGenerate(Boolean generate) {
this.generate = generate;
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/FacesComponent.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/FacesComponent.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/FacesComponent.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -91,12 +91,12 @@
* <p class="changed_added_4_0"></p>
* @return
*/
- public boolean isGenerate();
+ public Boolean getGenerate();
/**
* <p class="changed_added_4_0"></p>
* @param generate
*/
- public void setGenerate(boolean generate);
+ public void setGenerate(Boolean generate);
}
\ No newline at end of file
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java 2011-01-05
23:40:33 UTC (rev 20900)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -293,9 +293,7 @@
@Override
public void merge(PropertyBase other) {
- boolean generate = isGenerate();
ComponentLibrary.merge(this, other);
- setGenerate(generate || other.isGenerate());
}
public <R,D> R accept(Visitor<R,D> visitor, D data) {
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/RenderKitModel.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/RenderKitModel.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/RenderKitModel.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -44,8 +44,6 @@
private FacesId id;
- private boolean generate;
-
public RenderKitModel() {
}
@@ -100,22 +98,6 @@
/**
* <p class="changed_added_4_0"></p>
- * @return the generate
- */
- public boolean isGenerate() {
- return this.generate;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param generate the generate to set
- */
- public void setGenerate(boolean generate) {
- this.generate = generate;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
* @return the renderers
*/
public ModelCollection<RendererModel> getRenderers() {
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -45,6 +45,7 @@
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
+import org.richfaces.cdk.model.ConverterModel;
import org.richfaces.cdk.model.DescriptionGroup;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.FacesComponent;
@@ -56,9 +57,11 @@
import org.richfaces.cdk.model.RendererModel;
import org.richfaces.cdk.model.TagModel;
import org.richfaces.cdk.model.Taglib;
+import org.richfaces.cdk.model.ValidatorModel;
import org.richfaces.cdk.util.Strings;
import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
@@ -132,7 +135,78 @@
throw new CallbackException("Cannot infer Java class name for behavior
" + this.behavior);
}
}
+
+ private final class ConverterTypeCallback implements NamingConventionsCallback {
+ private final ConverterModel converter;
+
+ public ConverterTypeCallback(ConverterModel converter) {
+ this.converter = converter;
+ }
+ @Override
+ public FacesId inferType(ClassName targetClass) throws CallbackException {
+ // TODO use actual methods
+ return namingConventions.inferComponentType(targetClass);
+ }
+
+ @Override
+ public FacesId inferType() throws CallbackException {
+ throw new CallbackException("Cannot infer type for converter " +
this.converter);
+ }
+
+ @Override
+ public ClassName inferClass(FacesId id) throws CallbackException {
+ throw new CallbackException("Cannot infer target Java class name for
converter " + this.converter);
+ }
+
+ @Override
+ public ClassName getDefaultBaseClass() throws CallbackException {
+ throw new CallbackException("Cannot infer base Java class name for
converter " + this.converter);
+ }
+
+ @Override
+ public ClassName getDefaultClass() throws CallbackException {
+ return ClassName.get(Object.class);
+ }
+
+ }
+
+ private final class ValidatorTypeCallback implements NamingConventionsCallback {
+
+ private final ValidatorModel validator;
+
+ public ValidatorTypeCallback(ValidatorModel validator) {
+ this.validator = validator;
+ }
+
+ @Override
+ public FacesId inferType(ClassName targetClass) throws CallbackException {
+ // TODO use actual methods
+ return namingConventions.inferComponentType(targetClass);
+ }
+
+ @Override
+ public FacesId inferType() throws CallbackException {
+ throw new CallbackException("Cannot infer type for validator " +
this.validator);
+ }
+
+ @Override
+ public ClassName inferClass(FacesId id) throws CallbackException {
+ throw new CallbackException("Cannot infer target Java class name for
validator " + this.validator);
+ }
+
+ @Override
+ public ClassName getDefaultBaseClass() throws CallbackException {
+ throw new CallbackException("Cannot infer default Java class name for
validator " + this.validator);
+ }
+
+ @Override
+ public ClassName getDefaultClass() throws CallbackException {
+ return ClassName.get(Object.class);
+ }
+
+ }
+
private final class RendererTypeCallback implements NamingConventionsCallback {
private final ComponentLibrary library;
private final RendererModel renderer;
@@ -197,6 +271,8 @@
public static final ClassName DEFAULT_VALIDATOR_HANDLER = new
ClassName(ValidatorHandler.class);
public static final ClassName DEFAULT_CONVERTER_HANDLER = new
ClassName(ConverterHandler.class);
public static final ClassName DEFAULT_BEHAVIOR_HANDLER = new
ClassName(BehaviorHandler.class);
+ public static final ImmutableSet<String> SPECIAL_PROPERTIES =
ImmutableSet.of("eventNames", "defaultEventName",
+ "clientBehaviors", "family");
@Inject
private Logger log;
@@ -223,8 +299,23 @@
verifyBehaviors(library);
verifyRenderers(library);
verifyTaglib(library);
+ verifyConverters(library);
+ verifyValidators(library);
}
+ private void verifyValidators(ComponentLibrary library) {
+ for (ValidatorModel validator : library.getValidators()) {
+ verifyTypes(validator, new ValidatorTypeCallback(validator));
+ }
+
+ }
+
+ protected void verifyConverters(ComponentLibrary library) {
+ for (ConverterModel converter : library.getConverters()) {
+ verifyTypes(converter, new ConverterTypeCallback(converter));
+ }
+ }
+
protected void verifyEvents(ComponentLibrary library) {
for (EventModel event : library.getEvents()) {
ClassName listenerInterface = event.getListenerInterface();
@@ -232,7 +323,7 @@
// TODO - infer listener interface name.
}
SourceUtils sourceUtils = sourceUtilsProvider.get();
- event.setGenerateListener(null ==
sourceUtils.asTypeElement(listenerInterface));
+ event.setGenerateListener(!sourceUtils.isClassExists(listenerInterface));
String methodName = event.getListenerMethod();
if (null == methodName) {
// TODO infer listener method name.
@@ -243,7 +334,7 @@
if (null == sourceInterface) {
// TODO - infer source interface.
}
- event.setGenerateSource(null == sourceUtils.asTypeElement(sourceInterface));
+ event.setGenerateSource(!sourceUtils.isClassExists(sourceInterface));
// Propagate event to corresponding components.
for (ComponentModel component : library.getComponents()) {
for (EventModel componentEvent : component.getEvents()) {
@@ -278,7 +369,7 @@
}
// Verify tags. If we have renderer-specific component, it should have a tag ?
for (ComponentModel component : library.getComponents()) {
- if(null != component.getRendererType() &&
component.getTags().isEmpty()){
+ if (null != component.getRendererType() &&
component.getTags().isEmpty()) {
TagModel tag = new TagModel();
verifyTag(tag, component.getId(), DEFAULT_COMPONENT_HANDLER);
component.getTags().add(tag);
@@ -360,14 +451,7 @@
if (null != component.getBaseClass()) {
try {
// Step one, lookup for parent.
- ComponentModel parentComponent =
- Iterables.find(library.getComponents(), new
Predicate<ComponentModel>() {
-
- @Override
- public boolean apply(ComponentModel input) {
- return
component.getBaseClass().equals(input.getTargetClass());
- }
- });
+ ComponentModel parentComponent = findParent(library.getComponents(),
component);
// To be sure what all properties for parent component were
propagated.
verifyComponentAttributes(library, parentComponent, verified);
for (PropertyBase parentAttribute : parentComponent.getAttributes())
{
@@ -382,7 +466,7 @@
} // Check attributes.
for (PropertyBase attribute : component.getAttributes()) {
- verifyAttribute(attribute, component.isGenerate());
+ verifyAttribute(attribute, component);
}
// compact(component.getAttributes());
// Check renderers.
@@ -397,12 +481,23 @@
}
}
+ private <T extends FacesComponent> T findParent(Iterable<T> components,
final T component)
+ throws NoSuchElementException {
+ return Iterables.find(components, new Predicate<T>() {
+
+ @Override
+ public boolean apply(T input) {
+ return component.getBaseClass().equals(input.getTargetClass());
+ }
+ });
+ }
+
protected void verifyTag(TagModel tag, FacesId id, ClassName handler) {
if (Strings.isEmpty(tag.getName())) {
String defaultTagName = namingConventions.inferTagName(id);
tag.setName(defaultTagName);
}
- if(null == tag.getType()){
+ if (null == tag.getType()) {
tag.setType(TagType.Facelets);
}
if (tag.isGenerate()) {
@@ -457,14 +552,14 @@
}
}
// Check classes.
- if (component.isGenerate()) {
- if (null == component.getBaseClass()) {
- component.setBaseClass(callback.getDefaultBaseClass());
- // return;
- }
+ if (null == component.getGenerate()) {
if (null == component.getTargetClass()) {
component.setTargetClass(callback.inferClass(component.getId()));
}
+
component.setGenerate(!sourceUtilsProvider.get().isClassExists(component.getTargetClass()));
+ }
+ if (component.getGenerate()) {
+ verifyGeneratedClasses(component, callback);
} else if (null == component.getTargetClass()) {
if (null == component.getBaseClass()) {
component.setBaseClass(callback.getDefaultClass());
@@ -478,7 +573,17 @@
return true;
}
- protected void verifyAttribute(PropertyBase attribute, boolean generatedComponent) {
+ private void verifyGeneratedClasses(FacesComponent component,
NamingConventionsCallback callback) throws CallbackException {
+ if (null == component.getBaseClass()) {
+ component.setBaseClass(callback.getDefaultBaseClass());
+ // return;
+ }
+ if (null == component.getTargetClass()) {
+ component.setTargetClass(callback.inferClass(component.getId()));
+ }
+ }
+
+ protected void verifyAttribute(PropertyBase attribute, FacesComponent component) {
// Check name.
if (Strings.isEmpty(attribute.getName())) {
log.error("No name for attribute " + attribute);
@@ -493,6 +598,10 @@
if (null == attribute.getType()) {
log.error("Unknown type of attribute [" + attribute.getName() +
"]");
return;
+ }
+ if(attribute.getType().isPrimitive() && null ==
attribute.getDefaultValue()){
+ // Set default value for primitive
+ attribute.setDefaultValue(attribute.getType().getDefaultValue());
}
// Check binding properties.
if
("javax.faces.el.MethodBinding".equals(attribute.getType().getName())) {
@@ -505,9 +614,20 @@
// log.error("Signature for method expression attribute
"+attribute.getName()+" has not been set");
// }
// Check "generate" flag.
- if (generatedComponent) {
+ if (Boolean.TRUE.equals(component.getGenerate())) {
// TODO Attribute should be only generated if it does not exist or abstract
in the base class.
// Step one - check base class
+ SourceUtils sourceUtils = sourceUtilsProvider.get();
+ if (SPECIAL_PROPERTIES.contains(attribute.getName())) {
+ attribute.setGenerate(false);
+ } else if (null == attribute.getGenerate()) {
+ if (sourceUtils.isClassExists(component.getBaseClass())) {
+
attribute.setGenerate(!sourceUtils.getBeanProperty(component.getBaseClass(),
attribute.getName())
+ .isExists());
+ } else {
+ attribute.setGenerate(true);
+ }
+ }
} else {
attribute.setGenerate(false);
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -74,8 +74,8 @@
addImport(new JavaImportImpl(name));
}
- public void addImport(String name, boolean _static) {
- addImport(new JavaImportImpl(name, _static));
+ public void addImport(String name, boolean staticImport) {
+ addImport(new JavaImportImpl(name, staticImport));
}
public void addImport(Class<?> claz) {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -33,7 +33,7 @@
private String name;
- private boolean _static;
+ private boolean staticImport;
public JavaImportImpl(String name) {
this(name, false);
@@ -43,14 +43,14 @@
this(clazz.getName());
}
- public JavaImportImpl(String name, boolean _static) {
+ public JavaImportImpl(String name, boolean staticImport) {
super();
this.name = name;
- this._static = _static;
+ this.staticImport = staticImport;
}
- public JavaImportImpl(Class<?> clazz, boolean _static) {
- this(clazz.getName(), _static);
+ public JavaImportImpl(Class<?> clazz, boolean staticImport) {
+ this(clazz.getName(), staticImport);
}
public String getName() {
@@ -58,7 +58,7 @@
}
public boolean isStatic() {
- return _static;
+ return staticImport;
}
public boolean isDefault() {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -32,47 +32,47 @@
*/
public class ClassImport {
- @XmlAttribute(required = true)
- @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
- private String _package;
+ private String packageName;
- @XmlAttribute
- private boolean _static;
+ private boolean staticImport;
- @XmlAttribute
private List<String> names;
/**
* @return the package_
*/
+ @XmlAttribute(required = true)
+ @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
public String getPackage() {
- return _package;
+ return packageName;
}
/**
- * @param _package the package_ to set
+ * @param packageName the package_ to set
*/
- public void setPackage(String _package) {
- this._package = _package;
+ public void setPackage(String packageName) {
+ this.packageName = packageName;
}
/**
* @return the static_
*/
+ @XmlAttribute
public boolean isStatic() {
- return _static;
+ return staticImport;
}
/**
* @param static_ the static_ to set
*/
- public void setStatic(boolean _static) {
- this._static = _static;
+ public void setStatic(boolean staticImport) {
+ this.staticImport = staticImport;
}
/**
* @return the classes
*/
+ @XmlAttribute
public List<String> getNames() {
return names;
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -80,11 +80,6 @@
}
}
- private static String[] transformClassesToClassNames(Class<?>[] s) {
- Iterator<String> transformed = transform(forArray(s),
CLASS_TO_CLASS_NAME);
- return toArray(transformed, String.class);
- }
-
private HelperMethod(String name, String returnType, String... argumentTypes) {
this.name = name;
this.returnType = returnType;
@@ -95,6 +90,11 @@
this(name, CLASS_TO_CLASS_NAME.apply(returnType),
transformClassesToClassNames(argumentTypes));
}
+ private static String[] transformClassesToClassNames(Class<?>[] s) {
+ Iterator<String> transformed = transform(forArray(s),
CLASS_TO_CLASS_NAME);
+ return toArray(transformed, String.class);
+ }
+
public String getName() {
return name;
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -79,11 +79,12 @@
}
/**
- * @param value the value to set
+ * @param value
+ * the value to set
*/
public void setValueExpression(String valueExpression) {
try {
- this.value = parser.parse(valueExpression, this, TypesFactory.OBJECT_TYPE);
+ this.value = parser.parse(valueExpression, this, TypesFactory.OBJECT_TYPE);
} catch (ParsingException e) {
logger.error("Error parse scriptOption value expression: " +
valueExpression, e);
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -27,7 +27,6 @@
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.TemplateModel;
-import com.google.common.collect.Sets;
import com.google.inject.Inject;
/**
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsAnnotationsTest.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -3,7 +3,6 @@
import static org.junit.Assert.*;
import java.util.List;
-import java.util.Set;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.AnnotationMirror;
@@ -13,9 +12,7 @@
import org.richfaces.cdk.apt.TestAnnotation.TestEnum;
import org.richfaces.cdk.model.ClassName;
-import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
public class AptSourceUtilsAnnotationsTest extends SourceUtilsTestBase {
@@ -163,15 +160,4 @@
protected Iterable<String> sources() {
return ImmutableList.of(CLASS_JAVA, SUB_CLASS_JAVA);
}
-
- private Element findElement(RoundEnvironment roundEnvironment, final String name){
- Set<? extends Element> elements = roundEnvironment.getRootElements();
- return Iterables.find(elements, new Predicate<Element>() {
-
- @Override
- public boolean apply(Element input) {
- return name.equals(input.getSimpleName().toString());
- }
- });
- }
}
Added:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsPropertiesTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsPropertiesTest.java
(rev 0)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsPropertiesTest.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -0,0 +1,178 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.cdk.apt;
+
+import static org.junit.Assert.*;
+
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementVisitor;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.TypeParameterElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.util.AbstractElementVisitor6;
+import javax.lang.model.util.ElementKindVisitor6;
+import javax.lang.model.util.ElementScanner6;
+
+import org.junit.Test;
+import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class AptSourceUtilsPropertiesTest extends SourceUtilsTestBase {
+
+ private static final String TEST_SUB_CLASS = "PropertyTestClass";
+ private static final String TEST_CLASS = "TestClass";
+ private static final String TEST_INTERFACE = "TestInterface";
+ private static final String PROPERTY_TEST_INTERFACE = "TestInterface";
+ private static final String PACKAGE_PATH = "org/richfaces/cdk/apt/";
+ private static final String CLASS_JAVA = PACKAGE_PATH + TEST_CLASS +
".java";
+ private static final String SUB_CLASS_JAVA = PACKAGE_PATH + TEST_SUB_CLASS +
".java";
+ private static final String INTERFACE_JAVA = PACKAGE_PATH + TEST_INTERFACE +
".java";
+ private static final String PROPERTY_INTERFACE_JAVA = PACKAGE_PATH +
PROPERTY_TEST_INTERFACE + ".java";
+
+ @Test
+ public void testGetConcreteProperty() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ BeanProperty beanProperty = utils.getBeanProperty(subClassType,
"concreteValue");
+ assertTrue(beanProperty.isExists());
+ }
+ });
+ }
+
+ @Test
+ public void testGetAbstractProperty() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ BeanProperty beanProperty = utils.getBeanProperty(subClassType,
"value");
+ assertFalse(beanProperty.isExists());
+ }
+ });
+ }
+
+ @Test
+ public void testGetNotExistedProperty() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ BeanProperty beanProperty = utils.getBeanProperty(subClassType,
"notExistedValue");
+ assertFalse(beanProperty.isExists());
+ }
+ });
+ }
+
+ @Test
+ public void testGetInheritedProperty() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ BeanProperty beanProperty = utils.getBeanProperty(subClassType,
"inheritedValue");
+ assertTrue(beanProperty.isExists());
+ }
+ });
+ }
+
+ @Test
+ public void testGetReadOnlyProperty() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ BeanProperty beanProperty = utils.getBeanProperty(subClassType,
"readOnly");
+ assertTrue(beanProperty.isExists());
+ }
+ });
+ }
+
+ @Test
+ public void testGetWriteOnlyProperty() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ BeanProperty beanProperty = utils.getBeanProperty(subClassType,
"writeOnly");
+ assertTrue(beanProperty.isExists());
+ }
+ });
+ }
+
+ @Test
+ public void testGetWrongProperty() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ BeanProperty beanProperty = utils.getBeanProperty(subClassType,
"wrongValue");
+ assertTrue(beanProperty.isExists());
+ }
+ });
+ }
+
+ @Test
+ public void testGetBeanProperties() throws Exception {
+ execute(new SourceUtilsCallback() {
+
+ @Override
+ public void process(SourceUtils utils, RoundEnvironment roundEnv) {
+ AptSourceUtils aptUtils = (AptSourceUtils) utils;
+ TypeElement subClassType = (TypeElement) findElement(roundEnv,
TEST_SUB_CLASS);
+ assertEquals(6, aptUtils.getBeanProperties(subClassType).size());
+ }
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.apt.AnnotationProcessorTestBase#sources()
+ */
+ @Override
+ protected Iterable<String> sources() {
+ return ImmutableList.of(CLASS_JAVA, SUB_CLASS_JAVA,
INTERFACE_JAVA,PROPERTY_INTERFACE_JAVA);
+ }
+
+}
Property changes on:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/AptSourceUtilsPropertiesTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/SourceUtilsTestBase.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/SourceUtilsTestBase.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/SourceUtilsTestBase.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -33,6 +33,7 @@
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import org.junit.runner.RunWith;
@@ -42,6 +43,8 @@
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.Stub;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -77,6 +80,17 @@
assertTrue("Compilation error",factory.get().call());
}
+ protected Element findElement(RoundEnvironment roundEnvironment, final String name)
{
+ Set<? extends Element> elements = roundEnvironment.getRootElements();
+ return Iterables.find(elements, new Predicate<Element>() {
+
+ @Override
+ public boolean apply(Element input) {
+ return name.equals(input.getSimpleName().toString());
+ }
+ });
+ }
+
/**
* <p class="changed_added_4_0">Interface to call back test method
from APT</p>
* @author asmirnov(a)exadel.com
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -130,7 +130,7 @@
verify(utils, componentElement, jaxb, annotation, property, facet, description);
assertEquals(1, model.getFacets().size());
FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
- assertTrue(facetModel.isGenerate());
+ assertTrue(facetModel.getGenerate());
assertEquals("foo", facetModel.getName());
// assertEquals("my comment", facetModel.getDescription());
// assertEquals("fooFacet", facetModel.getDisplayname());
@@ -160,7 +160,7 @@
verify(utils, componentElement, jaxb, annotation, property, facet, description);
assertEquals(1, model.getFacets().size());
FacetModel facetModel = Iterables.getOnlyElement(model.getFacets());
- assertTrue(facetModel.isGenerate());
+ assertTrue(facetModel.getGenerate());
assertEquals("foo", facetModel.getName());
// assertEquals("my comment", facetModel.getDescription());
// assertEquals("fooFacet", facetModel.getDisplayname());
@@ -180,7 +180,7 @@
replay(utils, componentElement, jaxb, annotation);
processor.setClassNames(componentElement, model, "");
verify(utils, componentElement, jaxb, annotation);
- assertFalse(model.isGenerate());
+ assertFalse(model.getGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
assertNull(model.getTargetClass());
}
@@ -200,7 +200,7 @@
processor.setClassNames(componentElement, model, "");
verify(utils, componentElement, jaxb, annotation);
- assertTrue(model.isGenerate());
+ assertTrue(model.getGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
assertNull(model.getTargetClass());
}
@@ -220,7 +220,7 @@
processor.setClassNames(componentElement, model, FOO_HTML_BAR);
verify(utils, componentElement, jaxb, annotation);
- assertTrue(model.isGenerate());
+ assertTrue(model.getGenerate());
assertEquals(FOO_BAR, model.getBaseClass().toString());
assertEquals(FOO_HTML_BAR, model.getTargetClass().toString());
}
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -87,6 +87,7 @@
component.setTargetClass(className);
expect(namiingConventions.inferComponentType(className)).andReturn(type);
expect(namiingConventions.inferUIComponentFamily(type)).andReturn(FOO_BAZ);
+ expect(utils.isClassExists(className)).andReturn(true);
replay(log, utils, namiingConventions);
// Validator should set component type from base class.
validator.verifyComponentType(component);
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -104,12 +104,12 @@
assertEquals("panel-large.gif", component.getIcon().getLargeIcon());
assertEquals("Panel component", component.getDescription());
assertEquals("Panel", component.getDisplayname());
- assertTrue(component.isGenerate());
+ assertTrue(component.getGenerate());
FacetModel facet = Iterables.getOnlyElement(component.getFacets());
assertEquals("header", facet.getName());
assertEquals("Header facet", facet.getDescription());
- assertTrue(facet.isGenerate());
+ assertTrue(facet.getGenerate());
Collection<PropertyBase> attributes = component.getAttributes();
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-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -118,7 +118,7 @@
assertEquals("15", property.getSuggestedValue());
// CDK extensions.
- assertTrue(property.isGenerate());
+ assertTrue(property.getGenerate());
assertTrue(property.isHidden());
assertTrue(property.isLiteral());
assertTrue(property.isPassThrough());
Added:
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestClass.java
===================================================================
--- trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestClass.java
(rev 0)
+++
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestClass.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -0,0 +1,77 @@
+/*
+ * $Id: TestSubClass.java 18741 2010-08-18 03:07:27Z alexsmirnov $
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.richfaces.cdk.apt;
+
+import org.richfaces.cdk.apt.TestMethodAnnotation;
+
+/**
+ * <p class="changed_added_4_0">Java Bean to test bean properties
processor.
+ * that class contains next properties:
+ * <ol>
+ * <li>r/w concreteValue, type String, annotated with {@link TestMethodAnnotation}
"setter"</li>
+ * <li> r/w inheritedValue, type String, inherited from {@link
PropertyTestInterface}, annotated {@link TestMethodAnnotation} "inherited"
</li>
+ * <li> abstract r/w value, inherited from {@link TestInterface},{@link
TestMethodAnnotation} "baz"</li>
+ * <li> r readOnly, type Integer, inherited from {@link TestClass}</li>
+ * <li> w writeOnly, type Integer, inherited from {@link TestClass}</li>
+ * <li> wrongValue that should be ignored with warning message.</li>
+ * </ol>
+ * </p>
+ * @author asmirnov(a)exadel.com
+ */
+public class PropertyTestClass extends TestClass implements TestInterface,
PropertyTestInterface {
+ private String concreteValue;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param value the value to set
+ */
+ @TestMethodAnnotation("setter")
+ public void setConcreteValue(String value) {
+ this.value = concreteValue;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the value
+ */
+ public String getConcreteValue() {
+ return concreteValue;
+ }
+
+
+ public void setInheritedValue(String value) {
+ this.value = concreteValue;
+ }
+
+ public String getInheritedValue() {
+ return concreteValue;
+ }
+
+ public void setWrongValue(Integer value) {
+
+ }
+
+}
Property changes on:
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestClass.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestInterface.java
===================================================================
---
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestInterface.java
(rev 0)
+++
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestInterface.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -0,0 +1,44 @@
+/*
+ * $Id: TestInterface.java 18741 2010-08-18 03:07:27Z alexsmirnov $
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.richfaces.cdk.apt;
+
+import org.richfaces.cdk.apt.TestMethodAnnotation;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface PropertyTestInterface {
+
+ @TestMethodAnnotation("inherited")
+ public String getInheritedValue();
+
+ public void setInheritedValue(String value);
+
+ public void setWrongValue(String value);
+
+}
Property changes on:
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/PropertyTestInterface.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/TestClass.java
===================================================================
--- trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/TestClass.java 2011-01-05
23:40:33 UTC (rev 20900)
+++ trunk/cdk/generator/src/test/resources/org/richfaces/cdk/apt/TestClass.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -31,4 +31,13 @@
*
*/
//@TestAnnotation("foo")
-public class TestClass {}
+public class TestClass {
+
+ public Integer getReadOnly(){
+ return null;
+ }
+
+ public void setWriteOnly(Boolean value){
+
+ }
+}
Modified:
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.xml
===================================================================
---
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.xml 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/BehaviorBeanTest.xml 2011-01-06
00:59:41 UTC (rev 20901)
@@ -7,7 +7,6 @@
<attribute-name>attr2</attribute-name>
<attribute-class>java.lang.String</attribute-class>
<attribute-extension>
- <cdk:generate>false</cdk:generate>
<cdk:hidden>false</cdk:hidden>
<cdk:literal>false</cdk:literal>
<cdk:pass-through>false</cdk:pass-through>
@@ -19,7 +18,6 @@
<property-name>attr1</property-name>
<property-class>java.lang.String</property-class>
<property-extension>
- <cdk:generate>false</cdk:generate>
<cdk:hidden>false</cdk:hidden>
<cdk:literal>false</cdk:literal>
<cdk:pass-through>false</cdk:pass-through>
@@ -27,9 +25,7 @@
<cdk:required>false</cdk:required>
</property-extension>
</property>
- <behavior-extension>
- <cdk:generate>false</cdk:generate>
- </behavior-extension>
+ <behavior-extension/>
</behavior>
<faces-config-extension/>
</faces-config>
\ No newline at end of file
Modified:
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml
===================================================================
---
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml 2011-01-06
00:59:41 UTC (rev 20901)
@@ -3,9 +3,7 @@
<converter>
<converter-id>my_converter</converter-id>
<converter-class>java.lang.Object</converter-class>
- <converter-extension>
- <cdk:generate>false</cdk:generate>
- </converter-extension>
+ <converter-extension/>
</converter>
<faces-config-extension/>
</faces-config>
\ No newline at end of file
Modified:
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml
===================================================================
---
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml 2011-01-06
00:59:41 UTC (rev 20901)
@@ -3,9 +3,7 @@
<validator>
<validator-id>my_validator</validator-id>
<validator-class>java.lang.Object</validator-class>
- <validator-extension>
- <cdk:generate>false</cdk:generate>
- </validator-extension>
+ <validator-extension/>
</validator>
<faces-config-extension/>
</faces-config>
\ No newline at end of file
Modified: trunk/cdk/maven-cdk-plugin/src/it/annotated-component/pom.xml
===================================================================
--- trunk/cdk/maven-cdk-plugin/src/it/annotated-component/pom.xml 2011-01-05 23:40:33 UTC
(rev 20900)
+++ trunk/cdk/maven-cdk-plugin/src/it/annotated-component/pom.xml 2011-01-06 00:59:41 UTC
(rev 20901)
@@ -31,6 +31,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
<configuration>
<!--
http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<source>1.6</source>
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java 2011-01-05
23:40:33 UTC (rev 20900)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java 2011-01-06
00:59:41 UTC (rev 20901)
@@ -360,10 +360,14 @@
CdkClassLoader classLoader = null;
try {
- String outputDirectory = project.getBuild().getOutputDirectory();
- List<File> urls = new ArrayList<File>(classpathElements.size() +
1);
- urls.add(new File(outputDirectory));
-
+ // This Mojo executed befor process-resources phase, therefore we have to use
original resource folders.
+ List<Resource> resources = project.getResources();
+ List<File> urls = new ArrayList<File>(classpathElements.size() +
resources.size());
+ for (Resource resource : resources) {
+ String directory = resource.getDirectory();
+ // TODO - use includes/excludes and target path.
+ urls.add(resolveRelativePath(new File(directory)));
+ }
for (Iterator<String> iter = classpathElements.iterator();
iter.hasNext();) {
String element = iter.next();