Author: alexsmirnov
Date: 2010-04-01 19:54:08 -0400 (Thu, 01 Apr 2010)
New Revision: 16705
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributeProcessor.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java
Log:
CODING IN PROGRESS - issue RF-8567: Cleanup Annotation processor code
https://jira.jboss.org/jira/browse/RF-8567
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributeProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributeProcessor.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributeProcessor.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -1,137 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright , Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.cdk.apt.processors;
-
-import com.google.common.collect.Lists;
-import org.richfaces.cdk.annotations.Attribute;
-import org.richfaces.cdk.annotations.EventName;
-import org.richfaces.cdk.annotations.Signature;
-import org.richfaces.cdk.apt.SourceUtils;
-import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.PropertyBase;
-import org.richfaces.cdk.util.Strings;
-
-import javax.lang.model.type.MirroredTypeException;
-import javax.lang.model.type.MirroredTypesException;
-import javax.lang.model.type.TypeMirror;
-import java.util.List;
-
-/**
- * @author akolonitsky
- * @since Mar 23, 2010
- */
-public class AttributeProcessor extends ProcessorBase {
-
- private static final String SIGNATURE_NONE_CLASS_NAME =
Signature.NONE.class.getName().replace('$', '.');
- private static final String STRING_NAME = String.class.getName();
-
- public void process(SourceUtils.BeanProperty beanProperty, PropertyBase attribute) {
-
- attribute.setType(beanProperty.getType());
-
- Attribute attributeAnnotarion = beanProperty.getAnnotation(Attribute.class);
- if (attributeAnnotarion == null) {
- attribute.setGenerate(!beanProperty.isExists());
- setDescription(attribute, null, beanProperty.getDocComment());
-
- } else {
- attribute.setHidden(attributeAnnotarion.hidden());
- attribute.setLiteral(attributeAnnotarion.literal());
- attribute.setPassThrough(attributeAnnotarion.passThrough());
- attribute.setRequired(attributeAnnotarion.required());
- attribute.setReadOnly(attributeAnnotarion.readOnly());
- attribute.setGenerate(attributeAnnotarion.generate() ||
!beanProperty.isExists());
-
- setDescription(attribute, attributeAnnotarion.description(),
beanProperty.getDocComment());
-
- String defaultValue = attributeAnnotarion.defaultValue();
- if (!Strings.isEmpty(defaultValue)) {
- if (STRING_NAME.equals(attribute.getType().toString())) {
- defaultValue = "\"" + defaultValue +
"\"";
- }
- attribute.setDefaultValue(defaultValue);
- }
-
-
- String suggestedValue = attributeAnnotarion.suggestedValue();
- if (!Strings.isEmpty(suggestedValue)) {
- attribute.setSuggestedValue(suggestedValue);
- }
-
- // MethodExpression call signature.
- attribute.setSignature(getSignature(attributeAnnotarion.signature()));
-
- for (EventName event : attributeAnnotarion.events()) {
- setBehaviorEvent(attribute, event);
- }
- }
- }
-
- private List<ClassName> getSignature(Signature signature) {
- if (signature == null) {
- return null;
- }
-
- String returnType;
- try {
- returnType = signature.returnType().getName();
- } catch (MirroredTypeException e) {
- TypeMirror returnTypeMirror = e.getTypeMirror();
- returnType = returnTypeMirror.toString();
- }
-
- if (signature != null && SIGNATURE_NONE_CLASS_NAME.equals(returnType)) {
- List<ClassName> parameters = Lists.newArrayList();
-
- try {
- for (Class<?> parameterType : signature.parameters()) {
- parameters.add(new ClassName(parameterType.getName()));
- }
- } catch (MirroredTypeException e) {
- TypeMirror parameterType = e.getTypeMirror();
- parameters.add(new ClassName(parameterType.toString()));
- } catch (MirroredTypesException e) {
- for (TypeMirror parameterType : e.getTypeMirrors()) {
- parameters.add(new ClassName(parameterType.toString()));
- }
- }
-
- return parameters;
- // signature parameters always should be replaced.
- // TODO - set method return type.
- }
-
- return null;
- }
-
- private void setBehaviorEvent(PropertyBase attribute, EventName eventName) {
- if (null != eventName) {
- org.richfaces.cdk.model.EventName event = new
org.richfaces.cdk.model.EventName();
-
- event.setName(eventName.value());
- event.setDefaultEvent(eventName.defaultEvent());
- attribute.getEventNames().add(event);
- }
- }
-
-}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessor.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessor.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ *
+ * 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.processors;
+
+import java.util.Collection;
+
+import javax.lang.model.element.TypeElement;
+
+import org.richfaces.cdk.model.BeanModelBase;
+import org.richfaces.cdk.model.PropertyBase;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface AttributesProcessor {
+
+ /**
+ * <p class="changed_added_4_0">
+ * Process attributes defined by the faces-config fragment.
+ * </p>
+ *
+ * @param attributesConfig
+ * relative URL to the fragment file.
+ * @return properties defined by that fragment.
+ */
+ public void processXmlFragment(BeanModelBase component,String ...attributesConfig);
+
+ /**
+ * <p class="changed_added_4_0">
+ * Process all bean properties associated with type element. Recursively visit all
supertypes and interfaces. For
+ * each type, tries to read xml fragment with same name as class or interface with
".xml" suffix, then collect all
+ * bean properties marked by the {@link Attribute} annotation
+ * </p>
+ *
+ * @param element
+ * @return
+ */
+ public void processType(BeanModelBase component,TypeElement element);
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java
(from rev 16704,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributeProcessor.java)
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -0,0 +1,217 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright , Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.cdk.apt.processors;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.Signature;
+import org.richfaces.cdk.apt.SourceUtils;
+import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
+import org.richfaces.cdk.apt.SourceUtils.SuperTypeVisitor;
+import org.richfaces.cdk.model.BeanModelBase;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.PropertyBase;
+import org.richfaces.cdk.util.Strings;
+import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
+import org.richfaces.cdk.xmlconfig.FragmentParser;
+
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.MirroredTypeException;
+import javax.lang.model.type.MirroredTypesException;
+import javax.lang.model.type.TypeMirror;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author akolonitsky
+ * @since Mar 23, 2010
+ */
+public class AttributesProcessorImpl implements AttributesProcessor {
+
+ private static final String SIGNATURE_NONE_CLASS_NAME =
Signature.NONE.class.getName().replace('$', '.');
+ private static final String STRING_NAME = String.class.getName();
+
+ private final DescriptionProcessor descriptionProcessor;
+ private final Provider<SourceUtils> utilsProvider;
+ private final FragmentParser parser;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param descriptionProcessor
+ */
+ @Inject
+ public AttributesProcessorImpl(DescriptionProcessor
descriptionProcessor,Provider<SourceUtils> utilsProvider,FragmentParser parser) {
+ this.descriptionProcessor = descriptionProcessor;
+ this.utilsProvider = utilsProvider;
+ this.parser = parser;
+ }
+
+ public void process(SourceUtils.BeanProperty beanProperty, PropertyBase attribute) {
+
+ attribute.setType(beanProperty.getType());
+
+ Attribute attributeAnnotarion = beanProperty.getAnnotation(Attribute.class);
+ if (attributeAnnotarion == null) {
+ attribute.setGenerate(!beanProperty.isExists());
+ attribute.setDescription(beanProperty.getDocComment());
+ } else {
+ attribute.setHidden(attributeAnnotarion.hidden());
+ attribute.setLiteral(attributeAnnotarion.literal());
+ attribute.setPassThrough(attributeAnnotarion.passThrough());
+ attribute.setRequired(attributeAnnotarion.required());
+ attribute.setReadOnly(attributeAnnotarion.readOnly());
+ attribute.setGenerate(attributeAnnotarion.generate() ||
!beanProperty.isExists());
+
+ descriptionProcessor.processDescription(attribute,
attributeAnnotarion.description(), beanProperty.getDocComment());
+
+ String defaultValue = attributeAnnotarion.defaultValue();
+ if (!Strings.isEmpty(defaultValue)) {
+ if (STRING_NAME.equals(attribute.getType().toString())) {
+ defaultValue = "\"" + defaultValue +
"\"";
+ }
+ attribute.setDefaultValue(defaultValue);
+ }
+
+
+ String suggestedValue = attributeAnnotarion.suggestedValue();
+ if (!Strings.isEmpty(suggestedValue)) {
+ attribute.setSuggestedValue(suggestedValue);
+ }
+
+ // MethodExpression call signature.
+ attribute.setSignature(getSignature(attributeAnnotarion.signature()));
+
+ for (EventName event : attributeAnnotarion.events()) {
+ setBehaviorEvent(attribute, event);
+ }
+ }
+ }
+
+ private List<ClassName> getSignature(Signature signature) {
+ if (signature == null) {
+ return null;
+ }
+
+ String returnType;
+ try {
+ returnType = signature.returnType().getName();
+ } catch (MirroredTypeException e) {
+ TypeMirror returnTypeMirror = e.getTypeMirror();
+ returnType = returnTypeMirror.toString();
+ }
+
+ if (signature != null && SIGNATURE_NONE_CLASS_NAME.equals(returnType)) {
+ List<ClassName> parameters = Lists.newArrayList();
+
+ try {
+ for (Class<?> parameterType : signature.parameters()) {
+ parameters.add(new ClassName(parameterType.getName()));
+ }
+ } catch (MirroredTypeException e) {
+ TypeMirror parameterType = e.getTypeMirror();
+ parameters.add(new ClassName(parameterType.toString()));
+ } catch (MirroredTypesException e) {
+ for (TypeMirror parameterType : e.getTypeMirrors()) {
+ parameters.add(new ClassName(parameterType.toString()));
+ }
+ }
+
+ return parameters;
+ // signature parameters always should be replaced.
+ // TODO - set method return type.
+ }
+
+ return null;
+ }
+
+ private void setBehaviorEvent(PropertyBase attribute, EventName eventName) {
+ if (null != eventName) {
+ org.richfaces.cdk.model.EventName event = new
org.richfaces.cdk.model.EventName();
+
+ event.setName(eventName.value());
+ event.setDefaultEvent(eventName.defaultEvent());
+ attribute.getEventNames().add(event);
+ }
+ }
+
+ @Override
+ public void processType(final BeanModelBase component,TypeElement element) throws
CdkException {
+
+ // Process XML files with standard attributes definitions.
+ SourceUtils sourceUtils = getSourceUtils();
+ ClassName componentClassName =
ClassName.parseName(element.getQualifiedName().toString());
+ sourceUtils.visitSupertypes(componentClassName, new SuperTypeVisitor() {
+
+ @Override
+ public void visit(ClassName type) {
+ try {
+ component.getAttributes().addAll(parseProperties(
+ CdkEntityResolver.URN_ATTRIBUTES + type.toString() +
".xml"));
+ } catch (CdkException e) {
+ // TODO - log errors ?
+ }
+ }
+
+ });
+
+
+ Set<BeanProperty> properties = Sets.newHashSet();
+ properties.addAll(sourceUtils.getBeanPropertiesAnnotatedWith(Attribute.class,
componentClassName));
+ properties.addAll(sourceUtils.getAbstractBeanProperties(componentClassName));
+ // TODO - encapsulate attribute builder into utility class.
+ for (BeanProperty beanProperty : properties) {
+ process(beanProperty,
component.getOrCreateAttribute(beanProperty.getName()));
+ }
+ }
+
+ private Collection<? extends PropertyBase> parseProperties(String uri) {
+ return parser.parseProperties(uri);
+ }
+
+ private SourceUtils getSourceUtils() {
+ return utilsProvider.get();
+ }
+
+
+ @Override
+ public void processXmlFragment(BeanModelBase component,String ...attributesConfig) {
+ // Process all files from @Jsf.. attributes property.
+ for (String attributes : attributesConfig) {
+ try {
+ component.getAttributes().addAll(parseProperties(
+ CdkEntityResolver.URN_ATTRIBUTES + attributes));
+ } catch (CdkException e) {
+ // TODO - log errors ?
+ }
+ }
+ }
+
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/BehaviorProcessor.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -23,16 +23,17 @@
package org.richfaces.cdk.apt.processors;
+import java.lang.annotation.Annotation;
+
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.element.TypeElement;
+
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.JsfBehavior;
import org.richfaces.cdk.model.BehaviorModel;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.lang.model.element.TypeElement;
-import java.lang.annotation.Annotation;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
@@ -49,7 +50,9 @@
setClassNames(element, behaviorModel, behavior.generate());
setTagInfo(behavior.tag(), behaviorModel);
- processAttributes(element, behaviorModel,behavior.attributes());
+ AttributesProcessor attributesProcessor = getAttributeProcessor();
+ attributesProcessor.processXmlFragment(behaviorModel, behavior.attributes());
+ attributesProcessor.processType(behaviorModel,element);
setDescription(behaviorModel, behavior.description(), getDocComment(element));
library.getBehaviors().add(behaviorModel);
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -23,8 +23,15 @@
package org.richfaces.cdk.apt.processors;
-import com.google.common.collect.Lists;
-import com.google.inject.Inject;
+import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.Set;
+
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.MirroredTypeException;
+import javax.lang.model.type.MirroredTypesException;
+import javax.lang.model.type.TypeMirror;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.annotations.Event;
import org.richfaces.cdk.annotations.Facet;
@@ -40,13 +47,8 @@
import org.richfaces.cdk.model.FacetModel;
import org.richfaces.cdk.util.Strings;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.MirroredTypeException;
-import javax.lang.model.type.MirroredTypesException;
-import javax.lang.model.type.TypeMirror;
-import java.lang.annotation.Annotation;
-import java.util.List;
-import java.util.Set;
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">
@@ -77,8 +79,9 @@
// Should that component be generated ?
setClassNames(componentElement, component, annotation.generate());
setComponentProperties(componentElement, component, annotation, library);
+ // Process the second level annotations.
for (final SubComponent subcomponent : annotation.components()) {
- JsfComponent subAnnotation = new JsfSubComponent(subcomponent,
annotation.family());
+ JsfComponent subAnnotation = new JsfSubComponent(subcomponent, annotation);
ComponentModel subcomponentModel = new ComponentModel();
subcomponentModel.setBaseClass(component.getTargetClass());
subcomponentModel.setTargetClass(ClassName.parseName(subcomponent.generate()));
@@ -87,6 +90,14 @@
library.getComponents().add(component);
}
+ /**
+ * <p class="changed_added_4_0">process annotation and set component
model properties.</p>
+ * @param componentElement
+ * @param component
+ * @param annotation
+ * @param library
+ * @throws CdkException
+ */
void setComponentProperties(TypeElement componentElement, ComponentModel component,
JsfComponent annotation, ComponentLibrary library) throws CdkException {
@@ -97,6 +108,11 @@
processFacets(componentElement, component, annotation);
processEvents(componentElement, component, annotation);
+ AttributesProcessor attributesProcessor = getAttributeProcessor();
+ attributesProcessor.processXmlFragment(component, annotation.attributes());
+ if(null != componentElement){
+ attributesProcessor.processType(component,componentElement);
+ }
// TODO - process interfaces() attribute.
List<ClassName> interfaceNames = Lists.newArrayList();
try {
@@ -107,12 +123,12 @@
} catch (MirroredTypesException e) {
List<? extends TypeMirror> typeMirrors = e.getTypeMirrors();
for (TypeMirror mirror : typeMirrors) {
+ interfaceNames.add(ClassName.parseName(mirror.toString()));
// TODO call processAttributes with element from type mirror.
- interfaceNames.add(ClassName.parseName(mirror.toString()));
+// attributesProcessor.processType(component,mirror.);
}
}
- processAttributes(componentElement, component, annotation.attributes());
-
+ // TODO - store interfaces in the model.
for (Tag tag : annotation.tag()) {
setTagInfo(tag, component);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ConverterProcessor.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -61,7 +61,9 @@
setDescription(converterModel, converter.description(), getDocComment(element));
- processAttributes(element, converterModel,converter.attributes());
+ AttributesProcessor attributesProcessor = getAttributeProcessor();
+ attributesProcessor.processXmlFragment(converterModel, converter.attributes());
+ attributesProcessor.processType(converterModel,element);
setClassNames(element, converterModel, converter.generate());
setTagInfo(converter.tag(), converterModel);
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ *
+ * 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.processors;
+
+import org.richfaces.cdk.annotations.Description;
+import org.richfaces.cdk.model.DescriptionGroup;
+
+/**
+ * <p class="changed_added_4_0">Implementation of that interface process
{@link Description} annotation and set information from it into model.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface DescriptionProcessor {
+
+ /**
+ * <p class="changed_added_4_0">process {@link Description}
annotation and set information from it into model. Optional string from the JavaDoc
comment has precedence over {@link Desription#value()} attribute.</p>
+ * @param model
+ * @param description
+ * @param docComment JavaDoc comment associated with described element.
+ */
+ public void processDescription(DescriptionGroup model,Description description,String
docComment);
+
+ /**
+ * <p class="changed_added_4_0">process {@link Description}
annotation and set information from it into model.</p>
+ * @param model
+ * @param description
+ */
+ public void processDescription(DescriptionGroup model,Description description);
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * 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.processors;
+
+import org.richfaces.cdk.annotations.Description;
+import org.richfaces.cdk.model.DescriptionGroup;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class DescriptionProcessorImpl implements DescriptionProcessor {
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.apt.processors.DescriptionProcessor#processDescription(org.richfaces.cdk.model.DescriptionGroup,
org.richfaces.cdk.annotations.Description, java.lang.String)
+ */
+ @Override
+ public void processDescription(DescriptionGroup model, Description description,
String docComment) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.apt.processors.DescriptionProcessor#processDescription(org.richfaces.cdk.model.DescriptionGroup,
org.richfaces.cdk.annotations.Description)
+ */
+ @Override
+ public void processDescription(DescriptionGroup model, Description description) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/DescriptionProcessorImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/JsfSubComponent.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -22,6 +22,8 @@
package org.richfaces.cdk.apt.processors;
+import java.lang.annotation.Annotation;
+
import org.richfaces.cdk.annotations.Description;
import org.richfaces.cdk.annotations.Event;
import org.richfaces.cdk.annotations.Facet;
@@ -31,21 +33,22 @@
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.Test;
-import java.lang.annotation.Annotation;
-
/**
+ * This calss wraps {@link SubComponent} annotation so it would be used by {@link
ComponentProcessor} methods, so they
+ * can be reused for different types of the component annotations.
+ *
* @author akolonitsky
* @since Mar 31, 2010
*/
public class JsfSubComponent implements JsfComponent {
- private SubComponent subcomponent;
+ private final SubComponent subcomponent;
- private String family;
+ private final JsfComponent parent;
- public JsfSubComponent(SubComponent subcomponent, String family) {
+ public JsfSubComponent(SubComponent subcomponent, JsfComponent parent) {
this.subcomponent = subcomponent;
- this.family = family;
+ this.parent = parent;
}
@Override
@@ -90,7 +93,7 @@
@Override
public String family() {
- return this.family;
+ return this.parent.family();
}
@Override
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -1,50 +1,29 @@
package org.richfaces.cdk.apt.processors;
-import com.google.common.collect.Sets;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.NamingConventions;
-import org.richfaces.cdk.annotations.Attribute;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+
import org.richfaces.cdk.annotations.Description;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.apt.SourceUtils;
-import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
-import org.richfaces.cdk.apt.SourceUtils.SuperTypeVisitor;
-import org.richfaces.cdk.model.BeanModelBase;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.DescriptionGroup;
import org.richfaces.cdk.model.ModelElementBase;
-import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.TagModel;
import org.richfaces.cdk.util.Strings;
-import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
-import org.richfaces.cdk.xmlconfig.FragmentParser;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.TypeElement;
-import java.util.Collection;
-import java.util.Set;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
public abstract class ProcessorBase {
@Inject
private Provider<SourceUtils> sourceUtils;
- @Inject
- private FragmentParser fragmentParser;
@Inject
- private AttributeProcessor attributeProcessor;
+ private AttributesProcessor attributeProcessor;
- @Inject
- private NamingConventions namingConventions;
-
-
- public FragmentParser getFragmentParser() {
- return this.fragmentParser;
- }
-
public SourceUtils getSourceUtils() {
return this.sourceUtils.get();
}
@@ -53,10 +32,9 @@
TagModel tagModel = new TagModel();
String name = tag.name();
- if (Strings.isEmpty(name)) {
- name = getNamingConventions().inferTagName(model.getId());
+ if (!Strings.isEmpty(name)) {
+ tagModel.setName(name);
}
- tagModel.setName(name);
tagModel.setTargetClass(ClassName.parseName(tag.handler()));
tagModel.setType(tag.type());
tagModel.setBaseClass(ClassName.parseName(tag.baseClass()));
@@ -109,9 +87,6 @@
modelElement.setBaseClass(ClassName.parseName(componentElement.getQualifiedName().toString()));
}
- protected Collection<PropertyBase> parseProperties(String attributesConfig) {
- return getFragmentParser().parseProperties(CdkEntityResolver.URN_ATTRIBUTES +
attributesConfig + ".xml");
- }
protected ClassName asClassDesctiption(TypeElement componentElement) {
return new ClassName(componentElement.getQualifiedName().toString());
@@ -121,48 +96,12 @@
return null != componentElement ?
getSourceUtils().getDocComment(asClassDesctiption(componentElement)) : null;
}
- protected void processAttributes(TypeElement componentElement, final BeanModelBase
component, String[] annotationAttributes) throws CdkException {
-
- // Process XML files with standard attributes definitions.
- SourceUtils sourceUtils = getSourceUtils();
- ClassName componentClassName = asClassDesctiption(componentElement);
- sourceUtils.visitSupertypes(componentClassName, new SuperTypeVisitor() {
-
- @Override
- public void visit(ClassName type) {
- try {
- component.getAttributes().addAll(parseProperties(
- CdkEntityResolver.URN_ATTRIBUTES + type.toString() +
".xml"));
- } catch (CdkException e) {
- // TODO - log errors ?
- }
- }
- });
-
- // Process all files from @Jsf.. attributes property.
- for (String attributes : annotationAttributes) {
- try {
- component.getAttributes().addAll(parseProperties(
- CdkEntityResolver.URN_ATTRIBUTES + attributes));
- } catch (CdkException e) {
- // TODO - log errors ?
- }
- }
-
- Set<BeanProperty> properties = Sets.newHashSet();
- properties.addAll(sourceUtils.getBeanPropertiesAnnotatedWith(Attribute.class,
componentClassName));
- properties.addAll(sourceUtils.getAbstractBeanProperties(componentClassName));
- // TODO - encapsulate attribute builder into utility class.
- for (BeanProperty beanProperty : properties) {
- attributeProcessor.process(beanProperty,
component.getOrCreateAttribute(beanProperty.getName()));
- }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the attributeProcessor
+ */
+ protected AttributesProcessor getAttributeProcessor() {
+ return this.attributeProcessor;
}
- public NamingConventions getNamingConventions() {
- return namingConventions;
- }
-
- public void setNamingConventions(NamingConventions namingConventions) {
- this.namingConventions = namingConventions;
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -108,7 +108,7 @@
}
private void setComponentType(RendererModel rendererModel) {
- getNamingConventions().inferComponentType(rendererModel.getFamily());
+// getNamingConventions().inferComponentType(rendererModel.getFamily());
}
private void addToRenderKit(JsfRenderer annotation, ComponentLibrary library,
RendererModel rendererModel) {
@@ -154,8 +154,8 @@
return;
}
- rendererModel.setFamily(getNamingConventions()
-
.inferComponentFamilyByRendererClass(rendererElement.getQualifiedName().toString()));
+// rendererModel.setFamily(getNamingConventions()
+//
.inferComponentFamilyByRendererClass(rendererElement.getQualifiedName().toString()));
}
private String getRendererType(TypeElement rendererElement, JsfRenderer annotation)
{
@@ -169,7 +169,7 @@
return value.toString();
}
- return
getNamingConventions().inferRendererTypeByRendererClass(asClassDesctiption(rendererElement));
+ return
null;//getNamingConventions().inferRendererTypeByRendererClass(asClassDesctiption(rendererElement));
}
private void setRendererType(TypeElement rendererElement, RendererModel
rendererModel, JsfRenderer annotation) {
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java 2010-04-01
14:21:35 UTC (rev 16704)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/ComponentProcessorTest.java 2010-04-01
23:54:08 UTC (rev 16705)
@@ -274,37 +274,6 @@
assertNull(facetModel.getIcon());
}
- @Test
- public void testProcessAttributesFromProperty() throws Exception {
- Attribute attribute = createNiceMock(Attribute.class);
- expect(componentElement.getQualifiedName()).andStubReturn(new
TestName(FOO_BAR));
- utils.visitSupertypes(eq(ClassName.parseName(FOO_BAR)), (SuperTypeVisitor)
anyObject());expectLastCall();
-
expect(utils.getBeanPropertiesAnnotatedWith(eq(Attribute.class),eq(ClassName.parseName(FOO_BAR)))).andReturn(Collections.singleton(property));
-
expect(utils.getAbstractBeanProperties(eq(ClassName.parseName(FOO_BAR)))).andReturn(Collections.<BeanProperty>emptySet());
- expect(property.getName()).andReturn("foo");
-
expect(property.getType()).andReturn(ClassName.parseName("java.lang.Integer"));
- expect(property.getAnnotation(Attribute.class)).andReturn(attribute);
- expect(property.getDocComment()).andReturn("my comment");
-// expect(property.isExists()).andReturn(true);
- expect(attribute.description()).andReturn(this.description);
- expect(attribute.generate()).andReturn(true);
- expect(attribute.events()).andReturn(new EventName[]{});
- expect(this.description.smallIcon()).andReturn("");
- expect(this.description.largeIcon()).andReturn("");
- expect(this.description.displayName()).andReturn("fooFacet").times(2);
- expect(this.description.value()).andReturn("");
- replay(log, utils, componentElement, jaxb,
annotation,property,attribute,description);
- processor.processAttributes(componentElement, model,new String[0]);
- verify(log, utils, componentElement,
jaxb,annotation,property,attribute,description);
- assertEquals(1, model.getAttributes().size());
- PropertyBase propertyModel = Iterables.getOnlyElement(model.getAttributes());
- assertTrue(propertyModel.isGenerate());
- assertEquals("foo", propertyModel.getName());
- assertEquals("my comment", propertyModel.getDescription());
- assertEquals("fooFacet", propertyModel.getDisplayname());
- assertEquals(ClassName.parseName("java.lang.Integer"),
propertyModel.getType());
- assertNull(propertyModel.getIcon());
- }
@Override
protected Iterable<String> sources() {