You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/05/22 21:09:20 UTC

svn commit: r1126173 - in /tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc: ClassDescription.java ParameterDescription.java TapestryDocTaglet.java

Author: hlship
Date: Sun May 22 19:09:20 2011
New Revision: 1126173

URL: http://svn.apache.org/viewvc?rev=1126173&view=rev
Log:
TAP5-1528: Begin converting JavaDoc classes to Tapestry-specific ClassDescription and ParameterDescription
Output component events, if any present

Added:
    tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ClassDescription.java
    tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ParameterDescription.java
Modified:
    tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/TapestryDocTaglet.java

Added: tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ClassDescription.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ClassDescription.java?rev=1126173&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ClassDescription.java (added)
+++ tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ClassDescription.java Sun May 22 19:09:20 2011
@@ -0,0 +1,121 @@
+// Copyright 2007, 2009, 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.javadoc;
+
+import java.util.Map;
+
+import org.apache.tapestry5.annotations.Events;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+
+import com.sun.javadoc.AnnotationDesc;
+import com.sun.javadoc.AnnotationValue;
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.ProgramElementDoc;
+import com.sun.javadoc.AnnotationDesc.ElementValuePair;
+
+public class ClassDescription
+{
+    private final ClassDoc classDoc;
+
+    private final Map<String, ParameterDescription> parameters = CollectionFactory.newCaseInsensitiveMap();
+
+    private final Map<String, String> publishedParameters = CollectionFactory.newCaseInsensitiveMap();
+
+    private final Map<String, String> events = CollectionFactory.newCaseInsensitiveMap();
+
+    public ClassDescription(ClassDoc classDoc)
+    {
+        this.classDoc = classDoc;
+
+        loadEvents();
+        loadParameters();
+    }
+
+    private void loadEvents()
+    {
+        AnnotationDesc eventsAnnotation = getAnnotation(classDoc, Events.class);
+
+        if (eventsAnnotation == null)
+            return;
+
+        // Events has only a single attribute: value(), so we know its the first element
+        // in the array.
+
+        ElementValuePair pair = eventsAnnotation.elementValues()[0];
+
+        AnnotationValue annotationValue = pair.value();
+        AnnotationValue[] values = (AnnotationValue[]) annotationValue.value();
+
+        for (AnnotationValue eventValue : values)
+        {
+            String event = (String) eventValue.value();
+            int ws = event.indexOf(' ');
+
+            String name = ws < 0 ? event : event.substring(0, ws);
+            String description = ws < 0 ? "" : event.substring(ws + 1).trim();
+
+            events.put(name, description);
+        }
+    }
+
+    private void loadParameters()
+    {
+
+    }
+
+    private AnnotationDesc getAnnotation(ProgramElementDoc source, Class annotationType)
+    {
+        String name = annotationType.getName();
+
+        for (AnnotationDesc ad : source.annotations())
+        {
+            if (ad.annotationType().qualifiedTypeName().equals(name)) { return ad; }
+        }
+
+        return null;
+    }
+
+    public String getClassName()
+    {
+        return classDoc.qualifiedName();
+    }
+
+    public Map<String, ParameterDescription> getParameters()
+    {
+        return parameters;
+    }
+
+    public String getSuperClassName()
+    {
+        return classDoc.superclass().qualifiedName();
+    }
+
+    /**
+     * Case insensitive map, keyed on parameter name, value is class name of component from which the parameter is
+     * published.
+     */
+    public Map<String, String> getPublishedParameters()
+    {
+        return publishedParameters;
+    }
+
+    /**
+     * Case insensitive map, keyed on event name, value is optional description (often blank).
+     */
+    public Map<String, String> getEvents()
+    {
+        return events;
+    }
+}

Added: tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ParameterDescription.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ParameterDescription.java?rev=1126173&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ParameterDescription.java (added)
+++ tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/ParameterDescription.java Sun May 22 19:09:20 2011
@@ -0,0 +1,103 @@
+// Copyright 2007, 2008, 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.javadoc;
+
+public class ParameterDescription
+{
+    private final String name;
+
+    private final String type;
+
+    private final String defaultValue;
+
+    private final String defaultPrefix;
+
+    private final boolean required;
+
+    private final boolean allowNull;
+
+    private final boolean cache;
+
+    private final String description;
+    
+    private final String since;
+    
+    private final boolean deprecated;
+
+    public ParameterDescription(String name, String type, String defaultValue,
+                                String defaultPrefix, boolean required, boolean allowNull, boolean cache,
+                                String description, String since, boolean deprecated)
+    {
+        this.name = name;
+        this.type = type;
+        this.defaultValue = defaultValue;
+        this.defaultPrefix = defaultPrefix;
+        this.required = required;
+        this.allowNull = allowNull;
+        this.cache = cache;
+        this.description = description;
+        this.since = since;
+        this.deprecated = deprecated;
+    }
+
+    public boolean getCache()
+    {
+        return cache;
+    }
+
+    public String getDefaultPrefix()
+    {
+        return defaultPrefix;
+    }
+
+    public String getDefaultValue()
+    {
+        return defaultValue;
+    }
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public boolean getRequired()
+    {
+        return required;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public boolean getAllowNull()
+    {
+        return allowNull;
+    }
+
+	public String getSince() 
+	{
+		return since;
+	}
+
+	public boolean isDeprecated() {
+		return deprecated;
+	}
+}

Modified: tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/TapestryDocTaglet.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/TapestryDocTaglet.java?rev=1126173&r1=1126172&r2=1126173&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/TapestryDocTaglet.java (original)
+++ tapestry/tapestry5/trunk/tapestry-javadoc/src/main/java/org/apache/tapestry5/javadoc/TapestryDocTaglet.java Sun May 22 19:09:20 2011
@@ -15,9 +15,14 @@
 package org.apache.tapestry5.javadoc;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.StringWriter;
+import java.io.Writer;
 import java.util.Map;
 
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+
 import com.sun.javadoc.ClassDoc;
 import com.sun.javadoc.Tag;
 import com.sun.tools.doclets.Taglet;
@@ -27,6 +32,13 @@ import com.sun.tools.doclets.Taglet;
  */
 public class TapestryDocTaglet implements Taglet
 {
+    /**
+     * Map from class name to class description.
+     */
+    private final Map<String, ClassDescription> classDescriptions = CollectionFactory.newMap();
+
+    private ClassDoc firstSeen;
+
     private static final String NAME = "tapestrydoc";
 
     @SuppressWarnings("unchecked")
@@ -75,6 +87,20 @@ public class TapestryDocTaglet implement
         return NAME;
     }
 
+    public ClassDescription getDescription(String className)
+    {
+        ClassDescription result = classDescriptions.get(className);
+
+        if (result == null)
+        {
+            ClassDoc cd = firstSeen.findClass(className);
+            result = new ClassDescription(cd);
+            classDescriptions.put(className, result);
+        }
+
+        return result;
+    }
+
     public String toString(Tag tag)
     {
         throw new IllegalStateException("toString(Tag) should not be called for a non-inline tag.");
@@ -96,6 +122,13 @@ public class TapestryDocTaglet implement
 
             ClassDoc classDoc = (ClassDoc) tag.holder();
 
+            if (firstSeen == null)
+                firstSeen = classDoc;
+
+            ClassDescription cd = getDescription(classDoc.qualifiedName());
+
+            writeClassDescription(cd, writer);
+
             streamXdoc(classDoc, writer);
 
             return writer.toString();
@@ -109,7 +142,36 @@ public class TapestryDocTaglet implement
         }
     }
 
-    private void streamXdoc(ClassDoc classDoc, StringWriter writer) throws Exception
+    private void writeElement(Writer writer, String elementName, String text) throws IOException
+    {
+        writer.write(String.format("<%s>%s</%1$s>", elementName, text));
+    }
+
+    private void writeClassDescription(ClassDescription cd, Writer writer) throws IOException
+    {
+        Map<String, String> events = cd.getEvents();
+
+        if (events.isEmpty())
+            return;
+
+        writer.write("<dt><b>Events:</b></dt><dd><dl>");
+
+        for (String name : InternalUtils.sortedKeys(events))
+        {
+            writeElement(writer, "dt", name);
+
+            String value = events.get(name);
+
+            if (value.length() > 0)
+            {
+                writeElement(writer, "dd", value);
+            }
+        }
+
+        writer.write("</dl></dd>");
+    }
+
+    private void streamXdoc(ClassDoc classDoc, Writer writer) throws Exception
     {
         File sourceFile = classDoc.position().file();