use of com.sun.javadoc.ParameterizedType in project RESTdoclet by IG-Group.
the class DocTypeUtils method getTypeName.
/**
* Return the simple type name of the passed in type, and include the simple
* name of the template type if a generic
*
* @param type type info
* @return simple type name (including template type name in [] if
* applicable)
*/
public static String getTypeName(final Type type) {
String typeName = "";
typeName = type.simpleTypeName();
ParameterizedType pt = type.asParameterizedType();
if (pt != null && pt.typeArguments() != null && pt.typeArguments().length > 0) {
typeName += "[";
for (int i = 0; i < pt.typeArguments().length; i++) {
typeName += pt.typeArguments()[i].simpleTypeName();
if (i < pt.typeArguments().length - 1) {
typeName += ", ";
}
}
typeName += "]";
}
return typeName;
}
use of com.sun.javadoc.ParameterizedType in project RESTdoclet by IG-Group.
the class DocTypeUtils method getTypeDoc.
/**
* Returns as a string a list of attributes plus comments for the given
* iggroup complex type (or empty string if not iggroup), formatted in an
* HTML table. This method will recurse if attributes are iggroup complex
* types
*
* @param type
* @param processedTypes
* @param leafType
* @return
*/
private static String getTypeDoc(final Type type, HashMap<String, String> processedTypes, Boolean leafType) {
LOG.info("getTypeDoc " + type + " leafType=" + leafType);
String typeInfo = "";
if (isRelevantType(type)) {
ClassDoc typeDoc = type.asClassDoc();
typeInfo = processedTypes.get(type.toString());
if (typeInfo != null) {
LOG.debug("Found cached typedoc for " + type.typeName() + " - " + typeInfo);
}
if (typeInfo == null && typeDoc != null) {
typeInfo = "";
// if this is a generic type then recurse with the first type argument
if (isParameterisedType(type)) {
LOG.debug("Parameterised type");
if (type.asClassDoc() != null) {
typeInfo = getTypeDoc(type.asParameterizedType().typeArguments()[type.asParameterizedType().typeArguments().length - 1], processedTypes, true);
}
} else {
logType(type);
// put placeholder to stop recursion for self-referential types
LOG.debug("Starting to cache: " + type.typeName());
processedTypes.put(type.toString(), "");
LOG.debug(typeDoc.commentText() + " " + leafType);
if (leafType && !typeDoc.commentText().isEmpty()) {
typeInfo += "<tr><span class=\"javadoc-header\">" + typeDoc.commentText() + "</span></tr>";
LOG.debug(typeInfo);
}
if (typeDoc.isEnum()) {
LOG.debug("Enum type");
typeInfo += getEnumDoc(type);
} else {
// class
LOG.debug("Class");
// first do base class
if (typeDoc.superclass() != null) {
LOG.debug("base type = " + typeDoc.superclass().qualifiedName());
String baseTypeDoc = getTypeDoc(type.asClassDoc().superclassType(), processedTypes, false);
if (!baseTypeDoc.isEmpty()) {
LOG.debug("base type DOC = " + baseTypeDoc);
typeInfo += baseTypeDoc;
}
}
typeInfo += getPublicConstantDoc(type);
Collection<String> getterNames = getGetterNames(type);
for (MethodDoc method : typeDoc.methods()) {
if (method.isPublic() && getterNames.contains(method.name()) && !ignore(method)) {
String attributeInfo = "";
String attributeType = method.returnType().simpleTypeName();
// check if is this a parameterised type
ParameterizedType pt = method.returnType().asParameterizedType();
if (pt != null && pt.typeArguments().length > 0) {
attributeType += "[";
for (int i = 0; i < pt.typeArguments().length; i++) {
attributeType += pt.typeArguments()[i].simpleTypeName();
if (i < pt.typeArguments().length - 1) {
attributeType += ", ";
}
}
attributeType += "]";
}
// Check if this is an array
attributeType += method.returnType().dimension();
final String attributeName = getAttributeNameFromMethod(method.name());
attributeInfo += "<td>" + attributeType + " " + attributeName + "</td>";
// If type or parameterised type then recurse
LOG.debug("Generating attribute doc for " + method.returnType());
String attributeTypeDoc = getTypeDoc(method.returnType(), processedTypes, true);
if (!attributeTypeDoc.isEmpty()) {
LOG.debug("Found attribute doc for " + method.returnType());
attributeInfo += "<td>" + attributeTypeDoc + "</td>";
} else {
// no useful type information, so use whatever's on the attribute doc
LOG.debug("Found no attribute doc for " + method.returnType());
String fieldDoc = getFieldDoc(type, attributeName, method.commentText());
attributeInfo += "<td>" + fieldDoc + "</td>";
}
if (!attributeInfo.isEmpty()) {
typeInfo += "<tr>" + attributeInfo + "</tr>";
}
}
}
}
// Wrap in a table tag if this is concrete type
if (leafType && !typeInfo.isEmpty()) {
typeInfo = "<table>" + typeInfo + "</table>";
}
}
}
LOG.debug("Caching: " + type);
processedTypes.put(type.toString(), typeInfo);
}
if (typeInfo == null) {
typeInfo = "";
}
LOG.debug("XXX " + type.typeName() + " XXX " + typeInfo);
return typeInfo;
}
use of com.sun.javadoc.ParameterizedType in project com.revolsys.open by revolsys.
the class DocletUtil method typeNameLink.
public static void typeNameLink(final XmlWriter writer, final Type type) {
if (type instanceof WildcardType) {
final WildcardType wildCard = (WildcardType) type;
writer.text("?");
final Type[] extendsBounds = wildCard.extendsBounds();
if (extendsBounds.length > 0) {
writer.text(" extends ");
for (int i = 0; i < extendsBounds.length; i++) {
if (i > 0) {
writer.text(", ");
}
final Type extendsType = extendsBounds[i];
typeNameLink(writer, extendsType);
}
}
} else {
final String qualifiedTypeName = type.qualifiedTypeName();
final String externalLink = getExternalUrl(qualifiedTypeName);
final boolean included = isTypeIncluded(type);
if (externalLink != null) {
HtmlUtil.serializeA(writer, "", externalLink, type.typeName());
} else if (included) {
final String url = "#" + qualifiedTypeName;
HtmlUtil.serializeA(writer, "", url, type.typeName());
} else {
writer.text(qualifiedTypeName);
}
if (type instanceof ParameterizedType) {
final ParameterizedType parameterizedType = (ParameterizedType) type;
final Type[] typeArguments = parameterizedType.typeArguments();
if (typeArguments.length > 0) {
writer.text("<");
for (int i = 0; i < typeArguments.length; i++) {
if (i > 0) {
writer.text(", ");
}
final Type typeParameter = typeArguments[i];
typeNameLink(writer, typeParameter);
}
writer.text(">");
}
}
}
writer.text(type.dimension());
}
Aggregations