01: package org.umlgraph.doclet;
02:
03: import java.util.regex.Pattern;
04:
05: import com.sun.javadoc.ClassDoc;
06: import com.sun.javadoc.RootDoc;
07:
08: /**
09: * Matches every class that implements (directly or indirectly) an
10: * interfaces matched by regular expression provided.
11: */
12: public class InterfaceMatcher implements ClassMatcher {
13:
14: protected RootDoc root;
15: protected Pattern pattern;
16:
17: public InterfaceMatcher(RootDoc root, Pattern pattern) {
18: this .root = root;
19: this .pattern = pattern;
20: }
21:
22: public boolean matches(ClassDoc cd) {
23: // if it's the interface we're looking for, match
24: if (cd.isInterface()
25: && pattern.matcher(cd.toString()).matches())
26: return true;
27:
28: // for each interface, recurse, since classes and interfaces
29: // are treated the same in the doclet API
30: for (ClassDoc iface : cd.interfaces()) {
31: if (matches(iface))
32: return true;
33: }
34:
35: // recurse on supeclass, if available
36: if (cd.super class() != null)
37: return matches(cd.super class());
38:
39: return false;
40: }
41:
42: public boolean matches(String name) {
43: ClassDoc cd = root.classNamed(name);
44: if (cd == null)
45: return false;
46: return matches(cd);
47: }
48:
49: }
|