下面列出了怎么用com.sun.javadoc.ParamTag的API类实例代码及写法,或者点击链接到github查看源代码。
private void readMethodDoc() {
hidden |= methodDoc.getRawCommentText().contains("@hidden");
deprecated |= methodDoc.getRawCommentText().contains("@deprecated");
if (methodDoc.tags("see").length > 0) {
noteBuilder.append("<b> 查看 -> " + methodDoc.tags("see")[0].text() + " </b>\n");
}
if (!StringUtils.isEmpty(methodDoc.commentText())) {
value = methodDoc.commentText();
}
if (methodDoc.tags("return").length > 0) {
returnDescription = methodDoc.tags("return")[0].text();
}
for (ParamTag paramTag : methodDoc.paramTags()) {
paramInfos.add(ApiParamInfo.fromParamTag(paramTag));
}
if (methodDoc.paramTags().length != parameterCount()) {
DocLogger.warn("The number of comment parameters for method [" +
method.getDeclaringClass().getName() + "." + method.getName() +
"(" + parameterNames() + ")] in javadoc is incorrect");
}
if (paramInfos.size() != parameterCount()) {
for (int i = paramInfos.size(); i < parameterCount(); i++) {
String defaultName = methodDoc.parameters()[i].name();
paramInfos.add(ApiParamInfo.defaultInfo(defaultName));
}
}
}
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 boolean start(RootDoc root) throws IOException {
String dumpFileName = readOptions(root.options());
OutputStream os = Files.newOutputStream(Paths.get(dumpFileName));
Properties javaDocMap = new Properties();
for (ClassDoc classDoc : root.classes()) {
javaDocMap.put(classDoc.toString(), classDoc.commentText());
for (MethodDoc method : classDoc.methods()) {
javaDocMap.put(method.qualifiedName(), method.commentText());
for (ParamTag paramTag : method.paramTags()) {
Parameter[] parameters = method.parameters();
for (int i = 0; i < parameters.length; ++i) {
if (parameters[i].name().equals(paramTag.parameterName())) {
javaDocMap.put(method.qualifiedName() + ".paramCommentTag." + i,
paramTag.parameterComment());
}
}
}
Tag[] retTags = method.tags("return");
if (retTags != null && retTags.length == 1) {
Tag retTag = method.tags("return")[0];
javaDocMap.put(method.qualifiedName() + "." + "returnCommentTag",
retTag.text());
}
}
}
javaDocMap.store(os, "");
os.flush();
os.close();
return true;
}
private static String renderParameterName(ParamTag tag) {
if (!tag.isTypeParameter()) {
return tag.parameterName();
}
else {
return '<' + tag.parameterName() + '>';
}
}
public static ApiParamInfo fromParamTag(ParamTag tag) {
return new ApiParamInfo(tag.parameterName(), tag.parameterComment());
}
private static void processMethod(
Properties properties,
MethodDoc methodDoc,
String defaultRequestMethod,
String pathRoot,
boolean exceptionRef) {
for (AnnotationDesc annotationDesc : methodDoc.annotations()) {
String annotationType = annotationDesc.annotationType().toString();
if (isMapping(annotationType)) {
StringBuilder path = new StringBuilder(pathRoot);
for (AnnotationDesc.ElementValuePair pair : annotationDesc.elementValues()) {
if (VALUE.equals(pair.element().name()) || PATH.equals(pair.element().name())) {
appendPath(path, pair);
break;
}
}
if (!path.substring(path.length() - 1).equals(".")) {
path.append(".");
}
String requestMethod = getRequestMethod(annotationDesc, annotationType, defaultRequestMethod);
if (requestMethod != null) {
path.append(requestMethod);
saveProperty(properties, path.toString() + ".notes", methodDoc.commentText());
for (ParamTag paramTag : methodDoc.paramTags()) {
saveProperty(properties, path.toString() + ".param." + paramTag.parameterName(),
paramTag.parameterComment());
}
for (Tag tag : methodDoc.tags()) {
if (tag.name().equals(RETURN)) {
saveProperty(properties, path.toString() + ".return", tag.text());
break;
}
}
if (exceptionRef) {
processThrows(properties, methodDoc.throwsTags(), path);
}
}
}
}
}
@Override
public ParamTag[] typeParamTags() {
return this.delegate.typeParamTags();
}
@Override
public ParamTag[] typeParamTags() {
return this.delegate.typeParamTags();
}
@Override
public ParamTag[] paramTags() {
return this.delegate.paramTags();
}
@Override
public ParamTag[] typeParamTags() {
return this.delegate.typeParamTags();
}
@Override
public ParamTag[] paramTags() {
return this.delegate.paramTags();
}
@Override
public ParamTag[] typeParamTags() {
return this.delegate.typeParamTags();
}
@Override
public ParamTag[] paramTags() {
return this.delegate.paramTags();
}
@Override
public ParamTag[] typeParamTags() {
return this.delegate.typeParamTags();
}
@Override
public void render(ParamTag tag, StringBuilder target, MarkdownDoclet doclet) {
target.append(tag.name())
.append(' ').append(renderParameterName(tag))
.append(' ').append(TagRendering.simplifySingleParagraph(doclet.toHtml(tag.parameterComment())));
}