Skip to content

Commit 5a33544

Browse files
marko-bekhtagsmet
authored andcommitted
HV-1363 Remove ConstrainableFormatter and push the logic to toString implementations
1 parent e3a883a commit 5a33544

File tree

4 files changed

+26
-53
lines changed

4 files changed

+26
-53
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public int hashCode() {
176176
return result;
177177
}
178178

179+
@Override
180+
public String toString() {
181+
return ExecutableHelper.getExecutableAsString(
182+
getDeclaringClass().getSimpleName() + "#" + name,
183+
getParameterTypes()
184+
);
185+
}
186+
179187
private boolean hasReturnValue(Executable executable) {
180188
if ( executable instanceof Constructor ) {
181189
return true;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public int hashCode() {
9595
return result;
9696
}
9797

98+
@Override
99+
public String toString() {
100+
return getName();
101+
}
102+
98103
/**
99104
* Returns an accessible version of the given member. Will be the given member itself in case it is accessible,
100105
* otherwise a copy which is set accessible.

engine/src/main/java/org/hibernate/validator/internal/util/logging/Log.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.hibernate.validator.internal.util.logging.formatter.ClassObjectFormatter;
5555
import org.hibernate.validator.internal.util.logging.formatter.CollectionOfClassesObjectFormatter;
5656
import org.hibernate.validator.internal.util.logging.formatter.CollectionOfObjectsToStringFormatter;
57-
import org.hibernate.validator.internal.util.logging.formatter.ConstrainableFormatter;
5857
import org.hibernate.validator.internal.util.logging.formatter.DurationFormatter;
5958
import org.hibernate.validator.internal.util.logging.formatter.ExecutableFormatter;
6059
import org.hibernate.validator.internal.util.logging.formatter.ObjectArrayFormatter;
@@ -252,13 +251,13 @@ GroupDefinitionException getUnableToExpandDefaultGroupListException(@FormatWith(
252251
GroupDefinitionException getWrongDefaultGroupSequenceProviderTypeException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass);
253252

254253
@Message(id = 56, value = "Method or constructor %1$s doesn't have a parameter with index %2$d.")
255-
IllegalArgumentException getInvalidExecutableParameterIndexException(@FormatWith(ConstrainableFormatter.class) Callable callable, int index);
254+
IllegalArgumentException getInvalidExecutableParameterIndexException(Callable callable, int index);
256255

257256
@Message(id = 59, value = "Unable to retrieve annotation parameter value.")
258257
ValidationException getUnableToRetrieveAnnotationParameterValueException(@Cause Exception e);
259258

260259
@Message(id = 62, value = "Method or constructor %1$s has %2$s parameters, but the passed list of parameter meta data has a size of %3$s.")
261-
IllegalArgumentException getInvalidLengthOfParameterMetaDataListException(@FormatWith(ConstrainableFormatter.class) Callable callable, int nbParameters, int listSize);
260+
IllegalArgumentException getInvalidLengthOfParameterMetaDataListException(Callable callable, int nbParameters, int listSize);
262261

263262
@Message(id = 63, value = "Unable to instantiate %s.")
264263
ValidationException getUnableToInstantiateException(@FormatWith(ClassObjectFormatter.class) Class<?> clazz, @Cause Exception e);
@@ -464,11 +463,11 @@ ConstraintDeclarationException getMultipleGroupConversionsForSameSourceException
464463

465464
@Message(id = 131,
466465
value = "A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: %s, %s.")
467-
ConstraintDeclarationException getMethodReturnValueMustNotBeMarkedMoreThanOnceForCascadedValidationException(@FormatWith(ConstrainableFormatter.class) Callable executable1, @FormatWith(ConstrainableFormatter.class) Callable executable2);
466+
ConstraintDeclarationException getMethodReturnValueMustNotBeMarkedMoreThanOnceForCascadedValidationException(Callable executable1, Callable executable2);
468467

469468
@Message(id = 132,
470469
value = "Void methods must not be constrained or marked for cascaded validation, but method %s is.")
471-
ConstraintDeclarationException getVoidMethodsMustNotBeConstrainedException(@FormatWith(ConstrainableFormatter.class) Callable callable);
470+
ConstraintDeclarationException getVoidMethodsMustNotBeConstrainedException(Callable callable);
472471

473472
@Message(id = 133, value = "%1$s does not contain a constructor with the parameter types %2$s.")
474473
ValidationException getBeanDoesNotContainConstructorException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass,
@@ -503,7 +502,7 @@ ConstraintDeclarationException getImplicitConstraintTargetInAmbiguousConfigurati
503502
@Message(id = 142,
504503
value = "Cross parameter constraint %1$s is illegally placed on a parameterless method or constructor '%2$s'.")
505504
ConstraintDeclarationException getCrossParameterConstraintOnMethodWithoutParametersException(
506-
@FormatWith(ClassObjectFormatter.class) Class<? extends Annotation> constraint, @FormatWith(ConstrainableFormatter.class) Constrainable executable);
505+
@FormatWith(ClassObjectFormatter.class) Class<? extends Annotation> constraint, Constrainable executable);
507506

508507
@Message(id = 143,
509508
value = "Cross parameter constraint %1$s is illegally placed on class level.")
@@ -512,7 +511,7 @@ ConstraintDeclarationException getCrossParameterConstraintOnMethodWithoutParamet
512511
@Message(id = 144,
513512
value = "Cross parameter constraint %1$s is illegally placed on field '%2$s'.")
514513
ConstraintDeclarationException getCrossParameterConstraintOnFieldException(@FormatWith(ClassObjectFormatter.class) Class<? extends Annotation> constraint,
515-
@FormatWith(ConstrainableFormatter.class) Constrainable field);
514+
Constrainable field);
516515

517516
@Message(id = 146,
518517
value = "No parameter nodes may be added since path %s doesn't refer to a cross-parameter constraint.")
@@ -538,11 +537,11 @@ UnexpectedTypeException getMultipleValidatorsForSameTypeException(@FormatWith(Cl
538537

539538
@Message(id = 151,
540539
value = "A method overriding another method must not redefine the parameter constraint configuration, but method %2$s redefines the configuration of %1$s.")
541-
ConstraintDeclarationException getParameterConfigurationAlteredInSubTypeException(@FormatWith(ConstrainableFormatter.class) Callable superMethod, @FormatWith(ConstrainableFormatter.class) Callable subMethod);
540+
ConstraintDeclarationException getParameterConfigurationAlteredInSubTypeException(Callable superMethod, Callable subMethod);
542541

543542
@Message(id = 152,
544543
value = "Two methods defined in parallel types must not declare parameter constraints, if they are overridden by the same method, but methods %s and %s both define parameter constraints.")
545-
ConstraintDeclarationException getParameterConstraintsDefinedInMethodsFromParallelTypesException(@FormatWith(ConstrainableFormatter.class) Callable method1, @FormatWith(ConstrainableFormatter.class) Callable method2);
544+
ConstraintDeclarationException getParameterConstraintsDefinedInMethodsFromParallelTypesException(Callable method1, Callable method2);
546545

547546
@Message(id = 153,
548547
value = "The constraint %1$s used ConstraintTarget#%2$s but is not specified on a method or constructor.")
@@ -584,7 +583,7 @@ ConstraintDefinitionException getValidatorForCrossParameterConstraintMustEitherV
584583

585584
@Message(id = 161,
586585
value = "Two methods defined in parallel types must not define group conversions for a cascaded method return value, if they are overridden by the same method, but methods %s and %s both define parameter constraints.")
587-
ConstraintDeclarationException getMethodsFromParallelTypesMustNotDefineGroupConversionsForCascadedReturnValueException(@FormatWith(ConstrainableFormatter.class) Callable method1, @FormatWith(ConstrainableFormatter.class) Callable method2);
586+
ConstraintDeclarationException getMethodsFromParallelTypesMustNotDefineGroupConversionsForCascadedReturnValueException(Callable method1, Callable method2);
588587

589588
@Message(id = 162,
590589
value = "The validated type %1$s does not specify the constructor/method: %2$s")
@@ -632,19 +631,19 @@ ConstraintDefinitionException getValidatorForCrossParameterConstraintMustEitherV
632631

633632
@Message(id = 174,
634633
value = "Parameter %3$s of method or constructor %2$s of type %1$s is configured more than once via the programmatic constraint declaration API.")
635-
ValidationException getParameterHasAlreadyBeConfiguredViaProgrammaticApiException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass, @FormatWith(ConstrainableFormatter.class) Callable callable, int parameterIndex);
634+
ValidationException getParameterHasAlreadyBeConfiguredViaProgrammaticApiException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass, Callable callable, int parameterIndex);
636635

637636
@Message(id = 175,
638637
value = "The return value of method or constructor %2$s of type %1$s is configured more than once via the programmatic constraint declaration API.")
639-
ValidationException getReturnValueHasAlreadyBeConfiguredViaProgrammaticApiException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass, @FormatWith(ConstrainableFormatter.class) Callable callable);
638+
ValidationException getReturnValueHasAlreadyBeConfiguredViaProgrammaticApiException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass, Callable callable);
640639

641640
@Message(id = 176,
642641
value = "Constructor %2$s of type %1$s is configured more than once via the programmatic constraint declaration API.")
643642
ValidationException getConstructorHasAlreadyBeConfiguredViaProgrammaticApiException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass, String constructor);
644643

645644
@Message(id = 177,
646645
value = "Cross-parameter constraints for the method or constructor %2$s of type %1$s are declared more than once via the programmatic constraint declaration API.")
647-
ValidationException getCrossParameterElementHasAlreadyBeConfiguredViaProgrammaticApiException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass, @FormatWith(ConstrainableFormatter.class) Callable callable);
646+
ValidationException getCrossParameterElementHasAlreadyBeConfiguredViaProgrammaticApiException(@FormatWith(ClassObjectFormatter.class) Class<?> beanClass, Callable callable);
648647

649648
@Message(id = 178, value = "Multiplier cannot be negative: %d.")
650649
IllegalArgumentException getMultiplierCannotBeNegativeException(int multiplier);
@@ -717,7 +716,7 @@ ConstraintDeclarationException getInconsistentValueUnwrappingConfigurationBetwee
717716
ValueExtractorDefinitionException getValueExtractorDeclaresExtractedValueMultipleTimesException(@FormatWith(ClassObjectFormatter.class) Class<?> extractorType);
718717

719718
@Message(id = 205, value = "Invalid unwrapping configuration for constraint %2$s on %1$s. You can only define one of 'Unwrapping.Skip' or 'Unwrapping.Unwrap'.")
720-
ConstraintDeclarationException getInvalidUnwrappingConfigurationForConstraintException(@FormatWith(ConstrainableFormatter.class) Constrainable constrainable, @FormatWith(ClassObjectFormatter.class) Class<? extends Annotation> constraint);
719+
ConstraintDeclarationException getInvalidUnwrappingConfigurationForConstraintException(Constrainable constrainable, @FormatWith(ClassObjectFormatter.class) Class<? extends Annotation> constraint);
721720

722721
@Message(id = 206, value = "Unable to instantiate value extractor class %s.")
723722
ValidationException getUnableToInstantiateValueExtractorClassException(String valueExtractorClassName, @Cause ValidationException e);

engine/src/main/java/org/hibernate/validator/internal/util/logging/formatter/ConstrainableFormatter.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)