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