Search in sources :

Example 16 with JavaMethod

use of com.thoughtworks.qdox.model.JavaMethod 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 17 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 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)

Example 18 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 Throwable {
    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 + "}";
    JavaDocBuilder builder = new JavaDocBuilder();
    builder.setEncoding("UTF-8");
    builder.addSource(new StringReader(content));
    JavaClass[] classes = builder.getClasses();
    JavaClass clazz = classes[0];
    JavaMethod javaMethod = clazz.getMethods()[0];
    String methodJavadoc = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "getJavadocComment", new Class[] { String.class, AbstractJavaEntity.class }, new Object[] { content, javaMethod });
    assertEquals("     * Dummy method." + EOL + "     *", methodJavadoc);
    assertEquals(4, javaMethod.getTags().length);
    AbstractFixJavadocMojo mojoInstance = new FixJavadocMojo();
    setVariableValueToObject(mojoInstance, "fixTagsSplitted", new String[] { "all" });
    DocletTag tag = javaMethod.getTags()[0];
    String tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @param <K>  The Key type for the method", tagJavadoc);
    tag = javaMethod.getTags()[1];
    tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @param <V>  The Value type for the method", tagJavadoc);
    tag = javaMethod.getTags()[2];
    tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @param name The name.", tagJavadoc);
    tag = javaMethod.getTags()[3];
    tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @return A map configured.", tagJavadoc);
}
Also used : AbstractInheritableJavaEntity(com.thoughtworks.qdox.model.AbstractInheritableJavaEntity) JavaDocBuilder(com.thoughtworks.qdox.JavaDocBuilder) AbstractJavaEntity(com.thoughtworks.qdox.model.AbstractJavaEntity) JavaClass(com.thoughtworks.qdox.model.JavaClass) StringReader(java.io.StringReader) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaClass(com.thoughtworks.qdox.model.JavaClass) DocletTag(com.thoughtworks.qdox.model.DocletTag)

Aggregations

JavaMethod (com.thoughtworks.qdox.model.JavaMethod)18 Test (org.junit.Test)8 Type (com.thoughtworks.qdox.model.Type)6 DocletTag (com.thoughtworks.qdox.model.DocletTag)5 JavaClass (com.thoughtworks.qdox.model.JavaClass)4 StringReader (java.io.StringReader)4 JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)3 AbstractInheritableJavaEntity (com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)2 AbstractJavaEntity (com.thoughtworks.qdox.model.AbstractJavaEntity)2 JavaParameter (com.thoughtworks.qdox.model.JavaParameter)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 JavaField (com.thoughtworks.qdox.model.JavaField)1 TypeVariable (com.thoughtworks.qdox.model.TypeVariable)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 JavaEntityTags (org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.JavaEntityTags)1 MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)1