Class AnnotationMirrorSet

java.lang.Object
org.checkerframework.javacutil.AnnotationMirrorSet
All Implemented Interfaces:
Iterable<AnnotationMirror>, Collection<AnnotationMirror>, Set<@KeyFor("this") AnnotationMirror>, org.plumelib.util.DeepCopyable<AnnotationMirrorSet>

public class AnnotationMirrorSet extends Object implements Set<@KeyFor("this") AnnotationMirror>, org.plumelib.util.DeepCopyable<AnnotationMirrorSet>
The Set interface defines many methods with respect to the equals method. This implementation of Set violates those specifications, but fulfills the same property using AnnotationUtils.areSame(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror) rather than equals.

For example, the specification for the contains(Object o) method says: "returns true if and only if this collection contains at least one element e such that (o == null ? e == null : o.equals(e))." The specification for contains(java.lang.Object) is "returns true if and only if this collection contains at least one element e such that (o == null ? e == null : AnnotationUtils.areSame(o, e))".

AnnotationMirror is an interface and not all implementing classes provide a correct equals method; therefore, the existing implementations of Set cannot be used.

Implementation note: the backing store is an ArrayList with linear scan using AnnotationUtils.areSame(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror) rather than a TreeSet with AnnotationUtils.compareAnnotationMirrors(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror). In practice these sets are very small (typically 1-3 elements, almost always fewer than 5) so a linear scan beats a sorted structure whose comparator invocation and per-node allocation exceed the benefit of O(log n) lookup.

Unmodifiability is tracked by a boolean flag.

No longer implements NavigableSet; there is no point in asking for the "first" element in these sets - ask for the qualifier in a specific hierarchy.