Implement equals, hashCode, & toString in BeanMethod and *Metadata types

Prior to this commit, ConfigurationClass implemented equals(),
hashCode(), and toString(), but BeanMethod did not.

This commit introduces equals(), hashCode(), and toString()
implementations in BeanMethod for consistency with ConfigurationClass
to make it possible to use BeanMethod instances to index additional
metadata as well.

In order to properly implement equals() in BeanMethod, the method
argument types are required, but these are not directly available in
BeanMethod. However, they are available via ASM when processing @Bean
methods. This commit therefore implements equals(), hashCode(), and
toString() in SimpleMethodMetadata which BeanMethod delegates to.

For completeness, this commit also implements equals(), hashCode(), and
toString() in StandardClassMetadata, StandardMethodMetadata, and
SimpleAnnotationMetadata.

Closes gh-27076
This commit is contained in:
Sam Brannen
2021-06-23 14:27:51 +02:00
parent 882004fc9b
commit 2bc7a3aa0a
11 changed files with 452 additions and 12 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.context.annotation;
import org.springframework.beans.factory.parsing.Problem;
import org.springframework.beans.factory.parsing.ProblemReporter;
import org.springframework.core.type.MethodMetadata;
import org.springframework.lang.Nullable;
/**
* Represents a {@link Configuration @Configuration} class method annotated with
@@ -26,6 +27,7 @@ import org.springframework.core.type.MethodMetadata;
*
* @author Chris Beams
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.0
* @see ConfigurationClass
* @see ConfigurationClassParser
@@ -52,6 +54,21 @@ final class BeanMethod extends ConfigurationMethod {
}
}
@Override
public boolean equals(@Nullable Object obj) {
return ((this == obj) || ((obj instanceof BeanMethod) &&
this.metadata.equals(((BeanMethod) obj).metadata)));
}
@Override
public int hashCode() {
return this.metadata.hashCode();
}
@Override
public String toString() {
return "BeanMethod: " + this.metadata;
}
private class NonOverridableMethodError extends Problem {