Search in sources :

Example 6 with Type

use of com.thoughtworks.qdox.model.Type in project maven-plugins by apache.

the class AbstractFixJavadocMojo method addDefaultJavadocTags.

/**
     * @param sb           not null
     * @param entity       not null
     * @param indent       not null
     * @param isJavaMethod
     * @throws MojoExecutionException if any
     */
private void addDefaultJavadocTags(final StringBuilder sb, final AbstractInheritableJavaEntity entity, final String indent, final boolean isJavaMethod) throws MojoExecutionException {
    boolean separatorAdded = false;
    if (isJavaMethod) {
        JavaMethod javaMethod = (JavaMethod) entity;
        if (fixTag(PARAM_TAG) && javaMethod.getParameters() != null) {
            for (int i = 0; i < javaMethod.getParameters().length; i++) {
                JavaParameter javaParameter = javaMethod.getParameters()[i];
                separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, javaParameter);
            }
        }
        if (fixTag(RETURN_TAG)) {
            if (javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid()) {
                separatorAdded = appendDefaultReturnTag(sb, indent, separatorAdded, javaMethod);
            }
        }
        if (fixTag(THROWS_TAG) && javaMethod.getExceptions() != null) {
            for (int i = 0; i < javaMethod.getExceptions().length; i++) {
                Type exception = javaMethod.getExceptions()[i];
                separatorAdded = appendDefaultThrowsTag(sb, indent, separatorAdded, exception);
            }
        }
    } else {
        separatorAdded = appendDefaultAuthorTag(sb, indent, separatorAdded);
        separatorAdded = appendDefaultVersionTag(sb, indent, separatorAdded);
    }
    if (fixTag(SINCE_TAG)) {
        if (!isJavaMethod) {
            JavaClass javaClass = (JavaClass) entity;
            if (!ignoreClirr) {
                if (isNewClassFromLastVersion(javaClass)) {
                    separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
                }
            } else {
                separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
                addSinceClasses(javaClass);
            }
        } else {
            JavaMethod javaMethod = (JavaMethod) entity;
            if (!ignoreClirr) {
                if (isNewMethodFromLastRevision(javaMethod)) {
                    separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
                }
            } else {
                if (sinceClasses != null && !sinceClassesContains(javaMethod.getParentClass())) {
                    separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
                }
            }
        }
    }
}
Also used : Type(com.thoughtworks.qdox.model.Type) JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaParameter(com.thoughtworks.qdox.model.JavaParameter)

Example 7 with Type

use of com.thoughtworks.qdox.model.Type in project maven-plugins by apache.

the class AbstractFixJavadocMojo method writeThrowsTag.

void writeThrowsTag(final StringBuilder sb, final JavaMethod javaMethod, final JavaEntityTags javaEntityTags, final String[] params) {
    String exceptionClassName = params[0];
    String originalJavadocTag = javaEntityTags.getJavadocThrowsTag(exceptionClassName);
    if (originalJavadocTag == null) {
        return;
    }
    if (!fixTag(THROWS_TAG)) {
        // write original param tag if found
        sb.append(originalJavadocTag);
        return;
    }
    if (javaMethod.getExceptions() != null) {
        for (int j = 0; j < javaMethod.getExceptions().length; j++) {
            Type exception = javaMethod.getExceptions()[j];
            if (exception.getValue().endsWith(exceptionClassName)) {
                originalJavadocTag = StringUtils.replace(originalJavadocTag, exceptionClassName, exception.getValue());
                if (StringUtils.removeDuplicateWhitespace(originalJavadocTag).trim().endsWith("@" + THROWS_TAG + " " + exception.getValue())) {
                    originalJavadocTag += " if any.";
                }
                sb.append(originalJavadocTag);
                // added qualified name
                javaEntityTags.putJavadocThrowsTag(exception.getValue(), originalJavadocTag);
                return;
            }
        }
    }
    Class<?> clazz = getClass(javaMethod.getParentClass(), exceptionClassName);
    if (clazz != null) {
        if (ClassUtils.isAssignable(clazz, RuntimeException.class)) {
            sb.append(StringUtils.replace(originalJavadocTag, exceptionClassName, clazz.getName()));
            // added qualified name
            javaEntityTags.putJavadocThrowsTag(clazz.getName(), originalJavadocTag);
        } else if (ClassUtils.isAssignable(clazz, Throwable.class)) {
            getLog().debug("Removing '" + originalJavadocTag + "'; Throwable not specified by " + getJavaMethodAsString(javaMethod) + " and it is not a RuntimeException.");
        } else {
            getLog().debug("Removing '" + originalJavadocTag + "'; It is not a Throwable");
        }
    } else if (removeUnknownThrows) {
        getLog().warn("Ignoring unknown throws '" + exceptionClassName + "' defined on " + getJavaMethodAsString(javaMethod));
    } else {
        getLog().warn("Found unknown throws '" + exceptionClassName + "' defined on " + getJavaMethodAsString(javaMethod));
        sb.append(originalJavadocTag);
        if (params.length == 1) {
            sb.append(" if any.");
        }
        javaEntityTags.putJavadocThrowsTag(exceptionClassName, originalJavadocTag);
    }
}
Also used : Type(com.thoughtworks.qdox.model.Type)

Example 8 with Type

use of com.thoughtworks.qdox.model.Type in project maven-plugins by apache.

the class AbstractFixJavadocMojo method addMissingJavadocTags.

/**
     * Add missing tags not already written.
     *
     * @param sb             not null
     * @param entity         not null
     * @param indent         not null
     * @param isJavaMethod
     * @param javaEntityTags not null
     * @throws MojoExecutionException if any
     */
private void addMissingJavadocTags(final StringBuilder sb, final AbstractInheritableJavaEntity entity, final String indent, final boolean isJavaMethod, final JavaEntityTags javaEntityTags) throws MojoExecutionException {
    if (isJavaMethod) {
        JavaMethod javaMethod = (JavaMethod) entity;
        if (fixTag(PARAM_TAG)) {
            if (javaMethod.getParameters() != null) {
                for (int i = 0; i < javaMethod.getParameters().length; i++) {
                    JavaParameter javaParameter = javaMethod.getParameters()[i];
                    if (javaEntityTags.getJavadocParamTag(javaParameter.getName(), true) == null) {
                        appendDefaultParamTag(sb, indent, javaParameter);
                    }
                }
            }
            // is generic?
            if (javaMethod.getTypeParameters() != null) {
                for (int i = 0; i < javaMethod.getTypeParameters().length; i++) {
                    TypeVariable typeParam = javaMethod.getTypeParameters()[i];
                    if (javaEntityTags.getJavadocParamTag("<" + typeParam.getName() + ">", true) == null) {
                        appendDefaultParamTag(sb, indent, typeParam);
                    }
                }
            }
        }
        if (fixTag(RETURN_TAG) && StringUtils.isEmpty(javaEntityTags.getJavadocReturnTag()) && javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid()) {
            appendDefaultReturnTag(sb, indent, javaMethod);
        }
        if (fixTag(THROWS_TAG) && javaMethod.getExceptions() != null) {
            for (int i = 0; i < javaMethod.getExceptions().length; i++) {
                Type exception = javaMethod.getExceptions()[i];
                if (javaEntityTags.getJavadocThrowsTag(exception.getValue(), true) == null) {
                    appendDefaultThrowsTag(sb, indent, exception);
                }
            }
        }
    } else {
        if (!javaEntityTags.getNamesTags().contains(AUTHOR_TAG)) {
            appendDefaultAuthorTag(sb, indent);
        }
        if (!javaEntityTags.getNamesTags().contains(VERSION_TAG)) {
            appendDefaultVersionTag(sb, indent);
        }
    }
    if (fixTag(SINCE_TAG) && !javaEntityTags.getNamesTags().contains(SINCE_TAG)) {
        if (!isJavaMethod) {
            if (!ignoreClirr) {
                if (isNewClassFromLastVersion((JavaClass) entity)) {
                    appendDefaultSinceTag(sb, indent);
                }
            } else {
                appendDefaultSinceTag(sb, indent);
                addSinceClasses((JavaClass) entity);
            }
        } else {
            if (!ignoreClirr) {
                if (isNewMethodFromLastRevision((JavaMethod) entity)) {
                    appendDefaultSinceTag(sb, indent);
                }
            } else {
                if (sinceClasses != null && !sinceClassesContains(entity.getParentClass())) {
                    appendDefaultSinceTag(sb, indent);
                }
            }
        }
    }
}
Also used : Type(com.thoughtworks.qdox.model.Type) TypeVariable(com.thoughtworks.qdox.model.TypeVariable) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaParameter(com.thoughtworks.qdox.model.JavaParameter)

Aggregations

Type (com.thoughtworks.qdox.model.Type)8 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)6 Test (org.junit.Test)4 JavaParameter (com.thoughtworks.qdox.model.JavaParameter)3 TypeVariable (com.thoughtworks.qdox.model.TypeVariable)2 JavaClass (com.thoughtworks.qdox.model.JavaClass)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1