Search in sources :

Example 1 with JavaMember

use of com.thoughtworks.qdox.model.JavaMember 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);
                }
            }
        }
    }
}
Also used : JavaType(com.thoughtworks.qdox.model.JavaType) JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaGenericDeclaration(com.thoughtworks.qdox.model.JavaGenericDeclaration) JavaParameter(com.thoughtworks.qdox.model.JavaParameter) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaMember(com.thoughtworks.qdox.model.JavaMember) JavaExecutable(com.thoughtworks.qdox.model.JavaExecutable)

Example 2 with JavaMember

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

the class AbstractFixJavadocMojo method replaceLinkTags.

static String replaceLinkTags(String comment, JavaAnnotatedElement entity) {
    StringBuilder resolvedComment = new StringBuilder();
    // scan comment for {@link someClassName} and try to resolve this
    Matcher linktagMatcher = Pattern.compile("\\{@link\\s").matcher(comment);
    int startIndex = 0;
    while (linktagMatcher.find()) {
        int startName = linktagMatcher.end();
        resolvedComment.append(comment.substring(startIndex, startName));
        int endName = comment.indexOf("}", startName);
        if (endName >= 0) {
            String name;
            String link = comment.substring(startName, endName);
            int hashIndex = link.indexOf('#');
            if (hashIndex >= 0) {
                name = link.substring(0, hashIndex);
            } else {
                name = link;
            }
            if (StringUtils.isNotBlank(name)) {
                String typeName;
                if (entity instanceof JavaClass) {
                    JavaClass clazz = (JavaClass) entity;
                    typeName = TypeResolver.byClassName(clazz.getBinaryName(), clazz.getJavaClassLibrary(), clazz.getSource().getImports()).resolveType(name.trim());
                } else if (entity instanceof JavaMember) {
                    JavaClass clazz = ((JavaMember) entity).getDeclaringClass();
                    typeName = TypeResolver.byClassName(clazz.getBinaryName(), clazz.getJavaClassLibrary(), clazz.getSource().getImports()).resolveType(name.trim());
                } else {
                    typeName = null;
                }
                if (typeName == null) {
                    typeName = name.trim();
                } else {
                    typeName = typeName.replaceAll("\\$", ".");
                }
                // adjust name for inner classes
                resolvedComment.append(typeName);
            }
            if (hashIndex >= 0) {
                resolvedComment.append(link.substring(hashIndex).trim());
            }
            startIndex = endName;
        } else {
            startIndex = startName;
        }
    }
    resolvedComment.append(comment.substring(startIndex));
    return resolvedComment.toString();
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) Matcher(java.util.regex.Matcher) JavaMember(com.thoughtworks.qdox.model.JavaMember)

Aggregations

JavaClass (com.thoughtworks.qdox.model.JavaClass)2 JavaMember (com.thoughtworks.qdox.model.JavaMember)2 JavaExecutable (com.thoughtworks.qdox.model.JavaExecutable)1 JavaGenericDeclaration (com.thoughtworks.qdox.model.JavaGenericDeclaration)1 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)1 JavaParameter (com.thoughtworks.qdox.model.JavaParameter)1 JavaType (com.thoughtworks.qdox.model.JavaType)1 Matcher (java.util.regex.Matcher)1