public boolean isValueCompatible(Annotation structValue) { if (structValue.getType().inherits(this)) { //the value is of this type; or the supertype of the value is of this type, etc.... return true; } return false; }
@Override void annotate(Annotation annotation) { annotationType2Annotation.put(annotation.getType(), annotation); }
/** * Set an {@link Annotation} that this AnnotationReference shall refer to. * * @param reference an Annotation that this AnnotationReference shall refer to. * @throws IllegalArgumentException if the given annotation has a type that is not compatible with this reference */ public void setReference(Annotation reference) { if (reference == null) { this.reference = null; return; } AnnotationReferenceDataType type = getDataType(); if (type.getAnnotationType().isValueCompatible(reference) // The case if concrete annotation type || reference.getType() instanceof AnnotationType) { this.reference = reference; } else { throw new IllegalArgumentException("Cannot set reference, must be of type " + type + " (was of type " + reference.getType() + ")"); } }
/** * Sets the value of the annotation. * * @param fieldValue the value to set * @throws UnsupportedOperationException if the annotation type does not allow this annotation to have values. */ public void setFieldValue(FieldValue fieldValue) { if (fieldValue == null) { value = null; return; } DataType type = getType().getDataType(); if (type != null && type.isValueCompatible(fieldValue)) { this.value = fieldValue; } else { String typeName = (type == null) ? "null" : type.getValueClass().getName(); throw new IllegalArgumentException("Argument is of wrong type, must be of type " + typeName + ", was " + fieldValue.getClass().getName()); } }
continue; if (anno.getType() != AnnotationTypes.TERM) { continue;