You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2006/04/27 15:17:49 UTC
svn commit: r397536 - in
/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser:
ASTIntegerLiteral.java ASTJexlScript.java ASTLENode.java ASTLTNode.java
ASTMethod.java ASTModNode.java ASTMulNode.java
Author: dion
Date: Thu Apr 27 06:17:12 2006
New Revision: 397536
URL: http://svn.apache.org/viewcvs?rev=397536&view=rev
Log:
More checkstyle
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTJexlScript.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLENode.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLTNode.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTModNode.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMulNode.java
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java?rev=397536&r1=397535&r2=397536&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java Thu Apr 27 06:17:12 2006
@@ -1,12 +1,12 @@
/*
- * Copyright 2002,2004 The Apache Software Foundation.
- *
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,49 +18,36 @@
import org.apache.commons.jexl.JexlContext;
/**
- * represents an integer
- *
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id$
+ * represents an integer.
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id$
*/
-public class ASTIntegerLiteral extends SimpleNode
-{
+public class ASTIntegerLiteral extends SimpleNode {
Integer val;
- public ASTIntegerLiteral(int id)
- {
+ public ASTIntegerLiteral(int id) {
super(id);
}
- public ASTIntegerLiteral(Parser p, int id)
- {
+ public ASTIntegerLiteral(Parser p, int id) {
super(p, id);
}
-
- /** Accept the visitor. **/
- public Object jjtAccept(ParserVisitor visitor, Object data)
- {
+ /** Accept the visitor. * */
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/**
- * Part of reference resolution - wierd... in JSTL EL you can
- * have
- * foo.2
- * which is equiv to
- * foo[2]
- * it appears...
+ * Part of reference resolution - wierd... in JSTL EL you can have foo.2
+ * which is equiv to foo[2] it appears...
*/
- public Object execute(Object o, JexlContext ctx)
- throws Exception
- {
+ public Object execute(Object o, JexlContext ctx) throws Exception {
return ASTArrayAccess.evaluateExpr(o, val);
}
- public Object value(JexlContext jc)
- throws Exception
- {
+ public Object value(JexlContext jc) throws Exception {
return val;
}
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTJexlScript.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTJexlScript.java?rev=397536&r1=397535&r2=397536&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTJexlScript.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTJexlScript.java Thu Apr 27 06:17:12 2006
@@ -1,4 +1,18 @@
-/* Generated By:JJTree: Do not edit this line. ASTJexlScript.java */
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.commons.jexl.parser;
@@ -6,31 +20,30 @@
/**
* Top of the syntax tree - parsed Jexl code.
+ *
* @since 1.1
*/
public class ASTJexlScript extends SimpleNode {
- public ASTJexlScript(int id) {
- super(id);
- }
-
- public ASTJexlScript(Parser p, int id) {
- super(p, id);
- }
-
-
- /** Accept the visitor. **/
- public Object jjtAccept(ParserVisitor visitor, Object data) {
- return visitor.visit(this, data);
- }
-
- public Object value(JexlContext jc) throws Exception
- {
- int numChildren = jjtGetNumChildren();
- Object result = null;
- for (int i = 0; i < numChildren; i++) {
- SimpleNode child = (SimpleNode)jjtGetChild(i);
- result = child.value(jc);
- }
- return result;
- }
+ public ASTJexlScript(int id) {
+ super(id);
+ }
+
+ public ASTJexlScript(Parser p, int id) {
+ super(p, id);
+ }
+
+ /** Accept the visitor. * */
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
+ return visitor.visit(this, data);
+ }
+
+ public Object value(JexlContext jc) throws Exception {
+ int numChildren = jjtGetNumChildren();
+ Object result = null;
+ for (int i = 0; i < numChildren; i++) {
+ SimpleNode child = (SimpleNode) jjtGetChild(i);
+ result = child.value(jc);
+ }
+ return result;
+ }
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLENode.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLENode.java?rev=397536&r1=397535&r2=397536&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLENode.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLENode.java Thu Apr 27 06:17:12 2006
@@ -1,12 +1,12 @@
/*
- * Copyright 2002,2004 The Apache Software Foundation.
- *
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,88 +19,63 @@
import org.apache.commons.jexl.util.Coercion;
/**
- * LE : a <= b
- *
- * Follows A.3.6.1 of the JSTL 1.0 specification
- *
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
- * @version $Id$
+ * LE : a <= b.
+ *
+ * Follows A.3.6.1 of the JSTL 1.0 specification
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
+ * @version $Id$
*/
-public class ASTLENode extends SimpleNode
-{
- public ASTLENode(int id)
- {
+public class ASTLENode extends SimpleNode {
+ public ASTLENode(int id) {
super(id);
}
- public ASTLENode(Parser p, int id)
- {
+ public ASTLENode(Parser p, int id) {
super(p, id);
}
- /** Accept the visitor. **/
- public Object jjtAccept(ParserVisitor visitor, Object data)
- {
+ /** Accept the visitor. * */
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
- public Object value(JexlContext jc)
- throws Exception
- {
+ public Object value(JexlContext jc) throws Exception {
/*
* now get the values
*/
- Object left = ( (SimpleNode) jjtGetChild(0)).value(jc);
- Object right = ( (SimpleNode) jjtGetChild(1)).value(jc);
+ Object left = ((SimpleNode) jjtGetChild(0)).value(jc);
+ Object right = ((SimpleNode) jjtGetChild(1)).value(jc);
- if( left == right )
- {
+ if (left == right) {
return Boolean.TRUE;
- }
- else if ( ( left == null ) || ( right == null ) )
- {
+ } else if ((left == null) || (right == null)) {
return Boolean.FALSE;
- }
- else if( Coercion.isFloatingPoint( left ) || Coercion.isFloatingPoint( right ) )
- {
- double leftDouble = Coercion.coerceDouble( left ).doubleValue();
- double rightDouble = Coercion.coerceDouble( right ).doubleValue();
-
- return leftDouble <= rightDouble
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( Coercion.isNumberable( left ) || Coercion.isNumberable( right ) )
- {
- long leftLong = Coercion.coerceLong( left ).longValue();
- long rightLong = Coercion.coerceLong( right ).longValue();
-
- return leftLong <= rightLong
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( left instanceof String || right instanceof String )
- {
+ } else if (Coercion.isFloatingPoint(left)
+ || Coercion.isFloatingPoint(right)) {
+ double leftDouble = Coercion.coerceDouble(left).doubleValue();
+ double rightDouble = Coercion.coerceDouble(right).doubleValue();
+
+ return leftDouble <= rightDouble ? Boolean.TRUE : Boolean.FALSE;
+ } else if (Coercion.isNumberable(left) || Coercion.isNumberable(right)) {
+ long leftLong = Coercion.coerceLong(left).longValue();
+ long rightLong = Coercion.coerceLong(right).longValue();
+
+ return leftLong <= rightLong ? Boolean.TRUE : Boolean.FALSE;
+ } else if (left instanceof String || right instanceof String) {
String leftString = left.toString();
String rightString = right.toString();
- return leftString.compareTo( rightString ) <= 0
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( left instanceof Comparable )
- {
- return ( (Comparable)left ).compareTo( right ) <= 0
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( right instanceof Comparable )
- {
- return ( (Comparable)right ).compareTo( left ) >= 0
- ? Boolean.TRUE
- : Boolean.FALSE;
+ return leftString.compareTo(rightString) <= 0 ? Boolean.TRUE
+ : Boolean.FALSE;
+ } else if (left instanceof Comparable) {
+ return ((Comparable) left).compareTo(right) <= 0 ? Boolean.TRUE
+ : Boolean.FALSE;
+ } else if (right instanceof Comparable) {
+ return ((Comparable) right).compareTo(left) >= 0 ? Boolean.TRUE
+ : Boolean.FALSE;
}
throw new Exception("Invalid comparison : LE ");
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLTNode.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLTNode.java?rev=397536&r1=397535&r2=397536&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLTNode.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTLTNode.java Thu Apr 27 06:17:12 2006
@@ -1,12 +1,12 @@
/*
- * Copyright 2002,2004 The Apache Software Foundation.
- *
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,84 +20,61 @@
import org.apache.commons.jexl.util.Coercion;
/**
- * LT : a < b
- *
- * Follows A.3.6.1 of the JSTL 1.0 specification
- *
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
- * @version $Id$
+ * LT : a < b.
+ *
+ * Follows A.3.6.1 of the JSTL 1.0 specification
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
+ * @version $Id$
*/
-public class ASTLTNode extends SimpleNode
-{
- public ASTLTNode(int id)
- {
+public class ASTLTNode extends SimpleNode {
+ public ASTLTNode(int id) {
super(id);
}
- public ASTLTNode(Parser p, int id)
- {
+ public ASTLTNode(Parser p, int id) {
super(p, id);
}
- /** Accept the visitor. **/
- public Object jjtAccept(ParserVisitor visitor, Object data)
- {
+ /** Accept the visitor. * */
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
- public Object value(JexlContext jc)
- throws Exception
- {
+ public Object value(JexlContext jc) throws Exception {
/*
* now get the values
*/
- Object left = ( (SimpleNode) jjtGetChild(0)).value(jc);
- Object right = ( (SimpleNode) jjtGetChild(1)).value(jc);
+ Object left = ((SimpleNode) jjtGetChild(0)).value(jc);
+ Object right = ((SimpleNode) jjtGetChild(1)).value(jc);
- if( ( left == right ) || ( left == null ) || ( right == null ) )
- {
+ if ((left == right) || (left == null) || (right == null)) {
return Boolean.FALSE;
- }
- else if( Coercion.isFloatingPoint( left ) || Coercion.isFloatingPoint( right ) )
- {
- double leftDouble = Coercion.coerceDouble( left ).doubleValue();
- double rightDouble = Coercion.coerceDouble( right ).doubleValue();
-
- return leftDouble < rightDouble
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( Coercion.isNumberable( left ) || Coercion.isNumberable( right ) )
- {
- long leftLong = Coercion.coerceLong( left ).longValue();
- long rightLong = Coercion.coerceLong( right ).longValue();
-
- return leftLong < rightLong
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( left instanceof String || right instanceof String )
- {
+ } else if (Coercion.isFloatingPoint(left)
+ || Coercion.isFloatingPoint(right)) {
+ double leftDouble = Coercion.coerceDouble(left).doubleValue();
+ double rightDouble = Coercion.coerceDouble(right).doubleValue();
+
+ return leftDouble < rightDouble ? Boolean.TRUE : Boolean.FALSE;
+ } else if (Coercion.isNumberable(left) || Coercion.isNumberable(right)) {
+ long leftLong = Coercion.coerceLong(left).longValue();
+ long rightLong = Coercion.coerceLong(right).longValue();
+
+ return leftLong < rightLong ? Boolean.TRUE : Boolean.FALSE;
+ } else if (left instanceof String || right instanceof String) {
String leftString = left.toString();
String rightString = right.toString();
- return leftString.compareTo( rightString ) < 0
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( left instanceof Comparable )
- {
- return ( (Comparable)left ).compareTo( right ) < 0
- ? Boolean.TRUE
- : Boolean.FALSE;
- }
- else if( right instanceof Comparable )
- {
- return ( (Comparable)right ).compareTo( left ) > 0
- ? Boolean.TRUE
- : Boolean.FALSE;
+ return leftString.compareTo(rightString) < 0 ? Boolean.TRUE
+ : Boolean.FALSE;
+ } else if (left instanceof Comparable) {
+ return ((Comparable) left).compareTo(right) < 0 ? Boolean.TRUE
+ : Boolean.FALSE;
+ } else if (right instanceof Comparable) {
+ return ((Comparable) right).compareTo(left) > 0 ? Boolean.TRUE
+ : Boolean.FALSE;
}
throw new Exception("Invalid comparison : LT ");
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java?rev=397536&r1=397535&r2=397536&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java Thu Apr 27 06:17:12 2006
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.commons.jexl.parser;
import java.lang.reflect.InvocationTargetException;
@@ -12,80 +27,68 @@
/**
* Method execution.
*/
-public class ASTMethod extends SimpleNode
-{
- /** dummy velocity info */
+public class ASTMethod extends SimpleNode {
+ /** dummy velocity info. */
private static Info DUMMY = new Info("", 1, 1);
- public ASTMethod(int id)
- {
+ public ASTMethod(int id) {
super(id);
}
- public ASTMethod(Parser p, int id)
- {
+ public ASTMethod(Parser p, int id) {
super(p, id);
}
-
- /** Accept the visitor. **/
- public Object jjtAccept(ParserVisitor visitor, Object data)
- {
+ /** Accept the visitor. * */
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/**
- * returns the value of itself applied to the object.
- * We assume that an identifier can be gotten via a get(String)
+ * returns the value of itself applied to the object. We assume that an
+ * identifier can be gotten via a get(String)
*/
- public Object execute(Object obj, JexlContext jc)
- throws Exception
- {
- String methodName = ((ASTIdentifier)jjtGetChild(0)).val;
+ public Object execute(Object obj, JexlContext jc) throws Exception {
+ String methodName = ((ASTIdentifier) jjtGetChild(0)).val;
- int paramCount = jjtGetNumChildren()-1;
+ int paramCount = jjtGetNumChildren() - 1;
/*
- * get our params
+ * get our params
*/
- Object params[] = new Object[paramCount];
+ Object[] params = new Object[paramCount];
- try
- {
- for (int i=0; i<paramCount; i++)
- {
- params[i] = ( (SimpleNode) jjtGetChild(i+1)).value(jc);
+ try {
+ for (int i = 0; i < paramCount; i++) {
+ params[i] = ((SimpleNode) jjtGetChild(i + 1)).value(jc);
}
VelMethod vm = Introspector.getUberspect().getMethod(obj, methodName, params, DUMMY);
/*
- * DG: If we can't find an exact match, narrow the parameters and try again!
+ * DG: If we can't find an exact match, narrow the parameters and
+ * try again!
*/
- if (vm == null)
- {
-
- // replace all numbers with the smallest type that will fit
- for (int i = 0; i < params.length; i++)
- {
- Object param = params[i];
- if (param instanceof Number)
- {
- params[i] = narrow((Number)param);
- }
- }
- vm = Introspector.getUberspect().getMethod(obj, methodName, params, DUMMY);
- if (vm == null) return null;
+ if (vm == null) {
+
+ // replace all numbers with the smallest type that will fit
+ for (int i = 0; i < params.length; i++) {
+ Object param = params[i];
+ if (param instanceof Number) {
+ params[i] = narrow((Number) param);
+ }
+ }
+ vm = Introspector.getUberspect().getMethod(obj, methodName, params, DUMMY);
+ if (vm == null) {
+ return null;
+ }
}
return vm.invoke(obj, params);
- }
- catch(InvocationTargetException e)
- {
+ } catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
- if (t instanceof Exception)
- {
+ if (t instanceof Exception) {
throw (Exception) t;
}
@@ -94,43 +97,37 @@
}
/**
- * Given a Number, return back the value using the smallest type the result will fit into.
- * This works hand in hand with parameter 'widening' in java method calls,
- * e.g. a call to substring(int,int) with an int and a long will fail, but
- * a call to substring(int,int) with an int and a short will succeed.
+ * Given a Number, return back the value using the smallest type the result
+ * will fit into. This works hand in hand with parameter 'widening' in java
+ * method calls, e.g. a call to substring(int,int) with an int and a long
+ * will fail, but a call to substring(int,int) with an int and a short will
+ * succeed.
+ *
* @since 1.1
*/
- private Number narrow(Number original)
- {
- if (original == null || original instanceof BigDecimal || original instanceof BigInteger) return original;
- Number result = original;
- if (original instanceof Double || original instanceof Float)
- {
- double value = original.doubleValue();
- if (value <= Float.MAX_VALUE && value >= Float.MIN_VALUE)
- {
- result = new Float(result.floatValue());
- }
- // else it was already a double
- }
- else
- {
- long value = original.longValue();
- if (value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE)
- {
- // it will fit in a byte
- result = new Byte((byte)value);
- }
- else if (value <= Short.MAX_VALUE && value >= Short.MIN_VALUE)
- {
- result = new Short((short)value);
- }
- else if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE)
- {
- result = new Integer((int)value);
- }
- // else it was already a long
- }
+ private Number narrow(Number original) {
+ if (original == null || original instanceof BigDecimal || original instanceof BigInteger) {
+ return original;
+ }
+ Number result = original;
+ if (original instanceof Double || original instanceof Float) {
+ double value = original.doubleValue();
+ if (value <= Float.MAX_VALUE && value >= Float.MIN_VALUE) {
+ result = new Float(result.floatValue());
+ }
+ // else it was already a double
+ } else {
+ long value = original.longValue();
+ if (value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE) {
+ // it will fit in a byte
+ result = new Byte((byte) value);
+ } else if (value <= Short.MAX_VALUE && value >= Short.MIN_VALUE) {
+ result = new Short((short) value);
+ } else if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) {
+ result = new Integer((int) value);
+ }
+ // else it was already a long
+ }
return result;
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTModNode.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTModNode.java?rev=397536&r1=397535&r2=397536&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTModNode.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTModNode.java Thu Apr 27 06:17:12 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2003,2004 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,68 +20,61 @@
import org.apache.commons.jexl.util.Coercion;
/**
- * %
- *
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id$
+ * % (mod).
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id$
*/
-public class ASTModNode extends SimpleNode
-{
- public ASTModNode(int id)
- {
+public class ASTModNode extends SimpleNode {
+ public ASTModNode(int id) {
super(id);
}
- public ASTModNode(Parser p, int id)
- {
+ public ASTModNode(Parser p, int id) {
super(p, id);
}
-
- /** Accept the visitor. **/
- public Object jjtAccept(ParserVisitor visitor, Object data)
- {
+ /** Accept the visitor. * */
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
- public Object value(JexlContext jc)
- throws Exception
- {
+ public Object value(JexlContext jc) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(jc);
Object right = ((SimpleNode) jjtGetChild(1)).value(jc);
/*
- * the spec says 'and', I think 'or'
+ * the spec says 'and', I think 'or'
*/
- if (left == null && right == null)
- return new Byte((byte)0);
+ if (left == null && right == null) {
+ return new Byte((byte) 0);
+ }
/*
- * if anything is float, double or string with ( "." | "E" | "e")
- * coerce all to doubles and do it
+ * if anything is float, double or string with ( "." | "E" | "e") coerce
+ * all to doubles and do it
*/
- if ( left instanceof Float || left instanceof Double
- || right instanceof Float || right instanceof Double
- || ( left instanceof String
- && ( ((String) left).indexOf(".") != -1 ||
- ((String) left).indexOf("e") != -1 ||
- ((String) left).indexOf("E") != -1 )
- )
- || ( right instanceof String
- && ( ((String) right).indexOf(".") != -1 ||
- ((String) right).indexOf("e") != -1 ||
- ((String) right).indexOf("E") != -1 )
- )
- )
- {
+ if (left instanceof Float
+ || left instanceof Double
+ || right instanceof Float
+ || right instanceof Double
+ || (left instanceof String
+ && (((String) left).indexOf(".") != -1
+ || ((String) left).indexOf("e") != -1
+ || ((String) left).indexOf("E") != -1))
+ || (right instanceof String
+ && (((String) right).indexOf(".") != -1
+ || ((String) right).indexOf("e") != -1
+ || ((String) right).indexOf("E") != -1))) {
Double l = Coercion.coerceDouble(left);
Double r = Coercion.coerceDouble(right);
/*
* catch div/0
*/
- if (r.doubleValue() == 0.0)
+ if (r.doubleValue() == 0.0) {
return new Double(0.0);
+ }
return new Double(l.doubleValue() % r.doubleValue());
}
@@ -96,8 +89,9 @@
/*
* catch the div/0
*/
- if (r.longValue() == 0)
+ if (r.longValue() == 0) {
return new Long(0);
+ }
return new Long(l.longValue() % r.longValue());
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMulNode.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMulNode.java?rev=397536&r1=397535&r2=397536&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMulNode.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMulNode.java Thu Apr 27 06:17:12 2006
@@ -1,12 +1,12 @@
/*
- * Copyright 2002,2004 The Apache Software Foundation.
- *
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,64 +20,56 @@
import org.apache.commons.jexl.util.Coercion;
/**
- * Multiplication
- *
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id$
+ * Multiplication
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id$
*/
-public class ASTMulNode extends SimpleNode
-{
- public ASTMulNode(int id)
- {
+public class ASTMulNode extends SimpleNode {
+ public ASTMulNode(int id) {
super(id);
}
- public ASTMulNode(Parser p, int id)
- {
+ public ASTMulNode(Parser p, int id) {
super(p, id);
}
-
- /** Accept the visitor. **/
- public Object jjtAccept(ParserVisitor visitor, Object data)
- {
+ /** Accept the visitor. * */
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
- public Object value(JexlContext context)
- throws Exception
- {
+ public Object value(JexlContext context) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(context);
Object right = ((SimpleNode) jjtGetChild(1)).value(context);
/*
- * the spec says 'and', I think 'or'
+ * the spec says 'and', I think 'or'
*/
- if (left == null && right == null)
- return new Byte((byte)0);
+ if (left == null && right == null) {
+ return new Byte((byte) 0);
+ }
/*
- * if anything is float, double or string with ( "." | "E" | "e")
- * coerce all to doubles and do it
+ * if anything is float, double or string with ( "." | "E" | "e") coerce
+ * all to doubles and do it
*/
- if ( left instanceof Float || left instanceof Double
- || right instanceof Float || right instanceof Double
- || ( left instanceof String
- && ( ((String) left).indexOf(".") != -1 ||
- ((String) left).indexOf("e") != -1 ||
- ((String) left).indexOf("E") != -1 )
- )
- || ( right instanceof String
- && ( ((String) right).indexOf(".") != -1 ||
- ((String) right).indexOf("e") != -1 ||
- ((String) right).indexOf("E") != -1 )
- )
- )
- {
+ if (left instanceof Float
+ || left instanceof Double
+ || right instanceof Float
+ || right instanceof Double
+ || (left instanceof String
+ && (((String) left).indexOf(".") != -1
+ || ((String) left).indexOf("e") != -1
+ || ((String) left).indexOf("E") != -1))
+ || (right instanceof String
+ && (((String) right).indexOf(".") != -1
+ || ((String) right).indexOf("e") != -1
+ || ((String) right).indexOf("E") != -1))) {
Double l = Coercion.coerceDouble(left);
Double r = Coercion.coerceDouble(right);
- return new Double( l.doubleValue() * r.doubleValue() );
+ return new Double(l.doubleValue() * r.doubleValue());
}
/*
@@ -91,4 +83,3 @@
}
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org