@@ -388,7 +388,8 @@ public TypeAndQualifiers(Type type, Set<AnnotationInstance> qualifiers) {
388
388
public int hashCode () {
389
389
final int prime = 31 ;
390
390
int result = 1 ;
391
- result = prime * result + ((qualifiers == null ) ? 0 : qualifiers .hashCode ());
391
+ // We cannot use AnnotationInstance#hashCode() as it includes the AnnotationTarget
392
+ result = prime * result + annotationSetHashCode (qualifiers );
392
393
result = prime * result + ((type == null ) ? 0 : type .hashCode ());
393
394
return result ;
394
395
}
@@ -409,8 +410,8 @@ public boolean equals(Object obj) {
409
410
if (other .qualifiers != null ) {
410
411
return false ;
411
412
}
412
- } else if (!qualifiersAreEqual (qualifiers , other .qualifiers )) {
413
- // We cannot use AnnotationInstance#equals() as it requires the exact same annotationTarget instance
413
+ } else if (!annotationSetEquals (qualifiers , other .qualifiers )) {
414
+ // We cannot use AnnotationInstance#equals() as it requires the exact same AnnotationTarget instance
414
415
return false ;
415
416
}
416
417
if (type == null ) {
@@ -423,30 +424,44 @@ public boolean equals(Object obj) {
423
424
return true ;
424
425
}
425
426
426
- private boolean qualifiersAreEqual (Set <AnnotationInstance > q1 , Set <AnnotationInstance > q2 ) {
427
- if (q1 == q2 ) {
427
+ private static boolean annotationSetEquals (Set <AnnotationInstance > s1 , Set <AnnotationInstance > s2 ) {
428
+ if (s1 == s2 ) {
428
429
return true ;
429
430
}
430
- if (q1 .size () != q2 .size ()) {
431
+ if (s1 .size () != s2 .size ()) {
431
432
return false ;
432
433
}
433
- for (AnnotationInstance a1 : q1 ) {
434
- for (AnnotationInstance a2 : q2 ) {
435
- if (!annotationsAreEqual (a1 , a2 )) {
434
+ for (AnnotationInstance a1 : s1 ) {
435
+ for (AnnotationInstance a2 : s2 ) {
436
+ if (!annotationEquals (a1 , a2 )) {
436
437
return false ;
437
438
}
438
439
}
439
440
}
440
441
return true ;
441
442
}
442
443
443
- private boolean annotationsAreEqual (AnnotationInstance a1 , AnnotationInstance a2 ) {
444
+ private static boolean annotationEquals (AnnotationInstance a1 , AnnotationInstance a2 ) {
444
445
if (a1 == a2 ) {
445
446
return true ;
446
447
}
447
448
return a1 .name ().equals (a2 .name ()) && a1 .values ().equals (a2 .values ());
448
449
}
449
450
451
+ private static int annotationSetHashCode (Set <AnnotationInstance > s ) {
452
+ int result = 1 ;
453
+ for (AnnotationInstance a : s ) {
454
+ result = 31 * result + annotationHashCode (a );
455
+ }
456
+ return result ;
457
+ }
458
+
459
+ private static int annotationHashCode (AnnotationInstance a ) {
460
+ int result = a .name ().hashCode ();
461
+ result = 31 * result + a .values ().hashCode ();
462
+ return result ;
463
+ }
464
+
450
465
}
451
466
452
467
}
0 commit comments