freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject [10/13] incubator-freemarker git commit: FREEMARKER-55: cleanups - expose ARGS_LAYOUT only as possible
Date Thu, 04 Jan 2018 19:49:33 GMT
FREEMARKER-55: cleanups - expose ARGS_LAYOUT only as possible


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

Branch: refs/heads/3
Commit: 2ffeeae325f7959534ceaf4b783e43dd445b899c
Parents: 207d94e
Author: Woonsan Ko <woonsan@apache.org>
Authored: Thu Jan 4 14:20:52 2018 -0500
Committer: Woonsan Ko <woonsan@apache.org>
Committed: Thu Jan 4 14:20:52 2018 -0500

----------------------------------------------------------------------
 .../freemarker/core/util/StringToIndexMap.java    | 18 ++++++++++++++++++
 ...ataBoundFormElementTemplateDirectiveModel.java | 18 ++++++++++++++++--
 ...AbstractHtmlElementTemplateDirectiveModel.java | 11 ++++++-----
 ...actHtmlInputElementTemplateDirectiveModel.java | 10 ++++++----
 .../model/form/FormTemplateDirectiveModel.java    | 10 ++++++----
 .../model/form/InputTemplateDirectiveModel.java   | 10 ++++++----
 6 files changed, 58 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2ffeeae3/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
index 830a41f..6f997eb 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
@@ -37,6 +37,10 @@ public final class StringToIndexMap {
 
     private static final int MAX_VARIATIONS_TRIED = 4;
 
+    /** Input Entries from caller. */
+    private final Entry[] inputEntries;
+
+    /** Internal entry buckets. */
     private final Entry[] buckets;
     private final int bucketIndexMask;
     private final int bucketIndexOverlap;
@@ -131,6 +135,7 @@ public final class StringToIndexMap {
 
     // This is a very frequent case, so we optimize for it a bit.
     private StringToIndexMap(Entry entry) {
+        inputEntries = new Entry[] { entry };
         buckets = new Entry[] { entry };
         bucketIndexMask = 0;
         bucketIndexOverlap = 0;
@@ -143,11 +148,15 @@ public final class StringToIndexMap {
 
     private StringToIndexMap(Entry[] entries, int entriesLength) {
         if (entriesLength == 0) {
+            inputEntries = null;
             buckets = null;
             bucketIndexMask = 0;
             bucketIndexOverlap = 0;
             keys = Collections.emptyList();
         } else {
+            inputEntries = new Entry[entriesLength];
+            System.arraycopy(entries, 0, inputEntries, 0, entriesLength);
+
             String[] keyArray = new String[entriesLength];
             for (int i = 0; i < entriesLength; i++) {
                 keyArray[i] = entries[i].key;
@@ -273,6 +282,15 @@ public final class StringToIndexMap {
 
     }
 
+    /**
+     * Return a cloned array from the original {@link Entry} array which was given by the
caller through directly
+     * using {@link #of(Entry...)} or {@link #of(Entry[], int)} or indirectly using other
methods such as {@link #of(String, int)}.
+     * @return a cloned array from the original {@link Entry} array which was given by the
caller
+     */
+    public Entry[] getInputEntries() {
+        return inputEntries;
+    }
+
     private static int getPowerOf2GreaterThanOrEqualTo(int n) {
         if (n == 0) {
             return 0;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2ffeeae3/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java
index 3cb36d6..11b47c3 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java
@@ -53,11 +53,25 @@ abstract class AbstractDataBoundFormElementTemplateDirectiveModel extends
Abstra
 
     private static final String ID_PARAM_NAME = ID_ATTR_NAME;
 
-    protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES = {
+    private static final StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES = {
             new StringToIndexMap.Entry(ID_PARAM_NAME, ID_PARAM_IDX)
     };
 
-    private static final ArgumentArrayLayout ARGS_LAYOUT =
+    /**
+     * Returns the argument index of the last predefined named argument item in the {@code
argsLayout}.
+     * <P>
+     * <EM>Note:</EM> It is strongly assumed that the predefined named arguments
map contains only items with indexes,
+     * starting from the predefined positional argument count and incrementing by one sequentially.
+     * </P>
+     * @param argsLayout arguments layout
+     * @return the argument index of the last predefined named argument item in the {@code
argsLayout}
+     */
+    protected static int getLastPredefinedNamedArgumentIndex(ArgumentArrayLayout argsLayout)
{
+        return argsLayout.getPredefinedPositionalArgumentCount() + argsLayout.getPredefinedNamedArgumentsMap().size()
+                - 1;
+    }
+
+    protected static final ArgumentArrayLayout ARGS_LAYOUT =
             ArgumentArrayLayout.create(
                     1,
                     false,

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2ffeeae3/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java
index 0e64e8c..8e30dd2 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java
@@ -49,8 +49,8 @@ import org.springframework.web.servlet.support.RequestContext;
 abstract class AbstractHtmlElementTemplateDirectiveModel
         extends AbstractDataBoundFormElementTemplateDirectiveModel {
 
-    private static final int NAMED_ARGS_OFFSET = AbstractDataBoundFormElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length
-            + 1;
+    private static final int NAMED_ARGS_OFFSET =
+            getLastPredefinedNamedArgumentIndex(AbstractDataBoundFormElementTemplateDirectiveModel.ARGS_LAYOUT)
+ 1;
 
     private static final int CSS_CLASS_PARAM_IDX = NAMED_ARGS_OFFSET;
     private static final String CSS_CLASS_PARAM_NAME = "cssClass";
@@ -105,9 +105,10 @@ abstract class AbstractHtmlElementTemplateDirectiveModel
     private static final int CSSERRORCLASS_PARAM_IDX = NAMED_ARGS_OFFSET + 16;
     private static final String CSSERRORCLASS_PARAM_NAME = "cssErrorClass";
 
-    protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
+    private static final StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
             _ArrayUtils.addAll(
-                    AbstractDataBoundFormElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES,
+                    AbstractDataBoundFormElementTemplateDirectiveModel.ARGS_LAYOUT.getPredefinedNamedArgumentsMap()
+                            .getInputEntries(),
                     new StringToIndexMap.Entry(CSS_CLASS_PARAM_NAME, CSS_CLASS_PARAM_IDX),
                     new StringToIndexMap.Entry(CSS_STYLE_PARAM_NAME, CSS_STYLE_PARAM_IDX),
                     new StringToIndexMap.Entry(LANG_PARAM_NAME, LANG_PARAM_IDX),
@@ -127,7 +128,7 @@ abstract class AbstractHtmlElementTemplateDirectiveModel
                     new StringToIndexMap.Entry(CSSERRORCLASS_PARAM_NAME, CSSERRORCLASS_PARAM_IDX)
                     );
 
-    private static final ArgumentArrayLayout ARGS_LAYOUT =
+    protected static final ArgumentArrayLayout ARGS_LAYOUT =
             ArgumentArrayLayout.create(
                     1,
                     false,

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2ffeeae3/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java
index a840f56..fd48eae 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java
@@ -38,7 +38,8 @@ import org.springframework.web.servlet.support.RequestContext;
 
 abstract class AbstractHtmlInputElementTemplateDirectiveModel extends AbstractHtmlElementTemplateDirectiveModel
{
 
-    private static final int NAMED_ARGS_OFFSET = AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length
+ 1;
+    private static final int NAMED_ARGS_OFFSET =
+            getLastPredefinedNamedArgumentIndex(AbstractHtmlElementTemplateDirectiveModel.ARGS_LAYOUT)
+ 1;
 
     private static final int ONFOCUS_PARAM_IDX = NAMED_ARGS_OFFSET;
     private static final String ONFOCUS_PARAM_NAME = "onfocus";
@@ -58,9 +59,10 @@ abstract class AbstractHtmlInputElementTemplateDirectiveModel extends AbstractHt
     private static final int READONLY_PARAM_IDX = NAMED_ARGS_OFFSET + 5;
     private static final String READONLY_PARAM_NAME = "readonly";
 
-    protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
+    private static final StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
             _ArrayUtils.addAll(
-                    AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES,
+                    AbstractHtmlElementTemplateDirectiveModel.ARGS_LAYOUT.getPredefinedNamedArgumentsMap()
+                            .getInputEntries(),
                     new StringToIndexMap.Entry(ONFOCUS_PARAM_NAME, ONFOCUS_PARAM_IDX),
                     new StringToIndexMap.Entry(ONBLUR_PARAM_NAME, ONBLUR_PARAM_IDX),
                     new StringToIndexMap.Entry(ONCHANGE_PARAM_NAME, ONCHANGE_PARAM_IDX),
@@ -69,7 +71,7 @@ abstract class AbstractHtmlInputElementTemplateDirectiveModel extends AbstractHt
                     new StringToIndexMap.Entry(READONLY_PARAM_NAME, READONLY_PARAM_IDX)
                     );
 
-    private static final ArgumentArrayLayout ARGS_LAYOUT =
+    protected static final ArgumentArrayLayout ARGS_LAYOUT =
             ArgumentArrayLayout.create(
                     1,
                     false,

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2ffeeae3/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java
index a11c7cd..a453a76 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java
@@ -76,7 +76,8 @@ class FormTemplateDirectiveModel extends AbstractHtmlElementTemplateDirectiveMod
 
     public static final String NAME = "form";
 
-    private static final int NAMED_ARGS_OFFSET = AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length
+ 1;
+    private static final int NAMED_ARGS_OFFSET =
+            getLastPredefinedNamedArgumentIndex(AbstractHtmlElementTemplateDirectiveModel.ARGS_LAYOUT)
+ 1;
 
     private static final int ACTION_PARAM_IDX = NAMED_ARGS_OFFSET;
     private static final String ACTION_PARAM_NAME = "action";
@@ -117,9 +118,10 @@ class FormTemplateDirectiveModel extends AbstractHtmlElementTemplateDirectiveMod
     private static final int METHOD_PARAM_PARAM_IDX = NAMED_ARGS_OFFSET + 12;
     private static final String METHOD_PARAM_PARAM_NAME = "methodParam";
 
-    protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
+    private static final StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
             _ArrayUtils.addAll(
-                    AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES,
+                    AbstractHtmlElementTemplateDirectiveModel.ARGS_LAYOUT.getPredefinedNamedArgumentsMap()
+                            .getInputEntries(),
                     new StringToIndexMap.Entry(ACTION_PARAM_NAME, ACTION_PARAM_IDX),
                     new StringToIndexMap.Entry(METHOD_PARAM_NAME, METHOD_PARAM_IDX),
                     new StringToIndexMap.Entry(TARGET_PARAM_NAME, TARGET_PARAM_IDX),
@@ -135,7 +137,7 @@ class FormTemplateDirectiveModel extends AbstractHtmlElementTemplateDirectiveMod
                     new StringToIndexMap.Entry(METHOD_PARAM_PARAM_NAME, METHOD_PARAM_PARAM_IDX)
                     );
 
-    private static final ArgumentArrayLayout ARGS_LAYOUT =
+    protected static final ArgumentArrayLayout ARGS_LAYOUT =
             ArgumentArrayLayout.create(
                     1,
                     false,

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2ffeeae3/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java
index 6d0f49c..a38e3c3 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java
@@ -70,7 +70,8 @@ class InputTemplateDirectiveModel extends AbstractHtmlInputElementTemplateDirect
 
     public static final String NAME = "input";
 
-    private static final int NAMED_ARGS_OFFSET = AbstractHtmlInputElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length
+ 1;
+    private static final int NAMED_ARGS_OFFSET =
+            getLastPredefinedNamedArgumentIndex(AbstractHtmlInputElementTemplateDirectiveModel.ARGS_LAYOUT)
+ 1;
 
     private static final int SIZE_PARAM_IDX = NAMED_ARGS_OFFSET;
     private static final String SIZE_PARAM_NAME = "size";
@@ -87,9 +88,10 @@ class InputTemplateDirectiveModel extends AbstractHtmlInputElementTemplateDirect
     private static final int AUTOCOMPLETE_PARAM_IDX = NAMED_ARGS_OFFSET + 4;
     private static final String AUTOCOMPLETE_PARAM_NAME = "autocomplete";
 
-    protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
+    private static final StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES =
             _ArrayUtils.addAll(
-                    AbstractHtmlInputElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES,
+                    AbstractHtmlInputElementTemplateDirectiveModel.ARGS_LAYOUT.getPredefinedNamedArgumentsMap()
+                            .getInputEntries(),
                     new StringToIndexMap.Entry(SIZE_PARAM_NAME, SIZE_PARAM_IDX),
                     new StringToIndexMap.Entry(MAXLENGTH_PARAM_NAME, MAXLENGTH_PARAM_IDX),
                     new StringToIndexMap.Entry(ALT_PARAM_NAME, ALT_PARAM_IDX),
@@ -97,7 +99,7 @@ class InputTemplateDirectiveModel extends AbstractHtmlInputElementTemplateDirect
                     new StringToIndexMap.Entry(AUTOCOMPLETE_PARAM_NAME, AUTOCOMPLETE_PARAM_IDX)
                     );
 
-    private static final ArgumentArrayLayout ARGS_LAYOUT =
+    protected static final ArgumentArrayLayout ARGS_LAYOUT =
             ArgumentArrayLayout.create(
                     1,
                     false,


Mime
View raw message