Search in sources :

Example 1 with MethodMetaData

use of org.gradle.build.docs.dsl.source.model.MethodMetaData in project gradle by gradle.

the class ClassDocExtensionsBuilder method build.

private void build(ClassExtensionDoc extensionDoc) {
    Document doc;
    try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    } catch (ParserConfigurationException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
    LinkRenderer linkRenderer = new LinkRenderer(doc, model);
    for (Map.Entry<String, ClassDoc> entry : extensionDoc.getExtensionClasses().entrySet()) {
        String id = entry.getKey();
        ClassDoc type = entry.getValue();
        PropertyMetaData propertyMetaData = new PropertyMetaData(id, extensionDoc.getTargetClass().getClassMetaData());
        propertyMetaData.setType(new TypeMetaData(type.getName()));
        Element para = doc.createElement("para");
        para.appendChild(doc.createTextNode("The "));
        para.appendChild(linkRenderer.link(propertyMetaData.getType(), listener));
        para.appendChild(doc.createTextNode(String.format(" added by the %s plugin.", extensionDoc.getPluginId())));
        PropertyDoc propertyDoc = new PropertyDoc(propertyMetaData, Collections.singletonList(para), Collections.<ExtraAttributeDoc>emptyList());
        extensionDoc.getExtraProperties().add(propertyDoc);
        para = doc.createElement("para");
        para.appendChild(doc.createTextNode("Configures the "));
        para.appendChild(linkRenderer.link(propertyMetaData.getType(), listener));
        para.appendChild(doc.createTextNode(String.format(" added by the %s plugin.", extensionDoc.getPluginId())));
        MethodMetaData methodMetaData = new MethodMetaData(id, extensionDoc.getTargetClass().getClassMetaData());
        methodMetaData.addParameter("configClosure", new TypeMetaData(Closure.class.getName()));
        MethodDoc methodDoc = new MethodDoc(methodMetaData, Collections.singletonList(para));
        extensionDoc.getExtraBlocks().add(new BlockDoc(methodDoc, propertyDoc, propertyMetaData.getType(), false));
    }
}
Also used : Element(org.w3c.dom.Element) PropertyMetaData(org.gradle.build.docs.dsl.source.model.PropertyMetaData) MethodMetaData(org.gradle.build.docs.dsl.source.model.MethodMetaData) Document(org.w3c.dom.Document) TypeMetaData(org.gradle.build.docs.dsl.source.model.TypeMetaData) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MethodMetaData

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

use of org.gradle.build.docs.dsl.source.model.MethodMetaData in project gradle by gradle.

the class JavadocLinkConverter method doResolve.

private Node doResolve(String link, ClassMetaData classMetaData, GenerationListener listener) {
    Matcher matcher = LINK_PATTERN.matcher(link);
    if (!matcher.matches()) {
        return null;
    }
    String className = null;
    if (matcher.group(1).length() > 0) {
        className = typeNameResolver.resolve(matcher.group(1), classMetaData);
        if (className == null) {
            return null;
        }
    }
    if (matcher.group(2) == null) {
        return linkRenderer.link(new TypeMetaData(className), listener);
    }
    ClassMetaData targetClass;
    if (className != null) {
        targetClass = repository.find(className);
        if (targetClass == null) {
            return null;
        }
    } else {
        targetClass = classMetaData;
    }
    String methodSignature = matcher.group(3);
    if (matcher.group(5) != null) {
        StringBuilder signature = new StringBuilder();
        signature.append(methodSignature);
        signature.append("(");
        if (matcher.group(5).length() > 0) {
            String[] types = PARAM_DELIMITER.split(matcher.group(5));
            for (int i = 0; i < types.length; i++) {
                String type = types[i];
                Matcher typeMatcher = TYPE_PATTERN.matcher(type);
                if (!typeMatcher.matches()) {
                    return null;
                }
                if (i > 0) {
                    signature.append(", ");
                }
                signature.append(typeNameResolver.resolve(typeMatcher.group(1), classMetaData));
                String suffix = typeMatcher.group(2);
                if (suffix.equals("...")) {
                    suffix = "[]";
                }
                signature.append(suffix);
            }
        }
        signature.append(")");
        methodSignature = signature.toString();
    }
    if (targetClass.isEnum() && targetClass.getEnumConstant(methodSignature) != null) {
        return linkRenderer.link(targetClass.getEnumConstant(methodSignature), listener);
    }
    MethodMetaData method = findMethod(methodSignature, targetClass);
    if (method == null) {
        return null;
    }
    return linkRenderer.link(method, listener);
}
Also used : TypeMetaData(org.gradle.build.docs.dsl.source.model.TypeMetaData) Matcher(java.util.regex.Matcher) MethodMetaData(org.gradle.build.docs.dsl.source.model.MethodMetaData) ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData)

Aggregations

MethodMetaData (org.gradle.build.docs.dsl.source.model.MethodMetaData)3 TypeMetaData (org.gradle.build.docs.dsl.source.model.TypeMetaData)3 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BlockDoc (org.gradle.build.docs.dsl.docbook.model.BlockDoc)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 ClassMetaData (org.gradle.build.docs.dsl.source.model.ClassMetaData)1 PropertyMetaData (org.gradle.build.docs.dsl.source.model.PropertyMetaData)1 Document (org.w3c.dom.Document)1