I realize something like this, it check if a class has test method : you can modify this to iterate over all methods.
I hope it will help you.
David
package com.myclass.xdoclet;
import java.util.*;
import xjavadoc.*; import xdoclet.DocletContext;
import xdoclet.tagshandler.*; import xdoclet.XDocletException; import xdoclet.XDocletMessages; import xdoclet.XmlSubTask; import xdoclet.util.DocletUtil; import xdoclet.util.LogUtil; import xdoclet.util.Translator; import xdoclet.util.TypeConversionUtil;
/**
* This class offers new tags to XDoclet.
* Those tags returns function results to deal easily with the tests
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Sciamma</a>
* @created Feb 21, 2003
* @xdoclet.taghandler namespace="Test"
* @version $Revision: 1.1.1.1 $
*/
public class TestTagsHandler extends MethodTagsHandler
{
/**
* Evaluates if the class contains a test method.
* Use : <XDtTest:ifHasTestMethod></XDtTest:ifHasTestMethod>
*
* @param template The body of the block tag
* @param attributes The attributes of the template tag
* @exception XDocletException
*/
public void ifHasTestMethod(String template, Properties attributes) throws XDocletException
{
boolean superclasses = TypeConversionUtil.stringToBoolean(attributes.getProperty("superclasses"), true);
XClass currentClass = getCurrentClass();
boolean hasTest = false;
if (currentClass == null) {
throw new XDocletException("currentClass == null!!!");
}Collection members = null;
members = currentClass.getMethods(superclasses);
for (Iterator j = members.iterator(); j.hasNext(); ) {
XMember member = (XMember) j.next();
if (_isTestMethod((XMethod) member)) {
hasTest = true;
}
setCurrentClass(member.getContainingClass());}
setCurrentClass(currentClass);
if (hasTest) {
generate(template);
}
}
/**
* Evaluates if the method is a test method.
* Use : <XDtTest:ifIsTestMethod></XDtTest:ifIsTestMethod>
*
* @param template The body of the block tag
* @param attributes The attributes of the template tag
* @exception XDocletException
*/
public void ifIsTestMethod(String template, Properties attributes) throws XDocletException
{
String method_name = attributes.getProperty("method");
if (method_name != null) {
if (_isTest(method_name)) {
generate(template);
}
}
else {
if (_isTestMethod(getCurrentMethod())) {
generate(template);
}
}
}
/**
* Returns true if the str string starts with the "test", "load", "timed", "mixed" or "memory" prefix.
*
* @param str
*/
private static boolean _isTest(String str)
{
return str.startsWith("test");
}
/**
* Returns true if the method is a test method.
*
* @param method
*/ private static boolean _isTestMethod(XMethod method)
{
String str = method.getName();
return _isTest(str); } }
Rupp,Heiko wrote:
Hi,
I'm trying to write a template which
matches all public methods which start with 'test'.
Regular Expressions are not yet supported. Can't say about the simple test* case though. Afaik, there are currently investigations underway on how to support regexp in JDK 1.3, which does not have this capability. Xdoclet2 will probably require JDK1.4, so regexps are provided by the JDK and will probably be used.
Doesn't really help? :-/
Heiko
------------------------------------------------------- This SF.net email is sponsored by: ObjectStore. If flattening out C++ or Java code to make your application fit in a relational database is painful, don't do it! Check out ObjectStore. Now part of Progress Software. http://www.objectstore.net/sourceforge _______________________________________________ xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user
