* @return the output of the link.
*/
public Content getLink(LinkInfo linkInfo) {
if (linkInfo.type != null) {
Type type = linkInfo.type;
Content link = newContent();
if (type.isPrimitive()) {
//Just a primitive.
link.addContent(type.typeName());
} else if (type.asAnnotatedType() != null && type.dimension().length() == 0) {
link.addContent(getTypeAnnotationLinks(linkInfo));
linkInfo.type = type.asAnnotatedType().underlyingType();
link.addContent(getLink(linkInfo));
return link;
} else if (type.asWildcardType() != null) {
//Wildcard type.
linkInfo.isTypeBound = true;
link.addContent("?");
WildcardType wildcardType = type.asWildcardType();
Type[] extendsBounds = wildcardType.extendsBounds();
for (int i = 0; i < extendsBounds.length; i++) {
link.addContent(i > 0 ? ", " : " extends ");
setBoundsLinkInfo(linkInfo, extendsBounds[i]);
link.addContent(getLink(linkInfo));
}
Type[] superBounds = wildcardType.superBounds();
for (int i = 0; i < superBounds.length; i++) {
link.addContent(i > 0 ? ", " : " super ");
setBoundsLinkInfo(linkInfo, superBounds[i]);
link.addContent(getLink(linkInfo));
}
} else if (type.asTypeVariable()!= null) {
link.addContent(getTypeAnnotationLinks(linkInfo));
linkInfo.isTypeBound = true;
//A type variable.
Doc owner = type.asTypeVariable().owner();
if ((! linkInfo.excludeTypeParameterLinks) &&
owner instanceof ClassDoc) {
linkInfo.classDoc = (ClassDoc) owner;
Content label = newContent();
label.addContent(type.typeName());
linkInfo.label = label;
link.addContent(getClassLink(linkInfo));
} else {
//No need to link method type parameters.
link.addContent(type.typeName());
}
Type[] bounds = type.asTypeVariable().bounds();
if (! linkInfo.excludeTypeBounds) {
linkInfo.excludeTypeBounds = true;
for (int i = 0; i < bounds.length; i++) {
link.addContent(i > 0 ? " & " : " extends ");
setBoundsLinkInfo(linkInfo, bounds[i]);
link.addContent(getLink(linkInfo));
}
}
} else if (type.asClassDoc() != null) {
//A class type.
if (linkInfo.isTypeBound &&
linkInfo.excludeTypeBoundsLinks) {
//Since we are excluding type parameter links, we should not
//be linking to the type bound.
link.addContent(type.typeName());
link.addContent(getTypeParameterLinks(linkInfo));
return link;
} else {
linkInfo.classDoc = type.asClassDoc();
link = newContent();
link.addContent(getClassLink(linkInfo));
if (linkInfo.includeTypeAsSepLink) {
link.addContent(getTypeParameterLinks(linkInfo, false));
}
}
}
if (linkInfo.isVarArg) {
if (type.dimension().length() > 2) {
//Javadoc returns var args as array.
//Strip out the first [] from the var arg.
link.addContent(type.dimension().substring(2));
}
link.addContent("...");
} else {
while (type != null && type.dimension().length() > 0) {
if (type.asAnnotatedType() != null) {
linkInfo.type = type;
link.addContent(" ");
link.addContent(getTypeAnnotationLinks(linkInfo));
link.addContent("[]");
type = type.asAnnotatedType().underlyingType().getElementType();
} else {
link.addContent("[]");
type = type.getElementType();
}
}
linkInfo.type = type;
Content newLink = newContent();
newLink.addContent(getTypeAnnotationLinks(linkInfo));
newLink.addContent(link);
link = newLink;
}
return link;
} else if (linkInfo.classDoc != null) {
//Just a class link
Content link = newContent();
link.addContent(getClassLink(linkInfo));
if (linkInfo.includeTypeAsSepLink) {
link.addContent(getTypeParameterLinks(linkInfo, false));
}
return link;
} else {
return null;
}