下面列出了怎么用com.sun.javadoc.AnnotationDesc.ElementValuePair的API类实例代码及写法,或者点击链接到github查看源代码。
/** 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;
}
/** Replies the default value of the given parameter.
*
* @param member the member
* @param param the parameter.
* @param configuration the configuration.
* @return the default value or {@code null}.
*/
@SuppressWarnings("checkstyle:nestedifdepth")
public static String getParameterDefaultValue(ExecutableMemberDoc member, Parameter param, SarlConfiguration configuration) {
final AnnotationDesc annotation = Utils.findFirst(param.annotations(), it ->
qualifiedNameEquals(it.annotationType().qualifiedTypeName(), getKeywords().getDefaultValueAnnnotationName()));
if (annotation != null) {
final ElementValuePair[] pairs = annotation.elementValues();
if (pairs != null && pairs.length > 0) {
final String fieldId = pairs[0].value().value().toString();
final int index = fieldId.indexOf('#');
ClassDoc fieldContainer;
final String fieldName;
if (index > 0) {
final String referenceName = fieldId.substring(0, index);
if (qualifiedNameEquals(referenceName, member.containingClass().qualifiedName())) {
fieldContainer = member.containingClass();
} else {
fieldContainer = findFirst(configuration.classDocCatalog.allClasses(getPackageName(referenceName)),
false, it -> false);
if (fieldContainer == null) {
fieldContainer = member.containingClass();
}
}
fieldName = createNameForHiddenDefaultValueAttribute(fieldId.substring(index + 1));
} else {
fieldContainer = member.containingClass();
fieldName = createNameForHiddenDefaultValueAttribute(fieldId);
}
final FieldDoc field = Utils.findFirst(fieldContainer.fields(),
false, it -> simpleNameEquals(it.name(), fieldName));
if (field != null) {
final AnnotationDesc valueAnnotation = Utils.findFirst(field.annotations(), it ->
qualifiedNameEquals(it.annotationType().qualifiedTypeName(), getKeywords().getSarlSourceCodeAnnotationName()));
if (valueAnnotation != null) {
return valueAnnotation.elementValues()[0].value().value().toString();
}
}
}
}
return null;
}