Author: alexsmirnov
Date: 2010-12-30 18:45:12 -0500 (Thu, 30 Dec 2010)
New Revision: 20853
Modified:
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
Log:
CODING IN PROGRESS - issue RF-9323: CDK annotation @RendererSpecificComponent.attributes
doesn't work
https://issues.jboss.org/browse/RF-9323
Modified:
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java
===================================================================
---
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java 2010-12-30
23:14:04 UTC (rev 20852)
+++
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java 2010-12-30
23:45:12 UTC (rev 20853)
@@ -158,12 +158,16 @@
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);
}
- checkPropertyType(type, propertyName, propertyType, beanProperty);
- beanProperty.setAccessMethod(method, setter);
} else {
AptBeanProperty beanProperty = new AptBeanProperty(propertyName);
beanProperty.setAccessMethod(method, setter);
Modified:
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
===================================================================
---
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2010-12-30
23:14:04 UTC (rev 20852)
+++
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2010-12-30
23:45:12 UTC (rev 20853)
@@ -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:
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
===================================================================
---
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2010-12-30
23:14:04 UTC (rev 20852)
+++
branches/RF-9323/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2010-12-30
23:45:12 UTC (rev 20853)
@@ -51,7 +51,6 @@
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.FacetModel;
import org.richfaces.cdk.model.InvalidNameException;
-import org.richfaces.cdk.model.ModelElement;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.model.RendererModel;
@@ -60,6 +59,7 @@
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;
@@ -198,6 +198,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;
@@ -279,7 +281,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);
@@ -361,8 +363,7 @@
if (null != component.getBaseClass()) {
try {
// Step one, lookup for parent.
- ComponentModel parentComponent =
- findParent(library.getComponents(), component);
+ 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())
{
@@ -392,7 +393,8 @@
}
}
- private <T extends FacesComponent> T findParent(Iterable<T> components,
final T component) throws NoSuchElementException {
+ private <T extends FacesComponent> T findParent(Iterable<T> components,
final T component)
+ throws NoSuchElementException {
return Iterables.find(components, new Predicate<T>() {
@Override
@@ -407,7 +409,7 @@
String defaultTagName = namingConventions.inferTagName(id);
tag.setName(defaultTagName);
}
- if(null == tag.getType()){
+ if (null == tag.getType()) {
tag.setType(TagType.Facelets);
}
if (tag.isGenerate()) {
@@ -483,8 +485,8 @@
return true;
}
- protected void verifyAttribute(PropertyBase attribute, FacesComponent component) {
- // Check name.
+ protected void verifyAttribute(PropertyBase attribute, FacesComponent component) {
+ // Check name.
if (Strings.isEmpty(attribute.getName())) {
log.error("No name for attribute " + attribute);
return;
@@ -498,6 +500,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())) {
@@ -514,9 +520,12 @@
// 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(null == attribute.getGenerate()){
- if(sourceUtils.isClassExists(component.getBaseClass())){
-
attribute.setGenerate(!sourceUtils.getBeanProperty(component.getBaseClass(),
attribute.getName()).isExists());
+ 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);
}