/** * Constructs a new AnnotationReference, with a reference to the given {@link Annotation}. * * @param type the data type of this AnnotationReference * @param reference the reference to set * @throws IllegalArgumentException if the given annotation has a type that is not compatible with this reference */ public AnnotationReference(AnnotationReferenceDataType type, Annotation reference) { this.dataType = type; setReference(reference); }
@Override public void assign(Object o) { if (o != null && (!(o instanceof Annotation))) { throw new IllegalArgumentException("Cannot assign object of type " + o.getClass().getName() + " to an AnnotationReference, must be of type " + Annotation.class.getName()); } setReference((Annotation) o); }
private boolean removeObsoleteReferencesFromFieldValue(FieldValue value, Map<Annotation, Annotation> selectedAnnotations, boolean removeIfPresent) { if (value == null) { return false; } if (value.getDataType() instanceof AnnotationReferenceDataType) { AnnotationReference ref = (AnnotationReference) value; if (removeIfPresent) { if (selectedAnnotations.containsValue(ref.getReference())) { //this reference refers to a dead annotation ref.setReference(null); return true; } } else { if (!selectedAnnotations.containsValue(ref.getReference())) { //this reference refers to a dead annotation ref.setReference(null); return true; } } } else if (value.getDataType() instanceof StructuredDataType) { removeObsoleteReferencesFromStructuredType((StructuredFieldValue) value, selectedAnnotations, removeIfPresent); } else if (value.getDataType() instanceof CollectionDataType) { removeObsoleteReferencesFromCollectionType((CollectionFieldValue) value, selectedAnnotations, removeIfPresent); } else if (value.getDataType() instanceof MapDataType) { removeObsoleteReferencesFromMapType((MapFieldValue) value, selectedAnnotations, removeIfPresent); } return false; }
private void setCorrectAnnotationReference(FieldValue value, IdentityHashMap<Annotation, Integer> originalAnnotations, List<Annotation> newAnnotations) { if (value == null) { return; } if (value.getDataType() instanceof AnnotationReferenceDataType) { AnnotationReference ref = (AnnotationReference) value; if (ref.getReference() == null) { return; } Integer referenceIndex = originalAnnotations.get(ref.getReference()); if (referenceIndex == null) { throw new IllegalStateException("Cannot find Annotation pointed to by " + ref); } try { Annotation newReference = newAnnotations.get(referenceIndex); ref.setReference(newReference); } catch (IndexOutOfBoundsException ioobe) { throw new IllegalStateException("Cannot find Annotation pointed to by " + ref, ioobe); } } else if (value.getDataType() instanceof StructuredDataType) { setCorrectAnnotationReference((StructuredFieldValue) value, originalAnnotations, newAnnotations); } else if (value.getDataType() instanceof CollectionDataType) { setCorrectAnnotationReference((CollectionFieldValue) value, originalAnnotations, newAnnotations); } else if (value.getDataType() instanceof MapDataType) { setCorrectAnnotationReference((MapFieldValue) value, originalAnnotations, newAnnotations); } }
if (removedAnnotations.get(ref.getReference()) != null) { ref.setReference(null); a.setFieldValue(null); if (!a.isSpanNodeValid()) {