You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by le...@apache.org on 2004/05/05 14:21:16 UTC
cvs commit: jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/javadoc CATaglet.java
leosutic 2004/05/05 05:21:16
Modified: attributes/compiler project.xml
Added: attributes/compiler/src/java/org/apache/commons/attributes/javadoc
CATaglet.java
Log:
Added a Taglet for Javadoc 1.4 and later.
Revision Changes Path
1.7 +7 -1 jakarta-commons-sandbox/attributes/compiler/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/attributes/compiler/project.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- project.xml 21 Mar 2004 00:03:55 -0000 1.6
+++ project.xml 5 May 2004 12:21:16 -0000 1.7
@@ -22,7 +22,7 @@
<groupId>commons-attributes</groupId>
<id>commons-attributes-compiler</id>
- <name>Jakarta Commons Attributes Ant Task</name>
+ <name>Jakarta Commons Attributes Ant Tasks and Utilities</name>
<package>org.apache.commons.attributes.compiler</package>
<shortDescription>Attribute Compiler</shortDescription>
@@ -51,6 +51,12 @@
<groupId>commons-attributes</groupId>
<artifactId>commons-attributes-api</artifactId>
<version>SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javadoc</groupId>
+ <artifactId>javadoc</artifactId>
+ <version>1.4</version>
</dependency>
</dependencies>
1.1 jakarta-commons-sandbox/attributes/compiler/src/java/org/apache/commons/attributes/javadoc/CATaglet.java
Index: CATaglet.java
===================================================================
/*
* Copyright 2003-2004 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.commons.attributes.javadoc;
import com.sun.tools.doclets.Taglet;
import com.sun.tools.doclets.standard.Standard;
import com.sun.javadoc.*;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Map;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.Set;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.List;
import java.util.ArrayList;
public class CATaglet implements Taglet {
public static class AttributeTaglet extends CATaglet {
private final String name;
private final CATaglet caTaglet;
public AttributeTaglet (String name, CATaglet caTaglet) {
this.name = name;
this.caTaglet = caTaglet;
}
public String getName() {
return name;
}
public String toString(Tag[] tags) {
caTaglet.addTags (tags);
return null;
}
}
private List tagList = new ArrayList ();
private static final String NAME = "org.apache.commons.attributes.CATaglet";
public CATaglet () {
}
public void addTags (Tag[] tags) {
for (int i = 0; i < tags.length; i++) {
tagList.add (tags[i].name() + " " + tags[i].text ());
}
}
/**
* Return the name of this custom tag.
*/
public String getName() {
return NAME;
}
public boolean inField() {
return true;
}
public boolean inConstructor() {
return true;
}
public boolean inMethod() {
return true;
}
public boolean inOverview() {
return false;
}
public boolean inPackage() {
return false;
}
public boolean inType() {
return true;
}
public boolean isInlineTag() {
return false;
}
public static void register(Map tagletMap) {
CATaglet caTaglet = new CATaglet ();
caTaglet.registerTags (tagletMap);
}
public void registerTags (Map tagletMap) {
Set tagNames = new HashSet ();
StringTokenizer tok = new StringTokenizer (System.getProperty ("org.apache.commons.attributes.javadoc.CATaglet.sources"), File.pathSeparator);
while (tok.hasMoreTokens ()) {
try {
scanFiles (new File (tok.nextToken ()), tagNames);
} catch (Exception e) {
System.err.println ("Caught " + e.toString () + " trying to scan Java sources. Javadoc of attributes may be incomplete.");
}
}
if (tagNames.size () > 0) {
Iterator iter = tagNames.iterator ();
while (iter.hasNext ()) {
String name = (String) iter.next ();
register(name, tagletMap);
}
tagletMap.put (NAME, this);
}
}
private void scanFiles (File directory, Collection tagNames) throws Exception {
File[] files = directory.listFiles ();
if (files == null) {
return;
}
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory ()) {
scanFiles (files[i], tagNames);
} else {
scanFile (files[i], tagNames);
}
}
}
private void scanFile (File file, Collection tagNames) throws Exception {
BufferedReader br = new BufferedReader (new FileReader (file));
try {
String line = null;
while ((line = br.readLine ()) != null) {
scanLine (line, tagNames);
}
} finally {
br.close ();
}
}
private void scanLine (String line, Collection tagNames) throws Exception {
int start = line.indexOf ("@@");
while (start != -1) {
int end = line.indexOf (" ", start);
if (end == -1) {
end = line.length ();
}
tagNames.add (line.substring (start + 1, end));
start = line.indexOf ("@@", end);
}
}
private void register (String name, Map tagletMap) {
Taglet tag = new AttributeTaglet ("@" + name, this);
if (tagletMap.get (name) != null) {
tagletMap.remove(name);
}
tagletMap.put (name, tag);
}
public String toString(Tag tag) {
return null;
}
public String toString (Tag[] _t) {
String[] tags = (String[]) tagList.toArray (new String[0]);
if (tags.length == 0) {
return null;
}
// Sort by target
Map targets = new TreeMap ();
for (int i = 0; i < tags.length; i++) {
String target = "";
String attribute = tags[i];
if (tags[i].startsWith ("@@.")) {
int targetEnd = tags[i].indexOf (" ", 3);
if (targetEnd != -1) {
target = tags[i].substring (3, targetEnd);
attribute = "@@" + tags[i].substring (targetEnd).trim ();
} else {
}
}
if (!targets.containsKey (target)) {
targets.put (target, new ArrayList ());
}
List tagsForTarget = (List) targets.get (target);
tagsForTarget.add (attribute);
}
StringBuffer result = new StringBuffer ();
result.append ("<DT><B>Attributes:</B>");
List attrs = (List) targets.remove ("");
if (attrs != null) {
result.append ("<DD><CODE>");
Iterator iter = attrs.iterator ();
while (iter.hasNext ()) {
result.append (iter.next ());
if (iter.hasNext ()) {
result.append ("<BR>");
}
}
result.append ("</CODE>");
}
List returnAttrs = (List) targets.remove ("return");
if (targets.size () > 0) {
result.append ("<DT><B>Parameter Attributes:</B>");
Iterator parameterTargets = targets.keySet ().iterator ();
while (parameterTargets.hasNext ()) {
String target = (String) parameterTargets.next ();
attrs = (List) targets.remove (target);
result.append ("<DD><CODE>" + target + "</CODE> - <BR><CODE>");
Iterator iter = attrs.iterator ();
while (iter.hasNext ()) {
result.append ("    " + iter.next ());
if (iter.hasNext ()) {
result.append ("<BR>");
}
}
result.append ("</CODE>");
}
}
if (returnAttrs != null) {
result.append ("<DT><B>Return Value Attributes:</B>");
result.append ("<DD><CODE>");
Iterator iter = returnAttrs.iterator ();
while (iter.hasNext ()) {
result.append (iter.next ());
if (iter.hasNext ()) {
result.append ("<BR>");
}
}
result.append ("</CODE>");
}
tagList.clear ();
return result.toString ();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org