You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/02/08 15:53:02 UTC
svn commit: r1444033 [3/3] - in /myfaces/tobago/trunk: tobago-core/
tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-example/tobago-example-addressbook-cdi/ to...
Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/ReferenceGenerator.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/ReferenceGenerator.java?rev=1444033&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/ReferenceGenerator.java (added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/ReferenceGenerator.java Fri Feb 8 14:53:00 2013
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.apt.processor;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.tobago.apt.annotation.BodyContent;
+import org.apache.myfaces.tobago.apt.annotation.BodyContentDescription;
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.Taglib;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedOptions;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Locale;
+import java.util.Map;
+
+@SupportedAnnotationTypes({
+ "org.apache.myfaces.tobago.apt.annotation.Tag",
+ "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.Taglib"})
+@SupportedOptions({
+ ReferenceGenerator.TARGET_REFERENCE})
+public class ReferenceGenerator extends TldGenerator {
+
+ static final String TARGET_REFERENCE = "targetReference";
+
+ private String targetReference;
+
+ public void configure() {
+ final Map<String, String> options = processingEnv.getOptions();
+ targetReference = options.get(TARGET_REFERENCE);
+
+ info("Generating the faces-config.xml");
+ info("Options:");
+ info(TARGET_REFERENCE + ": " + targetReference);
+ }
+
+ public void generate() throws IOException, TransformerException, ParserConfigurationException,
+ ClassNotFoundException {
+ for (PackageElement packageElement : getPackages()) {
+ Taglib taglibAnnotation = packageElement.getAnnotation(Taglib.class);
+ Document document = createTaglib(taglibAnnotation, packageElement);
+ writeTaglib(packageElement, taglibAnnotation, document);
+ }
+ }
+
+ @Override
+ protected void writeTaglib(PackageElement packageElement, Taglib taglibAnnotation, Document document)
+ throws IOException, TransformerException {
+ Writer writer = null;
+ try {
+ final String file = taglibAnnotation.fileName().substring(0, taglibAnnotation.fileName().length() - 3) + "xml";
+ final String name = (StringUtils.isNotBlank(targetReference) ? targetReference + '/' : "")
+ + packageElement.getQualifiedName().toString().replace('.', '/') + '/' + file;
+ final FileObject resource = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", name);
+ info("Writing to file: " + resource.toUri());
+ writer = resource.openWriter();
+
+ TransformerFactory transFactory = TransformerFactory.newInstance();
+ transFactory.setAttribute("indent-number", 2);
+ Transformer transformer = transFactory.newTransformer();
+ // TODO transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
+ // "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN");
+ // TODO transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
+ // "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.transform(new DOMSource(document), new StreamResult(writer));
+ } finally {
+ IOUtils.closeQuietly(writer);
+ }
+ }
+
+ @Override
+ protected Element createTag(
+ TypeElement typeElement, Tag annotationTag, String className, Document document, boolean deprecated) {
+ Element tagElement = document.createElement("tag");
+ addDescription(typeElement, tagElement, document, false);
+ addLeafTextElement(annotationTag.name(), "name", tagElement, document);
+ addLeafTextElement(className, "tag-class", tagElement, document);
+
+ BodyContent bodyContent = annotationTag.bodyContent();
+ BodyContentDescription contentDescription = typeElement.getAnnotation(BodyContentDescription.class);
+ // TODO more error checking
+ if (contentDescription != null) {
+ if (bodyContent.equals(BodyContent.JSP)
+ && contentDescription.contentType().length() > 0) {
+ throw new IllegalArgumentException(
+ "contentType " + contentDescription.contentType() + " for bodyContent JSP not allowed!");
+ } else if (bodyContent.equals(BodyContent.TAGDEPENDENT)
+ && contentDescription.contentType().length() == 0) {
+ throw new IllegalArgumentException("contentType should set for tag-dependent bodyContent");
+ }
+ }
+
+ addLeafTextElement(bodyContent.toString(), "body-content", tagElement, document);
+ if (contentDescription != null) {
+ Element bodyContentDescription = document.createElement("body-content-description");
+ for (int i = 0; i < contentDescription.anyClassOf().length; i++) {
+ Element clazz = document.createElement("class");
+ String typeClass = contentDescription.anyClassOf()[i];
+ addLeafTextElement(ClassUtils.getShortClassName(typeClass), "name", clazz, document);
+ addLeafTextElement(ClassUtils.getPackageName(typeClass), "package", clazz, document);
+ bodyContentDescription.appendChild(clazz);
+ }
+ if (contentDescription.anyTagOf().length() > 0) {
+ addLeafTextElement(contentDescription.anyTagOf(), "tags", bodyContentDescription, document);
+ }
+ if (contentDescription.contentType().length() > 0) {
+ addLeafTextElement(contentDescription.contentType(), "content-type", bodyContentDescription, document);
+ }
+ tagElement.appendChild(bodyContentDescription);
+ }
+
+ return tagElement;
+ }
+
+ @Override
+ protected void addAttribute(ExecutableElement element, Element tagElement, Document document) {
+ TagAttribute tagAttribute = element.getAnnotation(TagAttribute.class);
+ if (tagAttribute != null) {
+ UIComponentTagAttribute uiTagAttribute = null;
+ try {
+ uiTagAttribute = element.getAnnotation(UIComponentTagAttribute.class);
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ }
+ String simpleName = element.getSimpleName().toString();
+ if (simpleName.startsWith("set")) {
+ Element attribute = document.createElement("attribute");
+ addDescription(element, attribute, document);
+ addLeafTextElement(simpleName.substring(3, 4).toLowerCase(Locale.ENGLISH)
+ + simpleName.substring(4), "name", attribute, document);
+ addLeafTextElement(Boolean.toString(tagAttribute.required()), "required", attribute, document);
+ addLeafTextElement(Boolean.toString(tagAttribute.rtexprvalue()), "rtexprvalue", attribute, document);
+ if (uiTagAttribute != null) {
+ addLeafTextElement(uiTagAttribute.expression().toString(), "ui-attribute-expression", attribute, document);
+
+ String[] uiTypeClasses = uiTagAttribute.type();
+ if (uiTypeClasses.length > 0) {
+ Element uiAttributeType = document.createElement("ui-attribute-type");
+ for (String typeClass : uiTypeClasses) {
+ Element clazz = document.createElement("class");
+ addLeafTextElement(ClassUtils.getShortClassName(typeClass), "name", clazz, document);
+ addLeafTextElement(ClassUtils.getPackageName(typeClass), "package", clazz, document);
+ uiAttributeType.appendChild(clazz);
+ }
+ attribute.appendChild(uiAttributeType);
+ }
+ if (uiTagAttribute.defaultValue().length() > 0) {
+ addLeafTextElement(uiTagAttribute.defaultValue(), "ui-attribute-default-value", attribute, document);
+ }
+
+ }
+
+ tagElement.appendChild(attribute);
+ } else {
+ throw new IllegalArgumentException("Only setter allowed found: " + simpleName);
+ }
+ }
+ }
+
+}
Copied: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/TldGenerator.java (from r1406180, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/TldGenerator.java?p2=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/TldGenerator.java&p1=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java&r1=1406180&r2=1444033&rev=1444033&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/TaglibAnnotationVisitor.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/TldGenerator.java Fri Feb 8 14:53:00 2013
@@ -17,16 +17,8 @@
* under the License.
*/
-package org.apache.myfaces.tobago.apt;
+package org.apache.myfaces.tobago.apt.processor;
-import com.sun.mirror.apt.AnnotationProcessorEnvironment;
-import com.sun.mirror.apt.Filer;
-import com.sun.mirror.declaration.ClassDeclaration;
-import com.sun.mirror.declaration.Declaration;
-import com.sun.mirror.declaration.InterfaceDeclaration;
-import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.declaration.PackageDeclaration;
-import com.sun.mirror.type.InterfaceType;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.myfaces.tobago.apt.annotation.BodyContent;
@@ -40,9 +32,17 @@ import org.apache.myfaces.tobago.apt.ann
import org.apache.myfaces.tobago.apt.annotation.Taglib;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.apt.generate.ClassUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedOptions;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -52,48 +52,58 @@ import javax.xml.transform.TransformerEx
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import java.io.File;
import java.io.IOException;
import java.io.Writer;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-/*
- * Created: Mar 22, 2005 8:18:35 PM
- */
-public class TaglibAnnotationVisitor extends AbstractAnnotationVisitor {
+@SupportedAnnotationTypes({
+ "org.apache.myfaces.tobago.apt.annotation.Tag",
+ "org.apache.myfaces.tobago.apt.annotation.TagAttribute",
+ "org.apache.myfaces.tobago.apt.annotation.Taglib"})
+@SupportedOptions({
+ TldGenerator.JSF_VERSION,
+ TldGenerator.TARGET_TLD})
+public class TldGenerator extends AbstractGenerator {
+
+ static final String TARGET_TLD = "targetTld";
private Set<String> tagSet = new HashSet<String>();
private Set<String> attributeSet = new HashSet<String>();
private String currentTag;
- private String jsfVersion = "1.1";
- public TaglibAnnotationVisitor(AnnotationProcessorEnvironment env) {
- super(env);
- for (Map.Entry<String, String> entry : getEnv().getOptions().entrySet()) {
- if (entry.getKey().startsWith("-Ajsf-version=")) {
- String version = entry.getKey().substring("-Ajsf-version=".length());
- if ("1.2".equals(version)) {
- jsfVersion = "1.2";
- }
- }
- }
+ private String jsfVersion;
+ private String targetTld;
+
+ public void configure() {
+ final Map<String, String> options = processingEnv.getOptions();
+ jsfVersion = options.get(JSF_VERSION);
+ targetTld = options.get(TARGET_TLD);
+
+ info("Generating the *.tld");
+ info("Options:");
+ info(JSF_VERSION + ": " + jsfVersion);
+ info(TARGET_TLD + ": " + targetTld);
}
- public void process() throws Exception {
- for (PackageDeclaration packageDeclaration : getCollectedPackageDeclarations()) {
- Taglib taglibAnnotation = packageDeclaration.getAnnotation(Taglib.class);
- Document document = createTaglib(taglibAnnotation, packageDeclaration);
- writeTaglib(packageDeclaration, taglibAnnotation, document);
+ public void generate()
+ throws IOException, TransformerException, ParserConfigurationException, ClassNotFoundException {
+ for (PackageElement packageElement : getPackages()) {
+ Taglib taglibAnnotation = packageElement.getAnnotation(Taglib.class);
+ Document document = createTaglib(taglibAnnotation, packageElement);
+ writeTaglib(packageElement, taglibAnnotation, document);
}
}
- private Document createTaglib(Taglib taglibAnnotation, PackageDeclaration packageDeclaration) throws
- ParserConfigurationException {
+ protected Document createTaglib(Taglib taglibAnnotation, PackageElement packageElement)
+ throws ParserConfigurationException, ClassNotFoundException {
resetDuplicateList();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
@@ -102,32 +112,23 @@ public class TaglibAnnotationVisitor ext
Document document = parser.newDocument();
Element taglib = document.createElement("taglib");
- if (isMinium12()) {
- taglib.setAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
- taglib.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
- taglib.setAttribute("xsi:schemaLocation",
+ taglib.setAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
+ taglib.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ taglib.setAttribute("xsi:schemaLocation",
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd");
- taglib.setAttribute("version", "2.1");
- }
- if (isMinium12()) {
- addLeafTextElement("1.2", "tlib-version", taglib, document);
- } else {
- addLeafTextElement(taglibAnnotation.tlibVersion(), "tlib-version", taglib, document);
- }
- if (!isMinium12()) {
- addLeafTextElement(taglibAnnotation.jspVersion(), "jsp-version", taglib, document);
+ taglib.setAttribute("version", "2.1");
+ String description = processingEnv.getElementUtils().getDocComment(packageElement);
+ if (description != null) {
+ addLeafCDATAElement(description, "description", taglib, document);
}
- addLeafTextElement(taglibAnnotation.shortName(), "short-name", taglib, document);
- addLeafTextElement(taglibAnnotation.uri(), "uri", taglib, document);
String displayName = taglibAnnotation.displayName();
if (displayName == null || displayName.length() == 0) {
displayName = taglibAnnotation.shortName();
}
addLeafTextElement(displayName, "display-name", taglib, document);
- String description = packageDeclaration.getDocComment();
- if (description != null) {
- addLeafCDATAElement(description, "description", taglib, document);
- }
+ addLeafTextElement("1.2", "tlib-version", taglib, document);
+ addLeafTextElement(taglibAnnotation.shortName(), "short-name", taglib, document);
+ addLeafTextElement(taglibAnnotation.uri(), "uri", taglib, document);
for (String listenerClass : taglibAnnotation.listener()) {
Element listener = document.createElement("listener");
// TODO check listenerClass implements ServletContextListener !!
@@ -135,96 +136,74 @@ public class TaglibAnnotationVisitor ext
taglib.appendChild(listener);
}
- for (ClassDeclaration decl : getCollectedClassDeclarations()) {
- if (decl.getPackage().equals(packageDeclaration)) {
- appendTag(decl, taglib, document);
- }
- }
- for (InterfaceDeclaration decl : getCollectedInterfaceDeclarations()) {
- if (decl.getPackage().equals(packageDeclaration)) {
- appendTag(decl, taglib, document);
+ for (TypeElement typeElement : getTypes()) {
+ if (processingEnv.getElementUtils().getPackageOf(typeElement).equals(packageElement)) {
+ appendTag(typeElement, taglib, document);
}
}
document.appendChild(taglib);
return document;
}
- protected void writeTaglib(PackageDeclaration packageDeclaration, Taglib taglibAnnotation, Document document) throws
- IOException, TransformerException {
+ protected void writeTaglib(PackageElement packageElement, Taglib taglibAnnotation, Document document)
+ throws IOException, TransformerException {
Writer writer = null;
try {
- getEnv().getMessager().printNotice("Create DOM");
- writer = getEnv().getFiler().createTextFile(Filer.Location.SOURCE_TREE,
- packageDeclaration.getQualifiedName(),
- new File(taglibAnnotation.fileName()), null);
+ final String name = (StringUtils.isNotBlank(targetTld) ? targetTld + '/' : "")
+ + packageElement.getQualifiedName().toString().replace('.', '/') + '/' + taglibAnnotation.fileName();
+ final FileObject resource = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", name);
+ info("Writing to file: " + resource.toUri());
+ writer = resource.openWriter();
+
TransformerFactory transFactory = TransformerFactory.newInstance();
transFactory.setAttribute("indent-number", 2);
Transformer transformer = transFactory.newTransformer();
- if (!isMinium12()) {
- transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
- "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN");
- transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
- "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"
- );
- }
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.transform(new DOMSource(document),
- new StreamResult(writer));
- getEnv().getMessager().printNotice("Write to file " + packageDeclaration.getQualifiedName()
- + " " + taglibAnnotation.fileName());
+ transformer.transform(new DOMSource(document), new StreamResult(writer));
} finally {
IOUtils.closeQuietly(writer);
}
}
- protected void appendTag(ClassDeclaration decl, Element parent, Document document) {
- Tag annotationTag = decl.getAnnotation(Tag.class);
- checkDuplicates(annotationTag.name());
- resetAttributeDuplicateList();
- String className = decl.getQualifiedName();
- TagGeneration tagGeneration = decl.getAnnotation(TagGeneration.class);
- if (tagGeneration != null) {
- className = tagGeneration.className();
- }
- Element tag = createTag(decl, annotationTag, className, document, false);
- addAttributes(decl, tag, document);
- parent.appendChild(tag);
- if (annotationTag.deprecatedName() != null&&annotationTag.deprecatedName().length() > 0) {
- Element deprecatedTag = createTag(decl, annotationTag, className, document, true);
- addAttributes(decl, deprecatedTag, document);
- parent.appendChild(deprecatedTag);
- }
- }
-
- protected void appendTag(InterfaceDeclaration decl, Element parent, Document document) {
- Tag annotationTag = decl.getAnnotation(Tag.class);
+ protected void appendTag(TypeElement typeElement, Element parent, Document document) throws ClassNotFoundException {
+ Tag annotationTag = typeElement.getAnnotation(Tag.class);
if (annotationTag != null) {
checkDuplicates(annotationTag.name());
resetAttributeDuplicateList();
// TODO configure replacement
-
- String className =
- decl.getQualifiedName().substring(0, decl.getQualifiedName().length() - "Declaration".length());
- if (decl.getAnnotation(UIComponentTag.class) != null) {
- className = "org.apache.myfaces.tobago.internal.taglib." + StringUtils.capitalize(annotationTag.name()) + "Tag";
- }
- //decl.getQualifiedName().replaceAll("Declaration", "");
- String msg = "Replacing: " + decl.getQualifiedName() + " -> " + className;
- getEnv().getMessager().printNotice(msg);
- Element tag = createTag(decl, annotationTag, className, document, false);
- addAttributes(decl, tag, document);
+ final String className;
+ if (typeElement.getAnnotation(TagGeneration.class) != null) {
+ className = typeElement.getAnnotation(TagGeneration.class).className();
+ info("G");
+ } else if (typeElement.getAnnotation(ExtensionTag.class) != null) {
+ className = typeElement.getQualifiedName().toString();
+ info("X");
+ } else if (typeElement.getAnnotation(UIComponentTag.class) != null) {
+ className = "org.apache.myfaces.tobago.internal.taglib." + StringUtils.capitalize(annotationTag.name())
+ + "Tag";
+ info("C");
+ } else {
+ className = typeElement.getQualifiedName().toString()
+ .substring(0, typeElement.getQualifiedName().length() - "Declaration".length());
+ info("?");
+ throw new RuntimeException("Not used, or?"); // XXX
+ }
+ info("Replacing: " + typeElement.getQualifiedName() + " -> " + className);
+ Element tag = createTag(typeElement, annotationTag, className, document, false);
+ addAttributes(typeElement, tag, document);
parent.appendChild(tag);
- if (annotationTag.deprecatedName() != null&&annotationTag.deprecatedName().length() > 0) {
- Element deprecatedTag = createTag(decl, annotationTag, className, document, true);
- addAttributes(decl, deprecatedTag, document);
+ if (annotationTag.deprecatedName() != null && annotationTag.deprecatedName().length() > 0) {
+ Element deprecatedTag = createTag(typeElement, annotationTag, className, document, true);
+ addAttributes(typeElement, deprecatedTag, document);
parent.appendChild(deprecatedTag);
}
}
}
protected Element createTag(
- Declaration decl, Tag annotationTag, String className, Document document, boolean deprecated) {
+ TypeElement typeElement, Tag annotationTag, String className, Document document, boolean deprecated) {
Element tagElement = document.createElement("tag");
+ addDescription(typeElement, tagElement, document, deprecated);
if (deprecated) {
addLeafTextElement(annotationTag.deprecatedName(), "name", tagElement, document);
} else {
@@ -232,12 +211,12 @@ public class TaglibAnnotationVisitor ext
}
addLeafTextElement(className, "tag-class", tagElement, document);
String tagExtraInfo = annotationTag.tagExtraInfoClassName();
- if (tagExtraInfo != null&& tagExtraInfo.length() > 0) {
+ if (tagExtraInfo != null && tagExtraInfo.length() > 0) {
// TODO check tagExtraInfo extends TagExtraInfo
addLeafTextElement(tagExtraInfo, "tei-class", tagElement, document);
}
BodyContent bodyContent = annotationTag.bodyContent();
- BodyContentDescription contentDescription = decl.getAnnotation(BodyContentDescription.class);
+ BodyContentDescription contentDescription = typeElement.getAnnotation(BodyContentDescription.class);
// TODO more error checking
if (contentDescription != null) {
if (bodyContent.equals(BodyContent.JSP) && contentDescription.contentType().length() > 0) {
@@ -248,13 +227,12 @@ public class TaglibAnnotationVisitor ext
}
}
addLeafTextElement(bodyContent.toString(), "body-content", tagElement, document);
- addDescription(decl, tagElement, document, deprecated);
return tagElement;
}
private void checkAttributeDuplicates(String attributeName) {
if (attributeSet.contains(attributeName)) {
- throw new IllegalArgumentException("Attribute " + attributeName + " in tag " + currentTag + " already defined!");
+ throw new IllegalArgumentException("Attribute " + attributeName + " in tag " + currentTag + " already defined!");
} else {
attributeSet.add(attributeName);
}
@@ -269,31 +247,31 @@ public class TaglibAnnotationVisitor ext
}
}
- protected void addDescription(Declaration decl, Element element, Document document) {
- addDescription(decl, element, document, false);
+ protected void addDescription(javax.lang.model.element.Element typeElement, Element element, Document document) {
+ addDescription(typeElement, element, document, false);
}
-
- protected void addDescription(Declaration decl, Element element, Document document, boolean deprecated) {
+ protected void addDescription(
+ javax.lang.model.element.Element typeElement, Element element, Document document, boolean deprecated) {
final StringBuilder description = new StringBuilder();
- final Deprecated deprecatedAnnotation = decl.getAnnotation(Deprecated.class);
- String comment = decl.getDocComment();
+ final Deprecated deprecatedAnnotation = typeElement.getAnnotation(Deprecated.class);
+ String comment = processingEnv.getElementUtils().getDocComment(typeElement);
final String deprecationComment = deprecationComment(comment);
if (deprecatedAnnotation != null || deprecationComment != null) {
description.append("<p>**** @deprecated. Will be removed in a future version **** </p>");
}
if (deprecated) {
- Tag annotationTag = decl.getAnnotation(Tag.class);
+ Tag annotationTag = typeElement.getAnnotation(Tag.class);
description.append("<p>**** @deprecated. Will be removed in a future version. Use ");
description.append(annotationTag.name());
description.append(" instead. **** </p>");
}
if (deprecationComment != null) {
- description.append("<p>" + deprecationComment + "</p>");
+ description.append("<p>").append(deprecationComment).append("</p>");
}
- Preliminary preliminary = decl.getAnnotation(Preliminary.class);
+ Preliminary preliminary = typeElement.getAnnotation(Preliminary.class);
if (preliminary != null) {
description.append("<p>**** Preliminary. Maybe subject to changed in a future version");
if (preliminary.value().length() > 0) {
@@ -315,11 +293,11 @@ public class TaglibAnnotationVisitor ext
//description.append("</p>");
}
}
- UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
+ UIComponentTag componentTag = typeElement.getAnnotation(UIComponentTag.class);
if (componentTag != null) {
description.append(createDescription(componentTag));
}
- UIComponentTagAttribute attributeTag = decl.getAnnotation(UIComponentTagAttribute.class);
+ UIComponentTagAttribute attributeTag = typeElement.getAnnotation(UIComponentTagAttribute.class);
if (attributeTag != null) {
if (null != attributeTag.type() && attributeTag.type().length > 0) {
description.append("<br />Type: <code>")
@@ -337,14 +315,14 @@ public class TaglibAnnotationVisitor ext
.append("</code>");
}
}
- ExtensionTag extensionTag = decl.getAnnotation(ExtensionTag.class);
+ ExtensionTag extensionTag = typeElement.getAnnotation(ExtensionTag.class);
if (extensionTag != null) {
String baseName = extensionTag.baseClassName();
description.append("<p><b>Extended tag: </b>");
description.append(baseName);
description.append("</p>");
- InterfaceDeclaration declaration = getInterfaceDeclaration(baseName + "Declaration");
+ TypeElement declaration = getInterfaceDeclaration(baseName + "Declaration");
if (declaration != null) {
UIComponentTag baseComponentTag = declaration.getAnnotation(UIComponentTag.class);
if (baseComponentTag != null) {
@@ -375,10 +353,10 @@ public class TaglibAnnotationVisitor ext
}
}
- private InterfaceDeclaration getInterfaceDeclaration(String name) {
- for (InterfaceDeclaration declaration : getCollectedInterfaceDeclarations()) {
- if (name.equals(declaration.getQualifiedName())) {
- return declaration;
+ private TypeElement getInterfaceDeclaration(String name) {
+ for (TypeElement type : getTypes()) {
+ if (name.equals(type.getQualifiedName().toString())) {
+ return type;
}
}
return null;
@@ -409,48 +387,44 @@ public class TaglibAnnotationVisitor ext
return description.toString();
}
- protected void addAttributes(Collection<InterfaceType> interfaces, Element tagElement, Document document) {
- for (InterfaceType type : interfaces) {
- addAttributes(type.getDeclaration(), tagElement, document);
- }
- }
+ protected void addAttributes(TypeElement type, Element tagElement, Document document) throws ClassNotFoundException {
- protected void addAttributes(InterfaceDeclaration type, Element tagElement, Document document) {
- addAttributes(type.getSuperinterfaces(), tagElement, document);
- for (MethodDeclaration decl : getCollectedMethodDeclarations()) {
- if (decl.getDeclaringType().equals(type)) {
- addAttribute(decl, tagElement, document);
+ for (javax.lang.model.element.Element element : getAllMembers(type)) {
+ if (element instanceof ExecutableElement) {
+ ExecutableElement executableElement = (ExecutableElement) element;
+ if (executableElement.getAnnotation(TagAttribute.class) == null
+ && executableElement.getAnnotation(UIComponentTagAttribute.class) == null) {
+ continue;
+ }
+ addAttribute(executableElement, tagElement, document);
}
}
}
- protected void addAttributes(ClassDeclaration d, Element tagElement, Document document) {
-
- for (MethodDeclaration decl : getCollectedMethodDeclarations()) {
- if (d.getQualifiedName().
- equals(decl.getDeclaringType().getQualifiedName())) {
- addAttribute(decl, tagElement, document);
- }
- }
- addAttributes(d.getSuperinterfaces(), tagElement, document);
- if (d.getSuperclass() != null) {
- addAttributes(d.getSuperclass().getDeclaration(), tagElement, document);
- }
+ private List<? extends javax.lang.model.element.Element> getAllMembers(TypeElement type) {
+ final List<? extends javax.lang.model.element.Element> members
+ = new ArrayList<javax.lang.model.element.Element>(processingEnv.getElementUtils().getAllMembers(type));
+ Collections.sort(members, new Comparator<javax.lang.model.element.Element>() {
+ public int compare(javax.lang.model.element.Element d1, javax.lang.model.element.Element d2) {
+ return d1.getSimpleName().toString().compareTo(d2.getSimpleName().toString());
+ }
+ });
+ return members;
}
-
+
private void resetDuplicateList() {
tagSet = new HashSet<String>();
}
-
+
private void resetAttributeDuplicateList() {
attributeSet = new HashSet<String>();
}
- protected void addAttribute(MethodDeclaration d, Element tagElement,
- Document document) {
- TagAttribute tagAttribute = d.getAnnotation(TagAttribute.class);
+ protected void addAttribute(ExecutableElement element, Element tagElement, Document document)
+ throws ClassNotFoundException {
+ TagAttribute tagAttribute = element.getAnnotation(TagAttribute.class);
if (tagAttribute != null) {
- String simpleName = d.getSimpleName();
+ String simpleName = element.getSimpleName().toString();
if (simpleName.startsWith("set") || simpleName.startsWith("get")) {
Element attribute = document.createElement("attribute");
String attributeStr = simpleName.substring(3, 4).toLowerCase(Locale.ENGLISH) + simpleName.substring(4);
@@ -458,11 +432,12 @@ public class TaglibAnnotationVisitor ext
attributeStr = tagAttribute.name();
}
checkAttributeDuplicates(attributeStr);
+ addDescription(element, attribute, document, false);
addLeafTextElement(attributeStr, "name", attribute, document);
addLeafTextElement(Boolean.toString(tagAttribute.required()), "required", attribute, document);
- UIComponentTagAttribute componentTagAttribute = d.getAnnotation(UIComponentTagAttribute.class);
- if (isMinium12() && !tagAttribute.rtexprvalue()) {
+ UIComponentTagAttribute componentTagAttribute = element.getAnnotation(UIComponentTagAttribute.class);
+ if (!tagAttribute.rtexprvalue()) {
if (componentTagAttribute != null) {
if (componentTagAttribute.expression().isMethodExpression()) {
Element deferredMethod = document.createElement("deferred-method");
@@ -475,21 +450,29 @@ public class TaglibAnnotationVisitor ext
signature.append(")");
addLeafTextElement(signature.toString(), "method-signature", deferredMethod, document);
attribute.appendChild(deferredMethod);
- } else if (componentTagAttribute != null && componentTagAttribute.expression().isValueExpression()) {
+ } else if (componentTagAttribute.expression().isValueExpression()) {
Element deferredValue = document.createElement("deferred-value");
- String type = "java.lang.Object";
- if (componentTagAttribute.expression().isValueExpression()) {
- if (componentTagAttribute.type().length == 1
- // XXX fix me hack
- && !"org.apache.myfaces.tobago.layout.Measure".equals(componentTagAttribute.type()[0])) {
- type = componentTagAttribute.type()[0];
+ String type;
+ if (componentTagAttribute.type().length == 1) {
+ type = componentTagAttribute.type()[0];
+ Class wrapper = ClassUtils.getWrapper(type);
+ if (wrapper != null) {
+ type = wrapper.getName(); // primitive types aren't allowed here
+/* } else {
+ XXX what is with inner classes and arrays?
+ if (type.endsWith("[]")) {
+ Class.forName(type.substring(0, type.length() - 2)); // type check
+ } else {
+ Class.forName(type); // type check
+ }
+*/
}
} else {
- type = componentTagAttribute.type()[0];
+ type = "java.lang.Object";
}
addLeafTextElement(type, "type", deferredValue, document);
attribute.appendChild(deferredValue);
- }
+ }
} else {
Element deferredValue = document.createElement("deferred-value");
addLeafTextElement(tagAttribute.type(), "type", deferredValue, document);
@@ -499,15 +482,10 @@ public class TaglibAnnotationVisitor ext
if (tagAttribute.rtexprvalue()) {
addLeafTextElement(Boolean.toString(tagAttribute.rtexprvalue()), "rtexprvalue", attribute, document);
}
- addDescription(d, attribute, document, false);
tagElement.appendChild(attribute);
} else {
throw new IllegalArgumentException("Only setter allowed found: " + simpleName);
}
}
}
-
- private boolean isMinium12() {
- return !"1.1".equals(jsfVersion);
- }
}
Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg?rev=1444033&r1=1444032&r2=1444033&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/tag1.2.stg Fri Feb 8 14:53:00 2013
@@ -207,6 +207,24 @@ if (<it.propertyName> != null) {
}
>>
+int() ::= <<
+if (<it.propertyName> != null) {
+ if (!<it.propertyName>.isLiteralText()) {
+ <createValueBinding(it)>
+ } else {
+ <if(it.widthOrHeight)>
+ String <it.propertyName>Str = <it.propertyName>.getExpressionString();
+ if (<it.propertyName>Str.endsWith("px")) {
+ <it.propertyName>Str = <it.propertyName>Str.substring(0, <it.propertyName>Str.length() - 2);
+ }
+ component.set<it.upperCamelCaseName>(Integer.parseInt(<it.propertyName>Str));
+ <else>
+ component.set<it.upperCamelCaseName>(Integer.parseInt(<it.propertyName>.getExpressionString()));
+ <endif>
+ }
+}
+>>
+
Integer() ::= <<
if (<it.propertyName> != null) {
if (!<it.propertyName>.isLiteralText()) {