You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/01/29 04:15:25 UTC
svn commit: r616152 -
/tapestry/tapestry5/trunk/tapestry-component-report/src/main/java/org/apache/tapestry/mojo/ParametersDoclet.java
Author: hlship
Date: Mon Jan 28 19:15:24 2008
New Revision: 616152
URL: http://svn.apache.org/viewvc?rev=616152&view=rev
Log:
TAPESTRY-2061: tapestry-component-report reports only components with parameters
Modified:
tapestry/tapestry5/trunk/tapestry-component-report/src/main/java/org/apache/tapestry/mojo/ParametersDoclet.java
Modified: tapestry/tapestry5/trunk/tapestry-component-report/src/main/java/org/apache/tapestry/mojo/ParametersDoclet.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-component-report/src/main/java/org/apache/tapestry/mojo/ParametersDoclet.java?rev=616152&r1=616151&r2=616152&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-component-report/src/main/java/org/apache/tapestry/mojo/ParametersDoclet.java (original)
+++ tapestry/tapestry5/trunk/tapestry-component-report/src/main/java/org/apache/tapestry/mojo/ParametersDoclet.java Mon Jan 28 19:15:24 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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.
@@ -20,22 +20,14 @@
import java.io.File;
import java.io.PrintWriter;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import java.util.regex.Pattern;
/**
- * Generates an XML file that identifies all the classes that contain parameters, and all the
- * parameters within each component class. This XML is later converted into part of the Maven
- * generated HTML site.
+ * Generates an XML file that identifies all the classes that contain parameters, and all the parameters within each
+ * component class. This XML is later converted into part of the Maven generated HTML site.
* <p/>
- * To keep the -doclet parameter passed to javadoc simple, this class should not have any outside
- * dependencies.
- * <p/>
- * Works in two passes: First we find any classes that have a field that has the parameter
- * annotation. Second we locate any subclasses of the initial set of classes, regardless of whether
- * they have a parameter or not.
+ * To keep the -doclet parameter passed to javadoc simple, this class should not have any outside dependencies.
*/
public class ParametersDoclet extends Doclet
{
@@ -47,18 +39,10 @@
{
private PrintWriter _out;
- private RootDoc _root;
-
- private final Set<ClassDoc> _processed = new HashSet<ClassDoc>();
-
- private final Pattern _stripper = java.util.regex.Pattern.compile(
- "(<.*?>|&.*?;)",
- Pattern.DOTALL);
+ private final Pattern _stripper = Pattern.compile("(<.*?>|&.*?;)", Pattern.DOTALL);
public void run(String outputPath, RootDoc root) throws Exception
{
- _root = root;
-
File output = new File(outputPath);
_out = new PrintWriter(output);
@@ -66,33 +50,20 @@
println("<component-parameters>");
for (ClassDoc cd : root.classes())
- {
- emitClass(cd, false);
- }
-
- for (ClassDoc potential : _root.classes())
- {
- for (ClassDoc potentialParent : _processed)
- {
- if (potential.subclassOf(potentialParent))
- {
- emitClass(potential, true);
- break;
- }
- }
- }
+ emitClass(cd);
println("</component-parameters>");
_out.close();
}
- private void emitClass(ClassDoc classDoc, boolean forceClassOutput)
+ private void emitClass(ClassDoc classDoc)
{
- if (_processed.contains(classDoc)) return;
-
if (!classDoc.isPublic()) return;
+ // Components must be root classes, not nested classes.
+ if (classDoc.containingClass() != null) return;
+
// Check for a no-args public constructor
boolean found = false;
@@ -108,7 +79,11 @@
if (!found) return;
- boolean wroteClass = false;
+ println("<class name=\"%s\" super-class=\"%s\">", classDoc.qualifiedTypeName(),
+ classDoc.superclass().qualifiedTypeName());
+ print("<description>");
+ printDescription(classDoc);
+ println("</description>", classDoc.commentText());
for (FieldDoc fd : classDoc.fields())
{
@@ -120,23 +95,13 @@
if (annotationValues == null) continue;
- if (!wroteClass)
- {
- printClassDescriptionStart(classDoc);
- wroteClass = true;
- }
-
String name = annotationValues.get("name");
if (name == null) name = fd.name().replaceAll("^[$_]*", "");
- print(
- "<parameter name=\"%s\" type=\"%s\" default=\"%s\" required=\"%s\" cache=\"%s\" default-prefix=\"%s\">",
- name,
- fd.type().qualifiedTypeName(),
- get(annotationValues, "value", ""),
- get(annotationValues, "required", "false"),
- get(annotationValues, "cache", "true"),
- get(annotationValues, "defaultPrefix", "prop"));
+ print("<parameter name=\"%s\" type=\"%s\" default=\"%s\" required=\"%s\" cache=\"%s\" default-prefix=\"%s\">",
+ name, fd.type().qualifiedTypeName(), get(annotationValues, "value", ""),
+ get(annotationValues, "required", "false"), get(annotationValues, "cache", "true"),
+ get(annotationValues, "defaultPrefix", "prop"));
// Body of a parameter is the comment text.
@@ -145,27 +110,7 @@
println("\n</parameter>");
}
- if (wroteClass)
- println("</class>");
- else if (forceClassOutput)
- {
- printClassDescriptionStart(classDoc);
- println("</class>");
- }
-
- if (wroteClass || forceClassOutput) _processed.add(classDoc);
-
- }
-
- private void printClassDescriptionStart(ClassDoc classDoc)
- {
- println(
- "<class name=\"%s\" super-class=\"%s\">",
- classDoc.qualifiedTypeName(),
- classDoc.superclass().qualifiedTypeName());
- print("<description>");
- printDescription(classDoc);
- println("</description>", classDoc.commentText());
+ println("</class>");
}
private String get(Map<String, String> map, String key, String defaultValue)
@@ -179,8 +124,7 @@
{
for (AnnotationDesc annotation : fd.annotations())
{
- if (annotation.annotationType().qualifiedTypeName().equals(
- "org.apache.tapestry.annotations.Parameter"))
+ if (annotation.annotationType().qualifiedTypeName().equals("org.apache.tapestry.annotations.Parameter"))
{
Map<String, String> result = new HashMap<String, String>();
@@ -231,16 +175,13 @@
continue;
}
- if (seeTag.referencedClassName() != null)
- builder.append(seeTag.referencedClassName());
+ if (seeTag.referencedClassName() != null) builder.append(seeTag.referencedClassName());
if (seeTag.referencedMemberName() != null)
{
builder.append("#");
builder.append(seeTag.referencedMemberName());
}
-
- continue;
}
}
@@ -281,8 +222,7 @@
// TODO: Check for duplicate -o?
}
- if (_outputPath == null)
- reporter.printError(String.format("Usage: javadoc %s path", OUTPUT_PATH_OPTION));
+ if (_outputPath == null) reporter.printError(String.format("Usage: javadoc %s path", OUTPUT_PATH_OPTION));
return true;
}