use of com.thoughtworks.qdox.model.JavaType in project maven-plugins by apache.
the class AbstractFixJavadocMojo method addDefaultMethodComment.
/**
* Add in the buffer a default Javadoc for the given class:
* <br/>
* <code>
* <font color="#808080">1</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">/**</font><br />
* <font color="#808080">2</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">* {Comment based on the method name}</font><br />
* <font color="#808080">3</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">*</font><br />
* <font color="#808080">4</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
* <font color="#3f5fbf">X {added if addMissingParam}</font><br />
* <font color="#808080">5</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">* </font><font color="#7f9fbf">@return </font>
* <font color="#3f5fbf">X {added if addMissingReturn}</font><br />
* <font color="#808080">6</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">* </font><font color="#7f9fbf">@throws </font>
* <font color="#3f5fbf">X {added if addMissingThrows}</font><br />
* <font color="#808080">7</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">* </font><font color="#7f9fbf">@since </font>
* <font color="#3f5fbf">X {added if addMissingSince and new classes
* from previous version}</font><br />
* <font color="#808080">8</font> <font color="#ffffff"> </font>
* <font color="#3f5fbf">*/</font><br />
* <font color="#808080">9</font> <font color="#7f0055"><b>public </b></font>
* <font color="#7f0055"><b>void </b></font><font color="#000000">dummyMethod</font>
* <font color="#000000">( </font><font color="#000000">String s </font>
* <font color="#000000">){}</font>
* </code>
*
* @param buffer not null
* @param javaExecutable not null
* @param indent not null
* @throws MojoExecutionException if any
* @see #getDefaultMethodJavadocComment(JavaMethod)
* @see #appendDefaultSinceTag(StringBuilder, String)
*/
private void addDefaultMethodComment(final StringWriter stringWriter, final JavaExecutable javaExecutable, final String indent) throws MojoExecutionException {
StringBuilder sb = new StringBuilder();
// special case
if (isInherited(javaExecutable)) {
sb.append(indent).append(INHERITED_JAVADOC);
sb.append(EOL);
stringWriter.write(sb.toString());
return;
}
sb.append(indent).append(START_JAVADOC);
sb.append(EOL);
sb.append(indent).append(SEPARATOR_JAVADOC);
sb.append(getDefaultMethodJavadocComment(javaExecutable));
sb.append(EOL);
boolean separatorAdded = false;
if (fixTag(PARAM_TAG)) {
if (javaExecutable.getParameters() != null) {
for (JavaParameter javaParameter : javaExecutable.getParameters()) {
separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, javaParameter);
}
}
// is generic?
if (javaExecutable.getTypeParameters() != null) {
for (JavaTypeVariable<JavaGenericDeclaration> typeParam : javaExecutable.getTypeParameters()) {
separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, typeParam);
}
}
}
if (javaExecutable instanceof JavaMethod) {
JavaMethod javaMethod = (JavaMethod) javaExecutable;
if (fixTag(RETURN_TAG) && javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid()) {
separatorAdded = appendDefaultReturnTag(sb, indent, separatorAdded, javaMethod);
}
}
if (fixTag(THROWS_TAG) && javaExecutable.getExceptions() != null) {
for (JavaType exception : javaExecutable.getExceptions()) {
separatorAdded = appendDefaultThrowsTag(sb, indent, separatorAdded, exception);
}
}
if (fixTag(SINCE_TAG) && isNewMethodFromLastRevision(javaExecutable)) {
separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
}
sb.append(indent).append(" ").append(END_JAVADOC);
sb.append(EOL);
stringWriter.write(sb.toString());
}
use of com.thoughtworks.qdox.model.JavaType in project maven-plugins by apache.
the class AbstractFixJavadocMojo method addDefaultJavadocTags.
/**
* @param sb not null
* @param entity not null
* @param indent not null
* @param isJavaExecutable
* @throws MojoExecutionException if any
*/
private void addDefaultJavadocTags(final StringBuilder sb, final JavaAnnotatedElement entity, final String indent, final boolean isJavaExecutable) throws MojoExecutionException {
boolean separatorAdded = false;
if (isJavaExecutable) {
JavaExecutable javaExecutable = (JavaExecutable) entity;
if (fixTag(PARAM_TAG) && javaExecutable.getParameters() != null) {
for (JavaParameter javaParameter : javaExecutable.getParameters()) {
separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, javaParameter);
}
}
if (javaExecutable instanceof JavaMethod && fixTag(RETURN_TAG)) {
JavaMethod javaMethod = (JavaMethod) javaExecutable;
if (javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid()) {
separatorAdded = appendDefaultReturnTag(sb, indent, separatorAdded, javaMethod);
}
}
if (fixTag(THROWS_TAG) && javaExecutable.getExceptions() != null) {
for (JavaType exception : javaExecutable.getExceptions()) {
separatorAdded = appendDefaultThrowsTag(sb, indent, separatorAdded, exception);
}
}
} else {
separatorAdded = appendDefaultAuthorTag(sb, indent, separatorAdded);
separatorAdded = appendDefaultVersionTag(sb, indent, separatorAdded);
}
if (fixTag(SINCE_TAG)) {
if (!isJavaExecutable) {
JavaClass javaClass = (JavaClass) entity;
if (!ignoreClirr) {
if (isNewClassFromLastVersion(javaClass)) {
separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
}
} else {
separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
addSinceClasses(javaClass);
}
} else {
JavaExecutable javaExecutable = (JavaExecutable) entity;
if (!ignoreClirr) {
if (isNewMethodFromLastRevision(javaExecutable)) {
separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
}
} else {
if (sinceClasses != null && !sinceClassesContains(javaExecutable.getDeclaringClass())) {
separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
}
}
}
}
}
use of com.thoughtworks.qdox.model.JavaType in project maven-plugins by apache.
the class AbstractFixJavadocMojo method writeThrowsTag.
void writeThrowsTag(final StringBuilder sb, final JavaExecutable javaExecutable, final JavaEntityTags javaEntityTags, final List<String> params) {
String exceptionClassName = params.get(0);
String originalJavadocTag = javaEntityTags.getJavadocThrowsTag(exceptionClassName);
if (originalJavadocTag == null) {
return;
}
if (!fixTag(THROWS_TAG)) {
// write original param tag if found
sb.append(originalJavadocTag);
return;
}
if (javaExecutable.getExceptions() != null) {
for (JavaType exception : javaExecutable.getExceptions()) {
if (exception.getValue().endsWith(exceptionClassName)) {
originalJavadocTag = StringUtils.replace(originalJavadocTag, exceptionClassName, exception.getFullyQualifiedName());
if (StringUtils.removeDuplicateWhitespace(originalJavadocTag).trim().endsWith("@" + THROWS_TAG + " " + exception.getValue())) {
originalJavadocTag += " if any.";
}
sb.append(originalJavadocTag);
// added qualified name
javaEntityTags.putJavadocThrowsTag(exception.getValue(), originalJavadocTag);
return;
}
}
}
Class<?> clazz = getClass(javaExecutable.getDeclaringClass(), exceptionClassName);
if (clazz != null) {
if (ClassUtils.isAssignable(clazz, RuntimeException.class)) {
sb.append(StringUtils.replace(originalJavadocTag, exceptionClassName, clazz.getName()));
// added qualified name
javaEntityTags.putJavadocThrowsTag(clazz.getName(), originalJavadocTag);
} else if (ClassUtils.isAssignable(clazz, Throwable.class)) {
getLog().debug("Removing '" + originalJavadocTag + "'; Throwable not specified by " + getJavaMethodAsString(javaExecutable) + " and it is not a RuntimeException.");
} else {
getLog().debug("Removing '" + originalJavadocTag + "'; It is not a Throwable");
}
} else if (removeUnknownThrows) {
getLog().warn("Ignoring unknown throws '" + exceptionClassName + "' defined on " + getJavaMethodAsString(javaExecutable));
} else {
getLog().warn("Found unknown throws '" + exceptionClassName + "' defined on " + getJavaMethodAsString(javaExecutable));
sb.append(originalJavadocTag);
if (params.size() == 1) {
sb.append(" if any.");
}
javaEntityTags.putJavadocThrowsTag(exceptionClassName, originalJavadocTag);
}
}
use of com.thoughtworks.qdox.model.JavaType 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);
}
}
}
}
}
Aggregations