Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.4] improve AnnotationInstance.hashCode() #332

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/main/java/org/jboss/jandex/AnnotationInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ void setTarget(AnnotationTarget target) {
/**
* Returns whether or not this annotation instance is equivalent to another instance.
* An annotation instance is equivalent if its name and values are equal, and it shares
* the exact same <code>AnnotationTarget</code> instance. The latter restriction
* may be softened in future versions.
* the exact same <code>AnnotationTarget</code> instance.
*
* @param o the annotation instance to compare to.
* @return true if equal, false if not
Expand Down Expand Up @@ -353,6 +352,36 @@ public int hashCode() {
int result = name.hashCode();
result = 31 * result + Arrays.hashCode(values);

if (target != null) {
switch (target.kind()) {
case CLASS:
result = 31 * result + target.asClass().name().hashCode();
break;
case METHOD:
result = 31 * result + target.asMethod().declaringClass().name().hashCode();
result = 31 * result + target.asMethod().name().hashCode();
break;
case FIELD:
result = 31 * result + target.asField().declaringClass().name().hashCode();
result = 31 * result + target.asField().name().hashCode();
break;
case METHOD_PARAMETER:
result = 31 * result + target.asMethodParameter().method().declaringClass().name().hashCode();
result = 31 * result + target.asMethodParameter().method().name().hashCode();
result = 31 * result + target.asMethodParameter().position();
break;
case RECORD_COMPONENT:
result = 31 * result + target.asRecordComponent().declaringClass().name().hashCode();
result = 31 * result + target.asRecordComponent().name().hashCode();
break;
case TYPE:
if (target.asType().target() != null) {
result = 31 * result + target.asType().target().name().hashCode();
}
break;
}
}

return result;
}
}