Search in sources :

Example 1 with ClassDoc

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

the class ClassDescriptionRenderer method addSubtypeLinks.

private void addSubtypeLinks(ClassDoc classDoc, Element parent, Document document) {
    if (!classDoc.getSubClasses().isEmpty()) {
        Element list = document.createElement("segmentedlist");
        parent.appendChild(list);
        Element segtitle = document.createElement("segtitle");
        list.appendChild(segtitle);
        segtitle.appendChild(document.createTextNode("Known Subtypes"));
        Element listItem = document.createElement("seglistitem");
        list.appendChild(listItem);
        Element seg = document.createElement("seg");
        listItem.appendChild(seg);
        Element simplelist = document.createElement("simplelist");
        int columns = 3;
        if (classDoc.getSubClasses().size() <= 3) {
            // if there are only 3 or fewer known subtypes, render them
            // in a single column
            columns = 1;
        }
        simplelist.setAttribute("columns", String.valueOf(columns));
        simplelist.setAttribute("type", "vert");
        for (ClassDoc subClass : classDoc.getSubClasses()) {
            Element member = document.createElement("member");
            Element apilink = document.createElement("apilink");
            apilink.setAttribute("class", subClass.getName());
            member.appendChild(apilink);
            simplelist.appendChild(member);
        }
        seg.appendChild(simplelist);
    }
}
Also used : Element(org.w3c.dom.Element) ClassDoc(org.gradle.build.docs.dsl.docbook.model.ClassDoc)

Example 2 with ClassDoc

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

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

the class ClassDocPropertiesBuilder method build.

/**
 * Builds the properties of the given class
 */
void build(ClassDoc classDoc) {
    Element thead = getChild(classDoc.getPropertiesTable(), "thead");
    Element tr = getChild(thead, "tr");
    List<Element> header = children(tr, "td");
    if (header.size() < 1) {
        throw new RuntimeException(String.format("Expected at least 1 <td> in <thead>/<tr>, found: %s", header));
    }
    Map<String, Element> inheritedValueTitleMapping = new HashMap<String, Element>();
    List<Element> valueTitles = new ArrayList<Element>();
    for (int i = 1; i < header.size(); i++) {
        Element element = header.get(i);
        Element override = findChild(element, "overrides");
        if (override != null) {
            element.removeChild(override);
            inheritedValueTitleMapping.put(override.getTextContent(), element);
        }
        Node firstChild = element.getFirstChild();
        if (firstChild instanceof Text) {
            firstChild.setTextContent(firstChild.getTextContent().replaceFirst("^\\s+", ""));
        }
        Node lastChild = element.getLastChild();
        if (lastChild instanceof Text) {
            lastChild.setTextContent(lastChild.getTextContent().replaceFirst("\\s+$", ""));
        }
        valueTitles.add(element);
    }
    // adding the properties from the super class onto the inheriting class
    Map<String, PropertyDoc> props = new TreeMap<String, PropertyDoc>();
    List<ClassDoc> superTypes = classDoc.getSuperTypes();
    for (ClassDoc superType : superTypes) {
        LOG.info("Getting properties for {}", superType.getName());
        for (PropertyDoc propertyDoc : superType.getClassProperties()) {
            Map<String, ExtraAttributeDoc> additionalValues = new LinkedHashMap<String, ExtraAttributeDoc>();
            for (ExtraAttributeDoc attributeDoc : propertyDoc.getAdditionalValues()) {
                String key = attributeDoc.getKey();
                if (inheritedValueTitleMapping.get(key) != null) {
                    ExtraAttributeDoc newAttribute = new ExtraAttributeDoc(inheritedValueTitleMapping.get(key), attributeDoc.getValueCell());
                    additionalValues.put(newAttribute.getKey(), newAttribute);
                } else {
                    additionalValues.put(key, attributeDoc);
                }
            }
            props.put(propertyDoc.getName(), propertyDoc.forClass(classDoc, additionalValues.values()));
        }
    }
    for (Element row : children(classDoc.getPropertiesTable(), "tr")) {
        List<Element> cells = children(row, "td");
        if (cells.size() != header.size()) {
            throw new RuntimeException(String.format("Expected %s <td> elements in <tr>, found: %s", header.size(), tr));
        }
        String propName = cells.get(0).getTextContent().trim();
        PropertyMetaData property = classDoc.getClassMetaData().findProperty(propName);
        if (property == null) {
            throw new RuntimeException(String.format("No metadata for property '%s.%s'. Available properties: %s", classDoc.getName(), propName, classDoc.getClassMetaData().getPropertyNames()));
        }
        Map<String, ExtraAttributeDoc> additionalValues = new LinkedHashMap<String, ExtraAttributeDoc>();
        if (!superTypes.isEmpty()) {
            PropertyDoc overriddenProp = props.get(propName);
            if (overriddenProp != null) {
                for (ExtraAttributeDoc attributeDoc : overriddenProp.getAdditionalValues()) {
                    additionalValues.put(attributeDoc.getKey(), attributeDoc);
                }
            }
        }
        for (int i = 1; i < header.size(); i++) {
            if (cells.get(i).getFirstChild() == null) {
                continue;
            }
            ExtraAttributeDoc attributeDoc = new ExtraAttributeDoc(valueTitles.get(i - 1), cells.get(i));
            additionalValues.put(attributeDoc.getKey(), attributeDoc);
        }
        PropertyDoc propertyDoc = new PropertyDoc(property, javadocConverter.parse(property, listener).getDocbook(), new ArrayList<ExtraAttributeDoc>(additionalValues.values()));
        if (propertyDoc.getDescription() == null) {
            throw new RuntimeException(String.format("Docbook content for '%s.%s' does not contain a description paragraph.", classDoc.getName(), propName));
        }
        props.put(propName, propertyDoc);
    }
    for (PropertyDoc propertyDoc : props.values()) {
        classDoc.addClassProperty(propertyDoc);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Text(org.w3c.dom.Text) PropertyMetaData(org.gradle.build.docs.dsl.source.model.PropertyMetaData) PropertyDoc(org.gradle.build.docs.dsl.docbook.model.PropertyDoc) ExtraAttributeDoc(org.gradle.build.docs.dsl.docbook.model.ExtraAttributeDoc) ClassDoc(org.gradle.build.docs.dsl.docbook.model.ClassDoc)

Example 4 with ClassDoc

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

the class ClassDocSuperTypeBuilder method build.

/**
 * Builds and attaches the supertypes of the given class
 */
void build(ClassDoc classDoc) {
    ClassMetaData classMetaData = classDoc.getClassMetaData();
    String superClassName = classMetaData.getSuperClassName();
    if (superClassName != null) {
        // Assume this is a class and so has implemented all properties and methods somewhere in the superclass hierarchy
        ClassDoc superClass = model.getClassDoc(superClassName);
        classDoc.setSuperClass(superClass);
        superClass.addSubClass(classDoc);
    }
    List<String> interfaceNames = classMetaData.getInterfaceNames();
    for (String interfaceName : interfaceNames) {
        ClassDoc superInterface = model.findClassDoc(interfaceName);
        if (superInterface != null) {
            classDoc.getInterfaces().add(superInterface);
            superInterface.addSubClass(classDoc);
        }
    }
}
Also used : ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData) ClassDoc(org.gradle.build.docs.dsl.docbook.model.ClassDoc)

Aggregations

ClassDoc (org.gradle.build.docs.dsl.docbook.model.ClassDoc)4 Element (org.w3c.dom.Element)3 PropertyDoc (org.gradle.build.docs.dsl.docbook.model.PropertyDoc)2 HashSet (java.util.HashSet)1 BlockDoc (org.gradle.build.docs.dsl.docbook.model.BlockDoc)1 ExtraAttributeDoc (org.gradle.build.docs.dsl.docbook.model.ExtraAttributeDoc)1 MethodDoc (org.gradle.build.docs.dsl.docbook.model.MethodDoc)1 ClassMetaData (org.gradle.build.docs.dsl.source.model.ClassMetaData)1 MethodMetaData (org.gradle.build.docs.dsl.source.model.MethodMetaData)1 PropertyMetaData (org.gradle.build.docs.dsl.source.model.PropertyMetaData)1 TypeMetaData (org.gradle.build.docs.dsl.source.model.TypeMetaData)1 Node (org.w3c.dom.Node)1 Text (org.w3c.dom.Text)1