protected void process(ClassDoc clss) { writer.println(""); writer.println("## *" + clss.simpleTypeName() + "*"); writer.println(clss.commentText()); writer.println(""); if (clss.isEnum()) { for (FieldDoc field : clss.enumConstants()) { printEnumConstant(field); } writer.println(""); for (MethodDoc method : clss.methods(false)) { printMethod(method); } } else if (clss.isInterface()) { /* for (ClassDoc subClass : getDerivedClassessubclasses( clss )) { printSubClass(subClass); } */ } else { for (FieldDoc field : clss.fields(false)) { printField(field); } for (MethodDoc method : clss.methods(false)) { printMethod(method); } } }
/** * Build the sorted list of all the deprecated APIs in this run. Build separate lists for * deprecated packages, classes, constructors, methods and fields. * * @param configuration the current configuration of the doclet. */ private void buildDeprecatedAPIInfo(Configuration configuration) { PackageDoc[] packages = configuration.packages; PackageDoc pkg; for (int c = 0; c < packages.length; c++) { pkg = packages[c]; if (Util.isDeprecated(pkg)) { getList(PACKAGE).add(pkg); } } ClassDoc[] classes = configuration.root.classes(); for (int i = 0; i < classes.length; i++) { ClassDoc cd = classes[i]; if (Util.isDeprecated(cd)) { if (cd.isOrdinaryClass()) { getList(CLASS).add(cd); } else if (cd.isInterface()) { getList(INTERFACE).add(cd); } else if (cd.isException()) { getList(EXCEPTION).add(cd); } else if (cd.isEnum()) { getList(ENUM).add(cd); } else if (cd.isError()) { getList(ERROR).add(cd); } else if (cd.isAnnotationType()) { getList(ANNOTATION_TYPE).add(cd); } } composeDeprecatedList(getList(FIELD), cd.fields()); composeDeprecatedList(getList(METHOD), cd.methods()); composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors()); if (cd.isEnum()) { composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants()); } if (cd.isAnnotationType()) { composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER), ((AnnotationTypeDoc) cd).elements()); } } sortDeprecatedLists(); }
/** * Given a ClassDoc, return the name of its type (Class, Interface, etc.). * * @param cd the ClassDoc to check. * @param lowerCaseOnly true if you want the name returned in lower case. If false, the first * letter of the name is capatilized. * @return */ public static String getTypeName(Configuration config, ClassDoc cd, boolean lowerCaseOnly) { String typeName = ""; if (cd.isOrdinaryClass()) { typeName = "doclet.Class"; } else if (cd.isInterface()) { typeName = "doclet.Interface"; } else if (cd.isException()) { typeName = "doclet.Exception"; } else if (cd.isError()) { typeName = "doclet.Error"; } else if (cd.isAnnotationType()) { typeName = "doclet.AnnotationType"; } else if (cd.isEnum()) { typeName = "doclet.Enum"; } return config.getText(lowerCaseOnly ? typeName.toLowerCase() : typeName); }
/** * Add the given class to the catalog. * * @param classdoc the ClassDoc to add to the catelog. */ public void addClassDoc(ClassDoc classdoc) { if (classdoc == null) { return; } addClass(classdoc, allClasses); if (classdoc.isOrdinaryClass()) { addClass(classdoc, ordinaryClasses); } else if (classdoc.isException()) { addClass(classdoc, exceptions); } else if (classdoc.isEnum()) { addClass(classdoc, enums); } else if (classdoc.isAnnotationType()) { addClass(classdoc, annotationTypes); } else if (classdoc.isError()) { addClass(classdoc, errors); } else if (classdoc.isInterface()) { addClass(classdoc, interfaces); } }
public static boolean start(RootDoc root) { try { init(root); ClassDoc[] classes = root.classes(); ArrayList<String> generatesTestClasses = new ArrayList<String>(); for (int i = 0; i < classes.length; i++) { ClassDoc classDoc = classes[i]; if (classDoc.isAbstract() || classDoc.isInterface() || classDoc.isEnum() || classDoc.isPrivate() || classDoc.isAnnotationType()) { } else if (!hasDefaultConstructor(classDoc)) { System.out.println(classDoc.qualifiedTypeName() + " does not have default Constructor."); } else { ClassBean testClassBean = ClassBeanCreator.create(classDoc); if (testClassBean.hasMethods()) { JavaCodeWriter writer = getWriter(testClassBean); if (writer != null) { JavaCodeGenerator.generate(testClassBean, writer); generatesTestClasses.add(classDoc.qualifiedTypeName()); writer.close(); } } else { System.out.println( classDoc.qualifiedTypeName() + " does not have any methods to cover."); } } } System.out.println("---------REPORT-----------------------------------------------"); for (Iterator iterator = generatesTestClasses.iterator(); iterator.hasNext(); ) { String clsName = (String) iterator.next(); System.out.println("\t" + clsName); } System.out.println("-------------------------------------------------------------"); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
/** * Return true if the given ClassDoc should be included in the serialized form. * * @param cd the ClassDoc object to check for serializability. */ private static boolean serialClassInclude(ClassDoc cd) { if (cd.isEnum()) { return false; } try { cd.superclassType(); } catch (NullPointerException e) { // Workaround for null pointer bug in ClassDoc.superclassType(). return false; } if (cd.isSerializable()) { if (cd.tags("serial").length > 0) { return serialDocInclude(cd); } else if (cd.isPublic() || cd.isProtected()) { return true; } else { return false; } } return false; }
/** * The entry point into the Parser class. * * @param root A RootDoc intstance obtained via the doclet API * @return A XML (XStream) serializable element, containing everything parsed from javadoc doclet */ public static Root ParseRoot(RootDoc root) { processingStorage = new HashMap<PackageDoc, ParserMediary>(); try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { log.error("unable to acquire MD5 algorithm", e); return null; } rootXml = new Root(); ClassDoc[] allClasses = root.classes(); for (ClassDoc classDoc : allClasses) { PackageDoc doc = classDoc.containingPackage(); ParserMediary mediary = null; // the age old 'if I have it pull out existing, if I don't make a new one' if (processingStorage.containsKey(doc)) { mediary = processingStorage.get(doc); } else { mediary = new ParserMediary( doc.name(), doc.commentText(), ParseAnnotationInstances(doc.annotations(), doc.name())); processingStorage.put(doc, mediary); } if (classDoc.isIncluded()) { // dev comment--why do enums show up as ordinary class? if (classDoc.isOrdinaryClass() || classDoc.isException() || classDoc.isError()) { mediary.addClass(ParseClass(classDoc)); } else if (classDoc.isEnum()) { mediary.addEnum(ParseEnum(classDoc)); } else if (isAnnotation(classDoc)) { mediary.addAnnotation(ParseAnnotation(classDoc)); } else if (classDoc.isInterface()) { mediary.addInterface(ParseInterface(classDoc)); } } else { log.debug("Skipping not-included class " + classDoc.qualifiedName()); } } if (processingStorage.size() > 0) { List list = new ArrayList<Package>(); for (ParserMediary mediary : processingStorage.values()) { list.add(mediary.wrapup()); } rootXml.packages = (Package[]) list.toArray(new Package[] {}); } else { log.warn("No packages found!"); } return rootXml; }