Polishing.
Add additional tests, add Javadoc to explain isEnclosingClassParameter() behavior. See #3038 Original pull request: #3039
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ class ParameterUnitTests<P extends PersistentProperty<P>> {
|
||||
static class StaticType {
|
||||
|
||||
class NonStaticInner {
|
||||
NonStaticInner(StaticType outer) {}
|
||||
NonStaticInner() {}
|
||||
}
|
||||
|
||||
static class StaticInner {
|
||||
|
||||
@@ -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) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user