Search in sources :

Example 1 with BlockDoc

use of org.gradle.build.docs.dsl.docbook.model.BlockDoc in project gradle by gradle.

the class BlocksRenderer method renderDetailsTo.

public void renderDetailsTo(ClassDoc classDoc, Element parent) {
    if (hasBlocks(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("Script block details"));
        for (BlockDoc blockDoc : classDoc.getClassBlocks()) {
            blockDetailRenderer.renderTo(blockDoc, detailsSection);
        }
        for (ClassExtensionDoc extensionDoc : classDoc.getClassExtensions()) {
            for (BlockDoc blockDoc : extensionDoc.getExtensionBlocks()) {
                blockDetailRenderer.renderTo(blockDoc, detailsSection);
            }
        }
    }
}
Also used : ClassExtensionDoc(org.gradle.build.docs.dsl.docbook.model.ClassExtensionDoc) BlockDoc(org.gradle.build.docs.dsl.docbook.model.BlockDoc) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 2 with BlockDoc

use of org.gradle.build.docs.dsl.docbook.model.BlockDoc 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 3 with BlockDoc

use of org.gradle.build.docs.dsl.docbook.model.BlockDoc in project gradle by gradle.

the class BlockTableRenderer method renderTo.

public void renderTo(Iterable<BlockDoc> blocks, Element parent) {
    Document document = parent.getOwnerDocument();
    // <thead>
    // <tr>
    // <td>Block</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("Block"));
    td = document.createElement("td");
    tr.appendChild(td);
    td.appendChild(document.createTextNode("Description"));
    for (BlockDoc blockDoc : blocks) {
        // <tr>
        // <td><link linkend="$id"><literal>$name</literal></link</td>
        // <td>$description</td>
        // </tr>
        tr = document.createElement("tr");
        parent.appendChild(tr);
        td = document.createElement("td");
        tr.appendChild(td);
        Element link = document.createElement("link");
        td.appendChild(link);
        link.setAttribute("linkend", blockDoc.getId());
        Element literal = document.createElement("literal");
        link.appendChild(literal);
        literal.appendChild(document.createTextNode(blockDoc.getName()));
        td = document.createElement("td");
        tr.appendChild(td);
        if (blockDoc.isDeprecated()) {
            Element caution = document.createElement("caution");
            td.appendChild(caution);
            caution.appendChild(document.createTextNode("Deprecated"));
        }
        if (blockDoc.isIncubating()) {
            Element caution = document.createElement("caution");
            td.appendChild(caution);
            caution.appendChild(document.createTextNode("Incubating"));
        }
        td.appendChild(document.importNode(blockDoc.getDescription(), true));
    }
}
Also used : BlockDoc(org.gradle.build.docs.dsl.docbook.model.BlockDoc) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 4 with BlockDoc

use of org.gradle.build.docs.dsl.docbook.model.BlockDoc in project gradle by gradle.

the class BlocksRenderer 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("Script blocks"));
    Collection<BlockDoc> classBlocks = classDoc.getClassBlocks();
    if (!classBlocks.isEmpty()) {
        Element table = document.createElement("table");
        summarySection.appendChild(table);
        title = document.createElement("title");
        table.appendChild(title);
        title.appendChild(document.createTextNode("Script blocks - " + classDoc.getSimpleName()));
        blockTableRenderer.renderTo(classBlocks, table);
    }
    for (ClassExtensionDoc extensionDoc : classDoc.getClassExtensions()) {
        extensionBlocksSummaryRenderer.renderTo(extensionDoc, summarySection);
    }
    if (!hasBlocks(classDoc)) {
        Element para = document.createElement("para");
        summarySection.appendChild(para);
        para.appendChild(document.createTextNode("No script blocks"));
    }
}
Also used : ClassExtensionDoc(org.gradle.build.docs.dsl.docbook.model.ClassExtensionDoc) BlockDoc(org.gradle.build.docs.dsl.docbook.model.BlockDoc) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Aggregations

BlockDoc (org.gradle.build.docs.dsl.docbook.model.BlockDoc)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 ClassDoc (org.gradle.build.docs.dsl.docbook.model.ClassDoc)1 MethodDoc (org.gradle.build.docs.dsl.docbook.model.MethodDoc)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