Search in sources :

Example 1 with MethodDoc

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);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) MethodMetaData(org.gradle.build.docs.dsl.source.model.MethodMetaData) TypeMetaData(org.gradle.build.docs.dsl.source.model.TypeMetaData) MethodDoc(org.gradle.build.docs.dsl.docbook.model.MethodDoc) BlockDoc(org.gradle.build.docs.dsl.docbook.model.BlockDoc) PropertyDoc(org.gradle.build.docs.dsl.docbook.model.PropertyDoc) HashSet(java.util.HashSet) ClassDoc(org.gradle.build.docs.dsl.docbook.model.ClassDoc)

Example 2 with MethodDoc

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));
    }
}
Also used : MethodDoc(org.gradle.build.docs.dsl.docbook.model.MethodDoc) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 3 with MethodDoc

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"));
    }
}
Also used : ClassExtensionDoc(org.gradle.build.docs.dsl.docbook.model.ClassExtensionDoc) MethodDoc(org.gradle.build.docs.dsl.docbook.model.MethodDoc) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 4 with MethodDoc

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);
            }
        }
    }
}
Also used : ClassExtensionDoc(org.gradle.build.docs.dsl.docbook.model.ClassExtensionDoc) MethodDoc(org.gradle.build.docs.dsl.docbook.model.MethodDoc) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Aggregations

MethodDoc (org.gradle.build.docs.dsl.docbook.model.MethodDoc)4 Element (org.w3c.dom.Element)4 Document (org.w3c.dom.Document)3 ClassExtensionDoc (org.gradle.build.docs.dsl.docbook.model.ClassExtensionDoc)2 HashSet (java.util.HashSet)1 BlockDoc (org.gradle.build.docs.dsl.docbook.model.BlockDoc)1 ClassDoc (org.gradle.build.docs.dsl.docbook.model.ClassDoc)1 PropertyDoc (org.gradle.build.docs.dsl.docbook.model.PropertyDoc)1 MethodMetaData (org.gradle.build.docs.dsl.source.model.MethodMetaData)1 TypeMetaData (org.gradle.build.docs.dsl.source.model.TypeMetaData)1