Search in sources :

Example 6 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 MethodMetaData methodMetaData, final GenerationListener listener) {
    listener.start(String.format("method %s", methodMetaData));
    try {
        ClassMetaData ownerClass = methodMetaData.getOwnerClass();
        String rawCommentText = methodMetaData.getRawCommentText();
        try {
            CommentSource commentSource = new InheritedMethodCommentSource(listener, methodMetaData);
            return parse(rawCommentText, ownerClass, commentSource, listener);
        } catch (Exception e) {
            throw new GradleException(String.format("Could not convert javadoc comment to docbook.%nClass: %s%nMethod: %s%nComment: %s", ownerClass.getClassName(), methodMetaData.getSignature(), 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 7 with ClassMetaData

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

the class TypeNameResolver method resolve.

/**
 * Resolves a source type name into a fully qualified type name.
 */
public String resolve(String name, ClassMetaData classMetaData) {
    if (primitiveTypes.contains(name)) {
        return name;
    }
    String candidateClassName;
    String[] innerNames = name.split("\\.");
    ClassMetaData pos = classMetaData;
    for (int i = 0; i < innerNames.length; i++) {
        String innerName = innerNames[i];
        candidateClassName = pos.getClassName() + '.' + innerName;
        if (!pos.getInnerClassNames().contains(candidateClassName)) {
            break;
        }
        if (i == innerNames.length - 1) {
            return candidateClassName;
        }
        pos = metaDataRepository.get(candidateClassName);
    }
    String outerClassName = classMetaData.getOuterClassName();
    while (outerClassName != null) {
        if (name.equals(StringUtils.substringAfterLast(outerClassName, "."))) {
            return outerClassName;
        }
        ClassMetaData outerClass = metaDataRepository.get(outerClassName);
        candidateClassName = outerClassName + '.' + name;
        if (outerClass.getInnerClassNames().contains(candidateClassName)) {
            return candidateClassName;
        }
        outerClassName = outerClass.getOuterClassName();
    }
    if (name.contains(".")) {
        return name;
    }
    for (String importedClass : classMetaData.getImports()) {
        String baseName = StringUtils.substringAfterLast(importedClass, ".");
        if (baseName.equals("*")) {
            candidateClassName = StringUtils.substringBeforeLast(importedClass, ".") + "." + name;
            if (metaDataRepository.find(candidateClassName) != null) {
                return candidateClassName;
            }
            if (importedClass.startsWith("java.") && isVisibleSystemClass(candidateClassName)) {
                return candidateClassName;
            }
        } else if (name.equals(baseName)) {
            return importedClass;
        }
    }
    candidateClassName = classMetaData.getPackageName() + "." + name;
    if (metaDataRepository.find(candidateClassName) != null) {
        return candidateClassName;
    }
    candidateClassName = "java.lang." + name;
    if (isVisibleSystemClass(candidateClassName)) {
        return candidateClassName;
    }
    if (classMetaData.isGroovy()) {
        candidateClassName = "java.math." + name;
        if (groovyImplicitTypes.contains(candidateClassName)) {
            return candidateClassName;
        }
        for (String prefix : groovyImplicitImportPackages) {
            candidateClassName = prefix + name;
            if (isVisibleSystemClass(candidateClassName)) {
                return candidateClassName;
            }
        }
    }
    return name;
}
Also used : ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData)

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