Author: alexsmirnov
Date: 2010-05-19 19:04:01 -0400 (Wed, 19 May 2010)
New Revision: 17149
Added:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Function.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FunctionModel.java
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/functions/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/functions/TestFunctions.java
Modified:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/TagLibrary.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.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/processors/TagLibProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.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/EmptyVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Taglib.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
Log:
DONE - issue RF-8363: Functions support
https://jira.jboss.org/browse/RF-8363
Added:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Function.java
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Function.java
(rev 0)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Function.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -0,0 +1,53 @@
+/*
+ * $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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p class="changed_added_4_0">This annotation defines static method or
all public static methods in the annotated class as EL functions.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)Retention(RetentionPolicy.CLASS)
+@Target( { ElementType.METHOD })
+public @interface Function {
+
+ public Description description() default @Description();
+
+ /**
+ * <p class="changed_added_4_0">Function n</p>
+ * @return
+ */
+ public String name() default "";
+
+ /**
+ * <p class="changed_added_4_0">Tag library for include given
function</p>
+ * @return
+ */
+ public TagType type() default TagType.Facelets;
+}
Property changes on:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Function.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/TagLibrary.java
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/TagLibrary.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/TagLibrary.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -45,6 +45,19 @@
public String uri();
/**
+ * <p class="changed_added_4_0">Library short name ( default prefix
)</p>
+ * @return
+ */
+ public String shortName();
+
+
+ /**
+ * <p class="changed_added_4_0">Default preffix for package names and
JSF ids in the library</p>
+ * @return
+ */
+ public String preffix() default "";
+
+ /**
* <p class="changed_added_4_0">Implementation version of the
generated taglib.</p>
* @return
*/
@@ -75,12 +88,6 @@
public String jspVersion() default "2.0";
- /**
- * <p class="changed_added_4_0">Library short name ( default prefix
)</p>
- * @return
- */
- public String shortName();
-
public static final class NONE {}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/AptModule.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -35,6 +35,7 @@
import org.richfaces.cdk.apt.processors.ConverterProcessor;
import org.richfaces.cdk.apt.processors.DescriptionProcessor;
import org.richfaces.cdk.apt.processors.DescriptionProcessorImpl;
+import org.richfaces.cdk.apt.processors.FunctionProcessor;
import org.richfaces.cdk.apt.processors.RendererProcessor;
import org.richfaces.cdk.apt.processors.TagLibProcessor;
import org.richfaces.cdk.apt.processors.ValidatorProcessor;
@@ -61,6 +62,7 @@
setBinder.addBinding().to(ConverterProcessor.class);
setBinder.addBinding().to(ValidatorProcessor.class);
setBinder.addBinding().to(TagLibProcessor.class);
+ setBinder.addBinding().to(FunctionProcessor.class);
bind(Processor.class).to(CdkProcessor.class);
bind(AttributesProcessor.class).to(AttributesProcessorImpl.class);
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 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -41,6 +41,9 @@
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
import java.util.Collections;
import java.util.Set;
@@ -94,12 +97,15 @@
}
// parse non-java sources
for (ModelBuilder builder : builders) {
+ log.debug("Run builder "+builder.getClass().getName());
builder.build();
}
// validator should be called even if previvous phases finish with errors, to
collect all possible problems.
+ log.debug("Validate model");
validator.verify(library);
} else if (0 == log.getErrorCount()) {
// processing over, generate files.
+ log.debug("Generate output files");
builder.generate();
}
@@ -107,25 +113,72 @@
}
protected void processAnnotation(CdkAnnotationProcessor processor, RoundEnvironment
environment) {
+ Class<? extends Annotation> processedAnnotation =
processor.getProcessedAnnotation();
+ log.debug("Process all elements annotated with
"+processedAnnotation.getName());
+ Target target = processedAnnotation.getAnnotation(Target.class);
try {
Set<? extends Element> rootElements = environment.getRootElements();
for (Element element : rootElements) {
- if ((ElementKind.CLASS.equals(element.getKind()) ||
ElementKind.PACKAGE.equals(element.getKind()))
- && null !=
element.getAnnotation(processor.getProcessedAnnotation())){
- try {
- processor.process(element, library);
- } catch (CdkProcessingException e) {
- sendError(element, e);
+ if (isAppropriateTarget(element, target)){
+ processElement(processor, processedAnnotation, element);
+ } else {
+ for (Element enclosedElement : element.getEnclosedElements()) {
+ if (isAppropriateTarget(enclosedElement, target)){
+ processElement(processor, processedAnnotation,
enclosedElement);
+ }
}
}
}
} catch (Exception e) {
processingEnv.getMessager().printMessage(Kind.ERROR,
- "Errorr processing annotation " +
processor.getProcessedAnnotation() + ": " + e);
- e.printStackTrace();
+ "Errorr processing annotation " + processedAnnotation + ":
" + e);
}
}
+ private void processElement(CdkAnnotationProcessor processor, Class<? extends
Annotation> processedAnnotation,
+ Element element) {
+ if (null != element.getAnnotation(processedAnnotation)) {
+ try {
+ log.debug("Process "+element.getSimpleName()+" annotated
with "+processedAnnotation.getName());
+ processor.process(element, library);
+ } catch (CdkProcessingException e) {
+ sendError(element, e);
+ }
+ }
+ }
+
+ private boolean isAppropriateTarget(Element element,Target target){
+ boolean match = false;
+ ElementKind kind = element.getKind();
+ if(null != target){
+ for(ElementType targetType : target.value()){
+ switch (targetType) {
+ case TYPE:
+ match |=
ElementKind.CLASS.equals(kind)||ElementKind.INTERFACE.equals(kind)||ElementKind.ENUM.equals(kind);
+ break;
+ case PACKAGE:
+ match |= ElementKind.PACKAGE.equals(kind);
+ break;
+ case METHOD:
+ match |= ElementKind.METHOD.equals(kind);
+ break;
+ case FIELD:
+ match |= ElementKind.FIELD.equals(kind);
+ break;
+ default:
+ break;
+ }
+ }
+ } else {
+ // Annotation without @Target match any element.
+ match =
+ ElementKind.CLASS.equals(kind) || ElementKind.INTERFACE.equals(kind) ||
ElementKind.ENUM.equals(kind)
+ || ElementKind.PACKAGE.equals(kind) ||
ElementKind.METHOD.equals(kind)
+ || ElementKind.FIELD.equals(kind);
+ }
+ return match;
+ }
+
protected void sendError(Element componentElement, CdkProcessingException e) {
// rise error and continue.
processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.ERROR,
e.getMessage(), componentElement);
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -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.apt.processors;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+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.TypeElement;
+import javax.lang.model.element.VariableElement;
+
+import org.richfaces.cdk.CdkProcessingException;
+import org.richfaces.cdk.annotations.Function;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.FunctionModel;
+import org.richfaces.cdk.util.Strings;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class FunctionProcessor extends ProcessorBase implements CdkAnnotationProcessor {
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.apt.processors.CdkAnnotationProcessor#getProcessedAnnotation()
+ */
+ @Override
+ public Class<? extends Annotation> getProcessedAnnotation() {
+ return Function.class;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.apt.processors.CdkAnnotationProcessor#process(javax.lang.model.element.Element,
org.richfaces.cdk.model.ComponentLibrary)
+ */
+ @Override
+ public void process(Element element, ComponentLibrary library) throws
CdkProcessingException {
+ switch (element.getKind()) {
+ case METHOD:
+ ExecutableElement methodElement = (ExecutableElement) element;
+ // Only public static methods can be registered as functions.
+ // TODO - move to validator.
+ Set<Modifier> modifiers = methodElement.getModifiers();
+ if(!modifiers.contains(Modifier.PUBLIC)){
+ throw new CdkProcessingException("Only public method can be
registered as EL function "+methodElement.getSimpleName());
+ }
+ if(!modifiers.contains(Modifier.STATIC)){
+ throw new CdkProcessingException("Only static method can be
registered as EL function "+methodElement.getSimpleName());
+ }
+ Function function = methodElement.getAnnotation(Function.class);
+ FunctionModel model = new FunctionModel();
+ if(!Strings.isEmpty(function.name())){
+ model.setName(function.name());
+ } else {
+ model.setName(methodElement.getSimpleName().toString());
+ }
+ model.setType(function.type());
+ setDescription(model, function.description(),
getDocComment(methodElement));
+ // Calculate method signature
+ StringBuilder signature = new StringBuilder();
+ signature.append(methodElement.getReturnType()).append(" ");
+ signature.append(methodElement.getSimpleName()).append("(");
+ boolean first = true;
+ for(VariableElement parameter :methodElement.getParameters()){
+ if(!first){
+ signature.append(",");
+ }
+ signature.append(parameter.asType());
+ first = false;
+ }
+ signature.append(")");
+ model.setSignature(signature.toString());
+ Element declaringClass = methodElement.getEnclosingElement();
+ if(ElementKind.CLASS.equals(declaringClass.getKind())){
+
model.setFunctionClass(ClassName.parseName(((TypeElement)declaringClass).getQualifiedName().toString()));
+ }
+ library.getFunctions().add(model);
+ break;
+ case CLASS:
+ // TODO - process all public static methods in the class.
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/FunctionProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/TagLibProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/TagLibProcessor.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/TagLibProcessor.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -26,6 +26,7 @@
import java.lang.annotation.Annotation;
import javax.lang.model.element.Element;
+import javax.lang.model.element.PackageElement;
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.TagLibrary;
@@ -54,7 +55,10 @@
@Override
public void process(Element element, ComponentLibrary library) throws
CdkProcessingException {
TagLibrary tagLibrary = element.getAnnotation(TagLibrary.class);
- Taglib taglibModel = new Taglib();
+ Taglib taglibModel = library.getTaglib();
+ if(null == taglibModel){
+ taglibModel = new Taglib();
+ }
taglibModel.setUri(tagLibrary.uri());
String shortName = tagLibrary.shortName();
if(!Strings.isEmpty(shortName)){
@@ -68,6 +72,18 @@
if(!Strings.isEmpty(tlibVersion)){
taglibModel.setTlibVersion(tlibVersion);
}
+ // Default prefix for library
+ String preffix = tagLibrary.preffix();
+ if(!Strings.isEmpty(preffix)){
+ library.setPrefix(preffix);
+ } else if (Strings.isEmpty(library.getPrefix())) {
+ // record package name to use in NamingConventions
+ PackageElement packageElement = (PackageElement) element;
+ preffix = packageElement.getQualifiedName().toString();
+ if(!Strings.isEmpty(preffix)){
+ library.setPrefix(preffix);
+ }
+ }
library.setTaglib(taglibModel);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -31,7 +31,9 @@
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.ConverterModel;
+import org.richfaces.cdk.model.DescriptionGroup;
import org.richfaces.cdk.model.EmptyVisitor;
+import org.richfaces.cdk.model.FunctionModel;
import org.richfaces.cdk.model.ListenerModel;
import org.richfaces.cdk.model.ModelElement;
import org.richfaces.cdk.model.PropertyBase;
@@ -40,6 +42,7 @@
import org.richfaces.cdk.model.TagModel;
import org.richfaces.cdk.model.ValidatorModel;
import org.richfaces.cdk.model.RendererModel.Type;
+import org.richfaces.cdk.util.Strings;
import java.util.List;
@@ -256,7 +259,41 @@
return null;
}
+
+ @Override
+ public void visitFunction(FunctionModel model) {
+
if(TagType.Facelets.equals(model.getType())||TagType.All.equals(model.getType())){
+ Element functionElement = faceletTaglib.addElement("function");
+ addDescription(functionElement, model);
+
functionElement.addElement("function-name").addText(model.getName());
+
functionElement.addElement("function-class").addText(model.getFunctionClass().toString());
+
functionElement.addElement("function-signature").addText(model.getSignature());
+ }
+ }
+ /**
+ * <p class="changed_added_4_0">Add common description
elements.</p>
+ * @param parant
+ * @param model
+ */
+ private void addDescription(Element parent, DescriptionGroup model){
+ if(!Strings.isEmpty(model.getDescription())){
+ parent.addElement("description").addText(model.getDescription());
+ }
+ if(!Strings.isEmpty(model.getDisplayname())){
+ parent.addElement("display-name").addText(model.getDisplayname());
+ }
+ if(null != model.getIcon()){
+ Element iconElement = parent.addElement("icon");
+ if(!Strings.isEmpty(model.getIcon().getSmallIcon())){
+
iconElement.addElement("small-icon").addText(model.getIcon().getSmallIcon());
+ }
+ if(!Strings.isEmpty(model.getIcon().getLargeIcon())){
+
iconElement.addElement("large-icon").addText(model.getIcon().getLargeIcon());
+ }
+
+ }
+ }
public void visitListener(ListenerModel model) {
// TODO
}
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 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -74,6 +74,8 @@
private final ModelCollection<ListenerModel> listeners =
ModelCollection.<ListenerModel> create();
+ private final ModelCollection<FunctionModel> functions =
ModelCollection.<FunctionModel> create();
+
private long lastModified = Long.MIN_VALUE;
/**
@@ -111,6 +113,7 @@
listeners.accept(visitor);
events.accept(visitor);
behaviors.accept(visitor);
+ functions.accept(visitor);
}
/**
@@ -279,6 +282,14 @@
}
/**
+ * <p class="changed_added_4_0"></p>
+ * @return the functions
+ */
+ public ModelCollection<FunctionModel> getFunctions() {
+ return this.functions;
+ }
+
+ /**
* <p class="changed_added_4_0">
* </p>
*
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/EmptyVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/EmptyVisitor.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/EmptyVisitor.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -76,7 +76,13 @@
public void visitListener(ListenerModel model) {
// Do nothing.
}
+
+ @Override
+ public void visitFunction(FunctionModel model) {
+ // Do nothing
+ }
+ @SuppressWarnings("unchecked")
public void visit(ModelElement model) {
// Do nothing.
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FunctionModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FunctionModel.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FunctionModel.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -0,0 +1,158 @@
+/*
+ * $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;
+
+import javax.xml.bind.annotation.XmlType;
+
+import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.cdk.util.ComparatorUtils;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@XmlType(name = "function-configType", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+public class FunctionModel extends DescriptionGroupBase implements Named,
ModelElement<FunctionModel> {
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ */
+ private static final long serialVersionUID = -358069932548425030L;
+
+ private String name;
+
+ private String signature;
+
+ private TagType type;
+
+ private ClassName functionClass;
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the name
+ */
+ @Merge
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param name
+ * the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the signature
+ */
+ @Merge
+ public String getSignature() {
+ return this.signature;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param signature
+ * the signature to set
+ */
+ public void setSignature(String signature) {
+ this.signature = signature;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the type
+ */
+ @Merge
+ public TagType getType() {
+ return this.type;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param type
+ * the type to set
+ */
+ public void setType(TagType type) {
+ this.type = type;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the functionClass
+ */
+ @Merge
+ public ClassName getFunctionClass() {
+ return this.functionClass;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param functionClass
+ * the functionClass to set
+ */
+ public void setFunctionClass(ClassName functionClass) {
+ this.functionClass = functionClass;
+ }
+
+ @Override
+ public void merge(FunctionModel other) {
+ ComponentLibrary.merge(this, other);
+ }
+
+ @Override
+ public boolean same(FunctionModel other) {
+ return ComparatorUtils.nullSafeEquals(getName(), other.getName());
+ }
+
+ @Override
+ public void accept(Visitor visitor) {
+ visitor.visitFunction(this);
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FunctionModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Taglib.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Taglib.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Taglib.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -35,7 +35,7 @@
* @author asmirnov
*
*/
-@XmlType(name = "taflib-configType", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+@XmlType(name = "taglib-configType", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public class Taglib {
private String tlibVersion = null;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitor.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitor.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -50,6 +50,8 @@
void visitRender(RendererModel model);
void visitListener(ListenerModel model);
+
+ void visitFunction(FunctionModel model);
void visit(ModelElement model);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -38,6 +38,7 @@
import org.richfaces.cdk.model.ConverterModel;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.Extensible;
+import org.richfaces.cdk.model.FunctionModel;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.model.Taglib;
import org.richfaces.cdk.model.ValidatorModel;
@@ -200,6 +201,8 @@
private Taglib taglib;
private List<EventModel> events = Lists.newArrayList();
+
+ private List<FunctionModel> functions = Lists.newArrayList();
@XmlElement(name = "faces-event", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
@XmlJavaTypeAdapter(EventAdapter.class)
@@ -233,5 +236,22 @@
public Taglib getTaglib() {
return taglib;
}
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the functions
+ */
+ @XmlElement(name = "function", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+ public List<FunctionModel> getFunctions() {
+ return this.functions;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param functions the functions to set
+ */
+ public void setFunctions(List<FunctionModel> functions) {
+ this.functions = functions;
+ }
}
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-05-19
20:30:27 UTC (rev 17148)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/CdkProcessorTest.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -127,6 +127,7 @@
expect(element.getKind()).andReturn(ElementKind.CLASS);
TestAnnotation2 testAnnotation2 = createNiceMock(TestAnnotation2.class);
expect(element.getAnnotation(TestAnnotation2.class)).andReturn(testAnnotation2);
+ expect(element.getSimpleName()).andStubReturn(new TestName("foo"));
cdkProcessor.process(element, library);
expectLastCall();
validator.verify(library);
@@ -140,6 +141,7 @@
public void testProcessOver() throws Exception {
expect(roundEnv.processingOver()).andReturn(true);
expect(log.getErrorCount()).andReturn(0);
+ log.debug((CharSequence) anyObject());expectLastCall().asStub();
builder.generate();
expectLastCall();
replay(log, element, roundEnv, builder, validator, cdkProcessor);
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/functions/TestFunctions.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/functions/TestFunctions.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/functions/TestFunctions.java 2010-05-19
23:04:01 UTC (rev 17149)
@@ -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.test.functions;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.richfaces.cdk.annotations.Description;
+import org.richfaces.cdk.annotations.Function;
+import org.richfaces.cdk.annotations.TagType;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TestFunctions {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param param
+ * @return
+ */
+ @Function
+ public static boolean testBoolean(String param){
+ return false;
+ }
+
+ @Function(description=@Description(displayName="test
string",value="Long, long description"))
+ public static String testString(List<String> param, char delim){
+ return null;
+ }
+
+ @Function(name="test")
+ public static Collection<Integer> testCollection(String param,String...strings
){
+ return null;
+ }
+
+ @Function(type=TagType.Jsp)
+ public static boolean testJSPBoolean(String param){
+ return false;
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/functions/TestFunctions.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain