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