private static Tag getSingleTagOrNull(final MethodDoc methodDoc, final String tagName) { final Tag[] tags = methodDoc.tags(tagName); if (tags != null && tags.length == 1) { return tags[0]; } return null; }
private static Map<String, List<Tag>> getResponseRepresentationTags(final MethodDoc methodDoc) { final Map<String, List<Tag>> tagsByStatus = new HashMap<>(); for (final Tag tag : methodDoc.tags()) { final Matcher matcher = PATTERN_RESPONSE_REPRESENTATION.matcher(tag.name()); if (matcher.matches()) { final String status = matcher.group(1); List<Tag> tags = tagsByStatus.get(status); if (tags == null) { tags = new ArrayList<>(); tagsByStatus.put(status, tags); } tags.add(tag); } } return tagsByStatus; }
final Tag[] responseParamTags = methodDoc.tags("response.param"); for (final Tag responseParamTag : responseParamTags) {
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(); } } }
private static Tag getSingleTagOrNull( MethodDoc methodDoc, String tagName ) { final Tag[] tags = methodDoc.tags( tagName ); if ( tags != null && tags.length == 1 ) { return tags[0]; } return null; }
/** * @param md * @param expression */ private static String getSingleJavadocTagValue(final MethodDoc md, final String tagName) { String rtn = null; final Tag[] tags = md.tags(tagName); if (tags != null && tags.length > 0) { rtn = tags[0].text().replace("@" + tagName, ""); rtn.replaceAll("\n", " "); } return rtn != null ? rtn : ""; }
private static Stream<Tag> streamRequestRepresentationTags(MethodDoc methodDoc) { return Arrays.stream(methodDoc.tags()) .filter(tag -> PATTERN_REQUEST_REPRESENTATION.matcher(tag.name()).matches()); }
private static Map<String, List<Tag>> getResponseRepresentationTags( MethodDoc methodDoc ) { final Map<String,List<Tag>> tagsByStatus = new HashMap<String, List<Tag>>(); for ( Tag tag : methodDoc.tags() ) { final Matcher matcher = PATTERN_RESPONSE_REPRESENATION.matcher( tag.name() ); if ( matcher.matches() ) { final String status = matcher.group( 1 ); List<Tag> tags = tagsByStatus.get( status ); if ( tags == null ) { tags = new ArrayList<Tag>(); tagsByStatus.put( status, tags ); } tags.add( tag ); } } return tagsByStatus; }
/** * {@inheritDoc} */ public void inherit(DocFinder.Input input, DocFinder.Output output) { Tag[] tags = input.method.tags("return"); if (tags.length > 0) { output.holder = input.method; output.holderTag = tags[0]; output.inlineTags = input.isFirstSentence ? tags[0].firstSentenceTags() : tags[0].inlineTags(); } }
public boolean isCorrectMethod(MethodDoc method) { return method.paramTags().length + method.tags("return").length + method.throwsTags().length + method.seeTags().length > 0; } }
@Override public String getReturnDoc(Method method) { final MethodDoc methodDoc = _doclet.getMethodDoc(method); if (methodDoc != null) { for (Tag tag : methodDoc.tags()) { if(tag.name().toLowerCase().equals("@return")) { return buildDoc(tag.text()); } } } return null; }
public boolean isCorrectMethod(MethodDoc method) { return method.paramTags().length + method.tags("return").length + method.throwsTags().length + method.seeTags().length > 0; } }
private void checkOnPropertiesTags(MethodDoc[] members) { for (MethodDoc methodDoc: members) { if (methodDoc.isIncluded()) { for (Tag tag: methodDoc.tags()) { String tagName = tag.name(); if (tagName.equals("@propertySetter") || tagName.equals("@propertyGetter") || tagName.equals("@propertyDescription")) { if (!isPropertyGetterOrSetter(members, methodDoc)) { configuration.message.warning(tag.position(), "doclet.javafx_tag_misuse"); } break; } } } } }
public static MethodDocumentation fromMethodDoc(MethodDoc methodDoc) { MethodDocumentation md = new MethodDocumentation(); md.comment = methodDoc.commentText(); for (Tag tag : methodDoc.tags()) { if (tag instanceof ParamTag) { ParamTag paramTag = (ParamTag) tag; md.parameters.put(paramTag.parameterName(), paramTag.parameterComment()); } else { md.tags.put(cleanupTagName(tag.name()), tag.text()); } } return md; } }
public static void returnDoc(ApiDoc apiDoc, ClassDoc classDoc, MethodDoc methodDoc) throws Exception { Method method = DocletUtil.getMethodByDoc(Class.forName(classDoc.qualifiedTypeName()), methodDoc); Type returnType = method.getGenericReturnType(); if (returnType.toString().equalsIgnoreCase("void")) { return; } ResultDoc resultDoc = new ResultDoc(); Tag[] tags = methodDoc.tags("return"); if (tags != null && tags.length == 1) { String[] returnTexts = tags[0].text().split("(e.g|eg|e.g.|example|exam|例如|如)(:|:)", 2); resultDoc.setDesc(returnTexts[0]); resultDoc.setExampleValue(returnTexts.length==2 ? returnTexts[1] : ""); resultDoc.setName(""); resultDoc.setType(methodDoc.returnType().typeName() + methodDoc.returnType().dimension()); } addRefType(classDoc, returnType, resultDoc); apiDoc.setResultDoc(resultDoc); }
/** * Build the method tags. */ public void buildMethodTags() { methodWriter.writeMemberTags((MethodDoc) currentMember); MethodDoc method = (MethodDoc)currentMember; if (method.name().compareTo("writeExternal") == 0 && method.tags("serialData").length == 0) { if (configuration.serialwarn) { configuration.getDocletSpecificMsg().warning( currentMember.position(), "doclet.MissingSerialDataTag", method.containingClass().qualifiedName(), method.name()); } } }
/** * Build the method tags. * * @param node the XML element that specifies which components to document * @param methodsContentTree content tree to which the documentation will be added */ public void buildMethodTags(XMLNode node, Content methodsContentTree) { methodWriter.addMemberTags((MethodDoc) currentMember, methodsContentTree); MethodDoc method = (MethodDoc)currentMember; if (method.name().compareTo("writeExternal") == 0 && method.tags("serialData").length == 0) { if (configuration.serialwarn) { configuration.getDocletSpecificMsg().warning( currentMember.position(), "doclet.MissingSerialDataTag", method.containingClass().qualifiedName(), method.name()); } } }
public void writeMemberTags(MethodDoc member) { TagletOutputImpl output = new TagletOutputImpl(""); TagletManager tagletManager = ConfigurationImpl.getInstance().tagletManager; TagletWriter.genTagOuput(tagletManager, member, tagletManager.getSerializedFormTags(), writer.getTagletWriterInstance(false), output); String outputString = output.toString().trim(); if (!outputString.isEmpty()) { writer.printMemberDetailsListStartTag(); writer.dd(); writer.dl(); print(outputString); writer.dlEnd(); writer.ddEnd(); } MethodDoc method = member; if (method.name().compareTo("writeExternal") == 0 && method.tags("serialData").length == 0) { serialWarning(member.position(), "doclet.MissingSerialDataTag", method.containingClass().qualifiedName(), method.name()); } }
/** * Add the tag information for this member. * * @param member the method to document. * @param methodsContentTree the tree to which the member tags info will be added */ public void addMemberTags(MethodDoc member, Content methodsContentTree) { Content tagContent = new ContentBuilder(); TagletManager tagletManager = configuration.tagletManager; TagletWriter.genTagOuput(tagletManager, member, tagletManager.getSerializedFormTaglets(), writer.getTagletWriterInstance(false), tagContent); Content dlTags = new HtmlTree(HtmlTag.DL); dlTags.addContent(tagContent); methodsContentTree.addContent(dlTags); // TODO: what if empty? MethodDoc method = member; if (method.name().compareTo("writeExternal") == 0 && method.tags("serialData").length == 0) { serialWarning(member.position(), "doclet.MissingSerialDataTag", method.containingClass().qualifiedName(), method.name()); } } }
protected void printMarkDown(MethodDoc method) throws IOException { appendNewline("## `.%s(%s)`", method.name(), parameters(method.parameters())); appendNewline(); appendNewline(asMarkdown(method.commentText())); appendNewline(); if (method.paramTags().length > 0) { appendNewline("Parameter | Description"); appendNewline("--------- | -----------"); for (ParamTag param : method.paramTags()) { appendNewline("%s | %s", param.parameterName(), asMarkdown(param.parameterComment())); } appendNewline(); } for (Tag t : method.tags("return")) { String text = t.text(); if (text != null) { appendNewline("- **returns:** %s", asMarkdown(text)); } } for (Tag t : method.tags("see")) { String text = t.text(); if (text != null) { appendNewline("- **see:** %s", asMarkdown(text)); } } appendNewline(); }