Search in sources :

Example 11 with JavaMethod

use of com.thoughtworks.qdox.model.JavaMethod in project jsonschema2pojo by joelittlejohn.

the class DescriptionIT method descriptionAppearsInGetterJavadoc.

@Test
public void descriptionAppearsInGetterJavadoc() throws IOException {
    JavaMethod javaMethod = classWithDescription.getMethodBySignature("getDescription", new Type[] {});
    String javaDocComment = javaMethod.getComment();
    assertThat(javaDocComment, containsString("A description for this property"));
}
Also used : JavaMethod(com.thoughtworks.qdox.model.JavaMethod) Test(org.junit.Test)

Example 12 with JavaMethod

use of com.thoughtworks.qdox.model.JavaMethod in project jsonschema2pojo by joelittlejohn.

the class TitleIT method descriptionAppearsInGetterJavadoc.

@Test
public void descriptionAppearsInGetterJavadoc() throws IOException {
    JavaMethod javaMethod = classWithTitle.getMethodBySignature("getTitle", new Type[] {});
    String javaDocComment = javaMethod.getComment();
    assertThat(javaDocComment, containsString("A title for this property"));
}
Also used : JavaMethod(com.thoughtworks.qdox.model.JavaMethod) Test(org.junit.Test)

Example 13 with JavaMethod

use of com.thoughtworks.qdox.model.JavaMethod in project arrow by NetEase.

the class PowerEmailableReporter method getAuthors.

// ~ JavaDoc-specific Methods --------------------------------------------------------
/**
	 * Get ITestNGMethod author(s) string, or class author(s) if no method author is present.
	 * Default return value is "unknown".
	 * 
	 * @param className
	 * @param method
	 * @return
	 * @author hzjingcheng
	 */
private String getAuthors(String className, ITestNGMethod method) {
    JavaClass cls = builder.getClassByName(className);
    DocletTag[] authors = cls.getTagsByName("author");
    // get class authors as default author name
    String allAuthors = "";
    if (authors.length == 0) {
        allAuthors = "unknown";
    } else {
        for (DocletTag author : authors) {
            allAuthors += author.getValue() + " ";
        }
    }
    // get method author name
    JavaMethod[] mtds = cls.getMethods();
    for (JavaMethod mtd : mtds) {
        if (mtd.getName().equals(method.getMethodName())) {
            authors = mtd.getTagsByName("author");
            if (authors.length != 0) {
                allAuthors = "";
                for (DocletTag author : authors) {
                    allAuthors += author.getValue() + " ";
                }
            }
            break;
        }
    }
    return allAuthors.trim();
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) DocletTag(com.thoughtworks.qdox.model.DocletTag)

Example 14 with JavaMethod

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

the class AbstractFixJavadocMojo method isInherited.

/**
     * @param clazz      the Java class object, not null
     * @param javaMethod the QDox JavaMethod object not null
     * @return <code>true</code> if <code>javaMethod</code> exists in the given <code>clazz</code>,
     *         <code>false</code> otherwise.
     * @see #isInherited(JavaMethod)
     */
private boolean isInherited(Class<?> clazz, JavaMethod javaMethod) {
    for (Method method : clazz.getDeclaredMethods()) {
        if (!method.getName().equals(javaMethod.getName())) {
            continue;
        }
        if (method.getParameterTypes().length != javaMethod.getParameters().length) {
            continue;
        }
        boolean found = false;
        int j = 0;
        for (Class<?> paramType : method.getParameterTypes()) {
            String name1 = paramType.getName();
            String name2 = javaMethod.getParameters()[j++].getType().getFullQualifiedName();
            // TODO check algo, seems broken (only takes in account the last param)
            found = name1.equals(name2);
        }
        return found;
    }
    return false;
}
Also used : Method(java.lang.reflect.Method) JavaMethod(com.thoughtworks.qdox.model.JavaMethod)

Example 15 with JavaMethod

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

the class AbstractFixJavadocMojo method updateJavadocTags.

/**
     * Write tags according javaEntityTags.
     *
     * @param sb             not null
     * @param entity         not null
     * @param isJavaMethod
     * @param javaEntityTags not null
     */
private void updateJavadocTags(final StringBuilder sb, final AbstractInheritableJavaEntity entity, final boolean isJavaMethod, final JavaEntityTags javaEntityTags) {
    for (int i = 0; i < entity.getTags().length; i++) {
        DocletTag docletTag = entity.getTags()[i];
        if (isJavaMethod) {
            JavaMethod javaMethod = (JavaMethod) entity;
            String[] params = docletTag.getParameters();
            if (params.length < 1) {
                continue;
            }
            if (docletTag.getName().equals(PARAM_TAG)) {
                writeParamTag(sb, javaMethod, javaEntityTags, params);
            } else if (docletTag.getName().equals(RETURN_TAG)) {
                writeReturnTag(sb, javaMethod, javaEntityTags);
            } else if (docletTag.getName().equals(THROWS_TAG)) {
                writeThrowsTag(sb, javaMethod, javaEntityTags, params);
            } else {
                // write unknown tags
                for (Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext(); ) {
                    String originalJavadocTag = it.next();
                    String simplified = StringUtils.removeDuplicateWhitespace(originalJavadocTag).trim();
                    if (simplified.contains("@" + docletTag.getName())) {
                        it.remove();
                        sb.append(originalJavadocTag);
                        sb.append(EOL);
                    }
                }
            }
        } else {
            for (Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext(); ) {
                String originalJavadocTag = it.next();
                String simplified = StringUtils.removeDuplicateWhitespace(originalJavadocTag).trim();
                if (simplified.contains("@" + docletTag.getName())) {
                    it.remove();
                    sb.append(originalJavadocTag);
                    sb.append(EOL);
                }
            }
        }
        if (sb.toString().endsWith(EOL)) {
            sb.delete(sb.toString().lastIndexOf(EOL), sb.toString().length());
        }
        sb.append(EOL);
    }
}
Also used : JavaMethod(com.thoughtworks.qdox.model.JavaMethod) 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