commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r929433 - in /commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser: ASTArrayLiteral.java ASTFloatLiteral.java ASTIntegerLiteral.java ASTStringLiteral.java SimpleNode.java StringParser.java
Date Wed, 31 Mar 2010 08:43:38 GMT
Author: henrib
Date: Wed Mar 31 08:43:37 2010
New Revision: 929433

URL: http://svn.apache.org/viewvc?rev=929433&view=rev
Log:
Javadoc updated ( manual Checkstyle );
Added check on ASTArrayLiteral to enforce literal is array;
StringParser constants explained

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/SimpleNode.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java?rev=929433&r1=929432&r2=929433&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
Wed Mar 31 08:43:37 2010
@@ -18,30 +18,37 @@ package org.apache.commons.jexl2.parser;
 
 public final class ASTArrayLiteral extends JexlNode implements JexlNode.Literal<Object>
{
     /** The type literal value. */
-    Object literal = null;
+    Object array = null;
 
-    public ASTArrayLiteral(int id) {
+    ASTArrayLiteral(int id) {
         super(id);
     }
 
-    public ASTArrayLiteral(Parser p, int id) {
+    ASTArrayLiteral(Parser p, int id) {
         super(p, id);
     }
 
+    /**
+     *  Gets the literal value.
+     * @return the array literal
+     */
     public Object getLiteral() {
-        return literal;
+        return array;
     }
 
+    /**
+     * Sets the literal value.
+     * @param literal the literal array value
+     * @throws IllegalArgumentException if literal is not an array or null
+     */
     public void setLiteral(Object literal) {
-        this.literal = literal;
+        if (literal != null && !literal.getClass().isArray()) {
+            throw new IllegalArgumentException(literal.getClass() + " is not an array");
+        }
+        this.array = literal;
     }
 
-    /**
-     * Accept the visitor.
-     * @param visitor the visitor
-     * @param data contextual data
-     * @return result of visit
-     **/
+    /** {@inheritDoc} */
     @Override
     public Object jjtAccept(ParserVisitor visitor, Object data) {
         return visitor.visit(this, data);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java?rev=929433&r1=929432&r2=929433&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
Wed Mar 31 08:43:37 2010
@@ -27,17 +27,16 @@ public final class ASTFloatLiteral exten
     public ASTFloatLiteral(Parser p, int id) {
         super(p, id);
     }
-
+    
+    /**
+     * Gets the literal value.
+     * @return the float literal
+     */
     public Float getLiteral() {
         return literal;
     }
     
-    /**
-     * Accept the visitor.
-     * @param visitor the visitor
-     * @param data contextual data
-     * @return result of visit
-     **/
+    /** {@inheritDoc} */
     @Override
     public Object jjtAccept(ParserVisitor visitor, Object data) {
         return visitor.visit(this, data);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java?rev=929433&r1=929432&r2=929433&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
Wed Mar 31 08:43:37 2010
@@ -20,24 +20,23 @@ public final class ASTIntegerLiteral ext
     /** The type literal value. */
     Integer literal = null;
 
-    public ASTIntegerLiteral(int id) {
+    ASTIntegerLiteral(int id) {
         super(id);
     }
 
-    public ASTIntegerLiteral(Parser p, int id) {
+    ASTIntegerLiteral(Parser p, int id) {
         super(p, id);
     }
-
+    
+    /**
+     * Gets the literal value.
+     * @return the integer literal
+     */
     public Integer getLiteral() {
         return literal;
     }
 
-    /**
-     * Accept the visitor.
-     * @param visitor the visitor
-     * @param data contextual data
-     * @return result of visit
-     **/
+    /** {@inheritDoc} */
     @Override
     public Object jjtAccept(ParserVisitor visitor, Object data) {
         return visitor.visit(this, data);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java?rev=929433&r1=929432&r2=929433&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
Wed Mar 31 08:43:37 2010
@@ -17,7 +17,7 @@
 package org.apache.commons.jexl2.parser;
 
 public final class ASTStringLiteral extends JexlNode implements JexlNode.Literal<String>
{
-    
+
     public ASTStringLiteral(int id) {
         super(id);
     }
@@ -26,16 +26,15 @@ public final class ASTStringLiteral exte
         super(p, id);
     }
 
+    /**
+     * Gets the literal value.
+     * @return the string literal
+     */
     public String getLiteral() {
         return image;
     }
 
-    /**
-     * Accept the visitor.
-     * @param visitor the visitor
-     * @param data contextual data
-     * @return result of visit
-     **/
+    /** {@inheritDoc} */
     @Override
     public Object jjtAccept(ParserVisitor visitor, Object data) {
         return visitor.visit(this, data);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/SimpleNode.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/SimpleNode.java?rev=929433&r1=929432&r2=929433&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/SimpleNode.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/SimpleNode.java
Wed Mar 31 08:43:37 2010
@@ -14,12 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.commons.jexl2.parser;
 
 /**
- * A class originally generated by JJTree:
- * /* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=
*\/
+ * A class originally generated by JJTree with the following JavaCCOptions:
+ * MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=
+ *
  * Worksaround issue https://javacc.dev.java.net/issues/show_bug.cgi?id=227
  * As soon as this issue if fixed and the maven plugin uses the correct version of Javacc,
this
  * class can go away.
@@ -32,100 +32,154 @@ package org.apache.commons.jexl2.parser;
  * so it can serve as a last evaluation cache even in multi-threaded executions.
  */
 public class SimpleNode implements Node {
-  protected JexlNode parent;
-  protected JexlNode[] children;
-  protected int id;
-  /** volatile value so it can be used as a last evaluation cache. */
-  protected volatile Object value;
-
-  public SimpleNode(int i) {
-    id = i;
-  }
-
-  public SimpleNode(Parser p, int i) {
-    this(i);
-  }
-
-  public void jjtOpen() {
-  }
-
-  public void jjtClose() {
-  }
-
-  public void jjtSetParent(Node n) {
-      parent = (JexlNode) n;
-  }
-  
-  public JexlNode jjtGetParent() {
-      return parent;
-  }
-
-  public void jjtAddChild(Node n, int i) {
-    if (children == null) {
-      children = new JexlNode[i + 1];
-    } else if (i >= children.length) {
-      JexlNode c[] = new JexlNode[i + 1];
-      System.arraycopy(children, 0, c, 0, children.length);
-      children = c;
-    }
-    children[i] = (JexlNode) n;
-  }
-
-  public JexlNode jjtGetChild(int i) {
-    return children[i];
-  }
-
-  public int jjtGetNumChildren() {
-    return (children == null) ? 0 : children.length;
-  }
-
-  public void jjtSetValue(Object value) {
-      this.value = value;
-  }
-
-  public Object jjtGetValue() {
-      return value;
-  }
-
-  /** Accept the visitor. **/
-  public Object jjtAccept(ParserVisitor visitor, Object data) {
-    return visitor.visit(this, data);
-  }
-
-  /** Accept the visitor. **/
-  public Object childrenAccept(ParserVisitor visitor, Object data) {
-    if (children != null) {
-      for (int i = 0; i < children.length; ++i) {
-        children[i].jjtAccept(visitor, data);
-      }
-    }
-    return data;
-  }
-
-  /* You can override these two methods in subclasses of SimpleNode to
-     customize the way the JexlNode appears when the tree is dumped.  If
-     your output uses more than one line you should override
-     toString(String), otherwise overriding toString() is probably all
-     you need to do. */
-
-  @Override
-  public String toString() { return ParserTreeConstants.jjtNodeName[id]; }
-  public String toString(String prefix) { return prefix + toString(); }
-
-  /* Override this method if you want to customize how the JexlNode dumps
-     out its children. */
-
-  public void dump(String prefix) {
-    System.out.println(toString(prefix));
-    if (children != null) {
-      for (int i = 0; i < children.length; ++i) {
-  SimpleNode n = children[i];
-  if (n != null) {
-    n.dump(prefix + " ");
-  }
-      }
+    /** The parent node. */
+    protected JexlNode parent;
+    /** The array of children nodes. */
+    protected JexlNode[] children;
+    /** The node type id. */
+    protected final int id;
+    /** volatile value so it can be used as a last evaluation cache. */
+    protected volatile Object value;
+
+    /**
+     * Creates a SimpleNode instance.
+     * @param i the node type identifier
+     */
+    public SimpleNode(int i) {
+        id = i;
+    }
+
+    /**
+     * Creates a SimpleNode instance.
+     * @param p the parser instance
+     * @param i the node type identifier
+     */
+    public SimpleNode(Parser p, int i) {
+        this(i);
+    }
+
+    /** {@inheritDoc} */
+    public void jjtOpen() {
+    }
+
+    /** {@inheritDoc} */
+    public void jjtClose() {
+    }
+
+    /**
+     * Sets this node's parent.
+     * @param n the parent
+     */
+    public void jjtSetParent(Node n) {
+        parent = (JexlNode) n;
+    }
+
+    /**
+     * Gets this node's parent.
+     * @return the parent node
+     */
+    public JexlNode jjtGetParent() {
+        return parent;
+    }
+
+    /** Adds a child node.
+     * @param n the child node
+     * @param i the child offset
+     */
+    public void jjtAddChild(Node n, int i) {
+        if (children == null) {
+            children = new JexlNode[i + 1];
+        } else if (i >= children.length) {
+            JexlNode[] c = new JexlNode[i + 1];
+            System.arraycopy(children, 0, c, 0, children.length);
+            children = c;
+        }
+        children[i] = (JexlNode) n;
+    }
+
+    /**
+     * Gets a child of this node.
+     * @param i the child offset
+     * @return the child node
+     */
+    public JexlNode jjtGetChild(int i) {
+        return children[i];
+    }
+
+    /**
+     * Gets this node number of children.
+     * @return the number of children
+     */
+    public int jjtGetNumChildren() {
+        return (children == null) ? 0 : children.length;
+    }
+
+    /** Sets this node value.
+     * @param value
+     */
+    public void jjtSetValue(Object value) {
+        this.value = value;
+    }
+
+    /** Gets this node value.
+     * @return value
+     */
+    public Object jjtGetValue() {
+        return value;
+    }
+
+    /**
+     * Accept the visitor.
+     * @param visitor the visitor
+     * @param data contextual data
+     * @return result of visit
+     **/
+    public Object jjtAccept(ParserVisitor visitor, Object data) {
+        return visitor.visit(this, data);
+    }
+
+    /**
+     * Accept the visitor on all this node's children.
+     * @param visitor the visitor
+     * @param data contextual data
+     * @return result of visit
+     **/
+    public Object childrenAccept(ParserVisitor visitor, Object data) {
+        if (children != null) {
+            for (int i = 0; i < children.length; ++i) {
+                children[i].jjtAccept(visitor, data);
+            }
+        }
+        return data;
+    }
+
+    /* You can override these two methods in subclasses of SimpleNode to
+    customize the way the JexlNode appears when the tree is dumped.  If
+    your output uses more than one line you should override
+    toString(String), otherwise overriding toString() is probably all
+    you need to do. */
+    @Override
+    public String toString() {
+        return ParserTreeConstants.jjtNodeName[id];
+    }
+
+    public String toString(String prefix) {
+        return prefix + toString();
+    }
+
+    /* Override this method if you want to customize how the JexlNode dumps
+    out its children. */
+    public void dump(String prefix) {
+        System.out.println(toString(prefix));
+        if (children != null) {
+            for (int i = 0; i < children.length; ++i) {
+                SimpleNode n = children[i];
+                if (n != null) {
+                    n.dump(prefix + " ");
+                }
+            }
+        }
     }
-  }
 }
 
 /* JavaCC - OriginalChecksum=7dff880883d088a37c1e3197e4b455a0 (do not edit this line) */

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java?rev=929433&r1=929432&r2=929433&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java
Wed Mar 31 08:43:37 2010
@@ -65,6 +65,9 @@ public class StringParser {
         return read(strb, str, index, str.length(), sep);
     }
 
+    /** The length of an escaped unicode sequence. */
+    private static final int UCHAR_LEN = 4;
+
     /**
      * Read the remainder of a string till a given separator,
      * handles escaping through '\' syntax.
@@ -81,13 +84,12 @@ public class StringParser {
         for (; index < end; ++index) {
             char c = str.charAt(index);
             if (escape) {
-                if (c == 'u' && (index + 4) < end && readUnicodeChar(strb,
str, index + 1) > 0) {
-                    index += 4;
-                }
-                else {
+                if (c == 'u' && (index + UCHAR_LEN) < end && readUnicodeChar(strb,
str, index + 1) > 0) {
+                    index += UCHAR_LEN;
+                } else {
                     // if c is not an escapable character, re-emmit the backslash before
it
                     boolean notSeparator = sep == 0? c != '\'' && c != '"' : c !=
sep;
-                    if (notSeparator && c != '\\' ) {
+                    if (notSeparator && c != '\\') {
                         strb.append('\\');
                     }
                     strb.append(c);
@@ -107,6 +109,10 @@ public class StringParser {
         return index;
     }
 
+    /** Initial shift value for composing a Unicode char from 4 nibbles (16 - 4). */
+    private static final int SHIFT = 12;
+    /** The base 10 offset used to convert hexa characters to decimal. */
+    private static final int BASE10 = 10;
     /**
      * Reads a Unicode escape character.
      * @param strb the builder to write the character to
@@ -114,31 +120,31 @@ public class StringParser {
      * @param begin the begin offset in sequence (after the '\\u')
      * @return 0 if char could not be read, 4 otherwise
      */
-    private static final int readUnicodeChar(StringBuilder strb, CharSequence str, int begin)
{
+    private static int readUnicodeChar(StringBuilder strb, CharSequence str, int begin) {
         char xc = 0;
-        int bits = 12;
+        int bits = SHIFT;
         int value = 0;
-        for(int offset = 0; offset < 4; ++offset) {
+        for(int offset = 0; offset < UCHAR_LEN; ++offset) {
             char c = str.charAt(begin + offset);
             if (c >= '0' && c <= '9') {
                 value = (c - '0');
-            }
-            else if (c >= 'a' && c <= 'h') {
-               value = (c - 'a' + 10);
-            }
-            else if (c >= 'A' && c <= 'H') {
-                value = (c - 'A' + 10);
-            }
-            else {
+            } else if (c >= 'a' && c <= 'h') {
+               value = (c - 'a' + BASE10);
+            } else if (c >= 'A' && c <= 'H') {
+                value = (c - 'A' + BASE10);
+            } else {
                 return 0;
             }
             xc |= value << bits;
-            bits -= 4;
+            bits -= UCHAR_LEN;
         }
         strb.append(xc);
-        return 4;
+        return UCHAR_LEN;
     }
     
+    /** The last 7bits ascii character. */
+    private static final char LAST_ASCII = 127;
+
     /**
      * Escapes a String representation, expand non-ASCII characters as Unicode escape sequence.
      * @param str the string to escape
@@ -153,7 +159,7 @@ public class StringParser {
         strb.append('\'');
         for (int i = 0; i < length; ++i) {
             char c = str.charAt(i);
-            if (c < 127) {
+            if (c < LAST_ASCII) {
                 if (c == '\'') {
                     // escape quote
                     strb.append('\\');
@@ -170,7 +176,7 @@ public class StringParser {
                 strb.append('\\');
                 strb.append('u');
                 String hex = Integer.toHexString(c);
-                for (int h = hex.length(); h < 4; ++h) {
+                for (int h = hex.length(); h < UCHAR_LEN; ++h) {
                     strb.append('0');
                 }
                 strb.append(hex);



Mime
View raw message