Skip to content

Commit

Permalink
WELD-2732 Support setter method for @resource annotated methods
Browse files Browse the repository at this point in the history
Signed-off-by: Arjan Tijms <[email protected]>
  • Loading branch information
arjantijms authored and manovotn committed Sep 27, 2022
1 parent 5ba2636 commit 046e7ae
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 046e7ae

Please sign in to comment.