ToyDoclet.java revision 4212:ead6d6c18bcc
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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26import java.util.Arrays; 27 28import com.sun.javadoc.ClassDoc; 29import com.sun.javadoc.PackageDoc; 30import com.sun.javadoc.ProgramElementDoc; 31import com.sun.javadoc.RootDoc; 32 33@SuppressWarnings("deprecation") 34public class ToyDoclet { 35 36 public static boolean start(RootDoc root) { 37 String whoami = "I am a toy doclet"; 38 root.printNotice("Notice: " + whoami); 39 boolean status = false; 40 for (ClassDoc cls : root.classes()) { 41 if (!status) status = true; 42 root.printNotice("Classes: " + cls); 43 printClassMembers(root, cls); 44 } 45 for (ClassDoc cls : root.specifiedClasses()) { 46 if (!status) status = true; 47 root.printNotice("Specified-classes: " + cls); 48 printClassMembers(root, cls); 49 } 50 for (PackageDoc pkg : root.specifiedPackages()) { 51 if (!status) status = true; 52 root.printNotice("Specified-packages: " + pkg); 53 } 54 return status; 55 } 56 57 static void printClassMembers(RootDoc root, ClassDoc cls) { 58 root.printNotice("Members for: " + cls); 59 root.printNotice(" extends " + Arrays.asList(cls.superclass())); 60 root.printNotice(" Fields: "); 61 printMembers(root, cls.fields()); 62 root.printNotice(" Constructor: "); 63 printMembers(root, cls.constructors()); 64 root.printNotice(" Method: "); 65 printMembers(root, cls.methods()); 66 if (cls.superclass() != null && !cls.superclassType().toString().equals("java.lang.Object")) 67 printClassMembers(root, cls.superclass()); 68 } 69 70 static void printMembers(RootDoc root, ProgramElementDoc[] pgmDocs) { 71 for (ProgramElementDoc pgmDoc : pgmDocs) { 72 root.printNotice(" " + pgmDoc + ", Comments: " + pgmDoc.getRawCommentText()); 73 } 74 } 75 76 public static int optionLength(String option) { 77 System.out.println("option: " + option); 78 return 0; // all options are unsupported 79 } 80} 81