001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.diff;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import com.sun.javadoc.*;
039:
040: public class ListDocumentedElements {
041: private static String tagName = null;
042: private static Collection<String> validValues = new HashSet<String>();
043: private static Collection<String> invalidValues = new HashSet<String>();
044: private static PrintWriter out = new PrintWriter(
045: new OutputStreamWriter(System.out));
046:
047: public static boolean start(RootDoc root) {
048: process(root.specifiedPackages());
049: process(root.classes());
050: out.close();
051: return true;
052: }
053:
054: public static int optionLength(String option) {
055: int result = 0;
056:
057: if (option.equals("-tag")) {
058: result = 2;
059: } else if (option.equals("-valid")) {
060: result = 2;
061: } else if (option.equals("-invalid")) {
062: result = 2;
063: } else if (option.equals("-out")) {
064: result = 2;
065: }
066:
067: return result;
068: }
069:
070: public static boolean validOptions(String options[][],
071: DocErrorReporter reporter) {
072: boolean valid = true;
073:
074: for (int i = 0; valid && i < options.length; i++) {
075: if (options[i][0].equals("-tag")) {
076: if (tagName == null) {
077: tagName = options[i][1];
078: } else {
079: reporter
080: .printError("Only one -tag option allowed.");
081: valid = false;
082: }
083: } else if (options[i][0].equals("-valid")) {
084: validValues.add(options[i][1]);
085: } else if (options[i][0].equals("-invalid")) {
086: invalidValues.add(options[i][1]);
087: } else if (options[i][0].equals("-out")) {
088: try {
089: out = new PrintWriter(new FileWriter(options[i][1]));
090: } catch (IOException ex) {
091: reporter.printError("Could not open output file \""
092: + options[i][1] + "\": " + ex);
093: valid = false;
094: }
095: }
096: }
097:
098: valid = valid && tagName != null;
099:
100: if (!valid) {
101: reporter
102: .printError("Usage: javadoc -tag mytag [-valid value]* [-invalid value]* -doclet ListPublicElements ...");
103: }
104:
105: return valid;
106: }
107:
108: private static void process(PackageDoc[] docs) {
109: for (PackageDoc doc : docs) {
110: process(doc);
111: }
112: }
113:
114: private static void process(PackageDoc doc) {
115: out.print(doc.name());
116: out.println(" [P]");
117: }
118:
119: private static void process(ProgramElementDoc[] docs) {
120: for (ProgramElementDoc doc : docs) {
121: process(doc);
122: }
123: }
124:
125: private static void process(ProgramElementDoc doc) {
126: boolean isVisible = !doc.name().equals("<clinit>");
127:
128: Tag[] tags = doc.tags(tagName);
129:
130: if (isVisible) {
131: if (!validValues.isEmpty()) {
132: // If it contains at least one valid value, then it will be visible
133: isVisible = false;
134: for (Tag tag : tags) {
135: if (validValues.contains(tag.text())) {
136: isVisible = true;
137: }
138: }
139: } else if (!invalidValues.isEmpty()) {
140: // Else if it contains at least one invalid value, then it will not be visible
141: for (Tag tag : tags) {
142: if (invalidValues.contains(tag.text())) {
143: isVisible = false;
144: }
145: }
146: }
147: }
148:
149: if (isVisible) {
150: out.print(doc.qualifiedName());
151: if (doc instanceof ConstructorDoc) {
152: out.print(".");
153: out.print(doc.name());
154: }
155: if (doc instanceof ExecutableMemberDoc) {
156: out.print(((ExecutableMemberDoc) doc).signature());
157: }
158:
159: if (doc instanceof ClassDoc) {
160: out.println(" [C]");
161: process(((ClassDoc) doc).fields());
162: process(((ClassDoc) doc).constructors());
163: process(((ClassDoc) doc).methods());
164: process(((ClassDoc) doc).innerClasses());
165: } else {
166: out.println(" [F]");
167: }
168: }
169: }
170: }
|