Polishing.

Add additional tests, add Javadoc to explain isEnclosingClassParameter() behavior.

See #3038
Original pull request: #3039
This commit is contained in:
Mark Paluch
2024-02-08 10:24:18 +01:00
parent 45b810a83c
commit f6eacd208a
3 changed files with 17 additions and 7 deletions

View File

@@ -156,10 +156,8 @@ public class Parameter<T, P extends PersistentProperty<P>> {
return false;
}
return Objects.equals(this.name, that.name)
&& Objects.equals(this.type, that.type)
&& Objects.equals(this.key, that.key)
&& Objects.equals(this.entity, that.entity);
return Objects.equals(this.name, that.name) && Objects.equals(this.type, that.type)
&& Objects.equals(this.key, that.key) && Objects.equals(this.entity, that.entity);
}
@Override
@@ -183,6 +181,15 @@ public class Parameter<T, P extends PersistentProperty<P>> {
return property.equals(referencedProperty);
}
/**
* Returns whether this parameter is a candidate for the enclosing class by checking the parameter type against
* {@link Class#getEnclosingClass()} and whether the defining class is an inner non-static one.
* <p>
* Note that for a proper check the parameter position must be compared to ensure that only the first parameter (at
* index {@code 0}/zero) qualifies as enclosing class instance parameter.
*
* @return {@literal true} if this parameter is a candidate for the enclosing class instance.
*/
boolean isEnclosingClassParameter() {
return enclosingClassCache.get();
}

View File

@@ -162,7 +162,7 @@ class ParameterUnitTests<P extends PersistentProperty<P>> {
static class StaticType {
class NonStaticInner {
NonStaticInner(StaticType outer) {}
NonStaticInner() {}
}
static class StaticInner {

View File

@@ -22,6 +22,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Iterator;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
@@ -99,8 +100,9 @@ class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
assertThat(constructor).isNotNull();
Parameter<?, P> parameter = constructor.getParameters().iterator().next();
assertThat(constructor.isParentParameter(parameter)).isTrue();
List<Parameter<Object, P>> parameters = constructor.getParameters();
assertThat(constructor.isParentParameter(parameters.get(0))).isTrue();
assertThat(constructor.isParentParameter(parameters.get(1))).isFalse();
}
@Test // DATACMNS-1082, DATACMNS-1126
@@ -231,6 +233,7 @@ class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
class Inner {
public Inner(Outer outer) {}
}
}