Align OverrideMetadata arguments and harmonize bean name

Rather than having to override the getBeanName method when there is one,
this commit moves it as a @Nullable argument. This makes sure that
equals and hashCode consistently use the bean name. getBeanName cannot
be final just yet as the test infrastructure overrides it.

Also, arguments are now ordered consistently, which improves code
readability and type signature.
This commit is contained in:
Stéphane Nicoll
2024-06-07 15:31:25 +02:00
parent 8b66eca932
commit 0165529d97
9 changed files with 78 additions and 93 deletions

View File

@@ -56,7 +56,7 @@ class OverrideMetadataTests {
ConcreteOverrideMetadata(Field field, ResolvableType typeToOverride,
BeanOverrideStrategy strategy) {
super(field, typeToOverride, strategy);
super(field, typeToOverride, null, strategy);
}
@Override

View File

@@ -37,9 +37,6 @@ class TestOverrideMetadata extends OverrideMetadata {
@Nullable
private final Method method;
@Nullable
private final String beanName;
private final String methodName;
@Nullable
@@ -79,25 +76,24 @@ class TestOverrideMetadata extends OverrideMetadata {
}
public TestOverrideMetadata(Field field, ExampleBeanOverrideAnnotation overrideAnnotation, ResolvableType typeToOverride) {
super(field, typeToOverride, overrideAnnotation.createIfMissing() ?
super(field, typeToOverride, overrideAnnotation.beanName(), overrideAnnotation.createIfMissing() ?
BeanOverrideStrategy.REPLACE_OR_CREATE_DEFINITION: BeanOverrideStrategy.REPLACE_DEFINITION);
this.method = findMethod(field, overrideAnnotation.value());
this.methodName = overrideAnnotation.value();
this.beanName = overrideAnnotation.beanName();
}
//Used to trigger duplicate detection in parser test
TestOverrideMetadata(String duplicateTrigger) {
super(null, null, null);
super(null, null, duplicateTrigger, null);
this.method = null;
this.methodName = duplicateTrigger;
this.beanName = duplicateTrigger;
}
@Override
protected String getBeanName() {
if (StringUtils.hasText(this.beanName)) {
return this.beanName;
public String getBeanName() {
String name = super.getBeanName();
if (StringUtils.hasText(name)) {
return name;
}
return getField().getName();
}
@@ -124,8 +120,8 @@ class TestOverrideMetadata extends OverrideMetadata {
public boolean equals(Object obj) {
if (this.method == null) {
return obj instanceof TestOverrideMetadata tem &&
tem.beanName != null &&
tem.beanName.startsWith(ExampleBeanOverrideAnnotation.DUPLICATE_TRIGGER);
tem.getBeanName() != null &&
tem.getBeanName().startsWith(ExampleBeanOverrideAnnotation.DUPLICATE_TRIGGER);
}
return super.equals(obj);
}
@@ -141,7 +137,7 @@ class TestOverrideMetadata extends OverrideMetadata {
@Override
public String toString() {
if (this.method == null) {
return "{" + this.beanName + "}";
return "{" + this.getBeanName() + "}";
}
return this.methodName;
}