[Checkers] AnnotatedTypeMirror as a key in a map

Artemus Harper subanark at gmail.com
Sun Sep 21 23:57:08 EDT 2008


Currently having AnnotatedTypeMirror as the key in a map doesn't work very
well (although doing so is probably not the best idea, except for caching).
Since:

1. The equals methods uses the string representation of the map of
annotations, which does not work for AnnotationBuilder's different string
representation (and might be situations where the annotations look the same,
but are different).

2. hashCode may give different hashCodes for equal annotation. In particular
the hashCode for the set of the annotations is being used rather than the
string representation. Since neither AnnotationBuilder or javac's
representaiton of AnnotationMirror overrides either equals or hashCode this
will probably give different hashCodes if there are any annotations at all.

I know that implementating a better version of equals and hashCode is a lot
of work for the little gain it gives, but fixing item #2 is trivial. In
paticular:
    @Override
    public int hashCode() {
        return this.annotations.hashCode() * 17
            + this.actualType.toString().hashCode() * 13;
    }
to
    @Override
    public int hashCode() {
        return this.annotations.toString().hashCode() * 17
            + this.actualType.toString().hashCode() * 13;
    }

-- 
Artemus Harper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/mailman/private/checkers/attachments/20080921/79492fe1/attachment.htm 


More information about the checkers mailing list