public class ExtractCommentsDoclet { public static boolean start(RootDoc root) throws IOException { for (ClassDoc c : root.classes()) { print(c.qualifiedName(), c.commentText()); for (FieldDoc f : c.fields(false)) { print(f.qualifiedName(), f.commentText()); } for (MethodDoc m : c.methods(false)) { print(m.qualifiedName(), m.commentText()); if (m.commentText() != null && m.commentText().length() > 0) { for (ParamTag p : m.paramTags()) print(m.qualifiedName() + "@" + p.parameterName(), p.parameterComment()); for (Tag t : m.tags("return")) { if (t.text() != null && t.text().length() > 0) print(m.qualifiedName() + "@return", t.text()); } } } } return true; } private static void print(String name, String comment) throws IOException { if (comment != null && comment.length() > 0) { new FileWriter(name + ".txt").append(comment).close(); } } }
public FieldDoc[] fields() { return wrapped.fields(); }
public FieldDoc[] fields(boolean arg0) { return wrapped.fields(arg0); }
/** @return All fields declared by the <var>clasS</var> and its superclasses */ private static FieldDoc[] allFields(ClassDoc clasS) { List<FieldDoc> result = new ArrayList<FieldDoc>(); for (ClassDoc cd : Docs.withSuperclasses(clasS)) { result.addAll(Arrays.asList(cd.fields())); } return result.toArray(new FieldDoc[result.size()]); }
/** @return All fields declared by the <var>clasS</var> and its superclasses */ private static FieldDoc[] allFields(ClassDoc clasS) { List<FieldDoc> result = new ArrayList<FieldDoc>(); for (ClassDoc cd : Docs.withSuperclasses(clasS)) { result.addAll(Arrays.asList(cd.fields())); } return result.toArray(new FieldDoc[result.size()]); }
/** Return a list of fields for this class and all it's superclasses */ protected static List<FieldDoc> getFields(ClassDoc classDoc) { List<FieldDoc> ret = new ArrayList<>(); ClassDoc parent = classDoc.superclass(); if (parent != null) { ret.addAll(getFields(parent)); } ret.addAll(Arrays.asList(classDoc.fields())); return ret; } }
public static FieldDoc getFieldDoc(ClassDoc classDoc, String name) { for (FieldDoc fieldDoc : classDoc.fields()) { if (fieldDoc.name().equals(name) ||name.equals(getAnnotationValue(fieldDoc, Param.class, "value"))) { return fieldDoc; } } return null; }
@Override public void processOperator(OperatorDesc operatorDesc) throws Exception { ClassDoc typeDoc = operatorDesc.getClassDoc(); StringBuilder sb = new StringBuilder(300); sb.append(String.format("Operator: %s\n", typeDoc.typeName())); sb.append(String.format("\tClass: %s\n", typeDoc.qualifiedTypeName())); sb.append(String.format("\tText: %s\n", typeDoc.commentText())); writeClassAnnotiations(typeDoc, sb); FieldDoc[] fieldDocs = typeDoc.fields(false); for (FieldDoc fieldDoc : fieldDocs) { writeFieldAnnotiations(fieldDoc, sb); } System.out.println(sb.toString()); }
/** * Returns an array of strings where each element * is a class, method or field name. This array is * used to create one meta keyword tag for each element. * Method parameter lists are converted to "()" and * overloads are combined. * * Constructors are not included because they have the same * name as the class, which is already included. * Nested class members are not included because their * definitions are on separate pages. */ public String[] getMetaKeywords(ClassDoc classdoc) { ArrayList<String> results = new ArrayList<String>(); // Add field and method keywords only if -keywords option is used if( configuration.keywords ) { results.addAll(getClassKeyword(classdoc)); results.addAll(getMemberKeywords(classdoc.fields())); results.addAll(getMemberKeywords(classdoc.methods())); } return results.toArray(new String[]{}); }
/** * Returns an array of strings where each element * is a class, method or field name. This array is * used to create one meta keyword tag for each element. * Method parameter lists are converted to "()" and * overloads are combined. * * Constructors are not included because they have the same * name as the class, which is already included. * Nested class members are not included because their * definitions are on separate pages. */ public String[] getMetaKeywords(ClassDoc classdoc) { ArrayList<String> results = new ArrayList<String>(); // Add field and method keywords only if -keywords option is used if( configuration.keywords ) { results.addAll(getClassKeyword(classdoc)); results.addAll(getMemberKeywords(classdoc.fields())); results.addAll(getMemberKeywords(classdoc.methods())); } return results.toArray(new String[]{}); }
private ProgramElementDoc[] properties(final ClassDoc cd, final boolean filter) { final MethodDoc[] allMethods = cd.methods(filter); final FieldDoc[] allFields = cd.fields(false); if (propertiesCache.containsKey(cd)) { return propertiesCache.get(cd); } final List<MethodDoc> result = new ArrayList<MethodDoc>(); for (final MethodDoc propertyMethod : allMethods) { if (!isPropertyMethod(propertyMethod)) { continue; } final MethodDoc getter = getterForField(allMethods, propertyMethod); final MethodDoc setter = setterForField(allMethods, propertyMethod); final FieldDoc field = fieldForProperty(allFields, propertyMethod); addToPropertiesMap(setter, getter, propertyMethod, field); getterSetterMap.put(propertyMethod, new GetterSetter(getter, setter)); result.add(propertyMethod); } final ProgramElementDoc[] resultAray = result.toArray(new ProgramElementDoc[result.size()]); propertiesCache.put(cd, resultAray); return resultAray; }
/** * Build the serial UID information for the given class. */ public void buildSerialUIDInfo() { FieldDoc[] fields = currentClass.fields(false); for (int i = 0; i < fields.length; i++) { if (fields[i].name().equals("serialVersionUID") && fields[i].constantValueExpression() != null) { writer.writeSerialUIDInfo(SERIAL_VERSION_UID_HEADER, fields[i].constantValueExpression()); return; } } }
/** * Put all the members(fields, methods and constructors) in the classdoc * to the indexmap. * * @param classdoc ClassDoc whose members will be added to the indexmap. */ protected void putMembersInIndexMap(ClassDoc classdoc) { adjustIndexMap(classdoc.fields()); adjustIndexMap(classdoc.methods()); adjustIndexMap(classdoc.constructors()); }
/** * Put all the members(fields, methods and constructors) in the classdoc * to the indexmap. * * @param classdoc ClassDoc whose members will be added to the indexmap. */ protected void putMembersInIndexMap(ClassDoc classdoc) { adjustIndexMap(classdoc.fields()); adjustIndexMap(classdoc.methods()); adjustIndexMap(classdoc.constructors()); }
/** * Helper routine that provides a FreeMarker map for an enumClass, grabbing the * values of the enum and their associated javadoc documentation. * * @param enumClass * @return */ @Requires("enumClass.isEnum()") private List<Map<String, Object>> docForEnumArgument(final Class enumClass) { final ClassDoc doc = this.getDoclet().getClassDocForClass(enumClass); if ( doc == null ) throw new RuntimeException("Tried to get docs for enum " + enumClass + " but got null instead"); final Set<String> enumConstantFieldNames = enumConstantsNames(enumClass); final List<Map<String, Object>> bindings = new ArrayList<Map<String, Object>>(); for (final FieldDoc fieldDoc : doc.fields(false)) { if (enumConstantFieldNames.contains(fieldDoc.name()) ) bindings.add( new HashMap<String, Object>() {{ put("name", fieldDoc.name()); put("summary", fieldDoc.commentText()); }}); } return bindings; }
/** * Build the serial UID information for the given class. * * @param node the XML element that specifies which components to document * @param classTree content tree to which the serial UID information will be added */ public void buildSerialUIDInfo(XMLNode node, Content classTree) { Content serialUidTree = writer.getSerialUIDInfoHeader(); FieldDoc[] fields = currentClass.fields(false); for (int i = 0; i < fields.length; i++) { if (fields[i].name().equals("serialVersionUID") && fields[i].constantValueExpression() != null) { writer.addSerialUIDInfo(SERIAL_VERSION_UID_HEADER, fields[i].constantValueExpression(), serialUidTree); break; } } classTree.addContent(serialUidTree); }
public static ClassDocumentation fromClassDoc(ClassDoc classDoc) { ClassDocumentation cd = new ClassDocumentation(); cd.setComment(classDoc.commentText()); for (FieldDoc fieldDoc : classDoc.fields(false)) { cd.addField(fieldDoc); } for (MethodDoc methodDoc : classDoc.methods(false)) { cd.addMethod(methodDoc); } return cd; }
/** * Prints associations recovered from the fields of a class. An association is inferred only * if another relation between the two classes is not already in the graph. * @param classes */ public void printInferredRelations(ClassDoc c) { Options opt = optionProvider.getOptionsFor(c); // check if the source is excluded from inference if (hidden(c)) return; for (FieldDoc field : c.fields(false)) { if(hidden(field)) continue; // skip statics if(field.isStatic()) continue; // skip primitives FieldRelationInfo fri = getFieldRelationInfo(field); if (fri == null) continue; // check if the destination is excluded from inference if (hidden(fri.cd)) continue; String destAdornment = fri.multiple ? "*" : ""; relation(opt, opt.inferRelationshipType, c, fri.cd, "", "", destAdornment); } }
/** * Process the class documentation. * * @param doc The class documentation. */ protected void processClass(ClassDoc doc) { defaultProcess(doc, true); for ( MemberDoc member : doc.fields() ) { processMember(member); } for ( MemberDoc member : doc.constructors() ) { processMember(member); } for ( MemberDoc member : doc.methods() ) { processMember(member); } if ( doc instanceof AnnotationTypeDoc ) { for ( MemberDoc member : ((AnnotationTypeDoc)doc).elements() ) { processMember(member); } } }
/** * Renders an individual class. * * @param doc input */ private void renderClass(ClassDoc doc, DocletRenderer renderer) { //handle the various parts of the Class doc renderer.renderDoc(doc); for (MemberDoc member : doc.fields()) { renderer.renderDoc(member); } for (MemberDoc member : doc.constructors()) { renderer.renderDoc(member); } for (MemberDoc member : doc.methods()) { renderer.renderDoc(member); } for (MemberDoc member : doc.enumConstants()) { renderer.renderDoc(member); } if (doc instanceof AnnotationTypeDoc) { for (MemberDoc member : ((AnnotationTypeDoc)doc).elements()) { renderer.renderDoc(member); } } }