1 package xdoclet.sdk.ant;
2
3 import org.apache.commons.collections.Predicate;
4
5 import xdoclet.util.TypeConversionUtil;
6
7 import xjavadoc.XClass;
8 import xjavadoc.XMethod;
9
10 /***
11 * Predicate that lets through Ant tasks.
12 *
13 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a>
14 * @author Erik Hatcher
15 * @version $Revision: 1.7 $
16 */
17 public class AntTaskPredicate implements Predicate {
18 /***
19 * Checks many factors to determine if the class is indeed an Ant task or
20 * not.
21 *
22 * @return true if o is a class and represents an Ant task.
23 */
24 public boolean evaluate(Object o) {
25 XClass clazz = (XClass) o;
26
27 if (clazz.isAbstract()) {
28 return false;
29 }
30
31 // no inner classes (for now - but is this possible? desired?)
32 if (clazz.isInner()) {
33 return false;
34 }
35
36 String ignoreValue = clazz.getDoc().getTagAttributeValue("ant.task", "ignore");
37 boolean ignore = TypeConversionUtil.stringToBoolean(ignoreValue, false);
38
39 if (ignore) {
40 return false;
41 }
42
43 /*
44 * Tag[] tags = clazz.tags();
45 * for (int i = 0; i < tags.length; i++) {
46 * if ("@deprecated".equals(tags[i].name())) {
47 * return false;
48 * }
49 * }
50 */
51 if (hasExecuteMethod(clazz)) {
52 return true;
53 }
54
55 return false;
56 }
57
58 /***
59 * Check for class implementing an execute() method.
60 *
61 * @param clazz the class to check.
62 * @return true if the class has an execute() method
63 */
64 private static boolean hasExecuteMethod(XClass clazz) {
65 if (clazz == null) {
66 return false;
67 }
68
69 // It ain't a task if we've climbed back to Task itself.
70 // Also ignore other special Ant classes
71 if ("org.apache.tools.ant.Task".equals(clazz.getQualifiedName())
72 || "org.apache.tools.ant.Target".equals(clazz.getQualifiedName())
73 || "org.apache.tools.ant.TaskAdapter".equals(clazz.getQualifiedName())
74 || "org.apache.tools.ant.UnknownElement".equals(clazz.getQualifiedName())) {
75 return false;
76 }
77
78 // need to check that only runtime exceptions are thrown?
79 XMethod method = clazz.getMethod("execute()", true);
80
81 if ((method != null) && method.getReturnType().getType().getQualifiedName().equals("void")) {
82 return true;
83 }
84
85 return false;
86 }
87 }
This page was automatically generated by Maven