Search in sources :

Example 1 with JavaParameter

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

the class AbstractFixJavadocMojo method isNewMethodFromLastRevision.

/**
     * Check under Clirr if this given method is newer from the last version.
     *
     * @param javaMethod a given method not null
     * @return <code>true</code> if Clirr said that this method is added from the last version,
     *         <code>false</code> otherwise or if {@link #clirrNewMethods} is null.
     * @throws MojoExecutionException if any
     */
private boolean isNewMethodFromLastRevision(JavaMethod javaMethod) throws MojoExecutionException {
    if (clirrNewMethods == null) {
        return false;
    }
    List<String> clirrMethods = clirrNewMethods.get(javaMethod.getParentClass().getFullyQualifiedName());
    if (clirrMethods == null) {
        return false;
    }
    for (String clirrMethod : clirrMethods) {
        // see net.sf.clirr.core.internal.checks.MethodSetCheck#getMethodId(JavaType clazz, Method method)
        String retrn = "";
        if (javaMethod.getReturns() != null) {
            retrn = javaMethod.getReturns().getFullQualifiedName();
        }
        StringBuilder params = new StringBuilder();
        for (JavaParameter parameter : javaMethod.getParameters()) {
            if (params.length() > 0) {
                params.append(", ");
            }
            params.append(parameter.getResolvedValue());
        }
        if (clirrMethod.contains(retrn + " ") && clirrMethod.contains(javaMethod.getName() + "(") && clirrMethod.contains("(" + params.toString() + ")")) {
            return true;
        }
    }
    return false;
}
Also used : JavaParameter(com.thoughtworks.qdox.model.JavaParameter)

Example 2 with JavaParameter

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

the class AbstractFixJavadocMojo method addDefaultMethodComment.

/**
     * Add in the buffer a default Javadoc for the given class:
     * <br/>
     * <code>
     * <font color="#808080">1</font>&nbsp;<font color="#ffffff">&nbsp;</font>
     * <font color="#3f5fbf">&#47;&#42;&#42;</font><br />
     * <font color="#808080">2</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font>
     * <font color="#3f5fbf">&#42;&nbsp;{Comment&nbsp;based&nbsp;on&nbsp;the&nbsp;method&nbsp;name}</font><br />
     * <font color="#808080">3</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font>
     * <font color="#3f5fbf">&#42;</font><br />
     * <font color="#808080">4</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font>
     * <font color="#3f5fbf">&#42;&nbsp;</font><font color="#7f9fbf">@param&nbsp;</font>
     * <font color="#3f5fbf">X&nbsp;{added&nbsp;if&nbsp;addMissingParam}</font><br />
     * <font color="#808080">5</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font>
     * <font color="#3f5fbf">&#42;&nbsp;</font><font color="#7f9fbf">@return&nbsp;</font>
     * <font color="#3f5fbf">X&nbsp;{added&nbsp;if&nbsp;addMissingReturn}</font><br />
     * <font color="#808080">6</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font>
     * <font color="#3f5fbf">&#42;&nbsp;</font><font color="#7f9fbf">@throws&nbsp;</font>
     * <font color="#3f5fbf">X&nbsp;{added&nbsp;if&nbsp;addMissingThrows}</font><br />
     * <font color="#808080">7</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font>
     * <font color="#3f5fbf">&#42;&nbsp;</font><font color="#7f9fbf">@since&nbsp;</font>
     * <font color="#3f5fbf">X&nbsp;{added&nbsp;if&nbsp;addMissingSince&nbsp;and&nbsp;new&nbsp;classes
     * from&nbsp;previous&nbsp;version}</font><br />
     * <font color="#808080">8</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;</font>
     * <font color="#3f5fbf">&#42;&#47;</font><br />
     * <font color="#808080">9</font>&nbsp;<font color="#7f0055"><b>public&nbsp;</b></font>
     * <font color="#7f0055"><b>void&nbsp;</b></font><font color="#000000">dummyMethod</font>
     * <font color="#000000">(&nbsp;</font><font color="#000000">String&nbsp;s&nbsp;</font>
     * <font color="#000000">){}</font>
     * </code>
     *
     * @param buffer     not null
     * @param javaMethod not null
     * @param indent     not null
     * @throws MojoExecutionException if any
     * @see #getDefaultMethodJavadocComment(JavaMethod)
     * @see #appendDefaultSinceTag(StringBuilder, String)
     */
private void addDefaultMethodComment(final StringWriter stringWriter, final JavaMethod javaMethod, final String indent) throws MojoExecutionException {
    StringBuilder sb = new StringBuilder();
    // special case
    if (isInherited(javaMethod)) {
        sb.append(indent).append(INHERITED_JAVADOC);
        sb.append(EOL);
        stringWriter.write(sb.toString());
        return;
    }
    sb.append(indent).append(START_JAVADOC);
    sb.append(EOL);
    sb.append(indent).append(SEPARATOR_JAVADOC);
    sb.append(getDefaultMethodJavadocComment(javaMethod));
    sb.append(EOL);
    boolean separatorAdded = false;
    if (fixTag(PARAM_TAG)) {
        if (javaMethod.getParameters() != null) {
            for (int i = 0; i < javaMethod.getParameters().length; i++) {
                JavaParameter javaParameter = javaMethod.getParameters()[i];
                separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, javaParameter);
            }
        }
        // is generic?
        if (javaMethod.getTypeParameters() != null) {
            for (int i = 0; i < javaMethod.getTypeParameters().length; i++) {
                TypeVariable typeParam = javaMethod.getTypeParameters()[i];
                separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, typeParam);
            }
        }
    }
    if (fixTag(RETURN_TAG) && javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid()) {
        separatorAdded = appendDefaultReturnTag(sb, indent, separatorAdded, javaMethod);
    }
    if (fixTag(THROWS_TAG) && javaMethod.getExceptions() != null && javaMethod.getExceptions().length > 0) {
        for (int i = 0; i < javaMethod.getExceptions().length; i++) {
            Type exception = javaMethod.getExceptions()[i];
            separatorAdded = appendDefaultThrowsTag(sb, indent, separatorAdded, exception);
        }
    }
    if (fixTag(SINCE_TAG) && isNewMethodFromLastRevision(javaMethod)) {
        separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
    }
    sb.append(indent).append(" ").append(END_JAVADOC);
    sb.append(EOL);
    stringWriter.write(sb.toString());
}
Also used : Type(com.thoughtworks.qdox.model.Type) TypeVariable(com.thoughtworks.qdox.model.TypeVariable) JavaParameter(com.thoughtworks.qdox.model.JavaParameter)

Example 3 with JavaParameter

use of com.thoughtworks.qdox.model.JavaParameter 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 4 with JavaParameter

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

the class AbstractFixJavadocMojo method writeParamTag.

private void writeParamTag(final StringBuilder sb, final JavaMethod javaMethod, final JavaEntityTags javaEntityTags, String[] params) {
    params = fixQdox173(params);
    String paramName = params[0];
    if (!fixTag(PARAM_TAG)) {
        // write original param tag if found
        String originalJavadocTag = javaEntityTags.getJavadocParamTag(paramName);
        if (originalJavadocTag != null) {
            sb.append(originalJavadocTag);
        }
        return;
    }
    boolean found = false;
    JavaParameter javaParam = javaMethod.getParameterByName(paramName);
    if (javaParam == null) {
        // is generic?
        TypeVariable[] typeParams = javaMethod.getTypeParameters();
        for (TypeVariable typeParam : typeParams) {
            if (typeParam.getGenericValue().equals(paramName)) {
                found = true;
            }
        }
    } else {
        found = true;
    }
    if (!found) {
        if (getLog().isWarnEnabled()) {
            getLog().warn("Fixed unknown param '" + paramName + "' defined in " + getJavaMethodAsString(javaMethod));
        }
        if (sb.toString().endsWith(EOL)) {
            sb.delete(sb.toString().lastIndexOf(EOL), sb.toString().length());
        }
    } else {
        String originalJavadocTag = javaEntityTags.getJavadocParamTag(paramName);
        if (originalJavadocTag != null) {
            sb.append(originalJavadocTag);
            String s = "@" + PARAM_TAG + " " + paramName;
            if (StringUtils.removeDuplicateWhitespace(originalJavadocTag).trim().endsWith(s)) {
                sb.append(" ");
                sb.append(getDefaultJavadocForType(javaParam.getType()));
            }
        }
    }
}
Also used : TypeVariable(com.thoughtworks.qdox.model.TypeVariable) JavaParameter(com.thoughtworks.qdox.model.JavaParameter)

Example 5 with JavaParameter

use of com.thoughtworks.qdox.model.JavaParameter 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

JavaParameter (com.thoughtworks.qdox.model.JavaParameter)5 Type (com.thoughtworks.qdox.model.Type)3 TypeVariable (com.thoughtworks.qdox.model.TypeVariable)3 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)2 JavaClass (com.thoughtworks.qdox.model.JavaClass)1