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