Skip to content

Commit 34e9db9

Browse files
marko-bekhtagsmet
authored andcommitted
HV-1623 Make parameters more specific in programmatic API executable mapping contexts
1 parent cace416 commit 34e9db9

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

engine/src/main/java/org/hibernate/validator/internal/cfg/context/ConstructorConstraintMappingContextImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package org.hibernate.validator.internal.cfg.context;
88

99
import org.hibernate.validator.cfg.context.ConstructorConstraintMappingContext;
10-
import org.hibernate.validator.internal.properties.Callable;
10+
import org.hibernate.validator.internal.properties.javabean.JavaBeanConstructor;
1111

1212
/**
1313
* Constraint mapping creational context representing a constructor.
@@ -16,7 +16,7 @@
1616
*/
1717
class ConstructorConstraintMappingContextImpl extends ExecutableConstraintMappingContextImpl implements ConstructorConstraintMappingContext {
1818

19-
<T> ConstructorConstraintMappingContextImpl(TypeConstraintMappingContextImpl<T> typeContext, Callable constructor) {
19+
<T> ConstructorConstraintMappingContextImpl(TypeConstraintMappingContextImpl<T> typeContext, JavaBeanConstructor constructor) {
2020
super( typeContext, constructor );
2121
}
2222

engine/src/main/java/org/hibernate/validator/internal/cfg/context/MethodConstraintMappingContextImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package org.hibernate.validator.internal.cfg.context;
88

99
import org.hibernate.validator.cfg.context.MethodConstraintMappingContext;
10-
import org.hibernate.validator.internal.properties.Callable;
10+
import org.hibernate.validator.internal.properties.javabean.JavaBeanMethod;
1111

1212
/**
1313
* Constraint mapping creational context representing a method.
@@ -16,7 +16,7 @@
1616
*/
1717
class MethodConstraintMappingContextImpl extends ExecutableConstraintMappingContextImpl implements MethodConstraintMappingContext {
1818

19-
MethodConstraintMappingContextImpl(TypeConstraintMappingContextImpl<?> typeContext, Callable callable) {
19+
MethodConstraintMappingContextImpl(TypeConstraintMappingContextImpl<?> typeContext, JavaBeanMethod callable) {
2020
super( typeContext, callable );
2121
}
2222

engine/src/main/java/org/hibernate/validator/internal/cfg/context/TypeConstraintMappingContextImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.hibernate.validator.internal.properties.javabean.JavaBeanExecutable;
4040
import org.hibernate.validator.internal.properties.javabean.JavaBeanField;
4141
import org.hibernate.validator.internal.properties.javabean.JavaBeanGetter;
42+
import org.hibernate.validator.internal.properties.javabean.JavaBeanMethod;
4243
import org.hibernate.validator.internal.util.Contracts;
4344
import org.hibernate.validator.internal.util.ExecutableHelper;
4445
import org.hibernate.validator.internal.util.ReflectionHelper;
@@ -150,17 +151,17 @@ public MethodConstraintMappingContext method(String name, Class<?>... parameterT
150151
throw LOG.getBeanDoesNotContainMethodException( beanClass, name, parameterTypes );
151152
}
152153

153-
JavaBeanExecutable<?> javaBeanExecutable = JavaBeanExecutable.of( method );
154+
JavaBeanMethod javaBeanMethod = JavaBeanExecutable.of( method );
154155

155-
if ( configuredMembers.contains( javaBeanExecutable ) ) {
156+
if ( configuredMembers.contains( javaBeanMethod ) ) {
156157
throw LOG.getMethodHasAlreadyBeenConfiguredViaProgrammaticApiException(
157158
beanClass,
158159
ExecutableHelper.getExecutableAsString( name, parameterTypes )
159160
);
160161
}
161162

162-
MethodConstraintMappingContextImpl context = new MethodConstraintMappingContextImpl( this, javaBeanExecutable );
163-
configuredMembers.add( javaBeanExecutable );
163+
MethodConstraintMappingContextImpl context = new MethodConstraintMappingContextImpl( this, javaBeanMethod );
164+
configuredMembers.add( javaBeanMethod );
164165
executableContexts.add( context );
165166

166167
return context;

engine/src/main/java/org/hibernate/validator/internal/properties/javabean/JavaBeanExecutable.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ public static JavaBeanExecutable<?> of(Executable executable) {
6969
return new JavaBeanConstructor( (Constructor<?>) executable );
7070
}
7171

72-
if ( ReflectionHelper.isGetterMethod( executable ) ) {
73-
return new JavaBeanGetter( (Method) executable );
72+
return of( ( (Method) executable ) );
73+
}
74+
75+
public static JavaBeanMethod of(Method method) {
76+
if ( ReflectionHelper.isGetterMethod( method ) ) {
77+
return new JavaBeanGetter( method );
7478
}
7579

76-
return new JavaBeanMethod( (Method) executable );
80+
return new JavaBeanMethod( method );
7781
}
7882

7983
@Override

0 commit comments

Comments
 (0)