Search in sources :

Example 6 with DocletTag

use of com.thoughtworks.qdox.model.DocletTag 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 7 with DocletTag

use of com.thoughtworks.qdox.model.DocletTag 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)

Example 8 with DocletTag

use of com.thoughtworks.qdox.model.DocletTag 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);
}
Also used : AbstractInheritableJavaEntity(com.thoughtworks.qdox.model.AbstractInheritableJavaEntity) JavaDocBuilder(com.thoughtworks.qdox.JavaDocBuilder) AbstractJavaEntity(com.thoughtworks.qdox.model.AbstractJavaEntity) JavaClass(com.thoughtworks.qdox.model.JavaClass) StringReader(java.io.StringReader) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaClass(com.thoughtworks.qdox.model.JavaClass) DocletTag(com.thoughtworks.qdox.model.DocletTag)

Example 9 with DocletTag

use of com.thoughtworks.qdox.model.DocletTag in project sling by apache.

the class ClassDescriptor method fromClass.

static ClassDescriptor fromClass(Log log, JavaClass javaClass) {
    DocletTag tag = javaClass.getTagByName(TAG_CLASS_DESCRIPTOR);
    if (tag == null) {
        return null;
    }
    ClassDescriptor cd = new ClassDescriptor(log, tag);
    cd.className = javaClass.getFullyQualifiedName();
    cd.isInterface = javaClass.isInterface();
    cd.isAbstract = !cd.isInterface && javaClass.isAbstract();
    cd.extend = tag.getNamedParameter(EXTEND);
    if (cd.extend == null) {
        if (javaClass.getSuperJavaClass() != null) {
            cd.extend = javaClass.getSuperJavaClass().getFullyQualifiedName();
            // do not declare extending Object :-)
            if (Object.class.getName().equals(cd.extend)) {
                cd.extend = null;
            }
        }
    } else if (cd.extend.length() == 0) {
        // explicit empty extend value prevents extend attribute from being
        // set
        cd.extend = null;
    }
    String interfaceList = tag.getNamedParameter(INTERFACES);
    if (interfaceList == null) {
        if (javaClass.getImplementedInterfaces() != null) {
            JavaClass[] implInterfaces = javaClass.getImplementedInterfaces();
            cd.interfaces = new HashSet();
            for (int i = 0; i < implInterfaces.length; i++) {
                cd.interfaces.add(implInterfaces[i].getFullyQualifiedName());
            }
        }
    } else if (interfaceList.length() == 0) {
        // empty interface list prevents creation of interface element
        cd.interfaces = null;
    } else {
        // split list and create set for interface elements
        StringTokenizer tokener = new StringTokenizer(interfaceList, ",");
        cd.interfaces = new HashSet();
        while (tokener.hasMoreTokens()) {
            String iface = tokener.nextToken().trim();
            if (iface.length() > 0) {
                cd.interfaces.add(iface);
            }
        }
    }
    cd.jcrType = tag.getNamedParameter(JCR_TYPE);
    cd.jcrSuperTypes = tag.getNamedParameter(JCR_SUPER_TYPES);
    cd.jcrMixinTypes = tag.getNamedParameter(JCR_MIXIN_TYPES);
    // only reset default if explicitly stated
    if (tag.getNamedParameter(DISCRIMINATOR) != null) {
        cd.discriminator = Boolean.valueOf(tag.getNamedParameter(DISCRIMINATOR)).booleanValue();
    }
    return cd;
}
Also used : StringTokenizer(java.util.StringTokenizer) JavaClass(com.thoughtworks.qdox.model.JavaClass) DocletTag(com.thoughtworks.qdox.model.DocletTag) HashSet(java.util.HashSet)

Example 10 with DocletTag

use of com.thoughtworks.qdox.model.DocletTag in project sling by apache.

the class FieldDescriptor method fromMethod.

static FieldDescriptor fromMethod(Log log, JavaMethod method) {
    DocletTag tag = method.getTagByName(TAG_FIELD_DESCRIPTOR);
    if (tag == null) {
        return null;
    }
    // field name is the method name, unless overwritten with the fieldName
    // tag
    String fieldName = tag.getNamedParameter(FIELD_NAME);
    if (fieldName == null) {
        fieldName = getFieldFromMethod(method);
    }
    return new FieldDescriptor(log, tag, fieldName);
}
Also used : DocletTag(com.thoughtworks.qdox.model.DocletTag)

Aggregations

DocletTag (com.thoughtworks.qdox.model.DocletTag)11 JavaClass (com.thoughtworks.qdox.model.JavaClass)5 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)5 JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)3 AbstractInheritableJavaEntity (com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)2 AbstractJavaEntity (com.thoughtworks.qdox.model.AbstractJavaEntity)2 StringReader (java.io.StringReader)2 JavaSource (com.thoughtworks.qdox.model.JavaSource)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 Resource (org.apache.maven.model.Resource)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1