test/langtools/tools/javadoc/lib/ToyDoclet.java
changeset 53885 e03bbe023e50
parent 53884 1a7b57d02107
child 53886 e94ed0236046
child 57204 7aa6f61ad1c0
equal deleted inserted replaced
53884:1a7b57d02107 53885:e03bbe023e50
     1 /*
       
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.util.Arrays;
       
    25 
       
    26 import com.sun.javadoc.ClassDoc;
       
    27 import com.sun.javadoc.PackageDoc;
       
    28 import com.sun.javadoc.ProgramElementDoc;
       
    29 import com.sun.javadoc.RootDoc;
       
    30 
       
    31 @SuppressWarnings("deprecation")
       
    32 public class ToyDoclet {
       
    33 
       
    34     public static boolean start(RootDoc root) {
       
    35         String whoami = "I am a toy doclet";
       
    36         root.printNotice("Notice: " + whoami);
       
    37         boolean status = false;
       
    38         for (ClassDoc cls : root.classes()) {
       
    39             if (!status) status = true;
       
    40             root.printNotice("Classes: " + cls);
       
    41             printClassMembers(root, cls);
       
    42         }
       
    43         for (ClassDoc cls : root.specifiedClasses()) {
       
    44             if (!status) status = true;
       
    45             root.printNotice("Specified-classes: " + cls);
       
    46             printClassMembers(root, cls);
       
    47         }
       
    48         for (PackageDoc pkg : root.specifiedPackages()) {
       
    49             if (!status) status = true;
       
    50             root.printNotice("Specified-packages: " + pkg);
       
    51         }
       
    52         return status;
       
    53     }
       
    54 
       
    55     static void printClassMembers(RootDoc root, ClassDoc cls) {
       
    56         root.printNotice("Members for: " + cls);
       
    57         root.printNotice("  extends " + Arrays.asList(cls.superclass()));
       
    58         root.printNotice("  Fields: ");
       
    59         printMembers(root, cls.fields());
       
    60         root.printNotice("  Constructor: ");
       
    61         printMembers(root, cls.constructors());
       
    62         root.printNotice("  Method: ");
       
    63         printMembers(root, cls.methods());
       
    64         if (cls.superclass() != null && !cls.superclassType().toString().equals("java.lang.Object"))
       
    65             printClassMembers(root, cls.superclass());
       
    66     }
       
    67 
       
    68     static void printMembers(RootDoc root, ProgramElementDoc[] pgmDocs) {
       
    69         for (ProgramElementDoc pgmDoc : pgmDocs) {
       
    70             root.printNotice("     " + pgmDoc + ", Comments: " + pgmDoc.getRawCommentText());
       
    71         }
       
    72     }
       
    73 
       
    74     public static int optionLength(String option) {
       
    75         System.out.println("option: " + option);
       
    76         return 0;  // all options are unsupported
       
    77     }
       
    78 }