use of com.sun.javadoc.MethodDoc 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.MethodDoc 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.MethodDoc 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.MethodDoc in project geode by apache.
the class UnitTestDoclet method getTestMethods.
/**
* Returns an array containing all of the "test" methods (including those that are inherited) for
* the given class.
*/
private static MethodDoc[] getTestMethods(ClassDoc c) {
Set set = new TreeSet();
while (c != null) {
MethodDoc[] methods = c.methods();
for (int i = 0; i < methods.length; i++) {
MethodDoc method = methods[i];
if (method.isPublic() && method.parameters().length == 0 && method.name().startsWith("test")) {
set.add(method);
}
}
c = c.superclass();
}
return (MethodDoc[]) set.toArray(new MethodDoc[0]);
}
use of com.sun.javadoc.MethodDoc in project geode by apache.
the class UnitTestDoclet method document.
/**
* Summarizes the test methods of the given class
*/
public static void document(ClassDoc c, PrintWriter pw) throws IOException {
pw.println(c.qualifiedName());
{
String comment = c.commentText();
if (comment != null && !comment.equals("")) {
pw.println("");
indent(comment, 4, pw);
pw.println("");
}
}
MethodDoc[] methods = getTestMethods(c);
for (int i = 0; i < methods.length; i++) {
MethodDoc method = methods[i];
pw.print(" ");
pw.println(method.name());
String comment = method.commentText();
if (comment != null && !comment.equals("")) {
pw.println("");
indent(comment, 6, pw);
pw.println("");
}
}
pw.println("");
}
Aggregations