com.sun.javadoc.AnnotationDesc.ElementValuePair Java Examples

The following examples show how to use com.sun.javadoc.AnnotationDesc.ElementValuePair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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;
}
 
Example #2
Source File: Utils.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** 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;
}