freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [2/5] incubator-freemarker git commit: FREEMARKER-55: narrow local var scope and reduce conditional blocks.
Date Tue, 19 Sep 2017 06:03:55 GMT
FREEMARKER-55: narrow local var scope and reduce conditional blocks.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/8837a923
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/8837a923
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/8837a923

Branch: refs/heads/3
Commit: 8837a923029528474d14edff467a5f1d3bc99904
Parents: 4779234
Author: Woonsan Ko <woonsan@apache.org>
Authored: Mon Sep 18 10:03:12 2017 -0400
Committer: Woonsan Ko <woonsan@apache.org>
Committed: Mon Sep 18 10:03:12 2017 -0400

----------------------------------------------------------------------
 .../freemarker/spring/model/UrlFunction.java    | 54 +++++++++-----------
 1 file changed, 25 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8837a923/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/UrlFunction.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/UrlFunction.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/UrlFunction.java
index 7f180ec..a2c8f72 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/UrlFunction.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/UrlFunction.java
@@ -114,43 +114,39 @@ class UrlFunction extends AbstractSpringTemplateFunctionModel {
         if (!paramsHashModel.isEmptyHash()) {
             params = new ArrayList<>();
 
-            TemplateHashModelEx2.KeyValuePair pair;
-            TemplateModel paramNameModel;
-            TemplateModel paramValueModel;
-            String paramName;
-            String paramValue;
-
             for (KeyValuePairIterator pairIt = paramsHashModel.keyValuePairIterator(); pairIt.hasNext();)
{
-                pair = pairIt.next();
-                paramNameModel = pair.getKey();
-                paramValueModel = pair.getValue();
+                TemplateHashModelEx2.KeyValuePair pair = pairIt.next();
+                TemplateModel paramNameModel = pair.getKey();
+                TemplateModel paramValueModel = pair.getValue();
 
-                if (paramNameModel instanceof TemplateStringModel) {
-                    paramName = ((TemplateStringModel) paramNameModel).getAsString();
+                if (!(paramNameModel instanceof TemplateStringModel)) {
+                    throw CallableUtils.newArgumentValueException(PARAMS_PARAM_IDX,
+                            "Parameter name must be a string.", this);
+                }
 
-                    if (paramName.isEmpty()) {
-                        throw CallableUtils.newArgumentValueException(PARAMS_PARAM_IDX,
-                                "Parameter name must be a non-blank string.", this);
-                    }
+                String paramName = ((TemplateStringModel) paramNameModel).getAsString();
 
-                    if (paramValueModel instanceof TemplateStringModel) {
-                        paramValue = ((TemplateStringModel) paramValueModel).getAsString();
-                    } else if (paramValueModel instanceof TemplateNumberModel) {
-                        paramValue = ((TemplateNumberModel) paramValueModel).getAsNumber().toString();
-                    } else if (paramValueModel instanceof TemplateBooleanModel) {
-                        paramValue = Boolean.toString(((TemplateBooleanModel) paramValueModel).getAsBoolean());
-                    } else {
-                        throw CallableUtils.newArgumentValueException(PARAMS_PARAM_IDX,
-                                "Format the parameter manually to properly coerce it to a
URL parameter value string. "
-                                        + "e.g, date?string.iso, date?long, list?join('_'),
etc.",
-                                this);
-                    }
+                if (paramName.isEmpty()) {
+                    throw CallableUtils.newArgumentValueException(PARAMS_PARAM_IDX,
+                            "Parameter name must be a non-blank string.", this);
+                }
+
+                String paramValue;
 
-                    params.add(new _KeyValuePair<String, String>(paramName, paramValue));
+                if (paramValueModel instanceof TemplateStringModel) {
+                    paramValue = ((TemplateStringModel) paramValueModel).getAsString();
+                } else if (paramValueModel instanceof TemplateNumberModel) {
+                    paramValue = ((TemplateNumberModel) paramValueModel).getAsNumber().toString();
+                } else if (paramValueModel instanceof TemplateBooleanModel) {
+                    paramValue = Boolean.toString(((TemplateBooleanModel) paramValueModel).getAsBoolean());
                 } else {
                     throw CallableUtils.newArgumentValueException(PARAMS_PARAM_IDX,
-                            "Parameter name must be a string.", this);
+                            "Format the parameter manually to properly coerce it to a URL
parameter value string. "
+                                    + "e.g, date?string.iso, date?long, list?join('_'), etc.",
+                            this);
                 }
+
+                params.add(new _KeyValuePair<String, String>(paramName, paramValue));
             }
         }
 


Mime
View raw message