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;
}
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);
}
}
}
}
}
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);
}
Aggregations