1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.diff; |
34 |
| |
35 |
| import java.io.*; |
36 |
| import java.util.*; |
37 |
| |
38 |
| import com.sun.javadoc.*; |
39 |
| |
40 |
| public class ListDocumentedElements { |
41 |
| private static String tagName = null; |
42 |
| private static Collection<String> validValues = new HashSet<String>(); |
43 |
| private static Collection<String> invalidValues = new HashSet<String>(); |
44 |
| private static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); |
45 |
| |
46 |
0
| public static boolean start(RootDoc root) {
|
47 |
0
| process(root.specifiedPackages());
|
48 |
0
| process(root.classes());
|
49 |
0
| out.close();
|
50 |
0
| return true;
|
51 |
| } |
52 |
| |
53 |
0
| public static int optionLength(String option) {
|
54 |
0
| int result = 0;
|
55 |
| |
56 |
0
| if (option.equals("-tag")) {
|
57 |
0
| result = 2;
|
58 |
0
| } else if (option.equals("-valid")) {
|
59 |
0
| result = 2;
|
60 |
0
| } else if (option.equals("-invalid")) {
|
61 |
0
| result = 2;
|
62 |
0
| } else if (option.equals("-out")) {
|
63 |
0
| result = 2;
|
64 |
| } |
65 |
| |
66 |
0
| return result;
|
67 |
| } |
68 |
| |
69 |
0
| public static boolean validOptions(String options[][], DocErrorReporter reporter) {
|
70 |
0
| boolean valid = true;
|
71 |
| |
72 |
0
| for (int i=0; valid && i<options.length; i++) {
|
73 |
0
| if (options[i][0].equals("-tag")) {
|
74 |
0
| if (tagName == null) {
|
75 |
0
| tagName = options[i][1];
|
76 |
| } else { |
77 |
0
| reporter.printError("Only one -tag option allowed.");
|
78 |
0
| valid = false;
|
79 |
| } |
80 |
0
| } else if (options[i][0].equals("-valid")) {
|
81 |
0
| validValues.add(options[i][1]);
|
82 |
0
| } else if (options[i][0].equals("-invalid")) {
|
83 |
0
| invalidValues.add(options[i][1]);
|
84 |
0
| } else if (options[i][0].equals("-out")) {
|
85 |
0
| try {
|
86 |
0
| out = new PrintWriter(new FileWriter(options[i][1]));
|
87 |
| } catch (IOException ex) { |
88 |
0
| reporter.printError("Could not open output file \"" + options[i][1] + "\": " + ex);
|
89 |
0
| valid = false;
|
90 |
| } |
91 |
| } |
92 |
| } |
93 |
| |
94 |
0
| valid = valid && tagName != null;
|
95 |
| |
96 |
0
| if (!valid) {
|
97 |
0
| reporter.printError("Usage: javadoc -tag mytag [-valid value]* [-invalid value]* -doclet ListPublicElements ...");
|
98 |
| } |
99 |
| |
100 |
0
| return valid;
|
101 |
| } |
102 |
| |
103 |
0
| private static void process(PackageDoc[] docs) {
|
104 |
0
| for (PackageDoc doc : docs) {
|
105 |
0
| process(doc);
|
106 |
| } |
107 |
| } |
108 |
| |
109 |
0
| private static void process(PackageDoc doc) {
|
110 |
0
| out.print(doc.name());
|
111 |
0
| out.println(" [P]");
|
112 |
| } |
113 |
| |
114 |
0
| private static void process(ProgramElementDoc[] docs) {
|
115 |
0
| for (ProgramElementDoc doc : docs) {
|
116 |
0
| process(doc);
|
117 |
| } |
118 |
| } |
119 |
| |
120 |
0
| private static void process(ProgramElementDoc doc) {
|
121 |
0
| boolean isVisible = !doc.name().equals("<clinit>");
|
122 |
| |
123 |
0
| Tag[] tags = doc.tags(tagName);
|
124 |
| |
125 |
0
| if (isVisible) {
|
126 |
0
| if (!validValues.isEmpty()) {
|
127 |
| |
128 |
0
| isVisible = false;
|
129 |
0
| for (Tag tag : tags) {
|
130 |
0
| if (validValues.contains(tag.text())) {
|
131 |
0
| isVisible = true;
|
132 |
| } |
133 |
| } |
134 |
0
| } else if (!invalidValues.isEmpty()) {
|
135 |
| |
136 |
0
| for (Tag tag : tags) {
|
137 |
0
| if (invalidValues.contains(tag.text())) {
|
138 |
0
| isVisible = false;
|
139 |
| } |
140 |
| } |
141 |
| } |
142 |
| } |
143 |
| |
144 |
0
| if (isVisible) {
|
145 |
0
| out.print(doc.qualifiedName());
|
146 |
0
| if (doc instanceof ConstructorDoc) {
|
147 |
0
| out.print(".");
|
148 |
0
| out.print(doc.name());
|
149 |
| } |
150 |
0
| if (doc instanceof ExecutableMemberDoc) {
|
151 |
0
| out.print(((ExecutableMemberDoc) doc).signature());
|
152 |
| } |
153 |
| |
154 |
0
| if (doc instanceof ClassDoc) {
|
155 |
0
| out.println(" [C]");
|
156 |
0
| process(((ClassDoc) doc).fields());
|
157 |
0
| process(((ClassDoc) doc).constructors());
|
158 |
0
| process(((ClassDoc) doc).methods());
|
159 |
0
| process(((ClassDoc) doc).innerClasses());
|
160 |
| } else { |
161 |
0
| out.println(" [F]");
|
162 |
| } |
163 |
| } |
164 |
| } |
165 |
| } |