Search in sources :

Example 1 with ClassMetaData

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

the class JavadocConverter method parse.

public DocComment parse(final PropertyMetaData propertyMetaData, final GenerationListener listener) {
    listener.start(String.format("property %s", propertyMetaData));
    try {
        ClassMetaData ownerClass = propertyMetaData.getOwnerClass();
        String rawCommentText = propertyMetaData.getRawCommentText();
        try {
            CommentSource commentSource = new InheritedPropertyCommentSource(propertyMetaData, listener);
            DocCommentImpl docComment = parse(rawCommentText, ownerClass, commentSource, listener);
            adjustGetterComment(docComment);
            return docComment;
        } catch (Exception e) {
            throw new GradleException(String.format("Could not convert javadoc comment to docbook.%nClass: %s%nProperty: %s%nComment: %s", ownerClass.getClassName(), propertyMetaData.getName(), rawCommentText), e);
        }
    } finally {
        listener.finish();
    }
}
Also used : GradleException(org.gradle.api.GradleException) ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData) GradleException(org.gradle.api.GradleException)

Example 2 with ClassMetaData

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

the class JavadocLinkConverter method resolveValue.

/**
 * Converts a javadoc value link into docbook.
 */
public Node resolveValue(String fieldName, ClassMetaData classMetaData, GenerationListener listener) {
    String[] parts = fieldName.split("#");
    ClassMetaData targetClass;
    if (parts[0].length() > 0) {
        String targetClassName = typeNameResolver.resolve(parts[0], classMetaData);
        targetClass = repository.find(targetClassName);
        if (targetClass == null) {
            listener.warning(String.format("Could not locate target class '%s' for field value link '%s'", targetClass, fieldName));
            Element element = document.createElement("UNHANDLED-VALUE");
            element.appendChild(document.createTextNode(targetClassName + ":" + parts[1]));
            return element;
        }
    } else {
        targetClass = classMetaData;
    }
    String value = targetClass.getConstants().get(parts[1]);
    if (value == null) {
        listener.warning(String.format("Field '%s' does not have any value", fieldName));
        Element element = document.createElement("NO-VALUE-FOR_FIELD");
        element.appendChild(document.createTextNode(targetClass.getClassName() + ":" + parts[1]));
        return element;
    }
    return createLiteralNode(value);
}
Also used : Element(org.w3c.dom.Element) ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData)

Example 3 with ClassMetaData

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

Example 4 with ClassMetaData

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

the class GenerateDefaultImportsTask method generate.

@TaskAction
public void generate() throws IOException {
    SimpleClassMetaDataRepository<ClassMetaData> repository = new SimpleClassMetaDataRepository<>();
    repository.load(getMetaDataFile().getAsFile().get());
    final Set<String> excludedPrefixes = new HashSet<>();
    final Set<String> excludedPackages = new HashSet<>();
    for (String excludePattern : excludePatterns) {
        if (excludePattern.endsWith(".**")) {
            String baseName = excludePattern.substring(0, excludePattern.length() - 3);
            excludedPrefixes.add(baseName + '.');
            excludedPackages.add(baseName);
        } else {
            excludedPackages.add(excludePattern);
        }
    }
    final Set<String> packages = new LinkedHashSet<>();
    final Multimap<String, String> simpleNames = LinkedHashMultimap.create();
    repository.each(new Action<ClassMetaData>() {

        public void execute(ClassMetaData classMetaData) {
            if (classMetaData.getOuterClassName() != null) {
                // Ignore inner classes
                return;
            }
            String packageName = classMetaData.getPackageName();
            if (excludedPackages.contains(packageName)) {
                return;
            }
            for (String excludedPrefix : excludedPrefixes) {
                if (packageName.startsWith(excludedPrefix)) {
                    return;
                }
            }
            simpleNames.put(classMetaData.getSimpleName(), classMetaData.getClassName());
            packages.add(packageName);
        }
    });
    try (PrintWriter mappingFileWriter = new PrintWriter(new FileWriter(getMappingDestFile().getAsFile().get()))) {
        for (Map.Entry<String, Collection<String>> entry : simpleNames.asMap().entrySet()) {
            if (entry.getValue().size() > 1) {
                System.out.println(String.format("Multiple DSL types have short name '%s'", entry.getKey()));
                for (String className : entry.getValue()) {
                    System.out.println("    * " + className);
                }
            }
            mappingFileWriter.print(entry.getKey());
            mappingFileWriter.print(":");
            for (String className : entry.getValue()) {
                mappingFileWriter.print(className);
                mappingFileWriter.print(";");
            }
            mappingFileWriter.println();
        }
    }
    try (PrintWriter writer = new PrintWriter(new FileWriter(getImportsDestFile().getAsFile().get()))) {
        for (String packageName : packages) {
            writer.print("import ");
            writer.print(packageName);
            writer.println(".*");
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileWriter(java.io.FileWriter) Collection(java.util.Collection) Map(java.util.Map) ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData) SimpleClassMetaDataRepository(org.gradle.build.docs.model.SimpleClassMetaDataRepository) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) PrintWriter(java.io.PrintWriter) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with ClassMetaData

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

ClassMetaData (org.gradle.build.docs.dsl.source.model.ClassMetaData)7 GradleException (org.gradle.api.GradleException)2 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 TaskAction (org.gradle.api.tasks.TaskAction)1 ClassDoc (org.gradle.build.docs.dsl.docbook.model.ClassDoc)1 MethodMetaData (org.gradle.build.docs.dsl.source.model.MethodMetaData)1 TypeMetaData (org.gradle.build.docs.dsl.source.model.TypeMetaData)1 SimpleClassMetaDataRepository (org.gradle.build.docs.model.SimpleClassMetaDataRepository)1 Element (org.w3c.dom.Element)1