commons-jexl-1.1-src/ 40755 0 0 0 10500374603 11603 5 ustar 0 0 commons-jexl-1.1-src/examples/ 40755 0 0 0 10500374603 13421 5 ustar 0 0 commons-jexl-1.1-src/src/ 40755 0 0 0 10500374603 12372 5 ustar 0 0 commons-jexl-1.1-src/src/conf/ 40755 0 0 0 10500374603 13317 5 ustar 0 0 commons-jexl-1.1-src/src/java/ 40755 0 0 0 10500374603 13313 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/ 40755 0 0 0 10500374603 14102 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/ 40755 0 0 0 10500374603 15323 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/ 40755 0 0 0 10500374603 16776 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/jexl/ 40755 0 0 0 10500374603 17740 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/jexl/context/ 40755 0 0 0 10500374603 21424 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/jexl/junit/ 40755 0 0 0 10500374603 21071 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ 40755 0 0 0 10500374603 21234 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/jexl/resolver/ 40755 0 0 0 10500374603 21601 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/ 40755 0 0 0 10500374603 20715 5 ustar 0 0 commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/ 40755 0 0 0 10500374603 23615 5 ustar 0 0 commons-jexl-1.1-src/src/test/ 40755 0 0 0 10500374603 13351 5 ustar 0 0 commons-jexl-1.1-src/src/test/org/ 40755 0 0 0 10500374603 14140 5 ustar 0 0 commons-jexl-1.1-src/src/test/org/apache/ 40755 0 0 0 10500374603 15361 5 ustar 0 0 commons-jexl-1.1-src/src/test/org/apache/commons/ 40755 0 0 0 10500374603 17034 5 ustar 0 0 commons-jexl-1.1-src/src/test/org/apache/commons/jexl/ 40755 0 0 0 10500374603 17776 5 ustar 0 0 commons-jexl-1.1-src/src/test/org/apache/commons/jexl/junit/ 40755 0 0 0 10500374603 21127 5 ustar 0 0 commons-jexl-1.1-src/src/test/org/apache/commons/jexl/parser/ 40755 0 0 0 10500374603 21272 5 ustar 0 0 commons-jexl-1.1-src/src/test-scripts/ 40755 0 0 0 10500374603 15036 5 ustar 0 0 commons-jexl-1.1-src/xdocs/ 40755 0 0 0 10500374603 12723 5 ustar 0 0 commons-jexl-1.1-src/xdocs/images/ 40755 0 0 0 10500374603 14170 5 ustar 0 0 commons-jexl-1.1-src/xdocs/reference/ 40755 0 0 0 10500374603 14661 5 ustar 0 0 commons-jexl-1.1-src/xdocs/style/ 40755 0 0 0 10500374603 14063 5 ustar 0 0 commons-jexl-1.1-src/build.properties.sample 100644 0 0 1510 10500374603 16372 0 ustar 0 0 # Copyright 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.
# The ant script is mostly self-sufficient as it fetches the
# dependencies it needs.
#
# Commons JEXL dependency information is here:
#
# http://jakarta.apache.org/commons/jexl/dependencies.html
commons-jexl-1.1-src/build.xml 100644 0 0 14233 10500374603 13544 0 ustar 0 0
This package only contains one JexlContext implementation, the HashMapContext. A HashMapContext is simply an extension of HashMap which implements the JexlContext interface.
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/Expression.java 100644 0 0 4337 10500374603 23046 0 ustar 0 0 /* * 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; /** ** Represents a single JEXL expression. This simple interface * provides access to the underlying expression through getExpression(), * and it provides hooks to add a pre- and post- expression resolver. *
* ** An expression is different than a script - it is simply a reference of * an expression. *
* * @since 1.0 * @author Geir Magnusson Jr. * @version $Id: Expression.java 397092 2006-04-26 05:11:28Z dion $ */ public interface Expression { /** * Evaluates the expression with the variables contained in the * supplied {@link JexlContext}. * * @param context A JexlContext containing variables. * @return The result of this evaluation * @throws Exception on any error */ Object evaluate(JexlContext context) throws Exception; /** * Returns the JEXL expression this Expression was created with. * * @return The JEXL expression to be evaluated */ String getExpression(); /** * Allows addition of a resolver to allow custom interdiction of * expression evaluation. * * @param resolver resolver to be called before Jexl expression evaluated */ void addPreResolver(JexlExprResolver resolver); /** * Allows addition of a resolver to allow custom interdiction of * expression evaluation. * * @param resolver resolver to be called if Jexl expression * evaluated to null. */ void addPostResolver(JexlExprResolver resolver); } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/ExpressionFactory.java 100644 0 0 13761 10500374603 24417 0 ustar 0 0 /* * 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; import java.io.StringReader; import org.apache.commons.jexl.parser.ASTExpressionExpression; import org.apache.commons.jexl.parser.ASTForeachStatement; import org.apache.commons.jexl.parser.ASTIfStatement; import org.apache.commons.jexl.parser.ASTReferenceExpression; import org.apache.commons.jexl.parser.ASTStatementExpression; import org.apache.commons.jexl.parser.ASTWhileStatement; import org.apache.commons.jexl.parser.ParseException; import org.apache.commons.jexl.parser.Parser; import org.apache.commons.jexl.parser.SimpleNode; import org.apache.commons.jexl.parser.TokenMgrError; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** ** Creates Expression objects. To create a JEXL Expression object, pass * valid JEXL syntax to the static createExpression() method: *
* ** String jexl = "array[1]"; * Expression expression = ExpressionFactory.createExpression( jexl ); ** *
* When an {@link Expression} object is created, the JEXL syntax is * parsed and verified. If the supplied expression is neither an * expression nor a reference, an exception is thrown from createException(). *
* @since 1.0 * @author Geir Magnusson Jr. * @version $Id: ExpressionFactory.java 429169 2006-08-06 18:36:29Z rahul $ */ public class ExpressionFactory { /** * The Log to which all ExpressionFactory messages will be logged. */ protected static Log log = LogFactory.getLog("org.apache.commons.jexl.ExpressionFactory"); /** * The singleton ExpressionFactory also holds a single instance of * {@link Parser}. * When parsing expressions, ExpressionFactory synchronizes on Parser. */ protected static Parser parser = new Parser(new StringReader(";")); //$NON-NLS-1$ /** * ExpressionFactory is a singleton and this is the private * instance fufilling that pattern. */ protected static ExpressionFactory ef = new ExpressionFactory(); /** * Private constructor, the single instance is always obtained * with a call to getInstance(). */ private ExpressionFactory() { } /** * Returns the single instance of ExpressionFactory. * @return the instance of ExpressionFactory. */ protected static ExpressionFactory getInstance() { return ef; } /** * Creates an Expression from a String containing valid * JEXL syntax. This method parses the expression which * must contain either a reference or an expression. * @param expression A String containing valid JEXL syntax * @return An Expression object which can be evaluated with a JexlContext * @throws Exception An exception can be thrown if there is a problem * parsing this expression, or if the expression is neither an * expression or a reference. */ public static Expression createExpression(String expression) throws Exception { return getInstance().createNewExpression(expression); } /** * Creates a new Expression based on the expression string. * * @param expression valid Jexl expression * @return Expression * @throws Exception for a variety of reasons - mostly malformed * Jexl expression */ protected Expression createNewExpression(final String expression) throws Exception { String expr = cleanExpression(expression); // Parse the Expression SimpleNode tree; synchronized (parser) { log.debug("Parsing expression: " + expr); try { tree = parser.parse(new StringReader(expr)); } catch (TokenMgrError tme) { throw new ParseException(tme.getMessage()); } } if (tree.jjtGetNumChildren() > 1 && log.isWarnEnabled()) { log.warn("The JEXL Expression created will be a reference" + " to the first expression from the supplied script: \"" + expression + "\" "); } // Must be a simple reference, expression, statement or if, otherwise // throw an exception. SimpleNode node = (SimpleNode) tree.jjtGetChild(0); // TODO: Can we get rid of these checks? if (node instanceof ASTReferenceExpression || node instanceof ASTExpressionExpression || node instanceof ASTStatementExpression || node instanceof ASTIfStatement || node instanceof ASTWhileStatement || node instanceof ASTForeachStatement ) { return new ExpressionImpl(expression, node); } log.error("Invalid Expression, node of type: " + node.getClass().getName()); throw new Exception("Invalid Expression: not a Reference, Expression, " + "Statement or If"); } /** * Trims the expression and adds a semi-colon if missing. * @param expression to clean * @return trimmed expression ending in a semi-colon */ private String cleanExpression(String expression) { String expr = expression.trim(); if (!expr.endsWith(";")) { expr += ";"; } return expr; } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/ExpressionImpl.java 100644 0 0 10464 10500374603 23706 0 ustar 0 0 /* * 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; import java.util.ArrayList; import java.util.List; import org.apache.commons.jexl.parser.SimpleNode; /** * Instances of ExpressionImpl are created by the {@link ExpressionFactory}, * and this is the default implementation of the {@link Expression} interface. * * @since 1.0 * @author Geir Magnusson Jr. * @version $Id: ExpressionImpl.java 397111 2006-04-26 06:47:52Z dion $ */ class ExpressionImpl implements Expression { /** resolvers called before expression evaluation. */ protected List preResolvers; /** resolvers called after expression evaluation. */ protected List postResolvers; /** * Original expression. This is just a 'snippet', not a valid statement * (i.e. foo.bar() vs foo.bar(); */ protected String expression; /** * The resulting AST we can call value() on. */ protected SimpleNode node; /** * do not let this be generally instantiated with a 'new'. * * @param expr the expression. * @param ref the parsed expression. */ ExpressionImpl(String expr, SimpleNode ref) { expression = expr; node = ref; } /** * {@inheritDoc} */ public Object evaluate(JexlContext context) throws Exception { Object val = null; /* * if we have pre resolvers, give them a wack */ if (preResolvers != null) { val = tryResolver(preResolvers, context); if (val != JexlExprResolver.NO_VALUE) { return val; } } val = node.value(context); /* * if null, call post resolvers */ if (val == null && postResolvers != null) { val = tryResolver(postResolvers, context); if (val != JexlExprResolver.NO_VALUE) { return val; } } return val; } /** * Tries the resolvers in the given resolverlist against the context. * * @param resolverList list of JexlExprResolvers * @param context JexlContext to use for evauluation * @return value (including null) or JexlExprResolver.NO_VALUE */ protected Object tryResolver(List resolverList, JexlContext context) { Object val = JexlExprResolver.NO_VALUE; String expr = getExpression(); for (int i = 0; i < resolverList.size(); i++) { JexlExprResolver jer = (JexlExprResolver) resolverList.get(i); val = jer.evaluate(context, expr); /* * as long as it's not NO_VALUE, return it */ if (val != JexlExprResolver.NO_VALUE) { return val; } } return val; } /** * {@inheritDoc} */ public String getExpression() { return expression; } /** * {@inheritDoc} */ public void addPreResolver(JexlExprResolver resolver) { if (preResolvers == null) { preResolvers = new ArrayList(); } preResolvers.add(resolver); } /** * {@inheritDoc} */ public void addPostResolver(JexlExprResolver resolver) { if (postResolvers == null) { postResolvers = new ArrayList(); } postResolvers.add(resolver); } /** * Provide a string representation of the expression. * * @return the expression or blank if it's null. */ public String toString() { String expr = getExpression(); return expr == null ? "" : expr; } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/JexlContext.java 100644 0 0 3237 10500374603 23154 0 ustar 0 0 /* * 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; import java.util.Map; /** * Holds a Map of variables which are referenced in a JEXL expression. * * @since 1.0 * @author Geir Magnusson Jr. * @version $Id: JexlContext.java 397092 2006-04-26 05:11:28Z dion $ */ public interface JexlContext { /** * Replaces variables in a JexlContext with the variables contained * in the supplied Map. When setVars() is called on a JexlContext, * it clears the current Map and puts each entry of the * supplied Map into the current variable Map. * * @param vars Contents of vars will be replaced with the content * of this Map */ void setVars(Map vars); /** * Retrives the Map of variables associated with this JexlContext. The * keys of this map correspond to variable names referenced in a * JEXL expression. * * @return A reference to the variable Map associated with this JexlContext. */ Map getVars(); } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/JexlExprResolver.java 100644 0 0 3101 10500374603 24156 0 ustar 0 0 /* * 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; /** * A Resolver allows custom resolution of the expression, and can be * added in front of the jexl engine, or after in the evaluation. * * @todo This needs to be explained in detail. Why do this? * @since 1.0 * @author Geir Magnusson Jr. * @version $Id: JexlExprResolver.java 397092 2006-04-26 05:11:28Z dion $ */ public interface JexlExprResolver { /** represents an expression result of no value. */ Object NO_VALUE = new Object(); /** * Evaluates an expression against the context. * * @todo Must detail the expectations and effects of this resolver. * @param context current data context * @param expression expression to evauluate * @return value (may be null) or the NO_VALUE object to * indicate no resolution. */ Object evaluate(JexlContext context, String expression); } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/JexlHelper.java 100644 0 0 3544 10500374603 22750 0 ustar 0 0 /* * 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; import org.apache.commons.jexl.context.HashMapContext; /** * Helper to create a context. In the current implementation of JEXL, there * is one implementation of JexlContext - {@link HashMapContext}, and there * is no reason not to directly instantiate {@link HashMapContext} in your * own application. * * @since 1.0 * @author Geir Magnusson Jr. * @version $Id: JexlHelper.java 397092 2006-04-26 05:11:28Z dion $ */ public class JexlHelper { /** singleton instance. */ protected static JexlHelper helper = new JexlHelper(); /** @return the single instance. */ protected static JexlHelper getInstance() { return helper; } /** * Returns a new {@link JexlContext}. * @return a new JexlContext */ public static JexlContext createContext() { return getInstance().newContext(); } /** * Creates and returns a new {@link JexlContext}. * The current implementation creates a new instance of * {@link HashMapContext}. * @return a new JexlContext */ protected JexlContext newContext() { return new HashMapContext(); } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/junit/Asserter.java 100644 0 0 5474 10500374603 23633 0 ustar 0 0 /* * 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. * 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.junit; import java.util.HashMap; import java.util.Map; import junit.framework.Assert; import org.apache.commons.jexl.Expression; import org.apache.commons.jexl.ExpressionFactory; import org.apache.commons.jexl.JexlContext; import org.apache.commons.jexl.JexlHelper; /** * A utility class for performing JUnit based assertions using Jexl * expressions. This class can make it easier to do unit tests using * Jexl navigation expressions. * * @since 1.0 * @author James Strachan * @version $Revision: 398153 $ */ public class Asserter extends Assert { /** variables used during asserts. */ private final Map variables = new HashMap(); /** context to use during asserts. */ private final JexlContext context = JexlHelper.createContext(); /** * * Create an asserter. */ public Asserter() { } /** * This constructor will register the given variableValue as the * "this" variable. * * @param variableValue 'this'. */ public Asserter(Object variableValue) { setVariable("this", variableValue); } /** * Performs an assertion that the value of the given Jexl expression * evaluates to the given expected value. * * @param expression is the Jexl expression to evaluate * @param expected is the expected value of the expression * @throws Exception if the expression could not be evaluationed or an assertion * fails */ public void assertExpression(String expression, Object expected) throws Exception { Expression exp = ExpressionFactory.createExpression(expression); context.setVars(variables); Object value = exp.evaluate(context); assertEquals("expression: " + expression, expected, value); } /** * Puts a variable of a certain name in the context so that it can be used from * assertion expressions. * * @param name variable name * @param value variable value */ public void setVariable(String name, Object value) { variables.put(name, value); } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/junit/package.html 100644 0 0 2276 10500374603 23456 0 ustar 0 0
This package only contains one class, Asserter, which allows you to use a JEXL expression in a JUnit assertion. The following example demonstrates the use of the Asserter class. An instance is created, and the internal JexlContext is populated via calls to setVariable(). Calls to assertExpression() succeed if the expression evaluates to the value of the second parameter, otherwise an AssertionFailedException is thrown.
Asserter asserter = new Asserter(); asserter.setVariable("foo", new Foo()); asserter.setVariable("person", "James"); asserter.assertExpression("person", "James"); asserter.assertExpression("size(person)", new Integer(5)); asserter.assertExpression("foo.getCount()", new Integer(5)); asserter.assertExpression("foo.count", new Integer(5));commons-jexl-1.1-src/src/java/org/apache/commons/jexl/package.html 100644 0 0 5452 10500374603 22324 0 ustar 0 0
Java Expression Language (JEXL) is an expression language engine which can be embedded in applications and frameworks. JEXL is inspired by Jakarta Velocity and the Expression Language defined in the JavaServer Pages Standard Tag Library version 1.1 (JSTL) and JavaServer Pages version 2.0 (JSP).
JEXL attempts to bring some of the lessons learned by the Velocity community about expression languages in templating to a wider audience. Commons Jelly needed Velocity-ish method access, it just had to have it.
It must be noted that JEXL is not a compatibile implementation of EL as defined in JSTL 1.1 (JSR-052) or JSP 2.0 (JSR-152). For a compatible implementation of these specifications, see the Commons EL project.
When evaluating expressions, JEXL merges an Expression with a JexlContext. An Expression is created using ExpressionFactory.createExpression(), passing a String containing valid JEXL syntax. A JexlContext is created using JexlHelper.createContext(), and variables are put into a map exposed through the getVars() method on JexlContext. The following example, takes a variable named foo, and invokes the bar() method on the property innerFoo:
// Create an expression object String jexlExp = "foo.innerFoo.bar()"; Expression e = ExpressionFactory.createExpression( jexlExp ); // Create a context and add data JexlContext jc = JexlHelper.createContext(); jc.getVars().put("foo", new Foo() ); // Now evaluate the expression, getting the result Object o = e.evaluate(jc);commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTAddNode.java 100644 0 0 7276 10500374603 24056 0 ustar 0 0 /* * 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 org.apache.commons.jexl.JexlContext; import org.apache.commons.jexl.util.Coercion; /** * Addition : either integer addition or string concatenation. * * @author Geir Magnusson Jr. * @version $Id: ASTAddNode.java 398180 2006-04-29 15:40:35Z dion $ */ public class ASTAddNode extends SimpleNode { /** * Create the node given an id. * * @param id node id. */ public ASTAddNode(int id) { super(id); } /** * Create a node with the given parser and id. * * @param p a parser. * @param id node id. */ public ASTAddNode(Parser p, int id) { super(p, id); } /** * {@inheritDoc} */ public Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } /** * {@inheritDoc} */ 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' */ if (left == null && right == null) { return new Long(0); } /* * 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) ) ) { /* * in the event that either is null and not both, then just make the * null a 0 */ try { Double l = Coercion.coerceDouble(left); Double r = Coercion.coerceDouble(right); return new Double(l.doubleValue() + r.doubleValue()); } catch (java.lang.NumberFormatException nfe) { /* * Well, use strings! */ return left.toString().concat(right.toString()); } } /* * attempt to use Longs */ try { Long l = Coercion.coerceLong(left); Long r = Coercion.coerceLong(right); return new Long(l.longValue() + r.longValue()); } catch (java.lang.NumberFormatException nfe) { /* * Well, use strings! */ return left.toString().concat(right.toString()); } } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTAndNode.java 100644 0 0 3651 10500374603 24061 0 ustar 0 0 /* * 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 org.apache.commons.jexl.JexlContext; import org.apache.commons.jexl.util.Coercion; /** * && and 'and'. * * @author Geir Magnusson Jr. * @version $Id: ASTAndNode.java 398180 2006-04-29 15:40:35Z dion $ */ public class ASTAndNode extends SimpleNode { /** * Create the node given an id. * * @param id node id. */ public ASTAndNode(int id) { super(id); } /** * Create a node with the given parser and id. * * @param p a parser. * @param id node id. */ public ASTAndNode(Parser p, int id) { super(p, id); } /** {@inheritDoc} */ public Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } /** {@inheritDoc} */ public Object value(JexlContext jc) throws Exception { Object left = ((SimpleNode) jjtGetChild(0)).value(jc); boolean leftValue = Coercion.coerceBoolean(left).booleanValue(); /* * coercion rules */ return (leftValue && Coercion.coerceBoolean( ((SimpleNode) jjtGetChild(1)).value(jc)).booleanValue()) ? Boolean.TRUE : Boolean.FALSE; } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTArrayAccess.java 100644 0 0 13374 10500374603 24774 0 ustar 0 0 /* * 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 org.apache.commons.jexl.JexlContext; import org.apache.commons.jexl.util.Coercion; import org.apache.commons.jexl.util.Introspector; import org.apache.commons.jexl.util.introspection.Info; import org.apache.commons.jexl.util.introspection.VelPropertyGet; import java.util.List; import java.util.Map; import java.lang.reflect.Array; /** * Like an ASTIdentifier, but with array access allowed. * * $foo[2] * * @author Geir Magnusson Jr. * @version $Id: ASTArrayAccess.java 398180 2006-04-29 15:40:35Z dion $ */ public class ASTArrayAccess extends SimpleNode { /** dummy velocity info. */ private static final Info DUMMY = new Info("", 1, 1); /** * Create the node given an id. * * @param id node id. */ public ASTArrayAccess(int id) { super(id); } /** * Create a node with the given parser and id. * * @param p a parser. * @param id node id. */ public ASTArrayAccess(Parser p, int id) { super(p, id); } /** {@inheritDoc} */ public Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } /** * evaluate array access upon a base object. * * foo.bar[2] * * makes me rethink the array operator :) * @param jc the {@link JexlContext} to evaluate against. * @param obj not used. * @return the value of the array expression. * @throws Exception on any error */ public Object execute(Object obj, JexlContext jc) throws Exception { ASTIdentifier base = (ASTIdentifier) jjtGetChild(0); Object result = base.execute(obj, jc); /* * ignore the first child - it's our identifier */ for (int i = 1; i < jjtGetNumChildren(); i++) { Object loc = ((SimpleNode) jjtGetChild(i)).value(jc); if (loc == null) { return null; } result = evaluateExpr(result, loc); } return result; } /** {@inheritDoc} */ public Object value(JexlContext jc) throws Exception { /* * get the base ASTIdentifier */ ASTIdentifier base = (ASTIdentifier) jjtGetChild(0); Object o = base.value(jc); /* * ignore the first child - it's our identifier */ for (int i = 1; i < jjtGetNumChildren(); i++) { Object loc = ((SimpleNode) jjtGetChild(i)).value(jc); if (loc == null) { return null; } o = evaluateExpr(o, loc); } return o; } /** * Evaluate the Array expression 'loc' on the given object, o. * e.g. in 'a[2]',
2
is 'loc' and a
is 'o'.
*
* If o or loc are null, null is returned.
* If o is a Map, o.get(loc) is returned.
* If o is a List, o.get(loc) is returned. loc must resolve to an int value.
* If o is an Array, o[loc] is returned. loc must resolve to an int value.
* Otherwise loc is treated as a bean property of o.
*
* @param o an object to be accessed using the array operator or '.' operator.
* @param loc the index of the object to be returned.
* @return the resulting value.
* @throws Exception on any error.
*/
public static Object evaluateExpr(Object o, Object loc) throws Exception {
/*
* following the JSTL EL rules
*/
if (o == null) {
return null;
}
if (loc == null) {
return null;
}
if (o instanceof Map) {
if (!((Map) o).containsKey(loc)) {
return null;
}
return ((Map) o).get(loc);
} else if (o instanceof List) {
int idx = Coercion.coerceInteger(loc).intValue();
try {
return ((List) o).get(idx);
} catch (IndexOutOfBoundsException iobe) {
return null;
}
} else if (o.getClass().isArray()) {
int idx = Coercion.coerceInteger(loc).intValue();
try {
return Array.get(o, idx);
} catch (ArrayIndexOutOfBoundsException aiobe) {
return null;
}
} else {
/*
* "Otherwise (a JavaBean object)..." huh? :)
*/
String s = loc.toString();
VelPropertyGet vg = Introspector.getUberspect().getPropertyGet(o, s, DUMMY);
if (vg != null) {
return vg.invoke(o);
}
}
throw new Exception("Unsupported object type for array [] accessor");
}
/**
* Gets the variable name piece of the expression.
* @return a String of the identifer.
* @see ASTIdentifier#getIdentifierString().
*/
public String getIdentifierString() {
return ((ASTIdentifier) jjtGetChild(0)).getIdentifierString();
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTAssignment.java 100644 0 0 4170 10500374603 24656 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* x = y, assigns a value to a variable in the context.
*
* @author Dion Gillard
*
*/
public class ASTAssignment extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTAssignment(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTAssignment(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
// left should be the variable (reference) to assign to
SimpleNode left = (SimpleNode) jjtGetChild(0);
// right should be the expression to evaluate
Object right = ((SimpleNode) jjtGetChild(1)).value(context);
if (left instanceof ASTReference) {
ASTReference reference = (ASTReference) left;
left = (SimpleNode) reference.jjtGetChild(0);
if (left instanceof ASTIdentifier) {
String identifier = ((ASTIdentifier) left)
.getIdentifierString();
context.getVars().put(identifier, right);
}
}
return right;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTBitwiseAndNode.java 100644 0 0 3564 10500374603 25413 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Bitwise And. Syntax: a & b Result is a {@link Long}
*
* @author Dion Gillard
* @since 1.1
*/
public class ASTBitwiseAndNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTBitwiseAndNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTBitwiseAndNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(context);
Object right = ((SimpleNode) jjtGetChild(1)).value(context);
Long l = left == null ? new Long(0) : Coercion.coerceLong(left);
Long r = right == null ? new Long(0) : Coercion.coerceLong(right);
return new Long(l.longValue() & r.longValue());
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTBitwiseComplNode.java 100644 0 0 3327 10500374603 25760 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Bitwise Complement. Syntax: ~a Result is a Long
*
* @author Dion Gillard
* @since 1.1
*/
public class ASTBitwiseComplNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTBitwiseComplNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTBitwiseComplNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(context);
Long l = left == null ? new Long(0) : Coercion.coerceLong(left);
return new Long(~l.longValue());
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTBitwiseOrNode.java 100644 0 0 3552 10500374603 25266 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Bitwise Or. Syntax: a | b Result is a Long
*
* @author Dion Gillard
* @since 1.1
*/
public class ASTBitwiseOrNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTBitwiseOrNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTBitwiseOrNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(context);
Object right = ((SimpleNode) jjtGetChild(1)).value(context);
Long l = left == null ? new Long(0) : Coercion.coerceLong(left);
Long r = right == null ? new Long(0) : Coercion.coerceLong(right);
return new Long(l.longValue() | r.longValue());
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTBitwiseXorNode.java 100644 0 0 3611 10500374603 25452 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Bitwise Or. Syntax: a ^ b Result is a Long
*
* @author Dion Gillard
* @since 1.1
*/
public class ASTBitwiseXorNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTBitwiseXorNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTBitwiseXorNode(Parser p, int id) {
super(p, id);
}
/**
* {@inheritDoc}
*/
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/**
* {@inheritDoc}
*/
public Object value(JexlContext context) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(context);
Object right = ((SimpleNode) jjtGetChild(1)).value(context);
Long l = left == null ? new Long(0) : Coercion.coerceLong(left);
Long r = right == null ? new Long(0) : Coercion.coerceLong(right);
return new Long(l.longValue() ^ r.longValue());
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTBlock.java 100644 0 0 3616 10500374603 23604 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* { code }, a block of statements enclosed in curly braces.
*
* @author Dion Gillard
*
*/
public class ASTBlock extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTBlock(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTBlock(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/**
* @return the value of the block. Execute all statements inside and return
* the value of the last.
* @param context the {@link JexlContext} to execute against.
* @throws Exception on any error.
*/
public Object value(JexlContext context) throws Exception {
int numChildren = jjtGetNumChildren();
Object result = null;
for (int i = 0; i < numChildren; i++) {
result = ((SimpleNode) jjtGetChild(i)).value(context);
}
return result;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTDivNode.java 100644 0 0 4243 10500374603 24077 0 ustar 0 0 /*
* 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.
* 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 org.apache.commons.jexl.util.Coercion;
import org.apache.commons.jexl.JexlContext;
/**
* a / b, mathematical divide.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTDivNode.java 398187 2006-04-29 15:58:45Z dion $
*/
public class ASTDivNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTDivNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTDivNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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'
*/
if (left == null && right == null) {
return new Byte((byte) 0);
}
Double l = Coercion.coerceDouble(left);
Double r = Coercion.coerceDouble(right);
/*
* catch div/0
*/
if (r.doubleValue() == 0.0) {
return new Double(0.0);
}
return new Double(l.doubleValue() / r.doubleValue());
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTEmptyFunction.java 100644 0 0 4662 10500374603 25360 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import java.util.Collection;
import java.util.Map;
/**
* function to see if reference doesn't exist in context.
*
* @author Geir Magnusson Jr.
* @author Tim O'Brien
* @version $Id: ASTEmptyFunction.java 398190 2006-04-29 16:04:10Z dion $
*/
public class ASTEmptyFunction extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTEmptyFunction(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTEmptyFunction(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
SimpleNode sn = (SimpleNode) jjtGetChild(0);
/*
* I can't believe this
*/
Object o = sn.value(jc);
if (o == null) {
return Boolean.TRUE;
}
if (o instanceof String && "".equals(o)) {
return Boolean.TRUE;
}
if (o.getClass().isArray() && ((Object[]) o).length == 0) {
return Boolean.TRUE;
}
if (o instanceof Collection && ((Collection) o).isEmpty()) {
return Boolean.TRUE;
}
/*
* Map isn't a collection
*/
if (o instanceof Map && ((Map) o).isEmpty()) {
return Boolean.TRUE;
}
return Boolean.FALSE;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTEQNode.java 100644 0 0 7704 10500374603 23667 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Represents equality between values.
*
* If the values are of the same class, .equals() is used.
*
* If either value is a {@link Float} or {@link Double} (but both are not the same class),
* the values are coerced to {@link Double}s before comparing.
*
* If either value is a {@link Number} or {@link Character} (but both are not the same class),
* the values are coerced to {@link Long}s before comparing.
*
* If either value is a {@link Boolean} (but both are not the same class),
* the values are coerced to {@link Boolean}s before comparing.
*
* If either value is a {@link String} (but both are not the same class),
* toString() is called on both before comparing.
*
* Otherwise left.equals(right) is returned.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTEQNode.java 398190 2006-04-29 16:04:10Z dion $
*/
public class ASTEQNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTEQNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTEQNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext pc) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(pc);
Object right = ((SimpleNode) jjtGetChild(1)).value(pc);
if (left == null && right == null) {
/*
* if both are null L == R
*/
return Boolean.TRUE;
} else if (left == null || right == null) {
/*
* we know both aren't null, therefore L != R
*/
return Boolean.FALSE;
} else if (left.getClass().equals(right.getClass())) {
return left.equals(right) ? Boolean.TRUE : Boolean.FALSE;
} else if (left instanceof Float || left instanceof Double
|| right instanceof Float || right instanceof Double) {
Double l = Coercion.coerceDouble(left);
Double r = Coercion.coerceDouble(right);
return l.equals(r) ? Boolean.TRUE : Boolean.FALSE;
} else if (left instanceof Number || right instanceof Number
|| left instanceof Character || right instanceof Character) {
return Coercion.coerceLong(left).equals(Coercion.coerceLong(right)) ? Boolean.TRUE
: Boolean.FALSE;
} else if (left instanceof Boolean || right instanceof Boolean) {
return Coercion.coerceBoolean(left).equals(
Coercion.coerceBoolean(right)) ? Boolean.TRUE
: Boolean.FALSE;
} else if (left instanceof java.lang.String || right instanceof String) {
return left.toString().equals(right.toString()) ? Boolean.TRUE
: Boolean.FALSE;
}
return left.equals(right) ? Boolean.TRUE : Boolean.FALSE;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTExpression.java 100644 0 0 3145 10500374603 24706 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* AST node for expression.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTExpression.java 398190 2006-04-29 16:04:10Z dion $
*/
public class ASTExpression extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTExpression(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTExpression(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
return ((SimpleNode) jjtGetChild(0)).value(context);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTExpressionExpression.java 100644 0 0 3270 10500374603 26765 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* represents equality between integers - use .equals() for strings.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTExpressionExpression.java 398190 2006-04-29 16:04:10Z dion $
*/
public class ASTExpressionExpression extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTExpressionExpression(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTExpressionExpression(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
return ((SimpleNode) jjtGetChild(0)).value(context);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTFalseNode.java 100644 0 0 3076 10500374603 24412 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* represents Boolean false.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTFalseNode.java 398194 2006-04-29 16:14:58Z dion $
*/
public class ASTFalseNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTFalseNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTFalseNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
return Boolean.FALSE;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTFloatLiteral.java 100644 0 0 3211 10500374603 25123 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* represents a float point number.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTFloatLiteral.java 398194 2006-04-29 16:14:58Z dion $
*/
public class ASTFloatLiteral extends SimpleNode {
/** the value of the literal. */
protected Float val;
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTFloatLiteral(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTFloatLiteral(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
return val;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTForeachStatement.java 100644 0 0 6234 10500374603 26005 0 ustar 0 0 /*
* 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.util.Iterator;
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jexl.util.introspection.Info;
/**
* ForEach statement. Syntax: foreach (var in iterable) Statement()
*
* @author Dion Gillard
* @since 1.1
*/
public class ASTForeachStatement extends SimpleNode {
/** dummy velocity info. */
private static final Info DUMMY = new Info("", 1, 1);
/** index of the loop variable. */
private static final int VAR_INDEX = 0;
/** index of the items. */
private static final int ITEMS_INDEX = 1;
/** index of the code to execute. */
private static final int STATEMENT_INDEX = 2;
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTForeachStatement(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTForeachStatement(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
Object result = null;
/* first child is the loop variable */
ASTReference loopVariable = (ASTReference) jjtGetChild(VAR_INDEX);
/* second child is the variable to iterate */
SimpleNode iterable = (SimpleNode) jjtGetChild(ITEMS_INDEX);
Object iterableValue = iterable.value(jc);
// make sure there is a value to iterate on and a statement to execute
if (iterableValue != null && jjtGetNumChildren() >= (STATEMENT_INDEX + 1)) {
/* third child is the statement to execute */
SimpleNode statement = (SimpleNode) jjtGetChild(2);
// get an iterator for the collection/array etc via the
// introspector.
Iterator itemsIterator = Introspector.getUberspect().getIterator(
iterableValue, DUMMY);
while (itemsIterator.hasNext()) {
// set loopVariable to value of iterator
Object value = itemsIterator.next();
jc.getVars().put(loopVariable.getRootString(), value);
// execute statement
result = statement.value(jc);
}
}
return result;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTGENode.java 100644 0 0 6464 10500374603 23657 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* GE : a >= b.
*
* Follows A.3.6.1 of the JSTL 1.0 specification
*
* @author Geir Magnusson Jr.
* @author Peter Royal
* @version $Id: ASTGENode.java 398197 2006-04-29 16:18:04Z dion $
*/
public class ASTGENode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTGENode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTGENode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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);
if (left == right) {
return Boolean.TRUE;
} 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) {
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;
}
throw new Exception("Invalid comparison : GE ");
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTGTNode.java 100644 0 0 6370 10500374603 23672 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* GT : a > b.
*
* Follows A.3.6.1 of the JSTL 1.0 specification
*
* @author Geir Magnusson Jr.
* @author Peter Royal
* @version $Id: ASTGTNode.java 398197 2006-04-29 16:18:04Z dion $
*/
public class ASTGTNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTGTNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTGTNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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);
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) {
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;
}
throw new Exception("Invalid comparison : GT ");
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTIdentifier.java 100644 0 0 5010 10500374603 24622 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* Simple identifier - $foo or $foo.bar (both parts are identifiers).
*
* @author Geir Magnusson Jr.
* @version $Id: ASTIdentifier.java 398199 2006-04-29 16:30:05Z dion $
*/
public class ASTIdentifier extends SimpleNode {
/** the name of the variable. */
protected String val;
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTIdentifier(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTIdentifier(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
return jc.getVars().get(val);
}
/**
* returns the value of itself applied to the object. We assume that an
* identifier can be gotten via a get(String).
* e.g. if we have bean.property, 'property' has been parsed as an identifier,
* and we need to resolve the expression by calling the property getter.
*
* @param obj the object to evaluate against.
* @param jc the {@link JexlContext}.
* @throws Exception on any error.
* @return the resulting value.
* @see ASTArrayAccess#evaluateExpr(Object, Object)
*/
public Object execute(Object obj, JexlContext jc) throws Exception {
return ASTArrayAccess.evaluateExpr(obj, val);
}
/**
* Gets the name of the variable.
* @return the variable name.
*/
public String getIdentifierString() {
return val;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTIfStatement.java 100644 0 0 4247 10500374603 24776 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* if ( expression ) statement [else statement].
*
* @author Dion Gillard
* @since 1.1
*/
public class ASTIfStatement extends SimpleNode {
/** child index of the else statement to execute. */
private static final int ELSE_STATEMENT_INDEX = 2;
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTIfStatement(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTIfStatement(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
Object result = null;
/* first child is the expression */
Object expression = ((SimpleNode) jjtGetChild(0)).value(jc);
if (Coercion.coerceBoolean(expression).booleanValue()) {
// true statement
result = ((SimpleNode) jjtGetChild(1)).value(jc);
} else {
// if there is a false, execute it
if (jjtGetNumChildren() == ELSE_STATEMENT_INDEX + 1) {
result = ((SimpleNode) jjtGetChild(2)).value(jc);
}
}
return result;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java 100644 0 0 4203 10500374603 25455 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* represents an integer.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTIntegerLiteral.java 398202 2006-04-29 16:40:34Z dion $
*/
public class ASTIntegerLiteral extends SimpleNode {
/** literal value. */
protected Integer val;
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTIntegerLiteral(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTIntegerLiteral(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
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...
*
* @param obj the object to evaluate against.
* @param ctx the {@link JexlContext}.
* @throws Exception on any error.
* @return the resulting value.
* @see ASTArrayAccess#evaluateExpr(Object, Object)
*/
public Object execute(Object obj, JexlContext ctx) throws Exception {
return ASTArrayAccess.evaluateExpr(obj, val);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
return val;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTJexlScript.java 100644 0 0 3275 10500374603 24642 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* Top of the syntax tree - parsed Jexl code.
*
* @since 1.1
*/
public class ASTJexlScript extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTJexlScript(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTJexlScript(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTLENode.java 100644 0 0 6464 10500374603 23664 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* LE : a <= b.
*
* Follows A.3.6.1 of the JSTL 1.0 specification
*
* @author Geir Magnusson Jr.
* @author Peter Royal
* @version $Id: ASTLENode.java 398203 2006-04-29 16:44:55Z dion $
*/
public class ASTLENode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTLENode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTLENode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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);
if (left == right) {
return Boolean.TRUE;
} 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) {
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;
}
throw new Exception("Invalid comparison : LE ");
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTLTNode.java 100644 0 0 6372 10500374603 23701 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* LT : a < b.
*
* Follows A.3.6.1 of the JSTL 1.0 specification
*
* @author Geir Magnusson Jr.
* @author Peter Royal
* @version $Id: ASTLTNode.java 398203 2006-04-29 16:44:55Z dion $
*/
public class ASTLTNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTLTNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTLTNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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);
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) {
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;
}
throw new Exception("Invalid comparison : LT ");
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTMethod.java 100644 0 0 12136 10500374603 24007 0 ustar 0 0 /*
* 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;
import java.math.BigDecimal;
import java.math.BigInteger;
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jexl.util.introspection.VelMethod;
import org.apache.commons.jexl.util.introspection.Info;
/**
* Method execution.
*/
public class ASTMethod extends SimpleNode {
/** dummy velocity info. */
private static final Info DUMMY = new Info("", 1, 1);
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTMethod(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTMethod(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/**
* evaluate a method invocation upon a base object.
*
* foo.bar(2)
*
* @param jc the {@link JexlContext} to evaluate against.
* @param obj The object to have the method invoked.
* @return the value of the method invocation.
* @throws Exception on any error
*/
public Object execute(Object obj, JexlContext jc) throws Exception {
String methodName = ((ASTIdentifier) jjtGetChild(0)).val;
int paramCount = jjtGetNumChildren() - 1;
/*
* get our params
*/
Object[] params = new Object[paramCount];
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!
*/
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) {
Throwable t = e.getTargetException();
if (t instanceof Exception) {
throw (Exception) t;
}
throw e;
}
}
/**
* 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.
*
* @param original the original number.
* @return a value of the smallest type the original number will fit into.
* @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
}
return result;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTModNode.java 100644 0 0 6412 10500374603 24074 0 ustar 0 0 /*
* 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.
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* % (mod).
*
* @author Geir Magnusson Jr.
* @version $Id: ASTModNode.java 398206 2006-04-29 16:51:38Z dion $
*/
public class ASTModNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTModNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTModNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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'
*/
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 (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) {
return new Double(0.0);
}
return new Double(l.doubleValue() % r.doubleValue());
}
/*
* otherwise to longs with thee!
*/
Long l = Coercion.coerceLong(left);
Long r = Coercion.coerceLong(right);
/*
* catch the div/0
*/
if (r.longValue() == 0) {
return new Long(0);
}
return new Long(l.longValue() % r.longValue());
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTMulNode.java 100644 0 0 5770 10500374603 24120 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Multiplication.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTMulNode.java 398206 2006-04-29 16:51:38Z dion $
*/
public class ASTMulNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTMulNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTMulNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
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'
*/
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 (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());
}
/*
* otherwise to longs with thee!
*/
Long l = Coercion.coerceLong(left);
Long r = Coercion.coerceLong(right);
return new Long(l.longValue() * r.longValue());
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTNENode.java 100644 0 0 6257 10500374603 23666 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Not equal to. Use '!=' or 'ne', do not use <>.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTNENode.java 398270 2006-04-30 03:02:58Z dion $
*/
public class ASTNENode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTNENode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTNENode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext pc) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(pc);
Object right = ((SimpleNode) jjtGetChild(1)).value(pc);
if (left == null && right == null) {
/*
* first, the possibility that both *are* null
*/
return Boolean.FALSE;
} else if (left == null || right == null) {
/*
* otherwise, both aren't, so it's clear L != R
*/
return Boolean.TRUE;
} else if (left.getClass().equals(right.getClass())) {
return (left.equals(right)) ? Boolean.FALSE : Boolean.TRUE;
} else if (left instanceof Float
|| left instanceof Double
|| right instanceof Float
|| right instanceof Double) {
return (Coercion.coerceDouble(left).equals(Coercion.coerceDouble(right))) ? Boolean.FALSE : Boolean.TRUE;
} else if (left instanceof Number || right instanceof Number || left instanceof Character
|| right instanceof Character) {
return (Coercion.coerceLong(left).equals(Coercion.coerceLong(right))) ? Boolean.FALSE : Boolean.TRUE;
} else if (left instanceof Boolean || right instanceof Boolean) {
return (Coercion.coerceBoolean(left).equals(Coercion.coerceBoolean(right))) ? Boolean.FALSE : Boolean.TRUE;
} else if (left instanceof java.lang.String || right instanceof String) {
return (left.toString().equals(right.toString())) ? Boolean.FALSE : Boolean.TRUE;
}
return (left.equals(right)) ? Boolean.FALSE : Boolean.TRUE;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTNotNode.java 100644 0 0 3630 10500374603 24114 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* Not : 'not' or '!'.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTNotNode.java 398270 2006-04-30 03:02:58Z dion $
*/
public class ASTNotNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTNotNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTNotNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
Object val = ((SimpleNode) jjtGetChild(0)).value(jc);
/*
* coercion rules
*/
Boolean b = Coercion.coerceBoolean(val);
if (b != null) {
return b.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
}
throw new Exception("expression not boolean valued");
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTNullLiteral.java 100644 0 0 2726 10500374603 25002 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* 'null'.
*
* @author Geir Magnusson Jr.
*/
public class ASTNullLiteral extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTNullLiteral(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTNullLiteral(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) {
return null;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTOrNode.java 100644 0 0 3634 10500374603 23740 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.util.Coercion;
import org.apache.commons.jexl.JexlContext;
/**
* || and 'or'.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTOrNode.java 398272 2006-04-30 03:14:01Z dion $
*/
public class ASTOrNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTOrNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTOrNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
Object left = ((SimpleNode) jjtGetChild(0)).value(jc);
boolean leftValue = Coercion.coerceBoolean(left).booleanValue();
/*
* coercion rules
*/
return (leftValue || Coercion.coerceBoolean(((SimpleNode) jjtGetChild(1)).value(jc)).booleanValue())
? Boolean.TRUE
: Boolean.FALSE;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTReference.java 100644 0 0 10414 10500374603 24462 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* reference - any variable expression.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTReference.java 398272 2006-04-30 03:14:01Z dion $
*/
public class ASTReference extends SimpleNode {
/** first variable in the expression. */
protected SimpleNode root;
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTReference(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTReference(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
return execute(null, jc);
}
/** Store the first child as {@link ASTReference#root root}. */
public void jjtClose() {
root = (SimpleNode) jjtGetChild(0);
}
/**
* evaluate each piece of the reference.
*
* e.g. foo.bar.woogie[2].name, foo is our 'root', and we need to
* evaluate 'bar.woogie[2].name' relative to foo.
*
* @param jc the {@link JexlContext} to evaluate against.
* @param obj not used. root.value(jc) is used instead.
* @return the value of the array expression.
* @throws Exception on any error
*/
public Object execute(Object obj, JexlContext jc) throws Exception {
Object o = root.value(jc);
/*
* ignore the first child - it's our identifier
*/
for (int i = 1; i < jjtGetNumChildren(); i++) {
o = ((SimpleNode) jjtGetChild(i)).execute(o, jc);
// check for a variable in the context named
// child0.child1.child2 etc
if (o == null) {
String varName = getIdentifierToDepth(i);
o = jc.getVars().get(varName);
}
}
return o;
}
/**
* This method returns a variable from this identifier and it's children.
* For an expression like 'a.b.c', a is child zero, b is child 1 and c is
* child 2.
*
* @param i the depth of the child nodes to go to
* @return the a dotted variable from this identifier and it's child nodes.
*/
private String getIdentifierToDepth(int i) {
StringBuffer varName = new StringBuffer();
for (int j = 0; j <= i; j++) {
SimpleNode node = (SimpleNode) jjtGetChild(j);
if (node instanceof ASTIdentifier) {
varName.append(((ASTIdentifier) node).getIdentifierString());
if (j != i) {
varName.append('.');
}
}
}
return varName.toString();
}
/**
* Gets the variable name of {@link ASTReference#root root}.
* @return the identifier.
* @throws Exception on any error
* @see ASTIdentifier#getIdentifierString()
* @see ASTArrayAccess#getIdentifierString()
*/
public String getRootString() throws Exception {
if (root instanceof ASTIdentifier) {
return ((ASTIdentifier) root).getIdentifierString();
}
if (root instanceof ASTArrayAccess) {
return ((ASTArrayAccess) root).getIdentifierString();
}
throw new Exception("programmer error : ASTReference : root not known" + root);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTReferenceExpression.java 100644 0 0 2764 10500374603 26533 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* variable; A reference by itself.
*/
public class ASTReferenceExpression extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTReferenceExpression(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTReferenceExpression(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
return ((SimpleNode) jjtGetChild(0)).value(context);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java 100644 0 0 6733 10500374603 25175 0 ustar 0 0 /*
* 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.Array;
import java.util.Collection;
import java.util.Map;
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jexl.util.introspection.Info;
import org.apache.commons.jexl.util.introspection.VelMethod;
/**
* generalized size() function for all classes we can think of.
*
* @author Geir Magnusson Jr.
* @author Mark H. Wilkinson
* @version $Id: ASTSizeFunction.java 398324 2006-04-30 12:20:24Z dion $
*/
public class ASTSizeFunction extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTSizeFunction(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTSizeFunction(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
SimpleNode arg = (SimpleNode) jjtGetChild(0);
Object val = arg.value(jc);
if (val == null) {
throw new Exception("size() : null arg");
}
return new Integer(ASTSizeFunction.sizeOf(val));
}
/**
* Calculate the size
of various types: Collection, Array, Map, String,
* and anything that has a int size() method.
*
* @param val the object to get the size of.
* @return the size of val
* @throws Exception if the size cannot be determined.
*/
public static int sizeOf(Object val) throws Exception {
if (val instanceof Collection) {
return ((Collection) val).size();
} else if (val.getClass().isArray()) {
return Array.getLength(val);
} else if (val instanceof Map) {
return ((Map) val).size();
} else if (val instanceof String) {
return ((String) val).length();
} else {
// check if there is a size method on the object that returns an
// integer
// and if so, just use it
Object[] params = new Object[0];
Info velInfo = new Info("", 1, 1);
VelMethod vm = Introspector.getUberspect().getMethod(val, "size", params, velInfo);
if (vm != null && vm.getReturnType() == Integer.TYPE) {
Integer result = (Integer) vm.invoke(val, params);
return result.intValue();
}
throw new Exception("size() : unknown type : " + val.getClass());
}
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTSizeMethod.java 100644 0 0 3577 10500374603 24633 0 ustar 0 0 /*
* Copyright 2003,2004 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 org.apache.commons.jexl.JexlContext;
/**
* Size Method, e.g. size().
*
* @author Mark H. Wilkinson
* @version $Id: ASTSizeMethod.java 398324 2006-04-30 12:20:24Z dion $
*/
public class ASTSizeMethod extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTSizeMethod(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTSizeMethod(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/**
* evaluate size as part of an expression on a base object.
*
* foo.bar.size
*
* @param jc the {@link JexlContext} to evaluate against.
* @param obj not used.
* @return the value of the array expression.
* @throws Exception on any error
*/
public Object execute(Object obj, JexlContext jc) throws Exception {
return new Integer(ASTSizeFunction.sizeOf(obj));
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTStatementExpression.java 100644 0 0 2760 10500374603 26575 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* Assignment as an expression.
*/
public class ASTStatementExpression extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTStatementExpression(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTStatementExpression(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext context) throws Exception {
return ((SimpleNode) jjtGetChild(0)).value(context);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTStringLiteral.java 100644 0 0 3211 10500374603 25324 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* represents a quoted string.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTStringLiteral.java 398324 2006-04-30 12:20:24Z dion $
*/
public class ASTStringLiteral extends SimpleNode {
/** the parsed literal. */
protected String literal;
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTStringLiteral(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTStringLiteral(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
return literal;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTSubtractNode.java 100644 0 0 6114 10500374603 25143 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.util.Coercion;
import org.apache.commons.jexl.JexlContext;
/**
* Subtraction.
*
* @author Geir Magnusson Jr.
* @author Mark H. Wilkinson
* @version $Id: ASTSubtractNode.java 398325 2006-04-30 12:34:29Z dion $
*/
public class ASTSubtractNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTSubtractNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTSubtractNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
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'
*/
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 (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());
}
/*
* otherwise to longs with thee!
*/
Long l = Coercion.coerceLong(left);
Long r = Coercion.coerceLong(right);
return new Long(l.longValue() - r.longValue());
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTTrueNode.java 100644 0 0 3070 10500374603 24271 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
/**
* represents Boolean true.
*
* @author Geir Magnusson Jr.
* @version $Id: ASTTrueNode.java 398325 2006-04-30 12:34:29Z dion $
*/
public class ASTTrueNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTTrueNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTTrueNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
return Boolean.TRUE;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTUnaryMinusNode.java 100644 0 0 5636 10500374603 25476 0 ustar 0 0 /*
* 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.math.BigDecimal;
import java.math.BigInteger;
import org.apache.commons.jexl.JexlContext;
/**
* - (unary minus).
*
* @author Mark H. Wilkinson
* @version $Id: ASTUnaryMinusNode.java 398325 2006-04-30 12:34:29Z dion $
*/
public class ASTUnaryMinusNode extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTUnaryMinusNode(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTUnaryMinusNode(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
Object val = ((SimpleNode) jjtGetChild(0)).value(jc);
if (val instanceof Byte) {
byte valueAsByte = ((Byte) val).byteValue();
return new Byte((byte) -valueAsByte);
} else if (val instanceof Short) {
short valueAsShort = ((Short) val).shortValue();
return new Short((short) -valueAsShort);
} else if (val instanceof Integer) {
int valueAsInt = ((Integer) val).intValue();
return new Integer(-valueAsInt);
} else if (val instanceof Long) {
long valueAsLong = ((Long) val).longValue();
return new Long(-valueAsLong);
} else if (val instanceof Float) {
float valueAsFloat = ((Float) val).floatValue();
return new Float(-valueAsFloat);
} else if (val instanceof Double) {
double valueAsDouble = ((Double) val).doubleValue();
return new Double(-valueAsDouble);
} else if (val instanceof BigDecimal) {
BigDecimal valueAsBigD = (BigDecimal) val;
return valueAsBigD.negate();
} else if (val instanceof BigInteger) {
BigInteger valueAsBigI = (BigInteger) val;
return valueAsBigI.negate();
}
throw new Exception("expression not a number");
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ASTWhileStatement.java 100644 0 0 3573 10500374603 25511 0 ustar 0 0 /*
* 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 org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
/**
* A while loop. Syntax: while ( expression ) statement
*
* @author Dion Gillard
* @since 1.1
*/
public class ASTWhileStatement extends SimpleNode {
/**
* Create the node given an id.
*
* @param id node id.
*/
public ASTWhileStatement(int id) {
super(id);
}
/**
* Create a node with the given parser and id.
*
* @param p a parser.
* @param id node id.
*/
public ASTWhileStatement(Parser p, int id) {
super(p, id);
}
/** {@inheritDoc} */
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
/** {@inheritDoc} */
public Object value(JexlContext jc) throws Exception {
Object result = null;
/* first child is the expression */
SimpleNode expressionNode = (SimpleNode) jjtGetChild(0);
while (Coercion.coerceBoolean(expressionNode.value(jc)).booleanValue()) {
// execute statement
result = ((SimpleNode) jjtGetChild(1)).value(jc);
}
return result;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/JJTParserState.java 100644 0 0 10205 10500374603 25017 0 ustar 0 0 /*
* 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.
*/
/* Generated By:JJTree: Do not edit this line. JJTParserState.java */
package org.apache.commons.jexl.parser;
import java.util.Stack;
class JJTParserState {
private final Stack nodes;
private final Stack marks;
private int sp; // number of nodes on stack
private int mk; // current mark
private boolean node_created;
JJTParserState() {
nodes = new Stack();
marks = new Stack();
sp = 0;
mk = 0;
}
/*
* Determines whether the current node was actually closed and pushed. This
* should only be called in the final user action of a node scope.
*/
boolean nodeCreated() {
return node_created;
}
/*
* Call this to reinitialize the node stack. It is called automatically by
* the parser's ReInit() method.
*/
void reset() {
nodes.removeAllElements();
marks.removeAllElements();
sp = 0;
mk = 0;
}
/*
* Returns the root node of the AST. It only makes sense to call this after
* a successful parse.
*/
Node rootNode() {
return (Node) nodes.elementAt(0);
}
/* Pushes a node on to the stack. */
void pushNode(Node n) {
nodes.push(n);
++sp;
}
/*
* Returns the node on the top of the stack, and remove it from the stack.
*/
Node popNode() {
if (--sp < mk) {
mk = ((Integer) marks.pop()).intValue();
}
return (Node) nodes.pop();
}
/* Returns the node currently on the top of the stack. */
Node peekNode() {
return (Node) nodes.peek();
}
/*
* Returns the number of children on the stack in the current node scope.
*/
int nodeArity() {
return sp - mk;
}
void clearNodeScope(Node n) {
while (sp > mk) {
popNode();
}
mk = ((Integer) marks.pop()).intValue();
}
void openNodeScope(Node n) {
marks.push(new Integer(mk));
mk = sp;
n.jjtOpen();
}
/*
* A definite node is constructed from a specified number of children. That
* number of nodes are popped from the stack and made the children of the
* definite node. Then the definite node is pushed on to the stack.
*/
void closeNodeScope(Node n, int num) {
mk = ((Integer) marks.pop()).intValue();
while (num-- > 0) {
Node c = popNode();
c.jjtSetParent(n);
n.jjtAddChild(c, num);
}
n.jjtClose();
pushNode(n);
node_created = true;
}
/*
* A conditional node is constructed if its condition is true. All the nodes
* that have been pushed since the node was opened are made children of the
* the conditional node, which is then pushed on to the stack. If the
* condition is false the node is not constructed and they are left on the
* stack.
*/
void closeNodeScope(Node n, boolean condition) {
if (condition) {
int a = nodeArity();
mk = ((Integer) marks.pop()).intValue();
while (a-- > 0) {
Node c = popNode();
c.jjtSetParent(n);
n.jjtAddChild(c, a);
}
n.jjtClose();
pushNode(n);
node_created = true;
} else {
mk = ((Integer) marks.pop()).intValue();
node_created = false;
}
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/Node.java 100644 0 0 4501 10500374603 23061 0 ustar 0 0 /*
* 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.
*/
/* Generated By:JJTree: Do not edit this line. Node.java */
package org.apache.commons.jexl.parser;
/**
* All AST nodes must implement this interface. It provides basic machinery for
* constructing the parent and child relationships between nodes.
*/
public interface Node {
/**
* This method is called after the node has been made the current node. It
* indicates that child nodes can now be added to it.
*/
void jjtOpen();
/**
* This method is called after all the child nodes have been added.
*/
void jjtClose();
/**
* This pair of methods are used to inform the node of its parent.
* @param n the parent node.
*/
void jjtSetParent(Node n);
/**
* Gets the parent node.
* @return the parent to this node.
*/
Node jjtGetParent();
/**
* This method tells the node to add its argument to the node's list of
* children.
* @param n the child node to add
* @param i the index to add it at.
*/
void jjtAddChild(Node n, int i);
/**
* This method returns a child node. The children are numbered from zero,
* left to right.
* @param i the index of the child to get.
* @return the child at the given index.
*/
Node jjtGetChild(int i);
/**
* Gets the number of children the node has.
* @return the number of children the node has.
*/
int jjtGetNumChildren();
/**
* Accept the visitor.
* @param data arbitrary data.
* @param visitor the visitor.
* @return the result of the visit.
*/
Object jjtAccept(ParserVisitor visitor, Object data);
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/package.html 100644 0 0 621 10500374603 23571 0 ustar 0 0
This package contains the Parser for JEXL script.
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/ParseException.java 100644 0 0 17152 10500374603 25153 0 ustar 0 0 /* * 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. */ /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 2.1 */ package org.apache.commons.jexl.parser; /** * This exception is thrown when parse errors are encountered. You can * explicitly create objects of this exception type by calling the method * generateParseException in the generated parser. * * You can modify this class to customize your error reporting mechanisms so * long as you retain the public fields. */ public class ParseException extends Exception { /** serialization version id jdk13 generated. */ static final long serialVersionUID = 654626477565941968L; /** * This constructor is used by the method "generateParseException" in the * generated parser. Calling this constructor generates a new object of this * type with the fields "currentToken", "expectedTokenSequences", and * "tokenImage" set. The boolean flag "specialConstructor" is also set to * true to indicate that this constructor was used to create this object. * This constructor calls its super class with the empty string to force the * "toString" method of parent class "Throwable" to print the error message * in the form: ParseException: (result of getMessage) */ public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal) { super(""); specialConstructor = true; currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; } /** * The following constructors are for use by you for whatever purpose you * can think of. Constructing the exception in this manner makes the * exception behave in the normal way - i.e., as documented in the class * "Throwable". The fields "errorToken", "expectedTokenSequences", and * "tokenImage" do not contain relevant information. The JavaCC generated * code does not use these constructors. */ public ParseException() { super(); specialConstructor = false; } public ParseException(String message) { super(message); specialConstructor = false; } /** * This variable determines which constructor was used to create this object * and thereby affects the semantics of the "getMessage" method (see below). */ protected boolean specialConstructor; /** * This is the last token that has been consumed successfully. If this * object has been created due to a parse error, the token followng this * token will (therefore) be the first error token. */ public Token currentToken; /** * Each entry in this array is an array of integers. Each array of integers * represents a sequence of tokens (by their ordinal values) that is * expected at this point of the parse. */ public int[][] expectedTokenSequences; /** * This is a reference to the "tokenImage" array of the generated parser * within which the parse error occurred. This array is defined in the * generated ...Constants interface. */ public String[] tokenImage; /** * This method has the standard behavior when this object has been created * using the standard constructors. Otherwise, it uses "currentToken" and * "expectedTokenSequences" to generate a parse error message and returns * it. If this object has been created due to a parse error, and you do not * catch it (it gets thrown from the parser), then this method is called * during the printing of the final stack trace, and hence the correct error * message gets displayed. */ public String getMessage() { if (!specialConstructor) { return super.getMessage(); } String expected = ""; int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { expected += tokenImage[expectedTokenSequences[i][j]] + " "; } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected += "..."; } expected += eol + " "; } String retval = "Encountered \""; Token tok = currentToken.next; for (int i = 0; i < maxSize; i++) { if (i != 0) retval += " "; if (tok.kind == 0) { retval += tokenImage[0]; break; } retval += add_escapes(tok.image); tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; if (expectedTokenSequences.length == 1) { retval += "Was expecting:" + eol + " "; } else { retval += "Was expecting one of:" + eol + " "; } retval += expected; return retval; } /** * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); /** * Used to convert raw characters to their escaped version when these raw * version cannot be used as part of an ASCII string literal. */ protected String add_escapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 0: continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u").append(s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/Parser.java 100644 0 0 426304 10500374603 23501 0 ustar 0 0 /* * 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. */ /* Generated By:JJTree&JavaCC: Do not edit this line. Parser.java */ package org.apache.commons.jexl.parser; import java.io.Reader; public class Parser/* @bgen(jjtree) */implements ParserTreeConstants, ParserConstants { /* @bgen(jjtree) */ protected JJTParserState jjtree = new JJTParserState(); public SimpleNode parse(Reader reader) throws Exception { ReInit(reader); /* * lets do the 'Unique Init' in here to be safe - it's a pain to * remember */ SimpleNode tree = JexlScript(); return tree; } /* * Program structuring syntax follows. */ public final SimpleNode JexlScript() throws ParseException { /* @bgen(jjtree) JexlScript */ ASTJexlScript jjtn000 = new ASTJexlScript(this, JJTJEXLSCRIPT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); String name; try { label_1: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case FLOAT_LITERAL: case 9: case 11: case 12: case 14: case 36: case 42: case 43: case 44: case 45: case 46: case 47: case 48: case 49: case 51: case 52: case IDENTIFIER: case STRING_LITERAL: ; break; default: jj_la1[0] = jj_gen; break label_1; } Statement(); } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; { if (true) return jjtn000; } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } throw new Error("Missing return statement in function"); } final public void Block() throws ParseException { /* @bgen(jjtree) Block */ ASTBlock jjtn000 = new ASTBlock(this, JJTBLOCK); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(9); label_2: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case FLOAT_LITERAL: case 9: case 11: case 12: case 14: case 36: case 42: case 43: case 44: case 45: case 46: case 47: case 48: case 49: case 51: case 52: case IDENTIFIER: case STRING_LITERAL: ; break; default: jj_la1[1] = jj_gen; break label_2; } Statement(); } jj_consume_token(10); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void EmptyFunction() throws ParseException { /* @bgen(jjtree) EmptyFunction */ ASTEmptyFunction jjtn000 = new ASTEmptyFunction(this, JJTEMPTYFUNCTION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(11); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case IDENTIFIER: Reference(); break; case 12: jj_consume_token(12); Reference(); jj_consume_token(13); break; default: jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void SizeFunction() throws ParseException { /* @bgen(jjtree) SizeFunction */ ASTSizeFunction jjtn000 = new ASTSizeFunction(this, JJTSIZEFUNCTION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(14); jj_consume_token(12); Reference(); jj_consume_token(13); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void Identifier() throws ParseException { /* @bgen(jjtree) Identifier */ ASTIdentifier jjtn000 = new ASTIdentifier(this, JJTIDENTIFIER); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); Token t; try { t = jj_consume_token(IDENTIFIER); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.val = t.image; } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } /* * Expression syntax follows. */ final public void Expression() throws ParseException { /* @bgen(jjtree) Expression */ ASTExpression jjtn000 = new ASTExpression(this, JJTEXPRESSION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { if (jj_2_1(2147483647)) { Assignment(); } else { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case FLOAT_LITERAL: case 11: case 12: case 14: case 36: case 42: case 43: case 44: case 45: case 46: case 47: case IDENTIFIER: case STRING_LITERAL: ConditionalOrExpression(); break; default: jj_la1[3] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void Assignment() throws ParseException { /* @bgen(jjtree) #Assignment( 2) */ ASTAssignment jjtn000 = new ASTAssignment(this, JJTASSIGNMENT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { PrimaryExpression(); jj_consume_token(15); Expression(); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, 2); } } } final public void ConditionalOrExpression() throws ParseException { ConditionalAndExpression(); label_3: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 16: case 17: ; break; default: jj_la1[4] = jj_gen; break label_3; } switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 16: jj_consume_token(16); ASTOrNode jjtn001 = new ASTOrNode(this, JJTORNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { ConditionalAndExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } break; case 17: jj_consume_token(17); ASTOrNode jjtn002 = new ASTOrNode(this, JJTORNODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { ConditionalAndExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte002; } } if (jjte002 instanceof ParseException) { { if (true) throw (ParseException) jjte002; } } { if (true) throw (Error) jjte002; } } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); } } break; default: jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void ConditionalAndExpression() throws ParseException { InclusiveOrExpression(); label_4: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 18: case 19: ; break; default: jj_la1[6] = jj_gen; break label_4; } switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 18: jj_consume_token(18); ASTAndNode jjtn001 = new ASTAndNode(this, JJTANDNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { InclusiveOrExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } break; case 19: jj_consume_token(19); ASTAndNode jjtn002 = new ASTAndNode(this, JJTANDNODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { InclusiveOrExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte002; } } if (jjte002 instanceof ParseException) { { if (true) throw (ParseException) jjte002; } } { if (true) throw (Error) jjte002; } } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); } } break; default: jj_la1[7] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void InclusiveOrExpression() throws ParseException { ExclusiveOrExpression(); label_5: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 20: ; break; default: jj_la1[8] = jj_gen; break label_5; } jj_consume_token(20); ASTBitwiseOrNode jjtn001 = new ASTBitwiseOrNode(this, JJTBITWISEORNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { ExclusiveOrExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } } } final public void ExclusiveOrExpression() throws ParseException { AndExpression(); label_6: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 21: ; break; default: jj_la1[9] = jj_gen; break label_6; } jj_consume_token(21); ASTBitwiseXorNode jjtn001 = new ASTBitwiseXorNode(this, JJTBITWISEXORNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { AndExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } } } final public void AndExpression() throws ParseException { EqualityExpression(); label_7: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 22: ; break; default: jj_la1[10] = jj_gen; break label_7; } jj_consume_token(22); ASTBitwiseAndNode jjtn001 = new ASTBitwiseAndNode(this, JJTBITWISEANDNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { EqualityExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } } } final public void EqualityExpression() throws ParseException { RelationalExpression(); label_8: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 23: case 24: case 25: case 26: ; break; default: jj_la1[11] = jj_gen; break label_8; } switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 23: jj_consume_token(23); ASTEQNode jjtn001 = new ASTEQNode(this, JJTEQNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { RelationalExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } break; case 24: jj_consume_token(24); ASTEQNode jjtn002 = new ASTEQNode(this, JJTEQNODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { RelationalExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte002; } } if (jjte002 instanceof ParseException) { { if (true) throw (ParseException) jjte002; } } { if (true) throw (Error) jjte002; } } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); } } break; case 25: jj_consume_token(25); ASTNENode jjtn003 = new ASTNENode(this, JJTNENODE); boolean jjtc003 = true; jjtree.openNodeScope(jjtn003); try { RelationalExpression(); } catch (Throwable jjte003) { if (jjtc003) { jjtree.clearNodeScope(jjtn003); jjtc003 = false; } else { jjtree.popNode(); } if (jjte003 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte003; } } if (jjte003 instanceof ParseException) { { if (true) throw (ParseException) jjte003; } } { if (true) throw (Error) jjte003; } } finally { if (jjtc003) { jjtree.closeNodeScope(jjtn003, 2); } } break; case 26: jj_consume_token(26); ASTNENode jjtn004 = new ASTNENode(this, JJTNENODE); boolean jjtc004 = true; jjtree.openNodeScope(jjtn004); try { RelationalExpression(); } catch (Throwable jjte004) { if (jjtc004) { jjtree.clearNodeScope(jjtn004); jjtc004 = false; } else { jjtree.popNode(); } if (jjte004 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte004; } } if (jjte004 instanceof ParseException) { { if (true) throw (ParseException) jjte004; } } { if (true) throw (Error) jjte004; } } finally { if (jjtc004) { jjtree.closeNodeScope(jjtn004, 2); } } break; default: jj_la1[12] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void RelationalExpression() throws ParseException { AdditiveExpression(); label_9: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 27: case 28: case 29: case 30: case 31: case 32: case 33: case 34: ; break; default: jj_la1[13] = jj_gen; break label_9; } switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 27: jj_consume_token(27); ASTLTNode jjtn001 = new ASTLTNode(this, JJTLTNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { AdditiveExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } break; case 28: jj_consume_token(28); ASTLTNode jjtn002 = new ASTLTNode(this, JJTLTNODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { AdditiveExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte002; } } if (jjte002 instanceof ParseException) { { if (true) throw (ParseException) jjte002; } } { if (true) throw (Error) jjte002; } } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); } } break; case 29: jj_consume_token(29); ASTGTNode jjtn003 = new ASTGTNode(this, JJTGTNODE); boolean jjtc003 = true; jjtree.openNodeScope(jjtn003); try { AdditiveExpression(); } catch (Throwable jjte003) { if (jjtc003) { jjtree.clearNodeScope(jjtn003); jjtc003 = false; } else { jjtree.popNode(); } if (jjte003 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte003; } } if (jjte003 instanceof ParseException) { { if (true) throw (ParseException) jjte003; } } { if (true) throw (Error) jjte003; } } finally { if (jjtc003) { jjtree.closeNodeScope(jjtn003, 2); } } break; case 30: jj_consume_token(30); ASTGTNode jjtn004 = new ASTGTNode(this, JJTGTNODE); boolean jjtc004 = true; jjtree.openNodeScope(jjtn004); try { AdditiveExpression(); } catch (Throwable jjte004) { if (jjtc004) { jjtree.clearNodeScope(jjtn004); jjtc004 = false; } else { jjtree.popNode(); } if (jjte004 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte004; } } if (jjte004 instanceof ParseException) { { if (true) throw (ParseException) jjte004; } } { if (true) throw (Error) jjte004; } } finally { if (jjtc004) { jjtree.closeNodeScope(jjtn004, 2); } } break; case 31: jj_consume_token(31); ASTLENode jjtn005 = new ASTLENode(this, JJTLENODE); boolean jjtc005 = true; jjtree.openNodeScope(jjtn005); try { AdditiveExpression(); } catch (Throwable jjte005) { if (jjtc005) { jjtree.clearNodeScope(jjtn005); jjtc005 = false; } else { jjtree.popNode(); } if (jjte005 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte005; } } if (jjte005 instanceof ParseException) { { if (true) throw (ParseException) jjte005; } } { if (true) throw (Error) jjte005; } } finally { if (jjtc005) { jjtree.closeNodeScope(jjtn005, 2); } } break; case 32: jj_consume_token(32); ASTLENode jjtn006 = new ASTLENode(this, JJTLENODE); boolean jjtc006 = true; jjtree.openNodeScope(jjtn006); try { AdditiveExpression(); } catch (Throwable jjte006) { if (jjtc006) { jjtree.clearNodeScope(jjtn006); jjtc006 = false; } else { jjtree.popNode(); } if (jjte006 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte006; } } if (jjte006 instanceof ParseException) { { if (true) throw (ParseException) jjte006; } } { if (true) throw (Error) jjte006; } } finally { if (jjtc006) { jjtree.closeNodeScope(jjtn006, 2); } } break; case 33: jj_consume_token(33); ASTGENode jjtn007 = new ASTGENode(this, JJTGENODE); boolean jjtc007 = true; jjtree.openNodeScope(jjtn007); try { AdditiveExpression(); } catch (Throwable jjte007) { if (jjtc007) { jjtree.clearNodeScope(jjtn007); jjtc007 = false; } else { jjtree.popNode(); } if (jjte007 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte007; } } if (jjte007 instanceof ParseException) { { if (true) throw (ParseException) jjte007; } } { if (true) throw (Error) jjte007; } } finally { if (jjtc007) { jjtree.closeNodeScope(jjtn007, 2); } } break; case 34: jj_consume_token(34); ASTGENode jjtn008 = new ASTGENode(this, JJTGENODE); boolean jjtc008 = true; jjtree.openNodeScope(jjtn008); try { AdditiveExpression(); } catch (Throwable jjte008) { if (jjtc008) { jjtree.clearNodeScope(jjtn008); jjtc008 = false; } else { jjtree.popNode(); } if (jjte008 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte008; } } if (jjte008 instanceof ParseException) { { if (true) throw (ParseException) jjte008; } } { if (true) throw (Error) jjte008; } } finally { if (jjtc008) { jjtree.closeNodeScope(jjtn008, 2); } } break; default: jj_la1[14] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void AdditiveExpression() throws ParseException { MultiplicativeExpression(); label_10: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 35: case 36: ; break; default: jj_la1[15] = jj_gen; break label_10; } switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 35: jj_consume_token(35); ASTAddNode jjtn001 = new ASTAddNode(this, JJTADDNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { MultiplicativeExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } break; case 36: jj_consume_token(36); ASTSubtractNode jjtn002 = new ASTSubtractNode(this, JJTSUBTRACTNODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { MultiplicativeExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte002; } } if (jjte002 instanceof ParseException) { { if (true) throw (ParseException) jjte002; } } { if (true) throw (Error) jjte002; } } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); } } break; default: jj_la1[16] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void MultiplicativeExpression() throws ParseException { UnaryExpression(); label_11: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 37: case 38: case 39: case 40: case 41: ; break; default: jj_la1[17] = jj_gen; break label_11; } switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 37: jj_consume_token(37); ASTMulNode jjtn001 = new ASTMulNode(this, JJTMULNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { UnaryExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 2); } } break; case 38: jj_consume_token(38); ASTDivNode jjtn002 = new ASTDivNode(this, JJTDIVNODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { UnaryExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte002; } } if (jjte002 instanceof ParseException) { { if (true) throw (ParseException) jjte002; } } { if (true) throw (Error) jjte002; } } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 2); } } break; case 39: jj_consume_token(39); ASTDivNode jjtn003 = new ASTDivNode(this, JJTDIVNODE); boolean jjtc003 = true; jjtree.openNodeScope(jjtn003); try { UnaryExpression(); } catch (Throwable jjte003) { if (jjtc003) { jjtree.clearNodeScope(jjtn003); jjtc003 = false; } else { jjtree.popNode(); } if (jjte003 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte003; } } if (jjte003 instanceof ParseException) { { if (true) throw (ParseException) jjte003; } } { if (true) throw (Error) jjte003; } } finally { if (jjtc003) { jjtree.closeNodeScope(jjtn003, 2); } } break; case 40: jj_consume_token(40); ASTModNode jjtn004 = new ASTModNode(this, JJTMODNODE); boolean jjtc004 = true; jjtree.openNodeScope(jjtn004); try { UnaryExpression(); } catch (Throwable jjte004) { if (jjtc004) { jjtree.clearNodeScope(jjtn004); jjtc004 = false; } else { jjtree.popNode(); } if (jjte004 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte004; } } if (jjte004 instanceof ParseException) { { if (true) throw (ParseException) jjte004; } } { if (true) throw (Error) jjte004; } } finally { if (jjtc004) { jjtree.closeNodeScope(jjtn004, 2); } } break; case 41: jj_consume_token(41); ASTModNode jjtn005 = new ASTModNode(this, JJTMODNODE); boolean jjtc005 = true; jjtree.openNodeScope(jjtn005); try { UnaryExpression(); } catch (Throwable jjte005) { if (jjtc005) { jjtree.clearNodeScope(jjtn005); jjtc005 = false; } else { jjtree.popNode(); } if (jjte005 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte005; } } if (jjte005 instanceof ParseException) { { if (true) throw (ParseException) jjte005; } } { if (true) throw (Error) jjte005; } } finally { if (jjtc005) { jjtree.closeNodeScope(jjtn005, 2); } } break; default: jj_la1[18] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final public void UnaryExpression() throws ParseException { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 36: jj_consume_token(36); ASTUnaryMinusNode jjtn001 = new ASTUnaryMinusNode(this, JJTUNARYMINUSNODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { UnaryExpression(); } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte001; } } if (jjte001 instanceof ParseException) { { if (true) throw (ParseException) jjte001; } } { if (true) throw (Error) jjte001; } } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, 1); } } break; case 42: jj_consume_token(42); ASTBitwiseComplNode jjtn002 = new ASTBitwiseComplNode(this, JJTBITWISECOMPLNODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { UnaryExpression(); } catch (Throwable jjte002) { if (jjtc002) { jjtree.clearNodeScope(jjtn002); jjtc002 = false; } else { jjtree.popNode(); } if (jjte002 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte002; } } if (jjte002 instanceof ParseException) { { if (true) throw (ParseException) jjte002; } } { if (true) throw (Error) jjte002; } } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, 1); } } break; case 43: jj_consume_token(43); ASTNotNode jjtn003 = new ASTNotNode(this, JJTNOTNODE); boolean jjtc003 = true; jjtree.openNodeScope(jjtn003); try { UnaryExpression(); } catch (Throwable jjte003) { if (jjtc003) { jjtree.clearNodeScope(jjtn003); jjtc003 = false; } else { jjtree.popNode(); } if (jjte003 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte003; } } if (jjte003 instanceof ParseException) { { if (true) throw (ParseException) jjte003; } } { if (true) throw (Error) jjte003; } } finally { if (jjtc003) { jjtree.closeNodeScope(jjtn003, 1); } } break; case 44: jj_consume_token(44); ASTNotNode jjtn004 = new ASTNotNode(this, JJTNOTNODE); boolean jjtc004 = true; jjtree.openNodeScope(jjtn004); try { UnaryExpression(); } catch (Throwable jjte004) { if (jjtc004) { jjtree.clearNodeScope(jjtn004); jjtc004 = false; } else { jjtree.popNode(); } if (jjte004 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte004; } } if (jjte004 instanceof ParseException) { { if (true) throw (ParseException) jjte004; } } { if (true) throw (Error) jjte004; } } finally { if (jjtc004) { jjtree.closeNodeScope(jjtn004, 1); } } break; case INTEGER_LITERAL: case FLOAT_LITERAL: case 11: case 12: case 14: case 45: case 46: case 47: case IDENTIFIER: case STRING_LITERAL: PrimaryExpression(); break; default: jj_la1[19] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public void PrimaryExpression() throws ParseException { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case FLOAT_LITERAL: case 45: case 46: case 47: case STRING_LITERAL: Literal(); break; case IDENTIFIER: Reference(); break; case 12: jj_consume_token(12); Expression(); jj_consume_token(13); break; case 11: EmptyFunction(); break; case 14: SizeFunction(); break; default: jj_la1[20] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public void Literal() throws ParseException { Token t; switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: IntegerLiteral(); break; case FLOAT_LITERAL: FloatLiteral(); break; case 46: case 47: BooleanLiteral(); break; case STRING_LITERAL: StringLiteral(); break; case 45: NullLiteral(); break; default: jj_la1[21] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public void NullLiteral() throws ParseException { /* @bgen(jjtree) NullLiteral */ ASTNullLiteral jjtn000 = new ASTNullLiteral(this, JJTNULLLITERAL); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(45); } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void BooleanLiteral() throws ParseException { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 46: ASTTrueNode jjtn001 = new ASTTrueNode(this, JJTTRUENODE); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); try { jj_consume_token(46); } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); } } break; case 47: ASTFalseNode jjtn002 = new ASTFalseNode(this, JJTFALSENODE); boolean jjtc002 = true; jjtree.openNodeScope(jjtn002); try { jj_consume_token(47); } finally { if (jjtc002) { jjtree.closeNodeScope(jjtn002, true); } } break; default: jj_la1[22] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } final public void IntegerLiteral() throws ParseException { /* @bgen(jjtree) IntegerLiteral */ ASTIntegerLiteral jjtn000 = new ASTIntegerLiteral(this, JJTINTEGERLITERAL); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); Token t; try { t = jj_consume_token(INTEGER_LITERAL); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.val = Integer.valueOf(t.image); } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void FloatLiteral() throws ParseException { /* @bgen(jjtree) FloatLiteral */ ASTFloatLiteral jjtn000 = new ASTFloatLiteral(this, JJTFLOATLITERAL); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); Token t; try { t = jj_consume_token(FLOAT_LITERAL); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.val = Float.valueOf(t.image); } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void StringLiteral() throws ParseException { /* @bgen(jjtree) StringLiteral */ ASTStringLiteral jjtn000 = new ASTStringLiteral(this, JJTSTRINGLITERAL); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); Token t; try { t = jj_consume_token(STRING_LITERAL); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.literal = t.image.substring(1, t.image.length() - 1); } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } /* * Statement syntax follows. */ final public void Statement() throws ParseException { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 48: jj_consume_token(48); break; case 9: Block(); break; default: jj_la1[23] = jj_gen; if (jj_2_2(2147483647)) { ReferenceExpression(); } else if (jj_2_3(2147483647)) { StatementExpression(); } else { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case FLOAT_LITERAL: case 11: case 12: case 14: case 36: case 42: case 43: case 44: case 45: case 46: case 47: case IDENTIFIER: case STRING_LITERAL: ExpressionExpression(); break; case 49: IfStatement(); break; case 52: ForeachStatement(); break; case 51: WhileStatement(); break; default: jj_la1[24] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } } final public void ExpressionExpression() throws ParseException { /* @bgen(jjtree) ExpressionExpression */ ASTExpressionExpression jjtn000 = new ASTExpressionExpression(this, JJTEXPRESSIONEXPRESSION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { Expression(); jj_consume_token(48); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void StatementExpression() throws ParseException { /* @bgen(jjtree) StatementExpression */ ASTStatementExpression jjtn000 = new ASTStatementExpression(this, JJTSTATEMENTEXPRESSION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { Assignment(); jj_consume_token(48); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void ReferenceExpression() throws ParseException { /* @bgen(jjtree) ReferenceExpression */ ASTReferenceExpression jjtn000 = new ASTReferenceExpression(this, JJTREFERENCEEXPRESSION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { Reference(); jj_consume_token(48); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void IfStatement() throws ParseException { /* @bgen(jjtree) IfStatement */ ASTIfStatement jjtn000 = new ASTIfStatement(this, JJTIFSTATEMENT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(49); jj_consume_token(12); Expression(); jj_consume_token(13); Statement(); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 50: jj_consume_token(50); Statement(); break; default: jj_la1[25] = jj_gen; ; } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void WhileStatement() throws ParseException { /* @bgen(jjtree) WhileStatement */ ASTWhileStatement jjtn000 = new ASTWhileStatement(this, JJTWHILESTATEMENT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(51); jj_consume_token(12); Expression(); jj_consume_token(13); Statement(); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void ForeachStatement() throws ParseException { /* @bgen(jjtree) ForeachStatement */ ASTForeachStatement jjtn000 = new ASTForeachStatement(this, JJTFOREACHSTATEMENT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(52); jj_consume_token(12); Reference(); jj_consume_token(53); Reference(); jj_consume_token(13); Statement(); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void Method() throws ParseException { /* @bgen(jjtree) Method */ ASTMethod jjtn000 = new ASTMethod(this, JJTMETHOD); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { Identifier(); jj_consume_token(12); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case FLOAT_LITERAL: case 11: case 12: case 14: case 36: case 42: case 43: case 44: case 45: case 46: case 47: case IDENTIFIER: case STRING_LITERAL: Parameter(); label_12: while (true) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 54: ; break; default: jj_la1[26] = jj_gen; break label_12; } jj_consume_token(54); Parameter(); } break; default: jj_la1[27] = jj_gen; ; } jj_consume_token(13); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void ArrayAccess() throws ParseException { /* @bgen(jjtree) ArrayAccess */ ASTArrayAccess jjtn000 = new ASTArrayAccess(this, JJTARRAYACCESS); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { Identifier(); label_13: while (true) { jj_consume_token(55); if (jj_2_4(3)) { Expression(); } else { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: IntegerLiteral(); break; case IDENTIFIER: Reference(); break; default: jj_la1[28] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } jj_consume_token(56); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 55: ; break; default: jj_la1[29] = jj_gen; break label_13; } } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void SizeMethod() throws ParseException { /* @bgen(jjtree) SizeMethod */ ASTSizeMethod jjtn000 = new ASTSizeMethod(this, JJTSIZEMETHOD); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { jj_consume_token(14); jj_consume_token(12); jj_consume_token(13); } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void Reference() throws ParseException { /* @bgen(jjtree) Reference */ ASTReference jjtn000 = new ASTReference(this, JJTREFERENCE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { if (jj_2_5(2147483647)) { ArrayAccess(); } else { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case IDENTIFIER: Identifier(); break; default: jj_la1[30] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } label_14: while (true) { if (jj_2_6(2)) { ; } else { break label_14; } jj_consume_token(57); if (jj_2_8(2147483647)) { ArrayAccess(); } else { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case 14: case IDENTIFIER: if (jj_2_7(3)) { Method(); } else { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case 14: SizeMethod(); break; case IDENTIFIER: Identifier(); break; case INTEGER_LITERAL: IntegerLiteral(); break; default: jj_la1[31] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } break; default: jj_la1[32] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { { if (true) throw (RuntimeException) jjte000; } } if (jjte000 instanceof ParseException) { { if (true) throw (ParseException) jjte000; } } { if (true) throw (Error) jjte000; } } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } final public void Parameter() throws ParseException { if (jj_2_9(3)) { Expression(); } else { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case INTEGER_LITERAL: case FLOAT_LITERAL: case 45: case 46: case 47: case STRING_LITERAL: Literal(); break; case IDENTIFIER: Reference(); break; default: jj_la1[33] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } final private boolean jj_2_1(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_1(); jj_save(0, xla); return retval; } final private boolean jj_2_2(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_2(); jj_save(1, xla); return retval; } final private boolean jj_2_3(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_3(); jj_save(2, xla); return retval; } final private boolean jj_2_4(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_4(); jj_save(3, xla); return retval; } final private boolean jj_2_5(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_5(); jj_save(4, xla); return retval; } final private boolean jj_2_6(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_6(); jj_save(5, xla); return retval; } final private boolean jj_2_7(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_7(); jj_save(6, xla); return retval; } final private boolean jj_2_8(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_8(); jj_save(7, xla); return retval; } final private boolean jj_2_9(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; boolean retval = !jj_3_9(); jj_save(8, xla); return retval; } final private boolean jj_3R_71() { if (jj_scan_token(17)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_58()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_59() { Token xsp; xsp = jj_scanpos; if (jj_3R_70()) { jj_scanpos = xsp; if (jj_3R_71()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_70() { if (jj_scan_token(16)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_58()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_64() { if (jj_scan_token(STRING_LITERAL)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_47() { if (jj_3R_58()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_59()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3_1() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(15)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_46() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(15)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_34() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_62() { if (jj_scan_token(FLOAT_LITERAL)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_36() { if (jj_3R_47()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_35() { if (jj_3R_46()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_17() { Token xsp; xsp = jj_scanpos; if (jj_3R_35()) { jj_scanpos = xsp; if (jj_3R_36()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_56() { if (jj_scan_token(12)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(13)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_37() { if (jj_scan_token(INTEGER_LITERAL)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_18() { if (jj_scan_token(IDENTIFIER)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_73() { if (jj_scan_token(47)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_63() { Token xsp; xsp = jj_scanpos; if (jj_3R_72()) { jj_scanpos = xsp; if (jj_3R_73()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_72() { if (jj_scan_token(46)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_45() { if (jj_scan_token(14)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(12)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(13)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_27() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_65() { if (jj_scan_token(45)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_55() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_41() { if (jj_3R_37()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_44() { if (jj_scan_token(11)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_55()) { jj_scanpos = xsp; if (jj_3R_56()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_21() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_54() { if (jj_3R_65()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_53() { if (jj_3R_64()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_67() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_52() { if (jj_3R_63()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_61() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_51() { if (jj_3R_62()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_43() { Token xsp; xsp = jj_scanpos; if (jj_3R_50()) { jj_scanpos = xsp; if (jj_3R_51()) { jj_scanpos = xsp; if (jj_3R_52()) { jj_scanpos = xsp; if (jj_3R_53()) { jj_scanpos = xsp; if (jj_3R_54()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_50() { if (jj_3R_37()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_26() { if (jj_3R_37()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_40() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_20() { if (jj_3R_37()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_32() { if (jj_3R_45()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_60() { if (jj_3R_43()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_31() { if (jj_3R_44()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_30() { if (jj_scan_token(12)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(13)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_66() { if (jj_3R_37()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_29() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_28() { if (jj_3R_43()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_15() { Token xsp; xsp = jj_scanpos; if (jj_3R_28()) { jj_scanpos = xsp; if (jj_3R_29()) { jj_scanpos = xsp; if (jj_3R_30()) { jj_scanpos = xsp; if (jj_3R_31()) { jj_scanpos = xsp; if (jj_3R_32()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_25() { if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_39() { if (jj_3R_48()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_109() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_19() { if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_108() { if (jj_scan_token(44)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_107() { if (jj_scan_token(43)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_106() { if (jj_scan_token(42)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_105() { if (jj_scan_token(36)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_101() { Token xsp; xsp = jj_scanpos; if (jj_3R_105()) { jj_scanpos = xsp; if (jj_3R_106()) { jj_scanpos = xsp; if (jj_3R_107()) { jj_scanpos = xsp; if (jj_3R_108()) { jj_scanpos = xsp; if (jj_3R_109()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_78() { if (jj_scan_token(54)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_49()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_114() { if (jj_scan_token(41)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_8() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(55)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_25()) { jj_scanpos = xsp; if (jj_3R_26()) { jj_scanpos = xsp; if (jj_3R_27()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(56)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_113() { if (jj_scan_token(40)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_9() { if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_49() { Token xsp; xsp = jj_scanpos; if (jj_3_9()) { jj_scanpos = xsp; if (jj_3R_60()) { jj_scanpos = xsp; if (jj_3R_61()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_112() { if (jj_scan_token(39)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_4() { if (jj_3R_17()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_111() { if (jj_scan_token(38)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_5() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(55)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_19()) { jj_scanpos = xsp; if (jj_3R_20()) { jj_scanpos = xsp; if (jj_3R_21()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(56)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_7() { if (jj_3R_24()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_110() { if (jj_scan_token(37)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_102() { Token xsp; xsp = jj_scanpos; if (jj_3R_110()) { jj_scanpos = xsp; if (jj_3R_111()) { jj_scanpos = xsp; if (jj_3R_112()) { jj_scanpos = xsp; if (jj_3R_113()) { jj_scanpos = xsp; if (jj_3R_114()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_23() { Token xsp; xsp = jj_scanpos; if (jj_3_7()) { jj_scanpos = xsp; if (jj_3R_39()) { jj_scanpos = xsp; if (jj_3R_40()) { jj_scanpos = xsp; if (jj_3R_41()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_22() { if (jj_3R_38()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_57() { if (jj_scan_token(55)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3_4()) { jj_scanpos = xsp; if (jj_3R_66()) { jj_scanpos = xsp; if (jj_3R_67()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(56)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_91() { if (jj_3R_101()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_102()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_42() { if (jj_3R_49()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_78()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3_6() { if (jj_scan_token(57)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_22()) { jj_scanpos = xsp; if (jj_3R_23()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_33() { if (jj_3R_38()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_48() { if (jj_scan_token(14)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(12)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(13)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_104() { if (jj_scan_token(36)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_91()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_16() { Token xsp; xsp = jj_scanpos; if (jj_3R_33()) { jj_scanpos = xsp; if (jj_3R_34()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; while (true) { xsp = jj_scanpos; if (jj_3_6()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_103() { if (jj_scan_token(35)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_91()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_92() { Token xsp; xsp = jj_scanpos; if (jj_3R_103()) { jj_scanpos = xsp; if (jj_3R_104()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_85() { if (jj_3R_91()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_92()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_38() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; if (jj_3R_57()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; while (true) { xsp = jj_scanpos; if (jj_3R_57()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_100() { if (jj_scan_token(34)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_99() { if (jj_scan_token(33)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_24() { if (jj_3R_18()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(12)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; xsp = jj_scanpos; if (jj_3R_42()) jj_scanpos = xsp; else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(13)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_98() { if (jj_scan_token(32)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_97() { if (jj_scan_token(31)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_96() { if (jj_scan_token(30)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_95() { if (jj_scan_token(29)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_94() { if (jj_scan_token(28)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_93() { if (jj_scan_token(27)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_86() { Token xsp; xsp = jj_scanpos; if (jj_3R_93()) { jj_scanpos = xsp; if (jj_3R_94()) { jj_scanpos = xsp; if (jj_3R_95()) { jj_scanpos = xsp; if (jj_3R_96()) { jj_scanpos = xsp; if (jj_3R_97()) { jj_scanpos = xsp; if (jj_3R_98()) { jj_scanpos = xsp; if (jj_3R_99()) { jj_scanpos = xsp; if (jj_3R_100()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_83() { if (jj_3R_85()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_86()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_90() { if (jj_scan_token(26)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_83()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_89() { if (jj_scan_token(25)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_83()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_88() { if (jj_scan_token(24)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_83()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_87() { if (jj_scan_token(23)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_83()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_84() { Token xsp; xsp = jj_scanpos; if (jj_3R_87()) { jj_scanpos = xsp; if (jj_3R_88()) { jj_scanpos = xsp; if (jj_3R_89()) { jj_scanpos = xsp; if (jj_3R_90()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_81() { if (jj_3R_83()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_84()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_82() { if (jj_scan_token(22)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_81()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_79() { if (jj_3R_81()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_82()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3_3() { if (jj_3R_15()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(15)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3_2() { if (jj_3R_16()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_scan_token(48)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_80() { if (jj_scan_token(21)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_79()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_74() { if (jj_3R_79()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_80()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_75() { if (jj_scan_token(20)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_74()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_68() { if (jj_3R_74()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_75()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } final private boolean jj_3R_77() { if (jj_scan_token(19)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_68()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_69() { Token xsp; xsp = jj_scanpos; if (jj_3R_76()) { jj_scanpos = xsp; if (jj_3R_77()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_76() { if (jj_scan_token(18)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; if (jj_3R_68()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } final private boolean jj_3R_58() { if (jj_3R_68()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; Token xsp; while (true) { xsp = jj_scanpos; if (jj_3R_69()) { jj_scanpos = xsp; break; } if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; } return false; } public ParserTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; private int jj_ntk; private Token jj_scanpos, jj_lastpos; private int jj_la; public boolean lookingAhead = false; private boolean jj_semLA; private int jj_gen; final private int[] jj_la1 = new int[34]; final private int[] jj_la1_0 = { 0x5b80, 0x5b80, 0x1000, 0x5980, 0x30000, 0x30000, 0xc0000, 0xc0000, 0x100000, 0x200000, 0x400000, 0x7800000, 0x7800000, 0xf8000000, 0xf8000000, 0x0, 0x0, 0x0, 0x0, 0x5980, 0x5980, 0x180, 0x0, 0x200, 0x5980, 0x0, 0x0, 0x5980, 0x80, 0x0, 0x0, 0x4080, 0x4080, 0x180, }; final private int[] jj_la1_1 = { 0x241bfc10, 0x241bfc10, 0x4000000, 0x2400fc10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x7, 0x18, 0x18, 0x3e0, 0x3e0, 0x2400fc10, 0x2400e000, 0x2000e000, 0xc000, 0x10000, 0x241afc10, 0x40000, 0x400000, 0x2400fc10, 0x4000000, 0x800000, 0x4000000, 0x4000000, 0x4000000, 0x2400e000, }; final private JJCalls[] jj_2_rtns = new JJCalls[9]; private boolean jj_rescan = false; private int jj_gc = 0; public Parser(java.io.InputStream stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new ParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 34; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(java.io.InputStream stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jjtree.reset(); jj_gen = 0; for (int i = 0; i < 34; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public Parser(java.io.Reader stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new ParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 34; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jjtree.reset(); jj_gen = 0; for (int i = 0; i < 34; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public Parser(ParserTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 34; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } public void ReInit(ParserTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jjtree.reset(); jj_gen = 0; for (int i = 0; i < 34; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } final private Token jj_consume_token(int kind) throws ParseException { Token oldToken; if ((oldToken = token).next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; if (token.kind == kind) { jj_gen++; if (++jj_gc > 100) { jj_gc = 0; for (int i = 0; i < jj_2_rtns.length; i++) { JJCalls c = jj_2_rtns[i]; while (c != null) { if (c.gen < jj_gen) c.first = null; c = c.next; } } } return token; } token = oldToken; jj_kind = kind; throw generateParseException(); } final private boolean jj_scan_token(int kind) { if (jj_scanpos == jj_lastpos) { jj_la--; if (jj_scanpos.next == null) { jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); } else { jj_lastpos = jj_scanpos = jj_scanpos.next; } } else { jj_scanpos = jj_scanpos.next; } if (jj_rescan) { int i = 0; Token tok = token; while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } if (tok != null) jj_add_error_token(kind, i); } return (jj_scanpos.kind != kind); } final public Token getNextToken() { if (token.next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; jj_gen++; return token; } final public Token getToken(int index) { Token t = lookingAhead ? jj_scanpos : token; for (int i = 0; i < index; i++) { if (t.next != null) t = t.next; else t = t.next = token_source.getNextToken(); } return t; } final private int jj_ntk() { if ((jj_nt = token.next) == null) return (jj_ntk = (token.next = token_source.getNextToken()).kind); else return (jj_ntk = jj_nt.kind); } private java.util.Vector jj_expentries = new java.util.Vector(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; private int jj_endpos; private void jj_add_error_token(int kind, int pos) { if (pos >= 100) return; if (pos == jj_endpos + 1) { jj_lasttokens[jj_endpos++] = kind; } else if (jj_endpos != 0) { jj_expentry = new int[jj_endpos]; for (int i = 0; i < jj_endpos; i++) { jj_expentry[i] = jj_lasttokens[i]; } boolean exists = false; for (java.util.Enumeration enumeration = jj_expentries.elements(); enumeration.hasMoreElements();) { int[] oldentry = (int[]) (enumeration.nextElement()); if (oldentry.length == jj_expentry.length) { exists = true; for (int i = 0; i < jj_expentry.length; i++) { if (oldentry[i] != jj_expentry[i]) { exists = false; break; } } if (exists) break; } } if (!exists) jj_expentries.addElement(jj_expentry); if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; } } final public ParseException generateParseException() { jj_expentries.removeAllElements(); boolean[] la1tokens = new boolean[62]; for (int i = 0; i < 62; i++) { la1tokens[i] = false; } if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } for (int i = 0; i < 34; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1 << j)) != 0) { la1tokens[j] = true; } if ((jj_la1_1[i] & (1 << j)) != 0) { la1tokens[32 + j] = true; } } } } for (int i = 0; i < 62; i++) { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; jj_expentries.addElement(jj_expentry); } } jj_endpos = 0; jj_rescan_token(); jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { exptokseq[i] = (int[]) jj_expentries.elementAt(i); } return new ParseException(token, exptokseq, tokenImage); } final public void enable_tracing() { } final public void disable_tracing() { } final private void jj_rescan_token() { jj_rescan = true; for (int i = 0; i < 9; i++) { JJCalls p = jj_2_rtns[i]; do { if (p.gen > jj_gen) { jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; switch (i) { case 0: jj_3_1(); break; case 1: jj_3_2(); break; case 2: jj_3_3(); break; case 3: jj_3_4(); break; case 4: jj_3_5(); break; case 5: jj_3_6(); break; case 6: jj_3_7(); break; case 7: jj_3_8(); break; case 8: jj_3_9(); break; } } p = p.next; } while (p != null); } jj_rescan = false; } final private void jj_save(int index, int xla) { JJCalls p = jj_2_rtns[index]; while (p.gen > jj_gen) { if (p.next == null) { p = p.next = new JJCalls(); break; } p = p.next; } p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; } static final class JJCalls { int gen; Token first; int arg; JJCalls next; } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/parser/Parser.jj 100644 0 0 133663 10500374603 23166 0 ustar 0 0 /* * Copyright 2002,2004 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. */ /** * Jexl : Java Expression Language * * @author Geir Magnusson Jr. * @author Mark H. Wilkinson * * @version $Id: Parser.jj 136562 2004-02-28 13:45:22Z yoavs $ */ options { STATIC=false; } PARSER_BEGIN(Parser) package org.apache.commons.jexl.parser; import java.io.Reader; import java.io.ByteArrayInputStream; public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/ protected JJTParserState jjtree = new JJTParserState(); /*@egen*/ public SimpleNode parse(Reader reader) throws Exception { ReInit(reader); /* * lets do the 'Unique Init' in here to be * safe - it's a pain to remember */ SimpleNode tree = JexlScript(); return tree; } } PARSER_END(Parser) SKIP : /* WHITE SPACE */ {A JEXL Script.
*A script is some valid JEXL syntax to be executed with * a given set of {@link JexlContext variables}.
*A script is a group of statements, separated by semicolons.
*The statements can be blocks
(curly braces containing code),
* Control statements such as if
and while
* as well as expressions and assignment statements.
* Creates {@link Script}s. To create a JEXL Script, pass * valid JEXL syntax to the static createScript() method: *
* ** String jexl = "y = x * 12 + 44; y = y * 4;"; * Script script = ScriptFactory.createScript( jexl ); ** *
* When an {@link Script} is created, the JEXL syntax is * parsed and verified. *
* @since 1.1 * @version $Id: ScriptFactory.java 429175 2006-08-06 19:05:23Z rahul $ */ public class ScriptFactory { /** The Log to which all ScriptFactory messages will be logged.*/ protected static Log log = LogFactory.getLog("org.apache.commons.jexl.ScriptFactory"); /** * The singleton ScriptFactory also holds a single instance of * {@link Parser}. When parsing expressions, ScriptFactory * synchronizes on Parser. */ protected static Parser parser = new Parser(new StringReader(";")); /** * ScriptFactory is a singleton and this is the private * instance fufilling that pattern. */ protected static ScriptFactory factory = new ScriptFactory(); /** * Private constructor, the single instance is always obtained * with a call to getInstance(). */ private ScriptFactory() { } /** * Returns the single instance of ScriptFactory. * @return the instance of ScriptFactory. */ protected static ScriptFactory getInstance() { return factory; } /** * Creates a Script from a String containing valid JEXL syntax. * This method parses the script which validates the syntax. * * @param scriptText A String containing valid JEXL syntax * @return A {@link Script} which can be executed with a * {@link JexlContext}. * @throws Exception An exception can be thrown if there is a * problem parsing the script. */ public static Script createScript(String scriptText) throws Exception { return getInstance().createNewScript(scriptText); } /** * Creates a Script from a {@link File} containing valid JEXL syntax. * This method parses the script and validates the syntax. * * @param scriptFile A {@link File} containing valid JEXL syntax. * Must not be null. Must be a readable file. * @return A {@link Script} which can be executed with a * {@link JexlContext}. * @throws Exception An exception can be thrown if there is a problem * parsing the script. */ public static Script createScript(File scriptFile) throws Exception { if (scriptFile == null) { throw new NullPointerException("scriptFile is null"); } if (!scriptFile.canRead()) { throw new IOException("Can't read scriptFile (" + scriptFile.getCanonicalPath() + ")"); } BufferedReader reader = new BufferedReader(new FileReader(scriptFile)); return createScript(readerToString(reader)); } /** * Creates a Script from a {@link URL} containing valid JEXL syntax. * This method parses the script and validates the syntax. * * @param scriptUrl A {@link URL} containing valid JEXL syntax. * Must not be null. Must be a readable file. * @return A {@link Script} which can be executed with a * {@link JexlContext}. * @throws Exception An exception can be thrown if there is a problem * parsing the script. */ public static Script createScript(URL scriptUrl) throws Exception { if (scriptUrl == null) { throw new NullPointerException("scriptUrl is null"); } URLConnection connection = scriptUrl.openConnection(); BufferedReader reader = new BufferedReader( new InputStreamReader(connection.getInputStream())); return createScript(readerToString(reader)); } /** * Creates a new Script based on the string. * * @param scriptText valid Jexl script * @return Script a new script * @throws Exception for a variety of reasons - mostly malformed scripts */ protected Script createNewScript(String scriptText) throws Exception { String cleanText = cleanScript(scriptText); SimpleNode script; // Parse the Expression synchronized (parser) { log.debug("Parsing script: " + cleanText); try { script = parser.parse(new StringReader(cleanText)); } catch (TokenMgrError tme) { throw new ParseException(tme.getMessage()); } } if (script instanceof ASTJexlScript) { return new ScriptImpl(cleanText, (ASTJexlScript) script); } else { throw new IllegalStateException("Parsed script is not " + "an ASTJexlScript"); } } /** * @todo move to ParseUtils? * Trims the expression and adds a semi-colon if missing. * @param script to clean * @return trimmed expression ending in a semi-colon */ private String cleanScript(String script) { String expr = script.trim(); if (!expr.endsWith(";")) { expr += ";"; } return expr; } /** * Read a buffered reader into a StringBuffer and return a String with * the contents of the reader. * @param reader to be read. * @return the contents of the reader as a String. * @throws IOException on any error reading the reader. */ private static String readerToString(BufferedReader reader) throws IOException { StringBuffer buffer = new StringBuffer(); try { String line = null; while ((line = reader.readLine()) != null) { buffer.append(line).append('\n'); } return buffer.toString(); } finally { reader.close(); } } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/ScriptImpl.java 100644 0 0 3106 10500374603 22766 0 ustar 0 0 /* * 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; import org.apache.commons.jexl.parser.ASTJexlScript; /** * Simple script implementation. * @since 1.1 */ class ScriptImpl implements Script { /** text of the script. */ private final String text; /** syntax tree. */ private final ASTJexlScript parsedScript; /** * Create a new Script from the given string and parsed syntax. * @param scriptText the text of the script. * @param scriptTree the parsed script. */ public ScriptImpl(String scriptText, ASTJexlScript scriptTree) { text = scriptText; parsedScript = scriptTree; } /** * {@inheritDoc} */ public Object execute(JexlContext context) throws Exception { // TODO Auto-generated method stub return parsedScript.value(context); } /** * {@inheritDoc} */ public String getText() { return text; } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/AbstractExecutor.java 100644 0 0 4277 10500374603 25151 0 ustar 0 0 /* * Copyright 2000-2001,2004 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.util; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.apache.commons.logging.Log; /** * Abstract class that is used to execute an arbitrary * method that is in introspected. This is the superclass * for the GetExecutor and PropertyExecutor. * * @since 1.0 * @author Jason van Zyl * @author Geir Magnusson Jr. * @version $Id: AbstractExecutor.java 398171 2006-04-29 14:57:29Z dion $ */ public abstract class AbstractExecutor { /** The executor instance log. */ protected Log rlog = null; /** * Method to be executed. */ protected Method method = null; /** * Execute method against context. * * @param o The owner. * @return The return value. * @throws IllegalAccessException Method is inaccessible. * @throws InvocationTargetException Method body throws an exception. */ public abstract Object execute(Object o) throws IllegalAccessException, InvocationTargetException; /** * Tell whether the executor is alive by looking * at the value of the method. * * @return boolean Whether the executor is alive. */ public boolean isAlive() { return (method != null); } /** * Get the method to be executed. * * @return Method The method to be executed. */ public Method getMethod() { return method; } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/ArrayIterator.java 100644 0 0 6340 10500374603 24450 0 ustar 0 0 /* * Copyright 1999-2001,2004 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.util; import java.util.Iterator; import java.util.NoSuchElementException; import java.lang.reflect.Array; /** ** An Iterator wrapper for an Object[]. This will * allow us to deal with all array like structures * in a consistent manner. *
** WARNING : this class's operations are NOT synchronized. * It is meant to be used in a single thread, newly created * for each use in the #foreach() directive. * If this is used or shared, synchronize in the * next() method. *
* * @since 1.0 * @author Jason van Zyl * @author Geir Magnusson Jr. * @version $Id: ArrayIterator.java 398329 2006-04-30 12:51:43Z dion $ */ public class ArrayIterator implements Iterator { /** * The objects to iterate over. */ private final Object array; /** * The current position and size in the array. */ private int pos; /** * The size of the array. */ private final int size; /** * Creates a new iterator instance for the specified array. * * @param arr The array for which an iterator is desired. */ public ArrayIterator(Object arr) { /* * if this isn't an array, then throw. Note that this is * for internal use - so this should never happen - if it does * we screwed up. */ if (!arr.getClass().isArray()) { throw new IllegalArgumentException("Programmer error :" + " internal ArrayIterator invoked w/o array"); } array = arr; pos = 0; size = Array.getLength(array); } /** * Move to next element in the array. * * @return The next object in the array. */ public Object next() { if (pos < size) { return Array.get(array, pos++); } /* * we screwed up... */ throw new NoSuchElementException("No more elements: " + pos + " / " + size); } /** * Check to see if there is another element in the array. * * @return Whether there is another element. */ public boolean hasNext() { return (pos < size); } /** * No op--merely added to satify theIterator
interface.
*/
public void remove() {
throw new UnsupportedOperationException();
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/BooleanPropertyExecutor.java 100644 0 0 5604 10500374603 26525 0 ustar 0 0 /*
* Copyright 2000-2001,2004 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.util;
import org.apache.commons.logging.Log;
/**
* Handles discovery and valuation of a
* boolean object property, of the
* form public boolean is<Property> when executed.
*
* We do this separately as to preserve the current
* quasi-broken semantics of get <as is property>
* get<flip 1st char> get("property") and now followed
* by is<Property>.
*
* @since 1.0
* @author Geir Magnusson Jr.
* @version $Id: BooleanPropertyExecutor.java 398171 2006-04-29 14:57:29Z dion $
*/
public class BooleanPropertyExecutor extends PropertyExecutor {
/**
* Constructor.
*
* @param rlog The instance log.
* @param is The JEXL introspector.
* @param clazz The class being analyzed.
* @param property The boolean property.
*/
public BooleanPropertyExecutor(Log rlog,
org.apache.commons.jexl.util.introspection.Introspector is,
Class clazz, String property) {
super(rlog, is, clazz, property);
}
/**
* Locate the getter method for this boolean property.
*
* @param clazz The class being analyzed.
* @param property Name of boolean property.
*/
protected void discover(Class clazz, String property) {
try {
char c;
StringBuffer sb;
Object[] params = {};
/*
* now look for a boolean isFoo
*/
sb = new StringBuffer("is");
sb.append(property);
c = sb.charAt(2);
if (Character.isLowerCase(c)) {
sb.setCharAt(2, Character.toUpperCase(c));
}
methodUsed = sb.toString();
method = introspector.getMethod(clazz, methodUsed, params);
if (method != null) {
/*
* now, this has to return a boolean
*/
if (method.getReturnType() == Boolean.TYPE) {
return;
}
method = null;
}
} catch (Exception e) {
rlog.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e);
}
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/Coercion.java 100644 0 0 12300 10500374603 23432 0 ustar 0 0 /*
* Copyright 2002,2004 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.util;
/**
* Coercion utilities for the JSTL EL-like coercion.
*
* @since 1.0
* @author Geir Magnusson Jr.
*/
public class Coercion {
/**
* Coerce to a Boolean.
*
* @param val Object to be coerced.
* @return The Boolean coerced value, or null if none possible.
*/
public static Boolean coerceBoolean(Object val) {
if (val == null) {
return Boolean.FALSE;
} else if (val instanceof Boolean) {
return (Boolean) val;
} else if (val instanceof String) {
return Boolean.valueOf((String) val);
}
return null;
}
/**
* Coerce to a Integer.
*
* @param val Object to be coerced.
* @return The Integer coerced value.
* @throws Exception If Integer coercion fails.
*/
public static Integer coerceInteger(Object val)
throws Exception {
if (val == null) {
return new Integer(0);
} else if (val instanceof String) {
if ("".equals(val)) {
return new Integer(0);
}
return Integer.valueOf((String) val);
} else if (val instanceof Character) {
return new Integer(((Character) val).charValue());
} else if (val instanceof Boolean) {
throw new Exception("Boolean->Integer coercion exception");
} else if (val instanceof Number) {
return new Integer(((Number) val).intValue());
}
throw new Exception("Integer coercion exception");
}
/**
* Coerce to a Long.
*
* @param val Object to be coerced.
* @return The Long coerced value.
* @throws Exception If Long coercion fails.
*/
public static Long coerceLong(Object val)
throws Exception {
if (val == null) {
return new Long(0);
} else if (val instanceof String) {
if ("".equals(val)) {
return new Long(0);
}
return Long.valueOf((String) val);
} else if (val instanceof Character) {
return new Long(((Character) val).charValue());
} else if (val instanceof Boolean) {
throw new Exception("Boolean->Long coercion exception");
} else if (val instanceof Number) {
return new Long(((Number) val).longValue());
}
throw new Exception("Long coercion exception");
}
/**
* Coerce to a Double.
*
* @param val Object to be coerced.
* @return The Double coerced value.
* @throws Exception If Double coercion fails.
*/
public static Double coerceDouble(Object val)
throws Exception {
if (val == null) {
return new Double(0);
} else if (val instanceof String) {
if ("".equals(val)) {
return new Double(0);
}
/*
* the spec seems to be iffy about this. Going to give it a wack
* anyway
*/
return new Double((String) val);
} else if (val instanceof Character) {
int i = ((Character) val).charValue();
return new Double(Double.parseDouble(String.valueOf(i)));
} else if (val instanceof Boolean) {
throw new Exception("Boolean->Double coercion exception");
} else if (val instanceof Double) {
return (Double) val;
} else if (val instanceof Number) {
//The below construct is used rather than ((Number)val).doubleValue() to ensure
//equality between comparint new Double( 6.4 / 3 ) and the jexl expression of 6.4 / 3
return new Double(Double.parseDouble(String.valueOf(val)));
}
throw new Exception("Double coercion exception");
}
/**
* Is Object a floating point number.
*
* @param o Object to be analyzed.
* @return true if it is a Float or a Double.
*/
public static boolean isFloatingPoint(final Object o) {
return o instanceof Float || o instanceof Double;
}
/**
* Is Object a whole number.
*
* @param o Object to be analyzed.
* @return true if Integer, Long, Byte, Short or Character.
*/
public static boolean isNumberable(final Object o) {
return o instanceof Integer
|| o instanceof Long
|| o instanceof Byte
|| o instanceof Short
|| o instanceof Character;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/EnumerationIterator.java 100644 0 0 3640 10500374603 25660 0 ustar 0 0 /*
* Copyright 1999-2001,2004 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.util;
import java.util.Iterator;
import java.util.Enumeration;
/**
* An Iterator wrapper for an Enumeration.
*
* @since 1.0
* @author Geir Magnusson Jr.
* @version $Id: EnumerationIterator.java 398330 2006-04-30 12:52:35Z dion $
*/
public class EnumerationIterator implements Iterator {
/**
* The enumeration to iterate over.
*/
private final Enumeration enumeration;
/**
* Creates a new iteratorwrapper instance for the specified
* Enumeration.
*
* @param enumer The Enumeration to wrap.
*/
public EnumerationIterator(Enumeration enumer) {
enumeration = enumer;
}
/**
* Move to next element in the array.
*
* @return The next object in the array.
*/
public Object next() {
return enumeration.nextElement();
}
/**
* Check to see if there is another element in the array.
*
* @return Whether there is another element.
*/
public boolean hasNext() {
return enumeration.hasMoreElements();
}
/**
* Unimplemented. No analogy in Enumeration
*/
public void remove() {
// not implemented
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/GetExecutor.java 100644 0 0 4232 10500374603 24114 0 ustar 0 0 /*
* Copyright 2000-2001,2004 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.util;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.logging.Log;
/**
* Executor that simply tries to execute a get(key)
* operation. This will try to find a get(key) method
* for any type of object, not just objects that
* implement the Map interface as was previously
* the case.
*
* @since 1.0
* @author Jason van Zyl
* @version $Id: GetExecutor.java 398171 2006-04-29 14:57:29Z dion $
*/
public class GetExecutor extends AbstractExecutor {
/**
* Container to hold the 'key' part of
* get(key).
*/
private final Object[] args = new Object[1];
/**
* Default constructor.
*
* @param r The instance log.
* @param ispect The JEXL introspector.
* @param c The class being examined.
* @param key The key for the get(key) operation.
* @throws Exception Failure while trying to obtain the pertinent method.
*/
public GetExecutor(Log r,
org.apache.commons.jexl.util.introspection.Introspector ispect,
Class c, String key) throws Exception {
rlog = r;
args[0] = key;
method = ispect.getMethod(c, "get", args);
}
/**
* {@inheritDoc}
*/
public Object execute(Object o)
throws IllegalAccessException, InvocationTargetException {
if (method == null) {
return null;
}
return method.invoke(o, args);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java 100644 0 0 35734 10500374603 26314 0 ustar 0 0 /*
* Copyright 2001-2002,2004 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.util.introspection;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Hashtable;
import java.util.Map;
/**
* Taken from the Velocity tree so we can be self-sufficient
*
* A cache of introspection information for a specific class instance. Keys
* {@link java.lang.Method} objects by a concatenation of the method name and
* the names of classes that make up the parameters.
*
* @since 1.0
* @author Jason van Zyl
* @author Bob McWhirter
* @author Attila Szegedi
* @author Geir Magnusson Jr.
* @version $Id: ClassMap.java 398459 2006-04-30 23:14:30Z dion $
*/
public class ClassMap {
/** represents a miss on the cached data. */
private static final class CacheMiss {
}
/** constant for a miss on the cached data. */
private static final CacheMiss CACHE_MISS = new CacheMiss();
/** represents null or missing arguments. */
private static final Object OBJECT = new Object();
/**
* Class passed into the constructor used to as the basis for the Method
* map.
*/
private Class clazz;
/**
* Cache of Methods, or CACHE_MISS, keyed by method name and actual
* arguments used to find it.
*/
private final Map methodCache = new Hashtable();
/** map from method name and args to a {@link Method}. */
private final MethodMap methodMap = new MethodMap();
/**
* Standard constructor.
* @param aClass the class to deconstruct.
*/
public ClassMap(Class aClass) {
clazz = aClass;
populateMethodCache();
}
/**
* @return the class object whose methods are cached by this map.
*/
Class getCachedClass() {
return clazz;
}
/**
* Find a Method using the methodKey provided.
*
* Look in the methodMap for an entry. If found, it'll either be a
* CACHE_MISS, in which case we simply give up, or it'll be a Method, in
* which case, we return it.
*
* If nothing is found, then we must actually go and introspect the method
* from the MethodMap.
*
* @param name method name
* @param params method parameters
* @return CACHE_MISS or a {@link Method}
* @throws MethodMap.AmbiguousException if the method and parameters are ambiguous.
*/
public Method findMethod(String name, Object[] params) throws MethodMap.AmbiguousException {
String methodKey = makeMethodKey(name, params);
Object cacheEntry = methodCache.get(methodKey);
if (cacheEntry == CACHE_MISS) {
return null;
}
if (cacheEntry == null) {
try {
cacheEntry = methodMap.find(name, params);
} catch (MethodMap.AmbiguousException ae) {
/*
* that's a miss :)
*/
methodCache.put(methodKey, CACHE_MISS);
throw ae;
}
if (cacheEntry == null) {
methodCache.put(methodKey, CACHE_MISS);
} else {
methodCache.put(methodKey, cacheEntry);
}
}
// Yes, this might just be null.
return (Method) cacheEntry;
}
/**
* Populate the Map of direct hits. These are taken from all the public
* methods that our class provides.
*/
private void populateMethodCache() {
/*
* get all publicly accessible methods
*/
Method[] methods = getAccessibleMethods(clazz);
/*
* map and cache them
*/
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
/*
* now get the 'public method', the method declared by a public
* interface or class. (because the actual implementing class may be
* a facade...
*/
Method publicMethod = getPublicMethod(method);
/*
* it is entirely possible that there is no public method for the
* methods of this class (i.e. in the facade, a method that isn't on
* any of the interfaces or superclass in which case, ignore it.
* Otherwise, map and cache
*/
if (publicMethod != null) {
methodMap.add(publicMethod);
methodCache.put(makeMethodKey(publicMethod), publicMethod);
}
}
}
/**
* Make a methodKey for the given method using the concatenation of the name
* and the types of the method parameters.
*/
private String makeMethodKey(Method method) {
Class[] parameterTypes = method.getParameterTypes();
StringBuffer methodKey = new StringBuffer(method.getName());
for (int j = 0; j < parameterTypes.length; j++) {
/*
* If the argument type is primitive then we want to convert our
* primitive type signature to the corresponding Object type so
* introspection for methods with primitive types will work
* correctly.
*/
if (parameterTypes[j].isPrimitive()) {
if (parameterTypes[j].equals(Boolean.TYPE))
methodKey.append("java.lang.Boolean");
else if (parameterTypes[j].equals(Byte.TYPE))
methodKey.append("java.lang.Byte");
else if (parameterTypes[j].equals(Character.TYPE))
methodKey.append("java.lang.Character");
else if (parameterTypes[j].equals(Double.TYPE))
methodKey.append("java.lang.Double");
else if (parameterTypes[j].equals(Float.TYPE))
methodKey.append("java.lang.Float");
else if (parameterTypes[j].equals(Integer.TYPE))
methodKey.append("java.lang.Integer");
else if (parameterTypes[j].equals(Long.TYPE))
methodKey.append("java.lang.Long");
else if (parameterTypes[j].equals(Short.TYPE))
methodKey.append("java.lang.Short");
} else {
methodKey.append(parameterTypes[j].getName());
}
}
return methodKey.toString();
}
private static String makeMethodKey(String method, Object[] params) {
StringBuffer methodKey = new StringBuffer().append(method);
for (int j = 0; j < params.length; j++) {
Object arg = params[j];
if (arg == null) {
arg = OBJECT;
}
methodKey.append(arg.getClass().getName());
}
return methodKey.toString();
}
/**
* Retrieves public methods for a class. In case the class is not public,
* retrieves methods with same signature as its public methods from public
* superclasses and interfaces (if they exist). Basically upcasts every
* method to the nearest acccessible method.
*/
private static Method[] getAccessibleMethods(Class clazz) {
Method[] methods = clazz.getMethods();
/*
* Short circuit for the (hopefully) majority of cases where the clazz
* is public
*/
if (Modifier.isPublic(clazz.getModifiers())) {
return methods;
}
/*
* No luck - the class is not public, so we're going the longer way.
*/
MethodInfo[] methodInfos = new MethodInfo[methods.length];
for (int i = methods.length; i-- > 0;) {
methodInfos[i] = new MethodInfo(methods[i]);
}
int upcastCount = getAccessibleMethods(clazz, methodInfos, 0);
/*
* Reallocate array in case some method had no accessible counterpart.
*/
if (upcastCount < methods.length) {
methods = new Method[upcastCount];
}
int j = 0;
for (int i = 0; i < methodInfos.length; ++i) {
MethodInfo methodInfo = methodInfos[i];
if (methodInfo.upcast) {
methods[j++] = methodInfo.method;
}
}
return methods;
}
/**
* Recursively finds a match for each method, starting with the class, and
* then searching the superclass and interfaces.
*
* @param clazz Class to check
* @param methodInfos array of methods we are searching to match
* @param upcastCount current number of methods we have matched
* @return count of matched methods
*/
private static int getAccessibleMethods(Class clazz, MethodInfo[] methodInfos, int upcastCount) {
int l = methodInfos.length;
/*
* if this class is public, then check each of the currently
* 'non-upcasted' methods to see if we have a match
*/
if (Modifier.isPublic(clazz.getModifiers())) {
for (int i = 0; i < l && upcastCount < l; ++i) {
try {
MethodInfo methodInfo = methodInfos[i];
if (!methodInfo.upcast) {
methodInfo.tryUpcasting(clazz);
upcastCount++;
}
} catch (NoSuchMethodException e) {
/*
* Intentionally ignored - it means it wasn't found in the
* current class
*/
}
}
/*
* Short circuit if all methods were upcast
*/
if (upcastCount == l) {
return upcastCount;
}
}
/*
* Examine superclass
*/
Class superclazz = clazz.getSuperclass();
if (superclazz != null) {
upcastCount = getAccessibleMethods(superclazz, methodInfos, upcastCount);
/*
* Short circuit if all methods were upcast
*/
if (upcastCount == l) {
return upcastCount;
}
}
/*
* Examine interfaces. Note we do it even if superclazz == null. This is
* redundant as currently java.lang.Object does not implement any
* interfaces, however nothing guarantees it will not in future.
*/
Class[] interfaces = clazz.getInterfaces();
for (int i = interfaces.length; i-- > 0;) {
upcastCount = getAccessibleMethods(interfaces[i], methodInfos, upcastCount);
/*
* Short circuit if all methods were upcast
*/
if (upcastCount == l) {
return upcastCount;
}
}
return upcastCount;
}
/**
* For a given method, retrieves its publicly accessible counterpart. This
* method will look for a method with same name and signature declared in a
* public superclass or implemented interface of this method's declaring
* class. This counterpart method is publicly callable.
*
* @param method a method whose publicly callable counterpart is requested.
* @return the publicly callable counterpart method. Note that if the
* parameter method is itself declared by a public class, this
* method is an identity function.
*/
public static Method getPublicMethod(Method method) {
Class clazz = method.getDeclaringClass();
/*
* Short circuit for (hopefully the majority of) cases where the
* declaring class is public.
*/
if ((clazz.getModifiers() & Modifier.PUBLIC) != 0) {
return method;
}
return getPublicMethod(clazz, method.getName(), method.getParameterTypes());
}
/**
* Looks up the method with specified name and signature in the first public
* superclass or implemented interface of the class.
*
* @param class the class whose method is sought
* @param name the name of the method
* @param paramTypes the classes of method parameters
*/
private static Method getPublicMethod(Class clazz, String name, Class[] paramTypes) {
/*
* if this class is public, then try to get it
*/
if ((clazz.getModifiers() & Modifier.PUBLIC) != 0) {
try {
return clazz.getMethod(name, paramTypes);
} catch (NoSuchMethodException e) {
/*
* If the class does not have the method, then neither its
* superclass nor any of its interfaces has it so quickly return
* null.
*/
return null;
}
}
/*
* try the superclass
*/
Class superclazz = clazz.getSuperclass();
if (superclazz != null) {
Method superclazzMethod = getPublicMethod(superclazz, name, paramTypes);
if (superclazzMethod != null) {
return superclazzMethod;
}
}
/*
* and interfaces
*/
Class[] interfaces = clazz.getInterfaces();
for (int i = 0; i < interfaces.length; ++i) {
Method interfaceMethod = getPublicMethod(interfaces[i], name, paramTypes);
if (interfaceMethod != null) {
return interfaceMethod;
}
}
return null;
}
/**
* Used for the iterative discovery process for public methods.
*/
private static final class MethodInfo {
Method method;
String name;
Class[] parameterTypes;
boolean upcast;
MethodInfo(Method method) {
this.method = null;
name = method.getName();
parameterTypes = method.getParameterTypes();
upcast = false;
}
void tryUpcasting(Class clazz) throws NoSuchMethodException {
method = clazz.getMethod(name, parameterTypes);
name = null;
parameterTypes = null;
upcast = true;
}
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/Info.java 100644 0 0 3564 10500374603 25460 0 ustar 0 0 /*
* 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.util.introspection;
/**
* Little class to carry in info such as template name, line and column for
* information error reporting from the uberspector implementations
*
* Taken from velocity for self-sufficiency.
*
* @since 1.0
* @author Geir Magnusson Jr.
* @version $Id: Info.java 398463 2006-04-30 23:48:42Z dion $
*/
public class Info {
/** line number. */
private int line;
/** column number. */
private int column;
/** name. */
private String templateName;
/**
* Create info.
* @param tn template name
* @param l line number
* @param c column
*/
public Info(String tn, int l, int c) {
templateName = tn;
line = l;
column = c;
}
/**
* Gets the template name.
* @return template name
*/
public String getTemplateName() {
return templateName;
}
/**
* Gets the line number.
* @return line number.
*/
public int getLine() {
return line;
}
/**
* Gets the column number.
* @return the column.
*/
public int getColumn() {
return column;
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/Introspector.java 100644 0 0 10025 10500374603 27266 0 ustar 0 0 /*
* Copyright 2001-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.util.introspection;
import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
/**
* This basic function of this class is to return a Method
* object for a particular class given the name of a method
* and the parameters to the method in the form of an Object[]
*
* The first time the Introspector sees a
* class it creates a class method map for the
* class in question. Basically the class method map
* is a Hashtable where Method objects are keyed by a
* concatenation of the method name and the names of
* classes that make up the parameters.
*
* For example, a method with the following signature:
*
* public void method(String a, StringBuffer b)
*
* would be mapped by the key:
*
* "method" + "java.lang.String" + "java.lang.StringBuffer"
*
* This mapping is performed for all the methods in a class
* and stored for
* @since 1.0
* @author Jason van Zyl
* @author Bob McWhirter
* @author Attila Szegedi
* @author Paulo Gaspar
* @version $Id: Introspector.java 398171 2006-04-29 14:57:29Z dion $
*/
public class Introspector extends IntrospectorBase {
/**
* define a public string so that it can be looked for
* if interested.
*/
public static final String CACHEDUMP_MSG =
"Introspector : detected classloader change. Dumping cache.";
/**
* our engine runtime services.
*/
private final Log rlog;
/**
* Recieves our RuntimeServices object.
* @param logger a {@link Log}.
*/
public Introspector(Log logger) {
this.rlog = logger;
}
/**
* Gets the method defined by name
and
* params
for the Class c
.
*
* @param c Class in which the method search is taking place
* @param name Name of the method being searched for
* @param params An array of Objects (not Classes) that describe the
* the parameters
*
* @return The desired Method object.
* @throws Exception if the superclass does.
*/
public Method getMethod(Class c, String name, Object[] params) throws Exception {
/*
* just delegate to the base class
*/
try {
return super.getMethod(c, name, params);
} catch (MethodMap.AmbiguousException ae) {
/*
* whoops. Ambiguous. Make a nice log message and return null...
*/
StringBuffer msg = new StringBuffer("Introspection Error : Ambiguous method invocation ")
.append(name).append("( ");
for (int i = 0; i < params.length; i++) {
if (i > 0) {
msg.append(", ");
}
msg.append(params[i].getClass().getName());
}
msg.append(") for class ").append(c.getName());
rlog.error(msg.toString());
}
return null;
}
/**
* Clears the classmap and classname
* caches, and logs that we did so.
*/
protected void clearCache() {
super.clearCache();
rlog.info(CACHEDUMP_MSG);
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/IntrospectorBase.java 100644 0 0 11333 10500374603 30064 0 ustar 0 0 /*
* Copyright 2001,2004 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.util.introspection;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.HashSet;
import java.lang.reflect.Method;
/**
* This basic function of this class is to return a Method object for a
* particular class given the name of a method and the parameters to the method
* in the form of an Object[]
*
* The first time the Introspector sees a class it creates a class method map
* for the class in question. Basically the class method map is a Hastable where
* Method objects are keyed by a concatenation of the method name and the names
* of classes that make up the parameters.
*
* For example, a method with the following signature:
*
* public void method(String a, StringBuffer b)
*
* would be mapped by the key:
*
* "method" + "java.lang.String" + "java.lang.StringBuffer"
*
* This mapping is performed for all the methods in a class and stored for
*
* @since 1.0
* @author Jason van Zyl
* @author Bob McWhirter
* @author Attila Szegedi
* @author Paulo Gaspar
* @version $Id: IntrospectorBase.java 398464 2006-04-30 23:50:43Z dion $
*/
public class IntrospectorBase {
/**
* Holds the method maps for the classes we know about, keyed by Class
* object.
*/
protected Map classMethodMaps = new HashMap();
/**
* Holds the qualified class names for the classes we hold in the
* classMethodMaps hash.
*/
protected Set cachedClassNames = new HashSet();
/**
* Gets the method defined by name
and params
* for the Class c
.
*
* @param c Class in which the method search is taking place
* @param name Name of the method being searched for
* @param params An array of Objects (not Classes) that describe the the
* parameters
*
* @return The desired Method object.
* @throws Exception on any logical error.
*/
public Method getMethod(Class c, String name, Object[] params) throws Exception {
if (c == null) {
throw new Exception("Introspector.getMethod(): Class method key was null: " + name);
}
ClassMap classMap = null;
synchronized (classMethodMaps) {
classMap = (ClassMap) classMethodMaps.get(c);
/*
* if we don't have this, check to see if we have it by name. if so,
* then we have a classloader change so dump our caches.
*/
if (classMap == null) {
if (cachedClassNames.contains(c.getName())) {
/*
* we have a map for a class with same name, but not this
* class we are looking at. This implies a classloader
* change, so dump
*/
clearCache();
}
classMap = createClassMap(c);
}
}
return classMap.findMethod(name, params);
}
/**
* Creates a class map for specific class and registers it in the cache.
* Also adds the qualified name to the name->class map for later Classloader
* change detection.
* @param c class.
* @return a {@link ClassMap}
*/
protected ClassMap createClassMap(Class c) {
ClassMap classMap = new ClassMap(c);
classMethodMaps.put(c, classMap);
cachedClassNames.add(c.getName());
return classMap;
}
/**
* Clears the classmap and classname caches.
*/
protected void clearCache() {
/*
* since we are synchronizing on this object, we have to clear it rather
* than just dump it.
*/
classMethodMaps.clear();
/*
* for speed, we can just make a new one and let the old one be GC'd
*/
cachedClassNames = new HashSet();
}
}
commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/MethodMap.java 100644 0 0 36330 10500374603 26460 0 ustar 0 0 /*
* Copyright 2001,2004 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.util.introspection;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
*
* @author Jason van Zyl
* @author Bob McWhirter
* @author Christoph Reck
* @author Geir Magnusson Jr.
* @author Attila Szegedi
* @since 1.0
* @version $Id: MethodMap.java 398495 2006-05-01 01:33:43Z dion $
*/
public class MethodMap {
/** whether a method is more specific than a previously compared one. */
private static final int MORE_SPECIFIC = 0;
/** whether a method is less specific than a previously compared one. */
private static final int LESS_SPECIFIC = 1;
/** A method doesn't match a previously compared one. */
private static final int INCOMPARABLE = 2;
/**
* Keep track of all methods with the same name.
*/
protected Map methodByNameMap = new Hashtable();
/**
* Add a method to a list of methods by name. For a particular class we are
* keeping track of all the methods with the same name.
* @param method the method.
*/
public void add(Method method) {
String methodName = method.getName();
List l = get(methodName);
if (l == null) {
l = new ArrayList();
methodByNameMap.put(methodName, l);
}
l.add(method);
}
/**
* Return a list of methods with the same name.
*
* @param key The method name.
* @return List list of methods
*/
public List get(String key) {
return (List) methodByNameMap.get(key);
}
/**
* * Find a method. Attempts to find the most specific applicable method using * the algorithm described in the JLS section 15.12.2 (with the exception * that it can't distinguish a primitive type argument from an object type * argument, since in reflection primitive type arguments are represented by * their object counterparts, so for an argument of type (say) * java.lang.Integer, it will not be able to decide between a method that * takes int and a method that takes java.lang.Integer as a parameter. *
* ** This turns out to be a relatively rare case where this is needed - * however, functionality like this is needed. *
* * @param methodName name of method * @param args the actual arguments with which the method is called * @return the most specific applicable method, or null if no method is * applicable. * @throws AmbiguousException if there is more than one maximally specific * applicable method */ public Method find(String methodName, Object[] args) throws AmbiguousException { List methodList = get(methodName); if (methodList == null) { return null; } int l = args.length; Class[] classes = new Class[l]; for (int i = 0; i < l; ++i) { Object arg = args[i]; /* * if we are careful down below, a null argument goes in there so we * can know that the null was passed to the method */ classes[i] = arg == null ? null : arg.getClass(); } return getMostSpecific(methodList, classes); } /** * simple distinguishable exception, used when we run across ambiguous * overloading. */ public static class AmbiguousException extends Exception { /** serialization version id jdk13 generated. */ static final long serialVersionUID = 8758118091728717367L; } /** * Gets the most specific method from a list. * @param methods list of {@link Method methods} * @param classes argument types * @return the most specific method, or null * @throws AmbiguousException if there is more than one specific method */ private static Method getMostSpecific(List methods, Class[] classes) throws AmbiguousException { LinkedList applicables = getApplicables(methods, classes); if (applicables.isEmpty()) { return null; } if (applicables.size() == 1) { return (Method) applicables.getFirst(); } /* * This list will contain the maximally specific methods. Hopefully at * the end of the below loop, the list will contain exactly one method, * (the most specific method) otherwise we have ambiguity. */ LinkedList maximals = new LinkedList(); for (Iterator applicable = applicables.iterator(); applicable.hasNext();) { Method app = (Method) applicable.next(); Class[] appArgs = app.getParameterTypes(); boolean lessSpecific = false; for (Iterator maximal = maximals.iterator(); !lessSpecific && maximal.hasNext();) { Method max = (Method) maximal.next(); switch (moreSpecific(appArgs, max.getParameterTypes())) { case MORE_SPECIFIC: /* * This method is more specific than the previously * known maximally specific, so remove the old maximum. */ maximal.remove(); break; case LESS_SPECIFIC: /* * This method is less specific than some of the * currently known maximally specific methods, so we * won't add it into the set of maximally specific * methods */ lessSpecific = true; break; } } if (!lessSpecific) { maximals.addLast(app); } } if (maximals.size() > 1) { // We have more than one maximally specific method throw new AmbiguousException(); } return (Method) maximals.getFirst(); } /** * Determines which method signature (represented by a class array) is more * specific. This defines a partial ordering on the method signatures. * * @param c1 first signature to compare * @param c2 second signature to compare * @return MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if c1 * is less specific than c2, INCOMPARABLE if they are incomparable. */ private static int moreSpecific(Class[] c1, Class[] c2) { boolean c1MoreSpecific = false; boolean c2MoreSpecific = false; for (int i = 0; i < c1.length; ++i) { if (c1[i] != c2[i]) { c1MoreSpecific = c1MoreSpecific || isStrictMethodInvocationConvertible(c2[i], c1[i]); c2MoreSpecific = c2MoreSpecific || isStrictMethodInvocationConvertible(c1[i], c2[i]); } } if (c1MoreSpecific) { if (c2MoreSpecific) { /* * Incomparable due to cross-assignable arguments (i.e. * foo(String, Object) vs. foo(Object, String)) */ return INCOMPARABLE; } return MORE_SPECIFIC; } if (c2MoreSpecific) { return LESS_SPECIFIC; } /* * Incomparable due to non-related arguments (i.e. foo(Runnable) vs. * foo(Serializable)) */ return INCOMPARABLE; } /** * Returns all methods that are applicable to actual argument types. * * @param methods list of all candidate methods * @param classes the actual types of the arguments * @return a list that contains only applicable methods (number of formal * and actual arguments matches, and argument types are assignable * to formal types through a method invocation conversion). */ private static LinkedList getApplicables(List methods, Class[] classes) { LinkedList list = new LinkedList(); for (Iterator imethod = methods.iterator(); imethod.hasNext();) { Method method = (Method) imethod.next(); if (isApplicable(method, classes)) { list.add(method); } } return list; } /** * Returns true if the supplied method is applicable to actual argument * types. * @param method the method to check * @param classes possible argument types * @return true if the arguments are applicable to the method. */ private static boolean isApplicable(Method method, Class[] classes) { Class[] methodArgs = method.getParameterTypes(); if (methodArgs.length != classes.length) { return false; } for (int i = 0; i < classes.length; ++i) { if (!isMethodInvocationConvertible(methodArgs[i], classes[i])) { return false; } } return true; } /** * Determines whether a type represented by a class object is convertible to * another type represented by a class object using a method invocation * conversion, treating object types of primitive types as if they were * primitive types (that is, a Boolean actual parameter type matches boolean * primitive formal type). This behavior is because this method is used to * determine applicable methods for an actual parameter list, and primitive * types are represented by their object duals in reflective method calls. * * @param formal the formal parameter type to which the actual parameter * type should be convertible * @param actual the actual parameter type. * @return true if either formal type is assignable from actual type, or * formal is a primitive type and actual is its corresponding object * type or an object type of a primitive type that can be converted * to the formal type. */ private static boolean isMethodInvocationConvertible(Class formal, Class actual) { /* * if it's a null, it means the arg was null */ if (actual == null && !formal.isPrimitive()) { return true; } /* * Check for identity or widening reference conversion */ if (actual != null && formal.isAssignableFrom(actual)) { return true; } /* * Check for boxing with widening primitive conversion. Note that actual * parameters are never primitives. */ if (formal.isPrimitive()) { if (formal == Boolean.TYPE && actual == Boolean.class) { return true; } if (formal == Character.TYPE && actual == Character.class) { return true; } if (formal == Byte.TYPE && actual == Byte.class) { return true; } if (formal == Short.TYPE && (actual == Short.class || actual == Byte.class)) { return true; } if (formal == Integer.TYPE && (actual == Integer.class || actual == Short.class || actual == Byte.class)) { return true; } if (formal == Long.TYPE && (actual == Long.class || actual == Integer.class || actual == Short.class || actual == Byte.class)) { return true; } if (formal == Float.TYPE && (actual == Float.class || actual == Long.class || actual == Integer.class || actual == Short.class || actual == Byte.class)) { return true; } if (formal == Double.TYPE && (actual == Double.class || actual == Float.class || actual == Long.class || actual == Integer.class || actual == Short.class || actual == Byte.class)) { return true; } } return false; } /** * Determines whether a type represented by a class object is convertible to * another type represented by a class object using a method invocation * conversion, without matching object and primitive types. This method is * used to determine the more specific type when comparing signatures of * methods. * * @param formal the formal parameter type to which the actual parameter * type should be convertible * @param actual the actual parameter type. * @return true if either formal type is assignable from actual type, or * formal and actual are both primitive types and actual can be * subject to widening conversion to formal. */ private static boolean isStrictMethodInvocationConvertible(Class formal, Class actual) { /* * we shouldn't get a null into, but if so */ if (actual == null && !formal.isPrimitive()) { return true; } /* * Check for identity or widening reference conversion */ if (formal.isAssignableFrom(actual)) { return true; } /* * Check for widening primitive conversion. */ if (formal.isPrimitive()) { if (formal == Short.TYPE && (actual == Byte.TYPE)) { return true; } if (formal == Integer.TYPE && (actual == Short.TYPE || actual == Byte.TYPE)) { return true; } if (formal == Long.TYPE && (actual == Integer.TYPE || actual == Short.TYPE || actual == Byte.TYPE)) { return true; } if (formal == Float.TYPE && (actual == Long.TYPE || actual == Integer.TYPE || actual == Short.TYPE || actual == Byte.TYPE)) { return true; } if (formal == Double.TYPE && (actual == Float.TYPE || actual == Long.TYPE || actual == Integer.TYPE || actual == Short.TYPE || actual == Byte.TYPE)) { return true; } } return false; } } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/Uberspect.java 100644 0 0 5317 10500374603 26517 0 ustar 0 0 /* * Copyright 2002,2004 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.util.introspection; import java.util.Iterator; /** * 'Federated' introspection/reflection interface to allow the introspection * behavior in Velocity to be customized. * * @since 1.0 * @author Geir Magusson Jr. * @version $Id: Uberspect.java 398498 2006-05-01 01:48:57Z dion $ */ public interface Uberspect { /** * Initializer - will be called before use. * @throws Exception on any error. */ void init() throws Exception; /** * To support iteratives - #foreach(). * @param info template info. * @param obj to get the iterator for. * @throws Exception on any error. * @return an iterator over obj. */ Iterator getIterator(Object obj, Info info) throws Exception; /** * Returns a general method, corresponding to $foo.bar( $woogie ). * @param obj the object * @param method the method name * @param args method arguments * @param info template info * @throws Exception on any error. * @return a {@link VelMethod}. */ VelMethod getMethod(Object obj, String method, Object[] args, Info info) throws Exception; /** * Property getter - returns VelPropertyGet appropos for #set($foo = * $bar.woogie). * @param obj the object to get the property from. * @param identifier property name * @param info template info * @throws Exception on any error. * @return a {@link VelPropertyGet}. */ VelPropertyGet getPropertyGet(Object obj, String identifier, Info info) throws Exception; /** * Property setter - returns VelPropertySet appropos for #set($foo.bar = * "geir"). * @param obj the object to get the property from. * @param identifier property name * @param arg value to set. * @param info template info * @throws Exception on any error. * @return a {@link VelPropertySet}. */ VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info info) throws Exception; } commons-jexl-1.1-src/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java 100644 0 0 25524 10500374603 27363 0 ustar 0 0 /* * Copyright 2002,2004 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.util.introspection; import org.apache.commons.jexl.util.ArrayIterator; import org.apache.commons.jexl.util.EnumerationIterator; import org.apache.commons.jexl.util.AbstractExecutor; import org.apache.commons.jexl.util.GetExecutor; import org.apache.commons.jexl.util.BooleanPropertyExecutor; import org.apache.commons.jexl.util.PropertyExecutor; import org.apache.commons.logging.Log; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import java.util.Collection; import java.util.Map; import java.util.Enumeration; import java.util.ArrayList; /** * Implementation of Uberspect to provide the default introspective * functionality of Velocity. * * @since 1.0 * @author Geir Magnusson Jr. * @version $Id: UberspectImpl.java 398509 2006-05-01 03:34:35Z dion $ */ public class UberspectImpl implements Uberspect, UberspectLoggable { /** index of the first character of the property. */ private static final int PROPERTY_START_INDEX = 3; /** * Our runtime logger. */ private Log rlog; /** * the default Velocity introspector. */ private static Introspector introspector; /** * init - does nothing - we need to have setRuntimeLogger called before * getting our introspector, as the default vel introspector depends upon * it. * @throws Exception on any error. */ public void init() throws Exception { } /** * Sets the runtime logger - this must be called before anything else * besides init() as to get the logger. Makes the pull model appealing... * @param runtimeLogger service to use for logging. */ public void setRuntimeLogger(Log runtimeLogger) { rlog = runtimeLogger; introspector = new Introspector(rlog); } /** * {@inheritDoc} */ public Iterator getIterator(Object obj, Info i) throws Exception { if (obj.getClass().isArray()) { return new ArrayIterator(obj); } else if (obj instanceof Collection) { return ((Collection) obj).iterator(); } else if (obj instanceof Map) { return ((Map) obj).values().iterator(); } else if (obj instanceof Iterator) { rlog.warn("Warning! The iterative " + " is an Iterator in the #foreach() loop at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable," + " if used in more than once, this may lead to" + " unexpected results."); return ((Iterator) obj); } else if (obj instanceof Enumeration) { rlog.warn("Warning! The iterative " + " is an Enumeration in the #foreach() loop at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable," + " if used in more than once, this may lead to" + " unexpected results."); return new EnumerationIterator((Enumeration) obj); } /* we have no clue what this is */ rlog.warn("Could not determine type of iterator in " + "#foreach loop " + " at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName()); return null; } /** * {@inheritDoc} */ public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception { if (obj == null) { return null; } Method m = introspector.getMethod(obj.getClass(), methodName, args); if (m == null && obj instanceof Class) { m = introspector.getMethod((Class) obj, methodName, args); } return (m == null) ? null : new VelMethodImpl(m); } /** * {@inheritDoc} */ public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception { AbstractExecutor executor; Class claz = obj.getClass(); /* * first try for a getFoo() type of property (also getfoo() ) */ executor = new PropertyExecutor(rlog, introspector, claz, identifier); /* * look for boolean isFoo() */ if (!executor.isAlive()) { executor = new BooleanPropertyExecutor(rlog, introspector, claz, identifier); } /* * if that didn't work, look for get("foo") */ if (!executor.isAlive()) { executor = new GetExecutor(rlog, introspector, claz, identifier); } return (executor == null) ? null : new VelGetterImpl(executor); } /** * {@inheritDoc} */ public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) throws Exception { Class claz = obj.getClass(); VelMethod vm = null; try { /* * first, we introspect for the setCommons JEXL uses Maven or Ant as a build system. The source is here.
To build a jar file, change into JEXL's root directory (see source link above) and run "maven jar". The result will be in the "target" subdirectory.
To build the Javadocs, run "maven javadoc". The result will be in "target/docs/apidocs".
To build the full website, run "maven site". The result will be in "target/docs".
To build the site, you need Maven 1.0.2 and version 1.9.2 of the maven-xdoc-plugin installed.
To build a jar file, change into JEXL's root directory and run "ant jar". The result will be in the "target" subdirectory.
To build the Javadocs, run "ant javadoc". The result will be in "dist/docs".
Jakarta Commons JEXL is hosted on the Apache subversion repository.
The project URL is:
http://svn.apache.org/repos/asf/jakarta/commons/proper/jexl/trunk
The best way to view the repository is via the subversion viewer.
The alternative is to use the native subversion display.