Coverage Report - com.jeantessier.diff.ListDocumentedElements
 
Classes in this File Line Coverage Branch Coverage Complexity
ListDocumentedElements
0%
0/76
0%
0/56
4.857
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 3  
  *  All rights reserved.
 4  
  *  
 5  
  *  Redistribution and use in source and binary forms, with or without
 6  
  *  modification, are permitted provided that the following conditions
 7  
  *  are met:
 8  
  *  
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *  
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *  
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *  
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.diff;
 34  
 
 35  
 import java.io.*;
 36  
 import java.util.*;
 37  
 
 38  
 import com.sun.javadoc.*;
 39  
 
 40  0
 public class ListDocumentedElements {
 41  0
     private static String tagName = null;
 42  0
     private static Collection<String> validValues = new HashSet<String>();
 43  0
     private static Collection<String> invalidValues = new HashSet<String>();
 44  0
     private static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
 45  
     
 46  
     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  
     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  
     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  
                 try {
 86  0
                     out = new PrintWriter(new FileWriter(options[i][1]));
 87  0
                 } catch (IOException ex) {
 88  0
                     reporter.printError("Could not open output file \"" + options[i][1] + "\": " + ex);
 89  0
                     valid = false;
 90  0
                 }
 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  
     private static void process(PackageDoc[] docs) {
 104  0
         for (PackageDoc doc : docs) {
 105  0
             process(doc);
 106  
         }
 107  0
     }
 108  
     
 109  
     private static void process(PackageDoc doc) {
 110  0
         out.print(doc.name());
 111  0
         out.println(" [P]");
 112  0
     }
 113  
     
 114  
     private static void process(ProgramElementDoc[] docs) {
 115  0
         for (ProgramElementDoc doc : docs) {
 116  0
             process(doc);
 117  
         }
 118  0
     }
 119  
 
 120  
     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  
                 // If it contains at least one valid value, then it will be visible
 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  
                 // Else if it contains at least one invalid value, then it will not be visible
 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  0
     }
 165  
 }