下面列出了怎么用com.sun.javadoc.ProgramElementDoc的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean isExcluded(Doc doc) {
if (Utils.isHiddenMember(doc.name())) {
return true;
}
if (doc.tags(EXCLUDE_FROM_JAVADOC_TAG).length > 0) {
return true;
}
if (doc instanceof ProgramElementDoc) {
final ProgramElementDoc element = (ProgramElementDoc) doc;
if (element.containingPackage().tags(EXCLUDE_FROM_JAVADOC_TAG).length > 0) {
return true;
}
if (Utils.findFirst(element.annotations(), it ->
Utils.qualifiedNameEquals(
Utils.getKeywords().getSyntheticMemberAnnotationName(),
it.annotationType().qualifiedName())) != null) {
return true;
}
}
// nothing above found a reason to exclude
return false;
}
public static boolean start(final RootDoc root) {
for (final ClassDoc cls : root.classes()) {
final List<ProgramElementDoc> elements = new LinkedList<>();
elements.add(cls);
elements.addAll(Arrays.asList(cls.constructors()));
elements.addAll(Arrays.asList(cls.methods()));
for (final ProgramElementDoc elem : elements) {
for (final Tag tag : elem.inlineTags()) {
final String name = tag.name();
if (name.equals("@code") && tag.text().trim().startsWith(">")) {
generateRunner(cls, elem, tag);
}
}
}
}
return true;
}
private static boolean exclude( Doc doc )
{
AnnotationDesc[] annotations = null;
if ( doc instanceof ProgramElementDoc )
{
annotations = ( (ProgramElementDoc) doc ).annotations();
}
else if ( doc instanceof PackageDoc )
{
annotations = ( (PackageDoc) doc ).annotations();
}
if ( annotations != null )
{
for ( AnnotationDesc annotation : annotations )
{
String qualifiedTypeName = annotation.annotationType().qualifiedTypeName();
if ( qualifiedTypeName.equals( JavadocExclude.class.getCanonicalName() ) )
{
return true;
}
}
}
// nothing above found a reason to exclude
return false;
}
private static boolean exclude(Doc doc) {
if (doc.tags(TAG_HIDE).length > 0) {
return true;
}
if (doc instanceof ProgramElementDoc) {
if (((ProgramElementDoc) doc).containingPackage().tags(TAG_HIDE).length > 0) {
return true;
}
}
return false;
}
@Override
public boolean isTranslatableToTag(Doc doc) {
if (doc instanceof ProgramElementDoc) {
final ProgramElementDoc element = (ProgramElementDoc) doc;
if (Utils.findFirst(element.annotations(), it ->
Utils.qualifiedNameEquals(
Utils.getKeywords().getSyntheticMemberAnnotationName(),
it.annotationType().qualifiedName())) != null) {
return true;
}
}
return false;
}
/** Find the first element into the given array.
*
* @param <T> the type of the elements to filter.
* @param original the original array.
* @param ignoreHidden indicates if the hidden elements should be ignored.
* @param filter the filtering action.
* @return the first element.
*/
public static <T extends ProgramElementDoc> T findFirst(T[] original, boolean ignoreHidden, Predicate<T> filter) {
for (final T element : original) {
if (!ignoreHidden || !isHiddenMember(element.name())) {
if (filter.test(element)) {
return element;
}
}
}
return null;
}
/** Replies the SARL element type of the given type.
*
* @param type the type.
* @return the SARL element type, or {@code null} if unknown.
*/
public static Integer getSarlClassification(ProgramElementDoc type) {
final AnnotationDesc annotation = Utils.findFirst(type.annotations(), it ->
qualifiedNameEquals(it.annotationType().qualifiedTypeName(), getKeywords().getSarlElementTypeAnnotationName()));
if (annotation != null) {
final ElementValuePair[] pairs = annotation.elementValues();
if (pairs != null && pairs.length > 0) {
return ((Number) pairs[0].value().value()).intValue();
}
}
return null;
}
/**
* Returns string representation of scope
*
* @param doc
* @return
*/
protected String parseScope(ProgramElementDoc doc) {
if (doc.isPrivate()) {
return "private";
} else if (doc.isProtected()) {
return "protected";
} else if (doc.isPublic()) {
return "public";
}
return "";
}