@Override public FieldValue createFieldValue() { return new AnnotationReference(this); }
@Override public String toString() { return "AnnotationReference " + getDataType() + " referring to " + reference; }
/** * 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); }
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); } }
public void read(FieldBase field, AnnotationReference value) { int seqId = buf.getInt1_2_4Bytes(); try { Annotation a = annotations.get(seqId); value.setReferenceNoCompatibilityCheck(a); } catch (IndexOutOfBoundsException iiobe) { throw new SerializationException("Could not serialize AnnotationReference value, reference not found.", iiobe); } }
public void write(FieldBase field, AnnotationReference value) { int annotationId = value.getReference().getScratchId(); if (annotationId >= 0) { buf.putInt1_2_4Bytes(annotationId); } else { throw new SerializationException("Could not serialize AnnotationReference value, reference not found (" + value + ")"); } }
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; }
public void read(FieldBase field, AnnotationReference value) { int seqId = buf.getInt1_2_4Bytes(); try { Annotation a = annotations.get(seqId); value.setReferenceNoCompatibilityCheck(a); } catch (IndexOutOfBoundsException iiobe) { throw new SerializationException("Could not serialize AnnotationReference value, reference not found.", iiobe); } }
public void write(FieldBase field, AnnotationReference value) { int annotationId = value.getReference().getScratchId(); if (annotationId >= 0) { buf.putInt1_2_4Bytes(annotationId); } else { throw new SerializationException("Could not serialize AnnotationReference value, reference not found (" + value + ")"); } }
if (removedAnnotations.get(ref.getReference()) != null) { ref.setReference(null); a.setFieldValue(null); if (!a.isSpanNodeValid()) {
@Override public boolean isValueCompatible(FieldValue value) { if (!(value instanceof AnnotationReference)) { return false; } AnnotationReference reference = (AnnotationReference) value; if (equals(reference.getDataType())) { return true; } return false; }
@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); }
/** * 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() + ")"); } }