diff --git a/build.gradle b/build.gradle index 7cbdbe38..c2effd25 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group 'com.docutools' -version = '1.4.2' +version = '1.4.3' sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 diff --git a/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java b/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java index 3c98ff70..d7f391ec 100644 --- a/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java +++ b/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java @@ -195,7 +195,10 @@ private Optional matchPattern(String placeholderName, Locale lo if (method.getParameterCount() == 1) { return evaluateSingleParameterFunction(placeholderName, method); } else if (method.getParameterCount() == 2) { - return evaluateTwoParameterFunction(placeholderName, locale, method); + var additionalParamType = method.getParameterTypes()[1]; + if(additionalParamType.isAssignableFrom(Locale.class)) + return evaluateTwoParameterFunction(placeholderName, locale, Locale.class, method); + return evaluateTwoParameterFunction(placeholderName, options, GenerationOptions.class, method); } else { logger.error("@MatchPlaceholder-annotated method {} must take exactly one parameter (String) or two (String, Locale). It takes {}.", method, method.getParameterCount()); @@ -237,7 +240,7 @@ private Optional evaluateSingleParameterFunction(String placeholderName, } } - private Optional evaluateTwoParameterFunction(String placeholderName, Locale locale, Method method) + private Optional evaluateTwoParameterFunction(String placeholderName, T additionalOption, Class additionalOptionClass, Method method) throws IllegalAccessException, InvocationTargetException { var parameterTypes = method.getParameterTypes(); if (!parameterTypes[0].equals(String.class)) { @@ -245,12 +248,12 @@ private Optional evaluateTwoParameterFunction(String placeholderName, Lo parameterTypes[0]); return Optional.empty(); } - if (!parameterTypes[1].equals(Locale.class)) { - logger.warn("@MatchPlaceholder-annotated method {} can only take a java.util.Locale as second parameter, but takes {}.", method, - parameterTypes[1]); + if (!parameterTypes[1].equals(additionalOptionClass)) { + logger.warn("@MatchPlaceholder-annotated method {} can only take a {} as second parameter, but takes {}.", method, + additionalOptionClass, parameterTypes[1]); return Optional.empty(); } - var returnValue = method.invoke(bean, placeholderName, locale); + var returnValue = method.invoke(bean, placeholderName, additionalOption); if (returnValue instanceof Optional optionalReturnValue) { return optionalReturnValue.map(Object::toString); } else {