use of com.sun.javadoc.ClassDoc in project wso2-axis2-transports by wso2.
the class TestkitJavadocDoclet method start.
public static boolean start(RootDoc root) throws Exception {
parseOptions(root.options());
ObjectInputStream in = new ObjectInputStream(new FileInputStream(resourceInfoFile));
ResourceInfo resourceInfo = (ResourceInfo) in.readObject();
in.close();
for (ClassDoc clazz : root.classes()) {
String qualifiedName = clazz.qualifiedName();
List<Resource> usedBy = resourceInfo.getUsedBy(qualifiedName);
Resource resource = resourceInfo.getResource(qualifiedName);
List<Dependency> dependencies = resource == null ? null : resource.getDependencies();
if (dependencies != null || usedBy != null) {
StringBuilder buffer = new StringBuilder(clazz.getRawCommentText());
buffer.append("<h2>Resource information</h2>");
if (usedBy != null) {
buffer.append("This resource is used by: ");
boolean first = true;
for (Resource r : usedBy) {
if (first) {
first = false;
} else {
buffer.append(", ");
}
buffer.append("{@link ");
buffer.append(r.getType());
buffer.append("}");
}
}
if (dependencies != null) {
buffer.append("<h3>Dependencies</h3>");
buffer.append("<dl>");
for (Dependency dependency : dependencies) {
buffer.append("<dt>{@link ");
buffer.append(dependency.getType());
buffer.append("} (");
buffer.append(dependency.getMultiplicity());
buffer.append(")</dt><dd>");
String comment = dependency.getComment();
if (comment == null) {
buffer.append("(no documentation available)");
} else {
buffer.append(comment);
}
buffer.append("</dd>");
}
buffer.append("</dl>");
}
clazz.setRawCommentText(buffer.toString());
}
}
return Standard.start(root);
}
use of com.sun.javadoc.ClassDoc in project wso2-axis2-transports by wso2.
the class ResourceInfoDoclet method start.
public static boolean start(RootDoc root) throws IOException {
parseOptions(root.options());
ResourceInfo resourceInfo = new ResourceInfo();
for (ClassDoc clazz : root.classes()) {
Resource resource = null;
for (MethodDoc method : clazz.methods()) {
if (getAnnotation(method, "org.apache.axis2.transport.testkit.tests.Setup") != null) {
if (resource == null) {
resource = new Resource(clazz.qualifiedName());
}
ParamTag[] paramTags = method.paramTags();
for (Parameter parameter : method.parameters()) {
Type type = parameter.type();
String name = parameter.name();
String comment = null;
for (ParamTag paramTag : paramTags) {
if (paramTag.parameterName().equals(name)) {
comment = paramTag.parameterComment();
break;
}
}
if (comment == null) {
comment = getFirstSentence(root.classNamed(type.qualifiedTypeName()));
}
resource.addDependency(type.qualifiedTypeName(), type.dimension().equals("[]") ? "0..*" : "1", comment);
}
}
}
if (resource != null) {
resourceInfo.addResource(resource);
}
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outFile));
out.writeObject(resourceInfo);
out.close();
return true;
}
use of com.sun.javadoc.ClassDoc in project cxf by apache.
the class DumpJavaDoc method start.
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;
}
use of com.sun.javadoc.ClassDoc in project jersey by jersey.
the class ResourceDoclet method start.
/**
* Start the doclet.
*
* @param root the root JavaDoc document.
* @return true if no exception is thrown.
*/
public static boolean start(final RootDoc root) {
final String output = getOptionArg(root.options(), OPTION_OUTPUT);
final String classpath = getOptionArg(root.options(), OPTION_CLASSPATH);
// LOG.info( "Have classpath: " + classpath );
final String[] classpathElements = classpath.split(File.pathSeparator);
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final ClassLoader ncl = new Loader(classpathElements, ResourceDoclet.class.getClassLoader());
Thread.currentThread().setContextClassLoader(ncl);
final String docProcessorOption = getOptionArg(root.options(), OPTION_DOC_PROCESSORS);
final String[] docProcessors = docProcessorOption != null ? docProcessorOption.split(":") : null;
final DocProcessorWrapper docProcessor = new DocProcessorWrapper();
try {
if (docProcessors != null && docProcessors.length > 0) {
final Class<?> clazz = Class.forName(docProcessors[0], true, Thread.currentThread().getContextClassLoader());
final Class<? extends DocProcessor> dpClazz = clazz.asSubclass(DocProcessor.class);
docProcessor.add(dpClazz.newInstance());
}
} catch (final Exception e) {
LOG.log(Level.SEVERE, "Could not load docProcessors " + docProcessorOption, e);
}
try {
final ResourceDocType result = new ResourceDocType();
final ClassDoc[] classes = root.classes();
for (final ClassDoc classDoc : classes) {
LOG.fine("Writing class " + classDoc.qualifiedTypeName());
final ClassDocType classDocType = new ClassDocType();
classDocType.setClassName(classDoc.qualifiedTypeName());
classDocType.setCommentText(classDoc.commentText());
docProcessor.processClassDoc(classDoc, classDocType);
for (final MethodDoc methodDoc : classDoc.methods()) {
final MethodDocType methodDocType = new MethodDocType();
methodDocType.setMethodName(methodDoc.name());
methodDocType.setMethodSignature(methodDoc.signature());
methodDocType.setCommentText(methodDoc.commentText());
docProcessor.processMethodDoc(methodDoc, methodDocType);
addParamDocs(methodDoc, methodDocType, docProcessor);
addRequestRepresentationDoc(methodDoc, methodDocType);
addResponseDoc(methodDoc, methodDocType);
classDocType.getMethodDocs().add(methodDocType);
}
result.getDocs().add(classDocType);
}
try {
final Class<?>[] clazzes = getJAXBContextClasses(result, docProcessor);
final JAXBContext c = JAXBContext.newInstance(clazzes);
final Marshaller m = c.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
final OutputStream out = new BufferedOutputStream(new FileOutputStream(output));
final String[] cdataElements = getCDataElements(docProcessor);
final XMLSerializer serializer = getXMLSerializer(out, cdataElements);
m.marshal(result, serializer);
out.close();
LOG.info("Wrote " + output);
} catch (final Exception e) {
LOG.log(Level.SEVERE, "Could not serialize ResourceDoc.", e);
return false;
}
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
return true;
}
use of com.sun.javadoc.ClassDoc 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;
}
Aggregations