Author: alexsmirnov
Date: 2009-08-10 20:35:58 -0400 (Mon, 10 Aug 2009)
New Revision: 15154
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/NamingConventions.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/PropertyUtils.java
root/cdk/trunk/plugins/generator/src/main/javadoc/generatedClasses.png
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/NamingConventions.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/AbstractCdkContext.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContext.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/JsfType.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/TagLibrary.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ProcessorTest.java
Log:
Parse attributes annotations.
Move naming conventions to CdkContext
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/AbstractCdkContext.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/AbstractCdkContext.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/AbstractCdkContext.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -43,7 +43,7 @@
private File resourceOutput;
- private String baseName;
+ private NamingConventions namingConventions;
/**
* <p class="changed_added_4_0"></p>
@@ -108,17 +108,21 @@
return loader;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the namingConventions
+ */
@Override
- public String getBaseName() {
- return this.baseName;
+ public NamingConventions getNamingConventions() {
+ return namingConventions;
}
/**
* <p class="changed_added_4_0"></p>
- * @param baseName the baseName to set
+ * @param namingConventions the namingConventions to set
*/
- public void setBaseName(String baseName) {
- this.baseName = baseName;
+ public void setNamingConventions(NamingConventions namingConventions) {
+ this.namingConventions = namingConventions;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContext.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContext.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContext.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -3,6 +3,7 @@
import java.io.File;
+
/**
* <p class="changed_added_4_0">
* That interface defines context for all CDK operations
@@ -50,14 +51,9 @@
public abstract File getJavaSource();
/**
- * <p class="changed_added_4_0">
- * Base name for generated JSF library, as described in the CDK <a href=
- * "http://www.jboss.org/community/wiki/RichFacesCDKnamingconventions"
- * >naming conventions</a>
- * </p>
- *
+ * <p class="changed_added_4_0"></p>
* @return
*/
- public String getBaseName();
+ public NamingConventions getNamingConventions();
}
\ No newline at end of file
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -101,7 +101,7 @@
* @return
*/
public ComponentLibrary createLibrary(){
- return new ComponentLibrary(getContext().getBaseName());
+ return new ComponentLibrary();
}
/**
Copied:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/NamingConventions.java
(from rev 15150,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/NamingConventions.java)
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/NamingConventions.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/NamingConventions.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -0,0 +1,70 @@
+/*
+ * $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;
+
+import org.richfaces.cdk.model.ClassDescription;
+import org.richfaces.cdk.model.Component;
+import org.richfaces.cdk.model.InvalidNameException;
+import org.richfaces.cdk.model.Component.Type;
+
+/**
+ * <p class="changed_added_4_0">
+ * That interface defines methods that calculates names according to <a
+ *
href="http://www.jboss.org/community/docs/DOC-13693">CDK naming
+ * conventions</>
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface NamingConventions {
+
+ /**
+ * <p class="changed_added_4_0">Calculates component type from explicit
value or base class name.</p>
+ * <ul>
+ *
<li><code><prefix>.component.Abstract<Name></code>
=> <code><prefix>.<Name></code>
</li>
+ *
<li><code><prefix>.component.<Name>Base</code>
=> <code><prefix>.<Name></code>
</li>
+ *
<li><code><prefix>.component.UI<Name></code>
=> <code><prefix>.<Name></code>
</li>
+ * </ul>
+ * @param explicitType
+ * @param className
+ * @return
+ * @throws InvalidNameException if className does not match naming conventions.
+ */
+ public String inferComponentType(String explicitType, String className) throws
InvalidNameException;
+
+ /**
+ * <p class="changed_added_4_0">Calculates concrete component class from
explicit value or type.</p>
+ * <ul>
+ * <li>Use explicit class name if it was provided by developer.</li>
+ * <li>Calculate name from type as
<code><prefix>.<Name></code> =>
<code><prefix>.component.UI<Name></code> for an
abstract class.</li>
+ * <li>Use base class name if concrete class should not be generated.
+ * </ul>
+ * @param explicitClass
+ * @param className
+ * @return
+ */
+ public String inferUIComponentClass(String componentType, String explicitClass, String
baseClass, boolean baseClassIsAbstract) throws InvalidNameException;
+
+}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -0,0 +1,115 @@
+package org.richfaces.cdk;
+
+import org.richfaces.cdk.model.ClassDescription;
+import org.richfaces.cdk.model.Component;
+import org.richfaces.cdk.model.InvalidNameException;
+import org.richfaces.cdk.model.Name;
+import org.richfaces.cdk.model.Component.Type;
+import org.richfaces.cdk.model.Name.Classifier;
+import org.richfaces.cdk.util.Strings;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+final class RichFacesConventions implements NamingConventions {
+
+ private static final String ABSTRACT = "Abstract";
+ private static final String UI = "UI";
+ private static final String BASE = "Base";
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ */
+ private final String baseName;
+
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param componentLibrary
+ */
+ RichFacesConventions(String baseName) {
+ this.baseName = baseName;
+ }
+
+
+ private final String[] COMPONENT_SUFFIXES = { BASE };
+ private final String[] COMPONENT_PREFIXES = { UI, ABSTRACT };
+
+ @Override
+ public String inferComponentType(String explicitType, String className)
+ throws InvalidNameException {
+ // check parameters.
+ if (Strings.isEmpty(explicitType)) {
+ if (Strings.isEmpty(className)) {
+ throw new IllegalArgumentException();
+ }
+ Name name = Name.create(className);
+ // Use base library prefix.
+ name.setPrefix(this.getBaseName());
+ // Component type does not contain class or markup parts.
+ name.setClassifier(null);
+ name.setMarkup(null);
+ String simpleName = name.getSimpleName();
+ // Remove common prefixes.
+ for (int i = 0; i < COMPONENT_PREFIXES.length; i++) {
+ if (simpleName.startsWith(COMPONENT_PREFIXES[i])) {
+ simpleName = simpleName.substring(COMPONENT_PREFIXES[i]
+ .length());
+ break;
+ }
+ }
+ // Remove common suffixes.
+ for (int i = 0; i < COMPONENT_SUFFIXES.length; i++) {
+ if (simpleName.endsWith(COMPONENT_SUFFIXES[i])) {
+ simpleName = simpleName.substring(0, simpleName
+ .length()
+ - COMPONENT_SUFFIXES[i].length());
+ break;
+ }
+ }
+ name.setSimpleName(simpleName);
+ return name.toString();
+ } else {
+ return explicitType;
+ }
+ }
+
+
+ @Override
+ public String inferUIComponentClass(String componentType,
+ String explicitClass, String baseClass, boolean baseClassIsAbstract)
+ throws InvalidNameException {
+ String className;
+ if(!Strings.isEmpty(explicitClass)){
+ // Class name provided by developer.
+ className = explicitClass;
+ } else if (baseClassIsAbstract || baseClass.startsWith(ABSTRACT)||
baseClass.endsWith(BASE)) {
+ // Infer UI class name from component type.
+ Name name = Name.create(componentType);
+ name.setClassifier(Classifier.component);
+ name.setMarkup(null);
+ name.setSimpleName(UI+name.getSimpleName());
+ className = name.toString();
+ } else {
+ // Do not generate class, use base name.
+ className = baseClass;
+ }
+ return className;
+ }
+
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the baseName
+ */
+ protected String getBaseName() {
+ return baseName;
+ }
+
+
+
+}
\ No newline at end of file
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -24,6 +24,7 @@
package org.richfaces.cdk.apt;
import java.lang.annotation.Annotation;
+import java.util.List;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
@@ -32,9 +33,16 @@
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.ElementFilter;
import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.model.InvalidNameException;
+import org.richfaces.cdk.util.PropertyUtils;
import com.google.common.collect.Sets;
@@ -50,13 +58,99 @@
public abstract class CdkProcessor extends AbstractProcessor {
/**
- * <p class="changed_added_4_0">CDK context.</p>
- */
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+ protected final class BeanProperty {
+
+ private TypeMirror type;
+
+ private Element element;
+
+ private final String name;
+
+ private boolean exists;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ BeanProperty other = (BeanProperty) obj;
+ if (!getOuterType().equals(other.getOuterType()))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param name
+ */
+ public BeanProperty(String name) {
+ this.name = name;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ private CdkProcessor getOuterType() {
+ return CdkProcessor.this;
+ }
+
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * CDK context.
+ * </p>
+ */
protected final CdkContext context;
/**
- * <p class="changed_added_4_0"></p>
- * @param context current CDK context
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param context
+ * current CDK context
*/
protected CdkProcessor(CdkContext context) {
super();
@@ -80,14 +174,22 @@
}
/**
- * <p class="changed_added_4_0">Get all classes annotated with
particular annotation.</p>
- * @param annotation annotation class.
- * @param round current round environment.
- * @return {@link Set} of all classes annotated with {@code annotation} type.
+ * <p class="changed_added_4_0">
+ * Get all classes annotated with particular annotation.
+ * </p>
+ *
+ * @param annotation
+ * annotation class.
+ * @param round
+ * current round environment.
+ * @return {@link Set} of all classes annotated with {@code annotation}
+ * type.
*/
- protected Set<? extends TypeElement> getClassesAnnotatedWith(Class<? extends
Annotation> annotation,RoundEnvironment round){
+ protected Set<? extends TypeElement> getClassesAnnotatedWith(
+ Class<? extends Annotation> annotation, RoundEnvironment round) {
Set<TypeElement> classes = Sets.newHashSet();
- Set<? extends Element> annotatedWith =
round.getElementsAnnotatedWith(annotation);
+ Set<? extends Element> annotatedWith = round
+ .getElementsAnnotatedWith(annotation);
for (Element element : annotatedWith) {
if (ElementKind.CLASS.equals(element.getKind())) {
TypeElement classElement = (TypeElement) element;
@@ -96,4 +198,66 @@
}
return classes;
}
+
+ /**
+ * <p class="changed_added_4_0">
+ * Get all fields and bean properties that are annotated with given
+ * annotation.
+ * </p>
+ *
+ * @param annotation
+ * @param type
+ * @return
+ */
+ protected Set<BeanProperty> getBeanPropertiesAnnotatedWith(
+ Class<? extends Annotation> annotation, TypeElement type) {
+ Set<BeanProperty> properties = Sets.newHashSet();
+ List<ExecutableElement> methodsIn = ElementFilter
+ .methodsIn(this.processingEnv.getElementUtils().getAllMembers(
+ type));
+ // Get all methods and fields annotated by annotation.
+ for (ExecutableElement executableElement : methodsIn) {
+ if (null != executableElement.getAnnotation(annotation)) {
+ // Have an annotation, infer property name.
+ String name;
+ TypeMirror propertyType;
+ if (ElementKind.METHOD.equals(executableElement.getKind())) {
+ propertyType = executableElement.getReturnType();
+ List<? extends VariableElement> parameters = executableElement
+ .getParameters();
+ if (TypeKind.VOID.equals(propertyType.getKind())
+ && 1 == parameters.size()) {
+ // 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 ?
+ continue;
+ }
+ try {
+ name = PropertyUtils
+ .methodToName(executableElement.getSimpleName()
+ .toString());
+ } catch (InvalidNameException e) {
+ // TODO Invalid method name for a bean property, throw
+ // exception ?
+ continue;
+ }
+
+ } else if (ElementKind.FIELD
+ .equals(executableElement.getKind())) {
+ name = executableElement.getSimpleName().toString();
+ propertyType = executableElement.asType();
+ } else {
+ continue;
+ }
+ BeanProperty property = new BeanProperty(name);
+ property.type = propertyType;
+ property.element = executableElement;
+ // TODO - merge properties with same name ?
+ properties.add(property);
+ }
+ }
+ return properties;
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -29,13 +29,17 @@
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.Element;
+import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.NamingConventions;
import org.richfaces.cdk.annotations.Component;
+import org.richfaces.cdk.annotations.Family;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.InvalidNameException;
-import org.richfaces.cdk.model.NamingConventions;
+import org.richfaces.cdk.model.Component.Type;
+import org.richfaces.cdk.util.Strings;
/**
* <p class="changed_added_4_0"></p>
@@ -64,19 +68,22 @@
RoundEnvironment roundEnv) {
if(null != annotations && !annotations.isEmpty()){
ComponentLibrary library = getLibrary();
- NamingConventions namingUtils = library.getNamingUtils();
+ NamingConventions namingUtils = getContext().getNamingConventions();
// Process all component classes.
Set<? extends TypeElement> componentClasses =
getClassesAnnotatedWith(Component.class, roundEnv);
for (TypeElement component : componentClasses) {
try {
// Process class-level annotations.
- // Calculate type
+ // Calculate type for base UI component class.
Component componentAnnotation = component.getAnnotation(Component.class);
- String componentType =
namingUtils.inferComponentType(componentAnnotation.type(),component.getQualifiedName().toString());
+ String baseClassName = component.getQualifiedName().toString();
+ String componentType =
namingUtils.inferComponentType(componentAnnotation.type(),baseClassName);
+ String uiComponentClass = namingUtils.inferUIComponentClass(componentType,
componentAnnotation.className(), baseClassName,
component.getModifiers().contains(Modifier.ABSTRACT));
org.richfaces.cdk.model.Component componentModel = library
- .getComponent(componentType, true);
- // Calculate classes.
- String componentClassName = componentAnnotation.className();
+ .createComponent(componentType, uiComponentClass, baseClassName);
+ // Component Family.
+ Family family = component.getAnnotation(Family.class);
+ componentModel.setFamily(Strings.isEmpty(family.value())?componentType:family.value());
// Process attributes.
} catch (InvalidNameException e) {
// rise error and continue.
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -23,49 +23,58 @@
package org.richfaces.cdk.model;
+import com.google.common.collect.ImmutableMap;
+
/**
- * <p class="changed_added_4_0">Tthat class represents information about
Jsf object class.</p>
+ * <p class="changed_added_4_0">
+ * Tthat class represents information about Jsf object class.
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
public class ClassDescription {
-
+
+ private static final ImmutableMap<String, String> primitiveTypes = ImmutableMap
+ .<String, String> builder().put(boolean.class.getName(),
+ Boolean.class.getName()).put(byte.class.getName(),
+ Byte.class.getName()).put(char.class.getName(),
+ Character.class.getName()).put(short.class.getName(),
+ Short.class.getName()).put(int.class.getName(),
+ Integer.class.getName()).put(long.class.getName(),
+ Long.class.getName()).put(float.class.getName(),
+ Float.class.getName()).put(double.class.getName(),
+ Double.class.getName()).build();
+
private final String name;
-
- private boolean exists;
-
- private boolean primitive;
-
- private String boxingClassName;
-
+
+ private final boolean primitive;
+
+ private final String boxingClassName;
+
private ClassDescription superClass;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @param name
*/
public ClassDescription(String name) {
this.name = name;
+ if (primitiveTypes.containsKey(name)) {
+ boxingClassName = primitiveTypes.get(name);
+ primitive = true;
+ } else {
+ boxingClassName = name;
+ primitive = false;
+ }
}
/**
- * <p class="changed_added_4_0"></p>
- * @return the exists
- */
- public boolean isExists() {
- return exists;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param exists the exists to set
- */
- public void setExists(boolean exists) {
- this.exists = exists;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the superClass
*/
public ClassDescription getSuperClass() {
@@ -73,15 +82,20 @@
}
/**
- * <p class="changed_added_4_0"></p>
- * @param superClass the superClass to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param superClass
+ * the superClass to set
*/
public void setSuperClass(ClassDescription superClass) {
this.superClass = superClass;
}
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the name
*/
public String getName() {
@@ -89,7 +103,9 @@
}
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the primitive
*/
public boolean isPrimitive() {
@@ -97,28 +113,18 @@
}
/**
- * <p class="changed_added_4_0"></p>
- * @param primitive the primitive to set
- */
- public void setPrimitive(boolean primitive) {
- this.primitive = primitive;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the boxingClassName
*/
- public String getBoxingClassName() {
- return primitive?boxingClassName:name;
+ public String getBoxingName() {
+ return boxingClassName;
}
- /**
- * <p class="changed_added_4_0"></p>
- * @param boxingClassName the boxingClassName to set
- */
- public void setBoxingClassName(String boxingClassName) {
- this.boxingClassName = boxingClassName;
+ @Override
+ public String toString() {
+ return name;
}
-
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
+import org.richfaces.cdk.model.Component.Type;
import org.richfaces.cdk.util.Strings;
import com.google.common.collect.Maps;
@@ -56,64 +57,6 @@
/**
* <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
- final class RichFacesConventions implements NamingConventions {
- private final String[] COMPONENT_SUFFIXES = { "Base" };
- private final String[] COMPONENT_PREFIXES = { "UI", "Abstract" };
-
- @Override
- public String inferComponentType(String explicitType, String className)
- throws InvalidNameException {
- // check parameters.
- if (Strings.isEmpty(explicitType)) {
- if (Strings.isEmpty(className)) {
- throw new IllegalArgumentException();
- }
- Name name = Name.create(className);
- // Use base library prefix.
- name.setPrefix(getBaseName());
- // Component type does not contain class or markup parts.
- name.setClassifier(null);
- name.setMarkup(null);
- String simpleName = name.getSimpleName();
- // Remove common prefixes.
- for (int i = 0; i < COMPONENT_PREFIXES.length; i++) {
- if (simpleName.startsWith(COMPONENT_PREFIXES[i])) {
- simpleName = simpleName.substring(COMPONENT_PREFIXES[i]
- .length());
- break;
- }
- }
- // Remove common suffixes.
- for (int i = 0; i < COMPONENT_SUFFIXES.length; i++) {
- if (simpleName.endsWith(COMPONENT_SUFFIXES[i])) {
- simpleName = simpleName.substring(0, simpleName
- .length()
- - COMPONENT_SUFFIXES[i].length());
- break;
- }
- }
- name.setSimpleName(simpleName);
- return name.toString();
- } else {
- return explicitType;
- }
- }
-
- @Override
- public String inferUIComponentClass(String explicitClass, String componentType) {
- // TODO Auto-generated method stub
- return null;
- }
-
- }
-
- /**
- * <p class="changed_added_4_0">
* JSF components in that library
* </p>
*/
@@ -144,13 +87,7 @@
*/
private final TagLibrary tagLibrary;
- /**
- * <p class="changed_added_4_0">
- * </p>
- */
- private final String baseName;
- private NamingConventions namingConventions = new RichFacesConventions();
/**
* <p class="changed_added_4_0">
@@ -158,9 +95,8 @@
*
* @param baseName
*/
- public ComponentLibrary(String baseName) {
- this.baseName = baseName;
- this.tagLibrary = new TagLibrary(baseName);
+ public ComponentLibrary() {
+ this.tagLibrary = new TagLibrary();
}
/**
@@ -191,7 +127,7 @@
* created
* </p>
*
- * @param type
+ * @param componentType2
* @param create
* @return
*/
@@ -206,6 +142,31 @@
}
/**
+ * <p class="changed_added_4_0">Create a new component
description.</p>
+ * @param type component type.
+ * @param className final component class name.
+ * @param superClassName name of the component superclass. May be empty or null for
already existed components.
+ * @return
+ */
+ public Component createComponent(String type, String className, String superClassName)
{
+ Component component = getComponent(type, true);
+ ClassDescription componentClass;
+ if(!Strings.isEmpty(className)){
+ componentClass = new ClassDescription(className);
+ if(!Strings.isEmpty(superClassName) && !className.equals(superClassName)){
+ componentClass.setSuperClass(new ClassDescription(superClassName));
+ }
+ } else if(!Strings.isEmpty(superClassName)) {
+ componentClass = new ClassDescription(superClassName);
+ } else {
+ // Do not modify class descriptions because it would be already existed component.
+ return component;
+ }
+ component.setComponentClass(componentClass);
+ return component;
+ }
+
+ /**
* <p class="changed_added_4_0">
* </p>
*
@@ -265,18 +226,5 @@
return tagLibrary;
}
- public NamingConventions getNamingUtils() {
- return namingConventions;
- }
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the baseName
- */
- protected String getBaseName() {
- return baseName;
- }
-
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/JsfType.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/JsfType.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/JsfType.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -40,6 +40,14 @@
this.type = type;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
@Override
public String toString() {
return type;
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/NamingConventions.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/NamingConventions.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/NamingConventions.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -1,63 +0,0 @@
-/*
- * $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.model;
-
-/**
- * <p class="changed_added_4_0">
- * That interface defines methods that calculates names according to <a
- *
href="http://www.jboss.org/community/docs/DOC-13693">CDK naming
- * conventions</>
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public interface NamingConventions {
-
- /**
- * <p class="changed_added_4_0">Calculates component type from explicit
value or base class name.</p>
- * <ul>
- *
<li><code><prefix>.component.Abstract<Name></code>
=> <code><prefix>.<Name></code>
</li>
- *
<li><code><prefix>.component.<Name>Base</code>
=> <code><prefix>.<Name></code>
</li>
- *
<li><code><prefix>.component.UI<Name></code>
=> <code><prefix>.<Name></code>
</li>
- * </ul>
- * @param explicitType
- * @param className
- * @return
- * @throws InvalidNameException if className does not match naming conventions.
- */
- public String inferComponentType(String explicitType, String className) throws
InvalidNameException;
-
- /**
- * <p class="changed_added_4_0">Calculates concrete component class from
explicit value or type.</p>
- * <ul>
- * <li><code><prefix>.<Name></code>
=> <code><prefix>.component.UI<Name></code>
</li>
- * </ul>
- * @param explicitClass
- * @param className
- * @return
- */
- public String inferUIComponentClass(String explicitClass, String componentType);
-
-}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/TagLibrary.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/TagLibrary.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/TagLibrary.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -38,12 +38,6 @@
*/
private final List<Tag> tags = new ArrayList<Tag>();
- private final String baseName;
-
- public TagLibrary(String baseName) {
- this.baseName = baseName;
- }
-
/**
* <p class="changed_added_4_0"></p>
* @return the tags
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/PropertyUtils.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/PropertyUtils.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/PropertyUtils.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -0,0 +1,46 @@
+/*
+ * $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.util;
+
+import org.richfaces.cdk.model.InvalidNameException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class PropertyUtils {
+
+ public static String methodToName(String methodName) throws InvalidNameException {
+ if(null != methodName ){
+ if(methodName.length()>3 && Character.isUpperCase(methodName.charAt(3))
&&(methodName.startsWith("set")||methodName.startsWith("get"))){
+ return Strings.firstToLowerCase(methodName.substring(3));
+ } else if(methodName.length()>2 &&
Character.isUpperCase(methodName.charAt(2)) &&
methodName.startsWith("is")) {
+ return Strings.firstToLowerCase(methodName.substring(2));
+ }
+ }
+ throw new InvalidNameException("Method name "+methodName+" is not valid
bean property getter or setter");
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/PropertyUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/trunk/plugins/generator/src/main/javadoc/generatedClasses.png
===================================================================
(Binary files differ)
Property changes on:
root/cdk/trunk/plugins/generator/src/main/javadoc/generatedClasses.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -0,0 +1,114 @@
+/*
+ * $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;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.cdk.model.InvalidNameException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class NamingConventionsTest {
+
+ private static final String BASE="foo.bar";
+ private RichFacesConventions conventions;
+
+ @Before
+ public void createConventions() {
+ conventions = new RichFacesConventions(BASE);
+ }
+
+ @After
+ public void destroyConventions(){
+ conventions = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.RichFacesConventions#inferComponentType(java.lang.String,
java.lang.String)}.
+ * @throws Exception
+ */
+ @Test
+ public void testInferComponentTypeExplicit() throws Exception {
+ assertEquals("foo.bar.Test",
conventions.inferComponentType("foo.bar.Test","foo.baz.UITest"));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.RichFacesConventions#inferComponentType(java.lang.String,
java.lang.String)}.
+ * @throws Exception
+ */
+ @Test
+ public void testInferComponentTypeFromUIClass() throws Exception {
+ assertEquals("foo.bar.Test",
conventions.inferComponentType("","foo.baz.component.UITest"));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.RichFacesConventions#inferComponentType(java.lang.String,
java.lang.String)}.
+ * @throws Exception
+ */
+ @Test
+ public void testInferComponentTypeFromAbstractClass() throws Exception {
+ assertEquals("foo.bar.Test",
conventions.inferComponentType("","foo.baz.component.AbstractTest"));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.RichFacesConventions#inferComponentType(java.lang.String,
java.lang.String)}.
+ * @throws Exception
+ */
+ @Test
+ public void testInferComponentTypeFromBaseClass() throws Exception {
+ assertEquals("foo.bar.Test",
conventions.inferComponentType("","foo.baz.component.TestBase"));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.RichFacesConventions#inferComponentType(java.lang.String,
java.lang.String)}.
+ * @throws Exception
+ */
+ @Test
+ public void testInferComponentTypeFromMarkupClass() throws Exception {
+ assertEquals("foo.bar.HtmlTest",
conventions.inferComponentType("","foo.baz.component.html.HtmlTest"));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.RichFacesConventions#inferUIComponentClass(java.lang.String,
java.lang.String, java.lang.String, boolean)}.
+ */
+ @Test
+ public void testInferUIComponentClassFromExplicit() throws Exception {
+ assertEquals("foo.bar.UITest",
conventions.inferUIComponentClass("foo.bar.Test", "foo.bar.UITest",
"foo.bar.AbstractClass", true));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.RichFacesConventions#inferUIComponentClass(java.lang.String,
java.lang.String, java.lang.String, boolean)}.
+ */
+ @Test
+ public void testInferUIComponentClassFromType() throws Exception {
+ assertEquals("foo.bar.component.UITest",
conventions.inferUIComponentClass("foo.bar.Test", "",
"foo.bar.AbstractClass", true));
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ProcessorTest.java 2009-08-10
17:48:55 UTC (rev 15153)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ProcessorTest.java 2009-08-11
00:35:58 UTC (rev 15154)
@@ -23,30 +23,18 @@
package org.richfaces.cdk.apt;
+import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
-import static org.easymock.EasyMock.*;
-import static org.hamcrest.CoreMatchers.*;
-
import static javax.lang.model.util.ElementFilter.*;
-
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.nio.channels.Channels;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
import java.util.Set;
-import java.util.logging.Level;
import java.util.logging.LogManager;
-import java.util.logging.Logger;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
@@ -54,95 +42,69 @@
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
-import javax.lang.model.element.VariableElement;
-import javax.lang.model.type.TypeMirror;
-import javax.lang.model.util.ElementFilter;
-import javax.lang.model.util.Elements;
-import javax.lang.model.util.Types;
-import javax.tools.Diagnostic;
-import javax.tools.DiagnosticListener;
-import javax.tools.JavaCompiler;
-import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
-import javax.tools.JavaCompiler.CompilationTask;
-import javax.tools.JavaFileObject.Kind;
import org.easymock.Capture;
import org.easymock.CaptureType;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.LoggerFactory;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.Component;
import org.richfaces.cdk.model.ComponentLibrary;
-import org.richfaces.cdk.model.InvalidNameException;
-import org.richfaces.cdk.model.Property;
-import org.richfaces.cdk.util.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
*
* @author asmirnov(a)exadel.com
*
*/
-public class ProcessorTest {
-
+public class ProcessorTest {
+
private static final String ANNOTATION2 = TestAnnotation2.class.getName();
- @SupportedAnnotationTypes(Component.NAME)
- @SupportedSourceVersion(SourceVersion.RELEASE_6)
- private final class TestProcessor extends CdkProcessor {
-
- ComponentLibrary library;
-
- private int numOfComponents;
+ private static abstract class TestProcessor extends CdkProcessor {
+ protected ComponentLibrary library;
+
+ protected int numOfComponents;
+
public TestProcessor(CdkContext context) {
super(context);
}
-
+
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
}
-
+
@Override
public synchronized boolean isInitialized() {
return super.isInitialized();
}
@Override
- public boolean process(Set<? extends TypeElement> annotations,
- RoundEnvironment roundEnv) {
- return false;
+ public Set<String> getSupportedAnnotationTypes() {
+ // Process all annotations
+ return ImmutableSet.of("*");
}
-
}
private static final String INTERFACE_JAVA =
"org/richfaces/cdk/apt/TestInterface.java";
private static final String SUB_CLASS_JAVA =
"org/richfaces/cdk/apt/TestSubClass.java";
private static final String CLASS_JAVA =
"org/richfaces/cdk/apt/TestClass.java";
- private static final ImmutableSet<String> PROCESS_ANNOTATIONS =
ImmutableSet.of(TestAnnotation.class.getName());
+ private static final ImmutableSet<String> PROCESS_ANNOTATIONS = ImmutableSet
+ .of(TestAnnotation.class.getName());
private static final String COMPONENT_CLASS_JAVA =
"org/richfaces/cdk/test/component/AbstractTestComponent.java";
-
+
private File testSourceDirectory;
private ClassLoader testLoader;
@@ -186,21 +148,28 @@
expect(cdkContext.getJavaSource()).andStubReturn(testSourceDirectory);
expect(cdkContext.getJavaSourceOutput()).andStubReturn(null);
expect(cdkContext.getResourceOutput()).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(TestAnnotation.class.getClassLoader());
+ expect(cdkContext.getLoader()).andStubReturn(
+ TestAnnotation.class.getClassLoader());
replay(cdkContext);
Processor processor = createMock(Processor.class);
processor.init((ProcessingEnvironment) anyObject());
- expect(processor.getSupportedOptions()).andReturn(ImmutableSet.<String>of());
-// processor.process(null,null);
+ expect(processor.getSupportedOptions()).andReturn(
+ ImmutableSet.<String> of());
+ // processor.process(null,null);
Capture<Set<? extends TypeElement>> capturedTypes = new Capture<Set<?
extends TypeElement>>();
- expect(processor.process(capture(capturedTypes), capture(new
Capture<RoundEnvironment>()))).andReturn(true).times(2);
- expect(processor.getSupportedAnnotationTypes()).andReturn(ImmutableSet.of(TestAnnotation.class.getName()));
- expect(processor.getSupportedSourceVersion()).andReturn(SourceVersion.RELEASE_6);
+ expect(
+ processor.process(capture(capturedTypes),
+ capture(new Capture<RoundEnvironment>()))).andReturn(
+ true).times(2);
+ expect(processor.getSupportedAnnotationTypes()).andReturn(
+ ImmutableSet.of(TestAnnotation.class.getName()));
+ expect(processor.getSupportedSourceVersion()).andReturn(
+ SourceVersion.RELEASE_6);
replay(processor);
CdkCompiler compiler = CdkCompiler.create(cdkContext);
compiler.process(ImmutableList.of(getJavaFile(CLASS_JAVA)), processor);
- verify(cdkContext,processor);
+ verify(cdkContext, processor);
}
/**
@@ -215,56 +184,124 @@
// Prepare Mock compilation context.
CdkContext cdkContext = createMock(CdkContext.class);
expect(cdkContext.getJavaSource()).andStubReturn(testSourceDirectory);
- expect(cdkContext.getJavaSourceOutput()).andStubReturn( null);
+ expect(cdkContext.getJavaSourceOutput()).andStubReturn(null);
expect(cdkContext.getResourceOutput()).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(TestAnnotation2.class.getClassLoader());
+ expect(cdkContext.getLoader()).andStubReturn(
+ TestAnnotation2.class.getClassLoader());
replay(cdkContext);
Processor processor = createMock(Processor.class);
processor.init((ProcessingEnvironment) anyObject());
- expect(processor.getSupportedOptions()).andReturn(ImmutableSet.<String>of());
-// processor.process(null,null);
- Capture<Set<? extends TypeElement>> capturedTypes = new Capture<Set<?
extends TypeElement>>(CaptureType.FIRST);
- expect(processor.process(capture(capturedTypes), capture(new
Capture<RoundEnvironment>()))).andReturn(true).times(2);
- expect(processor.getSupportedAnnotationTypes()).andReturn(ImmutableSet.of(TestAnnotation2.class.getName()));
- expect(processor.getSupportedSourceVersion()).andReturn(SourceVersion.RELEASE_6);
+ expect(processor.getSupportedOptions()).andReturn(
+ ImmutableSet.<String> of());
+ // processor.process(null,null);
+ Capture<Set<? extends TypeElement>> capturedTypes = new Capture<Set<?
extends TypeElement>>(
+ CaptureType.FIRST);
+ expect(
+ processor.process(capture(capturedTypes),
+ capture(new Capture<RoundEnvironment>()))).andReturn(
+ true).times(2);
+ expect(processor.getSupportedAnnotationTypes()).andReturn(
+ ImmutableSet.of(TestAnnotation2.class.getName()));
+ expect(processor.getSupportedSourceVersion()).andReturn(
+ SourceVersion.RELEASE_6);
replay(processor);
CdkCompiler compiler = CdkCompiler.create(cdkContext);
- compiler.process(ImmutableList.of(getJavaFile(SUB_CLASS_JAVA),getJavaFile(CLASS_JAVA)),
processor);
- verify(cdkContext,processor);
+ compiler.process(ImmutableList.of(getJavaFile(SUB_CLASS_JAVA),
+ getJavaFile(CLASS_JAVA)), processor);
+ verify(cdkContext, processor);
Set<? extends TypeElement> elements = capturedTypes.getValue();
assertFalse(elements.isEmpty());
- assertEquals("TestAnnotation2",
elements.iterator().next().getSimpleName().toString());
+ assertEquals("TestAnnotation2", elements.iterator().next()
+ .getSimpleName().toString());
}
/**
* Test method for
- * {@link org.richfaces.cdk.apt.CdkProcessor#process(java.util.Set,
javax.annotation.processing.RoundEnvironment)}
+ * {@link org.richfaces.cdk.apt.CdkProcessor#getClassesAnnotatedWith(Class,
RoundEnvironment)}
* .
*
* @throws Exception
*/
@Test
- public void testCDKProcessor() throws Exception {
+ public void testGetClassesAnnotatedWith() throws Exception {
// Prepare Mock compilation context.
CdkContext cdkContext = createMock(CdkContext.class);
expect(cdkContext.getJavaSource()).andStubReturn(testSourceDirectory);
expect(cdkContext.getJavaSourceOutput()).andStubReturn(null);
expect(cdkContext.getResourceOutput()).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(TestAnnotation2.class.getClassLoader());
+ expect(cdkContext.getLoader()).andStubReturn(
+ TestAnnotation2.class.getClassLoader());
replay(cdkContext);
- TestProcessor processor = new TestProcessor(cdkContext);
- ComponentLibrary library = new ComponentLibrary("org.richfaces.cdk.test");
- processor.library = library;
+ TestProcessor processor = new TestProcessor(cdkContext) {
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations,
+ RoundEnvironment roundEnv) {
+ if (!roundEnv.processingOver()) {
+ this.numOfComponents = getClassesAnnotatedWith(
+ Component.class, roundEnv).size();
+
+ }
+ return true;
+ }
+ };
+ // ComponentLibrary library = new
+ // ComponentLibrary("org.richfaces.cdk.test");
+ // processor.library = library;
CdkCompiler compiler = CdkCompiler.create(cdkContext);
- compiler.process(ImmutableList.of(getJavaFile(COMPONENT_CLASS_JAVA)), processor);
+ compiler.process(ImmutableList.of(getJavaFile(COMPONENT_CLASS_JAVA)),
+ processor);
verify(cdkContext);
- assertTrue(processor.isInitialized());
+ assertTrue(processor.isInitialized());
+ assertEquals(1, processor.numOfComponents);
}
-
+
/**
- * <p class="changed_added_4_0"></p>
+ * Test method for
+ * {@link org.richfaces.cdk.apt.CdkProcessor#getClassesAnnotatedWith(Class,
RoundEnvironment)}
+ * .
*
+ * @throws Exception
+ */
+ @Test
+ public void testGetPropertiesAnnotatedWith() throws Exception {
+ // Prepare Mock compilation context.
+ CdkContext cdkContext = createMock(CdkContext.class);
+ expect(cdkContext.getJavaSource()).andStubReturn(testSourceDirectory);
+ expect(cdkContext.getJavaSourceOutput()).andStubReturn(null);
+ expect(cdkContext.getResourceOutput()).andStubReturn(null);
+ expect(cdkContext.getLoader()).andStubReturn(
+ TestAnnotation2.class.getClassLoader());
+ replay(cdkContext);
+ TestProcessor processor = new TestProcessor(cdkContext) {
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations,
+ RoundEnvironment roundEnv) {
+ if (!roundEnv.processingOver()) {
+ TypeElement typeElement = getClassesAnnotatedWith(
+ Component.class, roundEnv).iterator().next();
+ Set<BeanProperty> beanProperties =
getBeanPropertiesAnnotatedWith(Attribute.class, typeElement);
+ assertEquals(1, beanProperties.size());
+ assertEquals("testValue", beanProperties.iterator().next().getName());
+ numOfComponents++;
+ }
+ return true;
+ }
+ };
+ // ComponentLibrary library = new
+ // ComponentLibrary("org.richfaces.cdk.test");
+ // processor.library = library;
+ CdkCompiler compiler = CdkCompiler.create(cdkContext);
+ compiler.process(ImmutableList.of(getJavaFile(COMPONENT_CLASS_JAVA)),
+ processor);
+ verify(cdkContext);
+ assertTrue(processor.isInitialized());
+ assertEquals(1, processor.numOfComponents);
+ }
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @param name
* TODO
* @return
@@ -273,7 +310,8 @@
private JavaFileObject getJavaFileObject(String name)
throws URISyntaxException {
final File classFile = getJavaFile(name);
- SimpleJavaFileObject fileObject = new VirtualJavaFileSystemObject(classFile);
+ SimpleJavaFileObject fileObject = new VirtualJavaFileSystemObject(
+ classFile);
return fileObject;
}