From 046e7ae47b227e72626c842b0e9222859ec5ed5f Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Wed, 21 Sep 2022 20:08:08 +0200 Subject: [PATCH] WELD-2732 Support setter method for @Resource annotated methods Signed-off-by: Arjan Tijms --- .../spi/helpers/AbstractResourceServices.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/weld-spi/src/main/java/org/jboss/weld/injection/spi/helpers/AbstractResourceServices.java b/weld-spi/src/main/java/org/jboss/weld/injection/spi/helpers/AbstractResourceServices.java index 79da3a79..c34e9be4 100644 --- a/weld-spi/src/main/java/org/jboss/weld/injection/spi/helpers/AbstractResourceServices.java +++ b/weld-spi/src/main/java/org/jboss/weld/injection/spi/helpers/AbstractResourceServices.java @@ -35,9 +35,6 @@ public abstract class AbstractResourceServices implements Service, ResourceInjectionServices { private static final String RESOURCE_LOOKUP_PREFIX = "java:comp/env"; - // because checkstyle magic numbers - private static final int GET_PREFIX_LENGTH = "get".length(); - public Object resolveResource(InjectionPoint injectionPoint) { if (getResourceAnnotation(injectionPoint) == null) { throw new IllegalArgumentException("No @Resource annotation found on injection point " + injectionPoint); @@ -114,8 +111,11 @@ protected String getResourceName(InjectionPoint injectionPoint) { public static String getPropertyName(Method method) { String methodName = method.getName(); - if (methodName.matches("^(get).*") && method.getParameterTypes().length == 0) { - return Introspector.decapitalize(methodName.substring(GET_PREFIX_LENGTH)); + + if (methodName.matches("^(set).*") && method.getParameterTypes().length == 1) { + return Introspector.decapitalize(methodName.substring(3)); + } else if (methodName.matches("^(get).*") && method.getParameterTypes().length == 0) { + return Introspector.decapitalize(methodName.substring(3)); } else if (methodName.matches("^(is).*") && method.getParameterTypes().length == 0) { return Introspector.decapitalize(methodName.substring(2)); } else {