use of org.gradle.build.docs.dsl.docbook.model.MethodDoc in project gradle by gradle.
the class ClassDocMethodsBuilder method build.
/**
* Builds the methods and script blocks of the given class. Assumes properties have already been built.
*/
public void build(ClassDoc classDoc) {
Set<String> signatures = new HashSet<String>();
for (Element tr : children(classDoc.getMethodsTable(), "tr")) {
List<Element> cells = children(tr, "td");
if (cells.size() != 1) {
throw new RuntimeException(String.format("Expected 1 cell in <tr>, found: %s", tr));
}
String methodName = cells.get(0).getTextContent().trim();
Collection<MethodMetaData> methods = classDoc.getClassMetaData().findDeclaredMethods(methodName);
if (methods.isEmpty()) {
throw new RuntimeException(String.format("No metadata for method '%s.%s()'. Available methods: %s", classDoc.getName(), methodName, classDoc.getClassMetaData().getDeclaredMethodNames()));
}
for (MethodMetaData method : methods) {
DocComment docComment = javadocConverter.parse(method, listener);
MethodDoc methodDoc = new MethodDoc(method, docComment.getDocbook());
if (methodDoc.getDescription() == null) {
throw new RuntimeException(String.format("Docbook content for '%s %s' does not contain a description paragraph.", classDoc.getName(), method.getSignature()));
}
PropertyDoc property = classDoc.findProperty(methodName);
boolean multiValued = false;
if (property != null && method.getParameters().size() == 1 && method.getParameters().get(0).getType().getSignature().equals(Closure.class.getName())) {
TypeMetaData type = property.getMetaData().getType();
if (type.getName().equals("java.util.List") || type.getName().equals("java.util.Collection") || type.getName().equals("java.util.Set") || type.getName().equals("java.util.Iterable")) {
type = type.getTypeArgs().get(0);
multiValued = true;
}
classDoc.addClassBlock(new BlockDoc(methodDoc, property, type, multiValued));
} else {
classDoc.addClassMethod(methodDoc);
signatures.add(method.getOverrideSignature());
}
}
}
for (ClassDoc supertype : classDoc.getSuperTypes()) {
for (MethodDoc method : supertype.getClassMethods()) {
if (signatures.add(method.getMetaData().getOverrideSignature())) {
classDoc.addClassMethod(method);
}
}
}
}
use of org.gradle.build.docs.dsl.docbook.model.MethodDoc in project gradle by gradle.
the class MethodTableRenderer method renderTo.
public void renderTo(Iterable<MethodDoc> methods, Element parent) {
Document document = parent.getOwnerDocument();
// <thead>
// <tr>
// <td>Method</td>
// <td>Description</td>
// </tr>
// </thead>
Element thead = document.createElement("thead");
parent.appendChild(thead);
Element tr = document.createElement("tr");
thead.appendChild(tr);
Element td = document.createElement("td");
tr.appendChild(td);
td.appendChild(document.createTextNode("Method"));
td = document.createElement("td");
tr.appendChild(td);
td.appendChild(document.createTextNode("Description"));
for (MethodDoc methodDoc : methods) {
// <tr>
// <td><literal><link linkend="$id">$name</link>$signature</literal></td>
// <td>$description</td>
// </tr>
tr = document.createElement("tr");
parent.appendChild(tr);
td = document.createElement("td");
tr.appendChild(td);
Element literal = document.createElement("literal");
td.appendChild(literal);
Element link = document.createElement("link");
literal.appendChild(link);
link.setAttribute("linkend", methodDoc.getId());
link.appendChild(document.createTextNode(methodDoc.getName()));
StringBuilder signature = new StringBuilder();
signature.append("(");
for (int i = 0; i < methodDoc.getMetaData().getParameters().size(); i++) {
if (i > 0) {
signature.append(", ");
}
signature.append(methodDoc.getMetaData().getParameters().get(i).getName());
}
signature.append(")");
literal.appendChild(document.createTextNode(signature.toString()));
td = document.createElement("td");
tr.appendChild(td);
if (methodDoc.isDeprecated()) {
Element caution = document.createElement("caution");
td.appendChild(caution);
caution.appendChild(document.createTextNode("Deprecated"));
}
if (methodDoc.isIncubating()) {
Element caution = document.createElement("caution");
td.appendChild(caution);
caution.appendChild(document.createTextNode("Incubating"));
}
td.appendChild(document.importNode(methodDoc.getDescription(), true));
}
}
use of org.gradle.build.docs.dsl.docbook.model.MethodDoc in project gradle by gradle.
the class MethodsRenderer method renderSummaryTo.
public void renderSummaryTo(ClassDoc classDoc, Element parent) {
Document document = parent.getOwnerDocument();
Element summarySection = document.createElement("section");
parent.appendChild(summarySection);
Element title = document.createElement("title");
summarySection.appendChild(title);
title.appendChild(document.createTextNode("Methods"));
Collection<MethodDoc> classMethods = classDoc.getClassMethods();
if (!classMethods.isEmpty()) {
Element table = document.createElement("table");
summarySection.appendChild(table);
title = document.createElement("title");
table.appendChild(title);
title.appendChild(document.createTextNode("Methods - " + classDoc.getSimpleName()));
methodTableRenderer.renderTo(classMethods, table);
}
for (ClassExtensionDoc extensionDoc : classDoc.getClassExtensions()) {
extensionMethodsSummaryRenderer.renderTo(extensionDoc, summarySection);
}
if (!hasMethods(classDoc)) {
Element para = document.createElement("para");
summarySection.appendChild(para);
para.appendChild(document.createTextNode("No methods"));
}
}
use of org.gradle.build.docs.dsl.docbook.model.MethodDoc in project gradle by gradle.
the class MethodsRenderer method renderDetailsTo.
public void renderDetailsTo(ClassDoc classDoc, Element parent) {
if (hasMethods(classDoc)) {
Document document = parent.getOwnerDocument();
Element detailsSection = document.createElement("section");
parent.appendChild(detailsSection);
Element title = document.createElement("title");
detailsSection.appendChild(title);
title.appendChild(document.createTextNode("Method details"));
for (MethodDoc methodDoc : classDoc.getClassMethods()) {
methodDetailRenderer.renderTo(methodDoc, detailsSection);
}
for (ClassExtensionDoc extensionDoc : classDoc.getClassExtensions()) {
for (MethodDoc methodDoc : extensionDoc.getExtensionMethods()) {
methodDetailRenderer.renderTo(methodDoc, detailsSection);
}
}
}
}
Aggregations