struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [2/2] struts git commit: Drops code duplication
Date Mon, 13 Feb 2017 11:01:09 GMT
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 <lukaszlenart@apache.org>
Authored: Mon Feb 13 12:00:59 2017 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
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;
 
 /**
  * <code>AnnotationValidationConfigurationBuilder</code>
@@ -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;
-    }
-
 }


Mime
View raw message