Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7C79C200C1A for ; Mon, 13 Feb 2017 12:01:10 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7B0D9160B60; Mon, 13 Feb 2017 11:01:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C6073160B4D for ; Mon, 13 Feb 2017 12:01:09 +0100 (CET) Received: (qmail 36936 invoked by uid 500); 13 Feb 2017 11:01:09 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 36911 invoked by uid 99); 13 Feb 2017 11:01:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Feb 2017 11:01:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A814FDFCC6; Mon, 13 Feb 2017 11:01:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lukaszlenart@apache.org To: commits@struts.apache.org Date: Mon, 13 Feb 2017 11:01:09 -0000 Message-Id: <0ee8a66c5be343adbfcb007e8cdcda62@git.apache.org> In-Reply-To: <75b9c56b29964c998fbc671d66247e7a@git.apache.org> References: <75b9c56b29964c998fbc671d66247e7a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] struts git commit: Drops code duplication archived-at: Mon, 13 Feb 2017 11:01:10 -0000 Drops code duplication Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/f22873e1 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/f22873e1 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/f22873e1 Branch: refs/heads/master Commit: f22873e127ca8c4de8b636415eb8097db77d79c6 Parents: 3dafd2a Author: Lukasz Lenart Authored: Mon Feb 13 12:00:59 2017 +0100 Committer: Lukasz Lenart Committed: Mon Feb 13 12:00:59 2017 +0100 ---------------------------------------------------------------------- ...nnotationValidationConfigurationBuilder.java | 32 ++------------------ 1 file changed, 2 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/f22873e1/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java b/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java index dc8d856..b587bf3 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java @@ -15,6 +15,7 @@ */ package com.opensymphony.xwork2.validator; +import com.opensymphony.xwork2.util.AnnotationUtils; import com.opensymphony.xwork2.validator.annotations.*; import org.apache.commons.lang3.StringUtils; @@ -24,8 +25,6 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * AnnotationValidationConfigurationBuilder @@ -36,9 +35,6 @@ import java.util.regex.Pattern; */ public class AnnotationValidationConfigurationBuilder { - private static final Pattern SETTER_PATTERN = Pattern.compile("set([A-Z][A-Za-z0-9]*)$"); - private static final Pattern GETTER_PATTERN = Pattern.compile("(get|is|has)([A-Z][A-Za-z0-9]*)$"); - private ValidatorFactory validatorFactory; public AnnotationValidationConfigurationBuilder(ValidatorFactory fac) { @@ -61,7 +57,7 @@ public class AnnotationValidationConfigurationBuilder { if (o instanceof Method) { Method method = (Method) o; - fieldName = resolvePropertyName(method); + fieldName = AnnotationUtils.resolvePropertyName(method); methodName = method.getName(); annotations = method.getAnnotations(); @@ -874,28 +870,4 @@ public class AnnotationValidationConfigurationBuilder { } - /** - * Returns the property name for a method. - * This method is independant from property fields. - * - * @param method The method to get the property name for. - * @return the property name for given method; null if non could be resolved. - */ - public String resolvePropertyName(Method method) { - - Matcher matcher = SETTER_PATTERN.matcher(method.getName()); - if (matcher.matches() && method.getParameterTypes().length == 1) { - String raw = matcher.group(1); - return raw.substring(0, 1).toLowerCase() + raw.substring(1); - } - - matcher = GETTER_PATTERN.matcher(method.getName()); - if (matcher.matches() && method.getParameterTypes().length == 0) { - String raw = matcher.group(2); - return raw.substring(0, 1).toLowerCase() + raw.substring(1); - } - - return null; - } - }