Search in sources :

Example 36 with JavaMethod

use of com.thoughtworks.qdox.model.JavaMethod 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 javaExecutable 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(JavaExecutable javaExecutable) throws MojoExecutionException {
    if (clirrNewMethods == null) {
        return false;
    }
    List<String> clirrMethods = clirrNewMethods.get(javaExecutable.getDeclaringClass().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 (javaExecutable instanceof JavaMethod && ((JavaMethod) javaExecutable).getReturns() != null) {
            retrn = ((JavaMethod) javaExecutable).getReturns().getFullyQualifiedName();
        }
        StringBuilder params = new StringBuilder();
        for (JavaParameter parameter : javaExecutable.getParameters()) {
            if (params.length() > 0) {
                params.append(", ");
            }
            params.append(parameter.getResolvedFullyQualifiedName());
        }
        if (clirrMethod.contains(retrn + " ") && clirrMethod.contains(javaExecutable.getName() + "(") && clirrMethod.contains("(" + params.toString() + ")")) {
            return true;
        }
    }
    return false;
}
Also used : JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaParameter(com.thoughtworks.qdox.model.JavaParameter)

Example 37 with JavaMethod

use of com.thoughtworks.qdox.model.JavaMethod 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 isJavaExecutable
 * @param javaEntityTags not null
 * @throws MojoExecutionException if any
 */
private void addMissingJavadocTags(final StringBuilder sb, final JavaAnnotatedElement entity, final String indent, final boolean isJavaExecutable, final JavaEntityTags javaEntityTags) throws MojoExecutionException {
    if (isJavaExecutable) {
        JavaExecutable javaExecutable = (JavaExecutable) entity;
        if (fixTag(PARAM_TAG)) {
            if (javaExecutable.getParameters() != null) {
                for (JavaParameter javaParameter : javaExecutable.getParameters()) {
                    if (javaEntityTags.getJavadocParamTag(javaParameter.getName(), true) == null) {
                        appendDefaultParamTag(sb, indent, javaParameter);
                    }
                }
            }
            // is generic?
            if (javaExecutable.getTypeParameters() != null) {
                for (JavaTypeVariable<JavaGenericDeclaration> typeParam : javaExecutable.getTypeParameters()) {
                    if (javaEntityTags.getJavadocParamTag("<" + typeParam.getName() + ">", true) == null) {
                        appendDefaultParamTag(sb, indent, typeParam);
                    }
                }
            }
        }
        if (javaExecutable instanceof JavaMethod) {
            JavaMethod javaMethod = (JavaMethod) javaExecutable;
            if (fixTag(RETURN_TAG) && StringUtils.isEmpty(javaEntityTags.getJavadocReturnTag()) && javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid()) {
                appendDefaultReturnTag(sb, indent, javaMethod);
            }
        }
        if (fixTag(THROWS_TAG) && javaExecutable.getExceptions() != null) {
            for (JavaType exception : javaExecutable.getExceptions()) {
                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 (!isJavaExecutable) {
            if (!ignoreClirr) {
                if (isNewClassFromLastVersion((JavaClass) entity)) {
                    appendDefaultSinceTag(sb, indent);
                }
            } else {
                appendDefaultSinceTag(sb, indent);
                addSinceClasses((JavaClass) entity);
            }
        } else {
            if (!ignoreClirr) {
                if (isNewMethodFromLastRevision((JavaExecutable) entity)) {
                    appendDefaultSinceTag(sb, indent);
                }
            } else if (sinceClasses != null) {
                if (entity instanceof JavaMember && !sinceClassesContains(((JavaMember) entity).getDeclaringClass())) {
                    appendDefaultSinceTag(sb, indent);
                } else if (entity instanceof JavaClass && !sinceClassesContains(((JavaClass) entity).getDeclaringClass())) {
                    appendDefaultSinceTag(sb, indent);
                }
            }
        }
    }
}
Also used : JavaType(com.thoughtworks.qdox.model.JavaType) JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaGenericDeclaration(com.thoughtworks.qdox.model.JavaGenericDeclaration) JavaParameter(com.thoughtworks.qdox.model.JavaParameter) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaMember(com.thoughtworks.qdox.model.JavaMember) JavaExecutable(com.thoughtworks.qdox.model.JavaExecutable)

Example 38 with JavaMethod

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

the class FixJavadocMojoTest method testJavadocCommentJdk5.

/**
 * @throws Throwable if any
 */
public void testJavadocCommentJdk5() throws Exception {
    String content = "/**" + EOL + " * Dummy Class." + EOL + " */" + EOL + "public class DummyClass" + EOL + "{" + EOL + "    /**" + EOL + "     * Dummy method." + EOL + "     *" + EOL + "     * @param <K>  The Key type for the method" + EOL + "     * @param <V>  The Value type for the method" + EOL + "     * @param name The name." + EOL + "     * @return A map configured." + EOL + "     */" + EOL + "    public <K, V> java.util.Map<K, V> dummyMethod( String name )" + EOL + "    {" + EOL + "        return null;" + EOL + "    }" + EOL + "}";
    JavaProjectBuilder builder = new JavaProjectBuilder();
    builder.setEncoding("UTF-8");
    JavaClass clazz = builder.addSource(new StringReader(content)).getClassByName("DummyClass");
    JavaMethod javaMethod = clazz.getMethods().get(0);
    String methodJavadoc = AbstractFixJavadocMojo.getJavadocComment(content, javaMethod);
    assertEquals("     * Dummy method." + EOL + "     *", methodJavadoc);
    assertEquals(4, javaMethod.getTags().size());
    AbstractFixJavadocMojo mojoInstance = new FixJavadocMojo();
    setVariableValueToObject(mojoInstance, "fixTagsSplitted", new String[] { "all" });
    DocletTag tag = javaMethod.getTags().get(0);
    String tagJavadoc = mojoInstance.getJavadocComment(content, javaMethod, tag);
    assertEquals("     * @param <K>  The Key type for the method", tagJavadoc);
    tag = javaMethod.getTags().get(1);
    tagJavadoc = mojoInstance.getJavadocComment(content, javaMethod, tag);
    assertEquals("     * @param <V>  The Value type for the method", tagJavadoc);
    tag = javaMethod.getTags().get(2);
    tagJavadoc = mojoInstance.getJavadocComment(content, javaMethod, tag);
    assertEquals("     * @param name The name.", tagJavadoc);
    tag = javaMethod.getTags().get(3);
    tagJavadoc = mojoInstance.getJavadocComment(content, javaMethod, tag);
    assertEquals("     * @return A map configured.", tagJavadoc);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) StringReader(java.io.StringReader) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaProjectBuilder(com.thoughtworks.qdox.JavaProjectBuilder) DocletTag(com.thoughtworks.qdox.model.DocletTag)

Aggregations

JavaMethod (com.thoughtworks.qdox.model.JavaMethod)38 DocletTag (com.thoughtworks.qdox.model.DocletTag)13 JavaClass (com.thoughtworks.qdox.model.JavaClass)12 Test (org.junit.Test)10 JavaParameter (com.thoughtworks.qdox.model.JavaParameter)8 StringReader (java.io.StringReader)8 Type (com.thoughtworks.qdox.model.Type)7 JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)3 JavaProjectBuilder (com.thoughtworks.qdox.JavaProjectBuilder)3 JavaExecutable (com.thoughtworks.qdox.model.JavaExecutable)3 JavaType (com.thoughtworks.qdox.model.JavaType)3 AbstractInheritableJavaEntity (com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)2 AbstractJavaEntity (com.thoughtworks.qdox.model.AbstractJavaEntity)2 BeanProperty (com.thoughtworks.qdox.model.BeanProperty)2 JavaField (com.thoughtworks.qdox.model.JavaField)2 JavaGenericDeclaration (com.thoughtworks.qdox.model.JavaGenericDeclaration)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 StringWriter (java.io.StringWriter)2 Method (java.lang.reflect.Method)2