You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/05/14 15:18:36 UTC
svn commit: r1103095 [6/24] - in /incubator/ognl/trunk/src:
main/java/org/apache/commons/ognl/ main/java/org/apache/commons/ognl/enhance/
main/java/org/apache/commons/ognl/internal/
test/java/org/apache/commons/ognl/ test/java/org/apache/commons/ognl/t...
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Evaluation.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Evaluation.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Evaluation.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Evaluation.java Sat May 14 13:18:29 2011
@@ -20,28 +20,36 @@
package org.apache.commons.ognl;
/**
- An <code>Evaluation</code> is and object that holds a node being evaluated
- and the source from which that node will take extract its
- value. It refers to child evaluations that occur as
- a result of the nodes' evaluation.
+ * An <code>Evaluation</code> is and object that holds a node being evaluated and the source from which that node will
+ * take extract its value. It refers to child evaluations that occur as a result of the nodes' evaluation.
*/
-public class Evaluation extends Object
+public class Evaluation
+ extends Object
{
- private SimpleNode node;
- private Object source;
- private boolean setOperation;
- private Object result;
- private Throwable exception;
- private Evaluation parent;
- private Evaluation next;
- private Evaluation previous;
- private Evaluation firstChild;
- private Evaluation lastChild;
+ private SimpleNode node;
+
+ private Object source;
+
+ private boolean setOperation;
+
+ private Object result;
+
+ private Throwable exception;
+
+ private Evaluation parent;
+
+ private Evaluation next;
+
+ private Evaluation previous;
+
+ private Evaluation firstChild;
+
+ private Evaluation lastChild;
/**
- Constructs a new "get" <code>Evaluation</code> from the node and source given.
+ * Constructs a new "get" <code>Evaluation</code> from the node and source given.
*/
- public Evaluation(SimpleNode node, Object source)
+ public Evaluation( SimpleNode node, Object source )
{
super();
this.node = node;
@@ -49,18 +57,17 @@ public class Evaluation extends Object
}
/**
- Constructs a new <code>Evaluation</code> from the node and source given.
- If <code>setOperation</code> is true this <code>Evaluation</code> represents
- a "set" as opposed to a "get".
+ * Constructs a new <code>Evaluation</code> from the node and source given. If <code>setOperation</code> is true
+ * this <code>Evaluation</code> represents a "set" as opposed to a "get".
*/
- public Evaluation(SimpleNode node, Object source, boolean setOperation)
+ public Evaluation( SimpleNode node, Object source, boolean setOperation )
{
- this(node, source);
+ this( node, source );
this.setOperation = setOperation;
}
/**
- Returns the <code>SimpleNode</code> for this <code>Evaluation</code>
+ * Returns the <code>SimpleNode</code> for this <code>Evaluation</code>
*/
public SimpleNode getNode()
{
@@ -68,18 +75,17 @@ public class Evaluation extends Object
}
/**
- Sets the node of the evaluation. Normally applications do not need to
- set this. Notable exceptions to this rule are custom evaluators that
- choose between navigable objects (as in a multi-root evaluator where
- the navigable node is chosen at runtime).
+ * Sets the node of the evaluation. Normally applications do not need to set this. Notable exceptions to this rule
+ * are custom evaluators that choose between navigable objects (as in a multi-root evaluator where the navigable
+ * node is chosen at runtime).
*/
- public void setNode(SimpleNode value)
+ public void setNode( SimpleNode value )
{
node = value;
}
/**
- Returns the source object on which this Evaluation operated.
+ * Returns the source object on which this Evaluation operated.
*/
public Object getSource()
{
@@ -87,18 +93,17 @@ public class Evaluation extends Object
}
/**
- Sets the source of the evaluation. Normally applications do not need to
- set this. Notable exceptions to this rule are custom evaluators that
- choose between navigable objects (as in a multi-root evaluator where
- the navigable node is chosen at runtime).
+ * Sets the source of the evaluation. Normally applications do not need to set this. Notable exceptions to this rule
+ * are custom evaluators that choose between navigable objects (as in a multi-root evaluator where the navigable
+ * node is chosen at runtime).
*/
- public void setSource(Object value)
+ public void setSource( Object value )
{
source = value;
}
/**
- Returns true if this Evaluation represents a set operation.
+ * Returns true if this Evaluation represents a set operation.
*/
public boolean isSetOperation()
{
@@ -106,16 +111,15 @@ public class Evaluation extends Object
}
/**
- Marks the Evaluation as a set operation if the value is true, else
- marks it as a get operation.
+ * Marks the Evaluation as a set operation if the value is true, else marks it as a get operation.
*/
- public void setSetOperation(boolean value)
+ public void setSetOperation( boolean value )
{
setOperation = value;
}
/**
- Returns the result of the Evaluation, or null if it was a set operation.
+ * Returns the result of the Evaluation, or null if it was a set operation.
*/
public Object getResult()
{
@@ -123,17 +127,16 @@ public class Evaluation extends Object
}
/**
- Sets the result of the Evaluation. This method is normally only used
- interally and should not be set without knowledge of what you are doing.
+ * Sets the result of the Evaluation. This method is normally only used interally and should not be set without
+ * knowledge of what you are doing.
*/
- public void setResult(Object value)
+ public void setResult( Object value )
{
result = value;
}
/**
- Returns the exception that occurred as a result of evaluating the
- Evaluation, or null if no exception occurred.
+ * Returns the exception that occurred as a result of evaluating the Evaluation, or null if no exception occurred.
*/
public Throwable getException()
{
@@ -141,18 +144,17 @@ public class Evaluation extends Object
}
/**
- Sets the exception that occurred as a result of evaluating the
- Evaluation. This method is normally only used interally and
- should not be set without knowledge of what you are doing.
+ * Sets the exception that occurred as a result of evaluating the Evaluation. This method is normally only used
+ * interally and should not be set without knowledge of what you are doing.
*/
- public void setException(Throwable value)
+ public void setException( Throwable value )
{
exception = value;
}
/**
- Returns the parent evaluation of this evaluation. If this returns
- null then it is is the root evaluation of a tree.
+ * Returns the parent evaluation of this evaluation. If this returns null then it is is the root evaluation of a
+ * tree.
*/
public Evaluation getParent()
{
@@ -160,8 +162,7 @@ public class Evaluation extends Object
}
/**
- Returns the next sibling of this evaluation. Returns null if
- this is the last in a chain of evaluations.
+ * Returns the next sibling of this evaluation. Returns null if this is the last in a chain of evaluations.
*/
public Evaluation getNext()
{
@@ -169,8 +170,7 @@ public class Evaluation extends Object
}
/**
- Returns the previous sibling of this evaluation. Returns null if
- this is the first in a chain of evaluations.
+ * Returns the previous sibling of this evaluation. Returns null if this is the first in a chain of evaluations.
*/
public Evaluation getPrevious()
{
@@ -178,8 +178,7 @@ public class Evaluation extends Object
}
/**
- Returns the first child of this evaluation. Returns null if
- there are no children.
+ * Returns the first child of this evaluation. Returns null if there are no children.
*/
public Evaluation getFirstChild()
{
@@ -187,8 +186,7 @@ public class Evaluation extends Object
}
/**
- Returns the last child of this evaluation. Returns null if
- there are no children.
+ * Returns the last child of this evaluation. Returns null if there are no children.
*/
public Evaluation getLastChild()
{
@@ -196,46 +194,50 @@ public class Evaluation extends Object
}
/**
- Gets the first descendent. In any Evaluation tree this will the
- Evaluation that was first executed.
+ * Gets the first descendent. In any Evaluation tree this will the Evaluation that was first executed.
*/
public Evaluation getFirstDescendant()
{
- if (firstChild != null) {
+ if ( firstChild != null )
+ {
return firstChild.getFirstDescendant();
}
return this;
}
/**
- Gets the last descendent. In any Evaluation tree this will the
- Evaluation that was most recently executing.
+ * Gets the last descendent. In any Evaluation tree this will the Evaluation that was most recently executing.
*/
public Evaluation getLastDescendant()
{
- if (lastChild != null) {
+ if ( lastChild != null )
+ {
return lastChild.getLastDescendant();
}
return this;
}
/**
- Adds a child to the list of children of this evaluation. The
- parent of the child is set to the receiver and the children
- references are modified in the receiver to reflect the new child.
- The lastChild of the receiver is set to the child, and the
- firstChild is set also if child is the first (or only) child.
+ * Adds a child to the list of children of this evaluation. The parent of the child is set to the receiver and the
+ * children references are modified in the receiver to reflect the new child. The lastChild of the receiver is set
+ * to the child, and the firstChild is set also if child is the first (or only) child.
*/
- public void addChild(Evaluation child)
+ public void addChild( Evaluation child )
{
- if (firstChild == null) {
+ if ( firstChild == null )
+ {
firstChild = lastChild = child;
- } else {
- if (firstChild == lastChild) {
+ }
+ else
+ {
+ if ( firstChild == lastChild )
+ {
firstChild.next = child;
lastChild = child;
lastChild.previous = firstChild;
- } else {
+ }
+ else
+ {
child.previous = lastChild;
lastChild.next = child;
lastChild = child;
@@ -245,9 +247,9 @@ public class Evaluation extends Object
}
/**
- Reinitializes this Evaluation to the parameters specified.
+ * Reinitializes this Evaluation to the parameters specified.
*/
- public void init(SimpleNode node, Object source, boolean setOperation)
+ public void init( SimpleNode node, Object source, boolean setOperation )
{
this.node = node;
this.source = source;
@@ -262,39 +264,43 @@ public class Evaluation extends Object
}
/**
- Resets this Evaluation to the initial state.
+ * Resets this Evaluation to the initial state.
*/
public void reset()
{
- init(null, null, false);
+ init( null, null, false );
}
/**
- Produces a String value for the Evaluation. If compact is
- true then a more compact form of the description only including
- the node type and unique identifier is shown, else a full
- description including source and result are shown. If showChildren
- is true the child evaluations are printed using the depth string
- given as a prefix.
+ * Produces a String value for the Evaluation. If compact is true then a more compact form of the description only
+ * including the node type and unique identifier is shown, else a full description including source and result are
+ * shown. If showChildren is true the child evaluations are printed using the depth string given as a prefix.
*/
- public String toString(boolean compact, boolean showChildren, String depth)
+ public String toString( boolean compact, boolean showChildren, String depth )
{
- String stringResult;
-
- if (compact) {
- stringResult = depth + "<" + node.getClass().getName() + " " + System.identityHashCode(this) + ">";
- } else {
- String ss = (source != null) ? source.getClass().getName() : "null",
- rs = (result != null) ? result.getClass().getName() : "null";
+ String stringResult;
- stringResult = depth + "<" + node.getClass().getName() + ": [" + (setOperation ? "set" : "get") + "] source = " + ss + ", result = " + result + " [" + rs + "]>";
+ if ( compact )
+ {
+ stringResult = depth + "<" + node.getClass().getName() + " " + System.identityHashCode( this ) + ">";
+ }
+ else
+ {
+ String ss = ( source != null ) ? source.getClass().getName() : "null", rs =
+ ( result != null ) ? result.getClass().getName() : "null";
+
+ stringResult =
+ depth + "<" + node.getClass().getName() + ": [" + ( setOperation ? "set" : "get" ) + "] source = " + ss
+ + ", result = " + result + " [" + rs + "]>";
}
- if (showChildren) {
- Evaluation child = firstChild;
+ if ( showChildren )
+ {
+ Evaluation child = firstChild;
stringResult += "\n";
- while (child != null) {
- stringResult += child.toString(compact, depth + " ");
+ while ( child != null )
+ {
+ stringResult += child.toString( compact, depth + " " );
child = child.next;
}
}
@@ -302,22 +308,20 @@ public class Evaluation extends Object
}
/**
- Produces a String value for the Evaluation. If compact is
- true then a more compact form of the description only including
- the node type and unique identifier is shown, else a full
- description including source and result are shown. Child
- evaluations are printed using the depth string given as a prefix.
+ * Produces a String value for the Evaluation. If compact is true then a more compact form of the description only
+ * including the node type and unique identifier is shown, else a full description including source and result are
+ * shown. Child evaluations are printed using the depth string given as a prefix.
*/
- public String toString(boolean compact, String depth)
+ public String toString( boolean compact, String depth )
{
- return toString(compact, true, depth);
+ return toString( compact, true, depth );
}
/**
- Returns a String description of the Evaluation.
+ * Returns a String description of the Evaluation.
*/
public String toString()
{
- return toString(false, "");
+ return toString( false, "" );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/EvaluationPool.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/EvaluationPool.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/EvaluationPool.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/EvaluationPool.java Sat May 14 13:18:29 2011
@@ -21,99 +21,109 @@ package org.apache.commons.ognl;
import java.util.*;
-public final class EvaluationPool extends Object
+public final class EvaluationPool
+ extends Object
{
- private List evaluations = new ArrayList();
- private int size = 0;
- private int created = 0;
- private int recovered = 0;
- private int recycled = 0;
+ private List evaluations = new ArrayList();
+
+ private int size = 0;
+
+ private int created = 0;
+
+ private int recovered = 0;
+
+ private int recycled = 0;
public EvaluationPool()
{
- this(0);
+ this( 0 );
}
- public EvaluationPool(int initialSize)
+ public EvaluationPool( int initialSize )
{
super();
- for (int i = 0; i < initialSize; i++) {
- evaluations.add(new Evaluation(null, null));
+ for ( int i = 0; i < initialSize; i++ )
+ {
+ evaluations.add( new Evaluation( null, null ) );
}
created = size = initialSize;
}
/**
- Returns an Evaluation that contains the node, source and whether it
- is a set operation. If there are no Evaluation objects in the
- pool one is created and returned.
+ * Returns an Evaluation that contains the node, source and whether it is a set operation. If there are no
+ * Evaluation objects in the pool one is created and returned.
*/
- public Evaluation create(SimpleNode node, Object source)
+ public Evaluation create( SimpleNode node, Object source )
{
- return create(node, source, false);
+ return create( node, source, false );
}
/**
- Returns an Evaluation that contains the node, source and whether it
- is a set operation. If there are no Evaluation objects in the
- pool one is created and returned.
+ * Returns an Evaluation that contains the node, source and whether it is a set operation. If there are no
+ * Evaluation objects in the pool one is created and returned.
*/
- public synchronized Evaluation create(SimpleNode node, Object source, boolean setOperation)
+ public synchronized Evaluation create( SimpleNode node, Object source, boolean setOperation )
{
- Evaluation result;
+ Evaluation result;
- if (size > 0) {
- result = (Evaluation)evaluations.remove(size - 1);
- result.init(node, source, setOperation);
+ if ( size > 0 )
+ {
+ result = (Evaluation) evaluations.remove( size - 1 );
+ result.init( node, source, setOperation );
size--;
recovered++;
- } else {
- result = new Evaluation(node, source, setOperation);
+ }
+ else
+ {
+ result = new Evaluation( node, source, setOperation );
created++;
}
return result;
}
/**
- Recycles an Evaluation
+ * Recycles an Evaluation
*/
- public synchronized void recycle(Evaluation value)
+ public synchronized void recycle( Evaluation value )
{
- if (value != null) {
+ if ( value != null )
+ {
value.reset();
- evaluations.add(value);
+ evaluations.add( value );
size++;
recycled++;
}
}
/**
- Recycles an of Evaluation and all of it's siblings
- and children.
+ * Recycles an of Evaluation and all of it's siblings and children.
*/
- public void recycleAll(Evaluation value)
+ public void recycleAll( Evaluation value )
{
- if (value != null) {
- recycleAll(value.getNext());
- recycleAll(value.getFirstChild());
- recycle(value);
+ if ( value != null )
+ {
+ recycleAll( value.getNext() );
+ recycleAll( value.getFirstChild() );
+ recycle( value );
}
}
/**
- Recycles a List of Evaluation objects
+ * Recycles a List of Evaluation objects
*/
- public void recycleAll(List value)
+ public void recycleAll( List value )
{
- if (value != null) {
- for (int i = 0, icount = value.size(); i < icount; i++) {
- recycle((Evaluation)value.get(i));
+ if ( value != null )
+ {
+ for ( int i = 0, icount = value.size(); i < icount; i++ )
+ {
+ recycle( (Evaluation) value.get( i ) );
}
}
}
/**
- Returns the number of items in the pool
+ * Returns the number of items in the pool
*/
public int getSize()
{
@@ -121,8 +131,7 @@ public final class EvaluationPool extend
}
/**
- Returns the number of items this pool has created since
- it's construction.
+ * Returns the number of items this pool has created since it's construction.
*/
public int getCreatedCount()
{
@@ -130,8 +139,7 @@ public final class EvaluationPool extend
}
/**
- Returns the number of items this pool has recovered from
- the pool since its construction.
+ * Returns the number of items this pool has recovered from the pool since its construction.
*/
public int getRecoveredCount()
{
@@ -139,8 +147,7 @@ public final class EvaluationPool extend
}
/**
- Returns the number of items this pool has recycled since
- it's construction.
+ * Returns the number of items this pool has recycled since it's construction.
*/
public int getRecycledCount()
{
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionNode.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionNode.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionNode.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionNode.java Sat May 14 13:18:29 2011
@@ -25,33 +25,44 @@ import org.apache.commons.ognl.enhance.E
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public abstract class ExpressionNode extends SimpleNode
+public abstract class ExpressionNode
+ extends SimpleNode
{
- public ExpressionNode(int i) {
- super(i);
+ public ExpressionNode( int i )
+ {
+ super( i );
}
- public ExpressionNode(OgnlParser p, int i) {
- super(p, i);
+ public ExpressionNode( OgnlParser p, int i )
+ {
+ super( p, i );
}
+
/**
- Returns true iff this node is constant without respect to the children.
+ * Returns true iff this node is constant without respect to the children.
*/
- public boolean isNodeConstant( OgnlContext context ) throws OgnlException
+ public boolean isNodeConstant( OgnlContext context )
+ throws OgnlException
{
return false;
}
- public boolean isConstant( OgnlContext context ) throws OgnlException
+ public boolean isConstant( OgnlContext context )
+ throws OgnlException
{
- boolean result = isNodeConstant(context);
+ boolean result = isNodeConstant( context );
- if ((_children != null) && (_children.length > 0)) {
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
result = true;
- for ( int i=0; result && (i < _children.length); ++i ) {
- if (_children[i] instanceof SimpleNode) {
- result = ((SimpleNode)_children[i]).isConstant( context );
- } else {
+ for ( int i = 0; result && ( i < _children.length ); ++i )
+ {
+ if ( _children[i] instanceof SimpleNode )
+ {
+ result = ( (SimpleNode) _children[i] ).isConstant( context );
+ }
+ else
+ {
result = false;
}
}
@@ -59,89 +70,107 @@ public abstract class ExpressionNode ext
return result;
}
- public String getExpressionOperator(int index)
+ public String getExpressionOperator( int index )
{
- throw new RuntimeException("unknown operator for " + OgnlParserTreeConstants.jjtNodeName[_id]);
+ throw new RuntimeException( "unknown operator for " + OgnlParserTreeConstants.jjtNodeName[_id] );
}
public String toString()
{
- StringBuilder result = new StringBuilder (_parent == null ? "" : "(" );
-
- if ((_children != null) && (_children.length > 0)) {
- for ( int i = 0; i < _children.length; ++i ) {
- if (i > 0) {
- result.append(" ").append(getExpressionOperator(i)).append(" ");
+ StringBuilder result = new StringBuilder( _parent == null ? "" : "(" );
+
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
+ for ( int i = 0; i < _children.length; ++i )
+ {
+ if ( i > 0 )
+ {
+ result.append( " " ).append( getExpressionOperator( i ) ).append( " " );
}
- result.append(_children[i].toString());
+ result.append( _children[i].toString() );
}
}
- if (_parent != null) {
- result.append(')');
+ if ( _parent != null )
+ {
+ result.append( ')' );
}
return result.toString();
}
-
- public String toGetSourceString(OgnlContext context, Object target)
+
+ public String toGetSourceString( OgnlContext context, Object target )
{
- StringBuilder result = new StringBuilder ((_parent == null || NumericExpression.class.isAssignableFrom(_parent.getClass())) ? "" : "(");
+ StringBuilder result =
+ new StringBuilder(
+ ( _parent == null || NumericExpression.class.isAssignableFrom( _parent.getClass() ) ) ? ""
+ : "(" );
+
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
+ for ( int i = 0; i < _children.length; ++i )
+ {
+ if ( i > 0 )
+ {
+ result.append( " " ).append( getExpressionOperator( i ) ).append( " " );
+ }
- if ((_children != null) && (_children.length > 0)) {
- for ( int i = 0; i < _children.length; ++i ) {
- if (i > 0) {
- result.append(" ").append(getExpressionOperator(i)).append(" ");
- }
-
- String value = _children[i].toGetSourceString(context, target);
-
- if ((ASTProperty.class.isInstance(_children[i]) || ASTMethod.class.isInstance(_children[i])
- || ASTSequence.class.isInstance(_children[i]) || ASTChain.class.isInstance(_children[i]))
- && value != null && value.trim().length() > 0) {
+ String value = _children[i].toGetSourceString( context, target );
+
+ if ( ( ASTProperty.class.isInstance( _children[i] ) || ASTMethod.class.isInstance( _children[i] )
+ || ASTSequence.class.isInstance( _children[i] ) || ASTChain.class.isInstance( _children[i] ) )
+ && value != null && value.trim().length() > 0 )
+ {
String pre = null;
- if (ASTMethod.class.isInstance(_children[i]))
+ if ( ASTMethod.class.isInstance( _children[i] ) )
{
- pre = (String)context.get("_currentChain");
+ pre = (String) context.get( "_currentChain" );
}
- if (pre == null)
+ if ( pre == null )
pre = "";
- String cast = (String)context.remove(ExpressionCompiler.PRE_CAST);
- if (cast == null)
+ String cast = (String) context.remove( ExpressionCompiler.PRE_CAST );
+ if ( cast == null )
cast = "";
- value = cast + ExpressionCompiler.getRootExpression(_children[i], context.getRoot(), context) + pre + value;
- }
+ value =
+ cast + ExpressionCompiler.getRootExpression( _children[i], context.getRoot(), context ) + pre
+ + value;
+ }
- result.append(value);
+ result.append( value );
}
}
- if (_parent != null && !NumericExpression.class.isAssignableFrom(_parent.getClass())) {
- result.append(")");
+ if ( _parent != null && !NumericExpression.class.isAssignableFrom( _parent.getClass() ) )
+ {
+ result.append( ")" );
}
-
+
return result.toString();
}
-
- public String toSetSourceString(OgnlContext context, Object target)
+
+ public String toSetSourceString( OgnlContext context, Object target )
{
- String result = (_parent == null) ? "" : "(";
-
- if ((_children != null) && (_children.length > 0)) {
- for ( int i = 0; i < _children.length; ++i ) {
- if (i > 0) {
- result += " " + getExpressionOperator(i) + " ";
+ String result = ( _parent == null ) ? "" : "(";
+
+ if ( ( _children != null ) && ( _children.length > 0 ) )
+ {
+ for ( int i = 0; i < _children.length; ++i )
+ {
+ if ( i > 0 )
+ {
+ result += " " + getExpressionOperator( i ) + " ";
}
-
- result += _children[i].toSetSourceString(context, target);
+
+ result += _children[i].toSetSourceString( context, target );
}
}
- if (_parent != null) {
+ if ( _parent != null )
+ {
result = result + ")";
}
-
+
return result;
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionSyntaxException.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionSyntaxException.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionSyntaxException.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ExpressionSyntaxException.java Sat May 14 13:18:29 2011
@@ -19,14 +19,14 @@
*/
package org.apache.commons.ognl;
-
/**
* Exception thrown if a malformed OGNL expression is encountered.
*
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class ExpressionSyntaxException extends OgnlException
+public class ExpressionSyntaxException
+ extends OgnlException
{
public ExpressionSyntaxException( String expression, Throwable reason )
{
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/InappropriateExpressionException.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/InappropriateExpressionException.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/InappropriateExpressionException.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/InappropriateExpressionException.java Sat May 14 13:18:29 2011
@@ -19,15 +19,15 @@
*/
package org.apache.commons.ognl;
-
/**
- * Exception thrown if an OGNL expression is evaluated in the wrong context; the usual
- * case is when an expression that does not end in a property reference is passed to
- * <code>setValue</code>.
+ * Exception thrown if an OGNL expression is evaluated in the wrong context; the usual case is when an expression that
+ * does not end in a property reference is passed to <code>setValue</code>.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class InappropriateExpressionException extends OgnlException
+public class InappropriateExpressionException
+ extends OgnlException
{
public InappropriateExpressionException( Node tree )
{
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IntHashMap.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IntHashMap.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IntHashMap.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IntHashMap.java Sat May 14 13:18:29 2011
@@ -23,49 +23,69 @@ import java.util.*;
/**
* A Map that uses ints as the keys.
- * <p>Use just like any java.util.Map, except that the keys must be ints.
- * This is much faster than creating a new Integer for each access.</p>
- * <p>For non-Map access (faster) use the put(int, Object) method.</p>
- * <p>This class implements Map for convenience, but this is not the most
- * efficient usage.</p>
+ * <p>
+ * Use just like any java.util.Map, except that the keys must be ints. This is much faster than creating a new Integer
+ * for each access.
+ * </p>
+ * <p>
+ * For non-Map access (faster) use the put(int, Object) method.
+ * </p>
+ * <p>
+ * This class implements Map for convenience, but this is not the most efficient usage.
+ * </p>
+ *
* @see java.util.HashMap
* @see java.util.Map
-*/
-public class IntHashMap extends Object implements Map
+ */
+public class IntHashMap
+ extends Object
+ implements Map
{
- private Entry table[];
- private int count;
- private int threshold;
- private float loadFactor;
-
- /*===================================================================
- Private static classes
- ===================================================================*/
- private static class IntHashMapIterator implements Iterator
- {
- boolean keys;
- int index;
- Entry table[];
- Entry entry;
-
- IntHashMapIterator(Entry table[], boolean keys)
- {
- super();
- this.table = table;
- this.keys = keys;
- this.index = table.length;
- }
-
- /*===================================================================
- Iterator interface
- ===================================================================*/
+ private Entry table[];
+
+ private int count;
+
+ private int threshold;
+
+ private float loadFactor;
+
+ /*
+ * =================================================================== Private static classes
+ * ===================================================================
+ */
+ private static class IntHashMapIterator
+ implements Iterator
+ {
+ boolean keys;
+
+ int index;
+
+ Entry table[];
+
+ Entry entry;
+
+ IntHashMapIterator( Entry table[], boolean keys )
+ {
+ super();
+ this.table = table;
+ this.keys = keys;
+ this.index = table.length;
+ }
+
+ /*
+ * =================================================================== Iterator interface
+ * ===================================================================
+ */
public boolean hasNext()
{
- if (entry != null) {
+ if ( entry != null )
+ {
return true;
}
- while (index-- > 0) {
- if ((entry = table[index]) != null) {
+ while ( index-- > 0 )
+ {
+ if ( ( entry = table[index] ) != null )
+ {
return true;
}
}
@@ -74,35 +94,43 @@ public class IntHashMap extends Object i
public Object next()
{
- if (entry == null) {
- while ((index-- > 0) && ((entry = table[index]) == null)) {
+ if ( entry == null )
+ {
+ while ( ( index-- > 0 ) && ( ( entry = table[index] ) == null ) )
+ {
/* do nothing */
}
}
- if (entry != null) {
- Entry e = entry;
+ if ( entry != null )
+ {
+ Entry e = entry;
entry = e.next;
- return keys ? new Integer(e.key) : e.value;
+ return keys ? new Integer( e.key ) : e.value;
}
- throw new NoSuchElementException("IntHashMapIterator");
+ throw new NoSuchElementException( "IntHashMapIterator" );
}
public void remove()
{
- throw new UnsupportedOperationException("remove");
+ throw new UnsupportedOperationException( "remove" );
}
}
- /*===================================================================
- Public static classes
- ===================================================================*/
- public static class Entry extends Object
+ /*
+ * =================================================================== Public static classes
+ * ===================================================================
+ */
+ public static class Entry
+ extends Object
{
- int hash;
- int key;
- Object value;
- Entry next;
+ int hash;
+
+ int key;
+
+ Object value;
+
+ Entry next;
public Entry()
{
@@ -110,46 +138,51 @@ public class IntHashMap extends Object i
}
}
- /*===================================================================
- Constructors
- ===================================================================*/
- public IntHashMap(int initialCapacity, float loadFactor)
+ /*
+ * =================================================================== Constructors
+ * ===================================================================
+ */
+ public IntHashMap( int initialCapacity, float loadFactor )
{
super();
- if (initialCapacity <= 0 || loadFactor <= 0.0) {
+ if ( initialCapacity <= 0 || loadFactor <= 0.0 )
+ {
throw new IllegalArgumentException();
}
this.loadFactor = loadFactor;
table = new Entry[initialCapacity];
- threshold = (int)(initialCapacity * loadFactor);
+ threshold = (int) ( initialCapacity * loadFactor );
}
- public IntHashMap(int initialCapacity)
+ public IntHashMap( int initialCapacity )
{
- this(initialCapacity, 0.75f);
+ this( initialCapacity, 0.75f );
}
public IntHashMap()
{
- this(101, 0.75f);
+ this( 101, 0.75f );
}
- /*===================================================================
- Protected methods
- ===================================================================*/
+ /*
+ * =================================================================== Protected methods
+ * ===================================================================
+ */
protected void rehash()
{
- int oldCapacity = table.length;
- Entry oldTable[] = table;
- int newCapacity = oldCapacity * 2 + 1;
- Entry newTable[] = new Entry[newCapacity];
+ int oldCapacity = table.length;
+ Entry oldTable[] = table;
+ int newCapacity = oldCapacity * 2 + 1;
+ Entry newTable[] = new Entry[newCapacity];
- threshold = (int)(newCapacity * loadFactor);
+ threshold = (int) ( newCapacity * loadFactor );
table = newTable;
- for (int i = oldCapacity ; i-- > 0 ;) {
- for (Entry old = oldTable[i] ; old != null;) {
- Entry e = old;
- int index = ( e.hash & 0x7FFFFFFF ) % newCapacity;
+ for ( int i = oldCapacity; i-- > 0; )
+ {
+ for ( Entry old = oldTable[i]; old != null; )
+ {
+ Entry e = old;
+ int index = ( e.hash & 0x7FFFFFFF ) % newCapacity;
old = old.next;
e.next = newTable[index];
@@ -158,56 +191,65 @@ public class IntHashMap extends Object i
}
}
- /*===================================================================
- Public methods
- ===================================================================*/
- public final boolean containsKey(int key)
- {
- int index = (key & 0x7FFFFFFF) % table.length;
+ /*
+ * =================================================================== Public methods
+ * ===================================================================
+ */
+ public final boolean containsKey( int key )
+ {
+ int index = ( key & 0x7FFFFFFF ) % table.length;
- for (Entry e = table[index] ; e != null ; e = e.next) {
- if ((e.hash == key) && (e.key == key)) {
+ for ( Entry e = table[index]; e != null; e = e.next )
+ {
+ if ( ( e.hash == key ) && ( e.key == key ) )
+ {
return true;
}
}
return false;
- }
+ }
- public final Object get(int key)
+ public final Object get( int key )
{
- int index = (key & 0x7FFFFFFF) % table.length;
+ int index = ( key & 0x7FFFFFFF ) % table.length;
- for (Entry e = table[index] ; e != null ; e = e.next) {
- if ((e.hash == key) && (e.key == key)) {
+ for ( Entry e = table[index]; e != null; e = e.next )
+ {
+ if ( ( e.hash == key ) && ( e.key == key ) )
+ {
return e.value;
}
}
return null;
}
- public final Object put(int key, Object value)
+ public final Object put( int key, Object value )
{
- int index = ( key & 0x7FFFFFFF ) % table.length;
+ int index = ( key & 0x7FFFFFFF ) % table.length;
- if (value == null) {
+ if ( value == null )
+ {
throw new IllegalArgumentException();
}
- for (Entry e = table[index] ; e != null ; e = e.next) {
- if ((e.hash == key) && (e.key == key)) {
- Object old = e.value;
+ for ( Entry e = table[index]; e != null; e = e.next )
+ {
+ if ( ( e.hash == key ) && ( e.key == key ) )
+ {
+ Object old = e.value;
e.value = value;
return old;
}
}
- if (count >= threshold) {
+ if ( count >= threshold )
+ {
// Rehash the table if the threshold is exceeded.
rehash();
- return put(key, value);
+ return put( key, value );
}
- Entry e = new Entry();
+ Entry e = new Entry();
e.hash = key;
e.key = key;
@@ -218,15 +260,20 @@ public class IntHashMap extends Object i
return null;
}
- public final Object remove(int key)
+ public final Object remove( int key )
{
- int index = (key & 0x7FFFFFFF) % table.length;
+ int index = ( key & 0x7FFFFFFF ) % table.length;
- for (Entry e = table[index], prev = null ; e != null ; prev = e, e = e.next) {
- if ((e.hash == key) && (e.key == key)) {
- if ( prev != null ) {
+ for ( Entry e = table[index], prev = null; e != null; prev = e, e = e.next )
+ {
+ if ( ( e.hash == key ) && ( e.key == key ) )
+ {
+ if ( prev != null )
+ {
prev.next = e.next;
- } else {
+ }
+ else
+ {
table[index] = e.next;
}
--count;
@@ -236,12 +283,13 @@ public class IntHashMap extends Object i
return null;
}
- /*===================================================================
- Map interface
- ===================================================================*/
+ /*
+ * =================================================================== Map interface
+ * ===================================================================
+ */
public int size()
{
- return count;
+ return count;
}
public boolean isEmpty()
@@ -249,67 +297,77 @@ public class IntHashMap extends Object i
return count == 0;
}
- public Object get(Object key)
- {
- if (!(key instanceof Number)) {
- throw new IllegalArgumentException("key is not an Number subclass");
+ public Object get( Object key )
+ {
+ if ( !( key instanceof Number ) )
+ {
+ throw new IllegalArgumentException( "key is not an Number subclass" );
}
- return get(((Number)key).intValue());
- }
+ return get( ( (Number) key ).intValue() );
+ }
- public Object put(Object key, Object value)
+ public Object put( Object key, Object value )
{
- if (!(key instanceof Number)) {
+ if ( !( key instanceof Number ) )
+ {
throw new IllegalArgumentException( "key cannot be null" );
}
- return put(((Number)key).intValue(), value );
+ return put( ( (Number) key ).intValue(), value );
}
- public void putAll(Map otherMap)
+ public void putAll( Map otherMap )
{
- for (Iterator it = otherMap.keySet().iterator(); it.hasNext();) {
- Object k = it.next();
+ for ( Iterator it = otherMap.keySet().iterator(); it.hasNext(); )
+ {
+ Object k = it.next();
- put(k, otherMap.get(k));
+ put( k, otherMap.get( k ) );
}
}
- public Object remove(Object key)
- {
- if (!(key instanceof Number)) {
- throw new IllegalArgumentException("key cannot be null");
+ public Object remove( Object key )
+ {
+ if ( !( key instanceof Number ) )
+ {
+ throw new IllegalArgumentException( "key cannot be null" );
}
- return remove(((Number)key).intValue());
- }
+ return remove( ( (Number) key ).intValue() );
+ }
public void clear()
- {
- Entry tab[] = table;
+ {
+ Entry tab[] = table;
- for (int index = tab.length; --index >= 0;) {
+ for ( int index = tab.length; --index >= 0; )
+ {
tab[index] = null;
}
count = 0;
- }
+ }
- public boolean containsKey(Object key)
- {
- if (!(key instanceof Number)) {
+ public boolean containsKey( Object key )
+ {
+ if ( !( key instanceof Number ) )
+ {
throw new InternalError( "key is not an Number subclass" );
}
- return containsKey(((Number)key).intValue());
- }
+ return containsKey( ( (Number) key ).intValue() );
+ }
- public boolean containsValue(Object value)
+ public boolean containsValue( Object value )
{
- Entry tab[] = table;
+ Entry tab[] = table;
- if (value == null) {
+ if ( value == null )
+ {
throw new IllegalArgumentException();
}
- for (int i = tab.length ; i-- > 0;) {
- for (Entry e = tab[i] ; e != null ; e = e.next ) {
- if (e.value.equals(value)) {
+ for ( int i = tab.length; i-- > 0; )
+ {
+ for ( Entry e = tab[i]; e != null; e = e.next )
+ {
+ if ( e.value.equals( value ) )
+ {
return true;
}
}
@@ -319,26 +377,28 @@ public class IntHashMap extends Object i
public Set keySet()
{
- Set result = new HashSet();
+ Set result = new HashSet();
- for (Iterator it = new IntHashMapIterator(table, true); it.hasNext();) {
- result.add(it.next());
+ for ( Iterator it = new IntHashMapIterator( table, true ); it.hasNext(); )
+ {
+ result.add( it.next() );
}
return result;
}
public Collection values()
{
- List result = new ArrayList();
+ List result = new ArrayList();
- for (Iterator it = new IntHashMapIterator(table, false); it.hasNext();) {
- result.add(it.next());
+ for ( Iterator it = new IntHashMapIterator( table, false ); it.hasNext(); )
+ {
+ result.add( it.next() );
}
return result;
}
public Set entrySet()
{
- throw new UnsupportedOperationException("entrySet");
+ throw new UnsupportedOperationException( "entrySet" );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorElementsAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorElementsAccessor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorElementsAccessor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorElementsAccessor.java Sat May 14 13:18:29 2011
@@ -22,15 +22,16 @@ package org.apache.commons.ognl;
import java.util.*;
/**
- * Implementation of the ElementsAccessor interface for Iterators, which simply returns
- * the target iterator itself.
+ * Implementation of the ElementsAccessor interface for Iterators, which simply returns the target iterator itself.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class IteratorElementsAccessor implements ElementsAccessor
+public class IteratorElementsAccessor
+ implements ElementsAccessor
{
public Enumeration getElements( Object target )
{
- return new IteratorEnumeration( (Iterator)target );
+ return new IteratorEnumeration( (Iterator) target );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorEnumeration.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorEnumeration.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorEnumeration.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorEnumeration.java Sat May 14 13:18:29 2011
@@ -23,24 +23,29 @@ import java.util.*;
/**
* Maps an Iterator to an Enumeration
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class IteratorEnumeration extends Object implements Enumeration
+public class IteratorEnumeration
+ extends Object
+ implements Enumeration
{
- private Iterator it;
+ private Iterator it;
- public IteratorEnumeration(Iterator it)
- {
- super();
- this.it = it;
- }
+ public IteratorEnumeration( Iterator it )
+ {
+ super();
+ this.it = it;
+ }
- public boolean hasMoreElements() {
+ public boolean hasMoreElements()
+ {
return it.hasNext();
}
- public Object nextElement() {
+ public Object nextElement()
+ {
return it.next();
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorPropertyAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorPropertyAccessor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorPropertyAccessor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/IteratorPropertyAccessor.java Sat May 14 13:18:29 2011
@@ -22,36 +22,48 @@ package org.apache.commons.ognl;
import java.util.*;
/**
- * Implementation of PropertyAccessor that provides "property" reference to
- * "next" and "hasNext".
+ * Implementation of PropertyAccessor that provides "property" reference to "next" and "hasNext".
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class IteratorPropertyAccessor extends ObjectPropertyAccessor
+public class IteratorPropertyAccessor
+ extends ObjectPropertyAccessor
implements PropertyAccessor // This is here to make javadoc show this class as an implementor
{
- public Object getProperty( Map context, Object target, Object name ) throws OgnlException
+ public Object getProperty( Map context, Object target, Object name )
+ throws OgnlException
{
- Object result;
- Iterator iterator = (Iterator)target;
+ Object result;
+ Iterator iterator = (Iterator) target;
- if ( name instanceof String ) {
- if (name.equals("next")) {
+ if ( name instanceof String )
+ {
+ if ( name.equals( "next" ) )
+ {
result = iterator.next();
- } else {
- if (name.equals("hasNext")) {
+ }
+ else
+ {
+ if ( name.equals( "hasNext" ) )
+ {
result = iterator.hasNext() ? Boolean.TRUE : Boolean.FALSE;
- } else {
+ }
+ else
+ {
result = super.getProperty( context, target, name );
}
}
- } else {
- result = super.getProperty(context, target, name);
+ }
+ else
+ {
+ result = super.getProperty( context, target, name );
}
return result;
}
- public void setProperty( Map context, Object target, Object name, Object value ) throws OgnlException
+ public void setProperty( Map context, Object target, Object name, Object value )
+ throws OgnlException
{
throw new IllegalArgumentException( "can't set property " + name + " on Iterator" );
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JJTOgnlParserState.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JJTOgnlParserState.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JJTOgnlParserState.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JJTOgnlParserState.java Sat May 14 13:18:29 2011
@@ -20,123 +20,147 @@
/* Generated By:JavaCC: Do not edit this line. JJTOgnlParserState.java Version 4.1d1 */
package org.apache.commons.ognl;
-public class JJTOgnlParserState {
- private java.util.List nodes;
- private java.util.List marks;
-
- private int sp; // number of nodes on stack
- private int mk; // current mark
- private boolean node_created;
-
- public JJTOgnlParserState() {
- nodes = new java.util.ArrayList();
- marks = new java.util.ArrayList();
- 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. */
- public boolean nodeCreated() {
- return node_created;
- }
-
- /* Call this to reinitialize the node stack. It is called
- automatically by the parser's ReInit() method. */
- public void reset() {
- nodes.clear();
- marks.clear();
- sp = 0;
- mk = 0;
- }
-
- /* Returns the root node of the AST. It only makes sense to call
- this after a successful parse. */
- public Node rootNode() {
- return (Node)nodes.get(0);
- }
-
- /* Pushes a node on to the stack. */
- public void pushNode(Node n) {
- nodes.add(n);
- ++sp;
- }
-
- /* Returns the node on the top of the stack, and remove it from the
- stack. */
- public Node popNode() {
- if (--sp < mk) {
- mk = ((Integer)marks.remove(marks.size()-1)).intValue();
- }
- return (Node)nodes.remove(nodes.size()-1);
- }
-
- /* Returns the node currently on the top of the stack. */
- public Node peekNode() {
- return (Node)nodes.get(nodes.size()-1);
- }
-
- /* Returns the number of children on the stack in the current node
- scope. */
- public int nodeArity() {
- return sp - mk;
- }
-
-
- public void clearNodeScope(Node n) {
- while (sp > mk) {
- popNode();
- }
- mk = ((Integer)marks.remove(marks.size()-1)).intValue();
- }
-
-
- public void openNodeScope(Node n) {
- marks.add(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. */
- public void closeNodeScope(Node n, int num) {
- mk = ((Integer)marks.remove(marks.size()-1)).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 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. */
- public void closeNodeScope(Node n, boolean condition) {
- if (condition) {
- int a = nodeArity();
- mk = ((Integer)marks.remove(marks.size()-1)).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.remove(marks.size()-1)).intValue();
- node_created = false;
+public class JJTOgnlParserState
+{
+ private java.util.List nodes;
+
+ private java.util.List marks;
+
+ private int sp; // number of nodes on stack
+
+ private int mk; // current mark
+
+ private boolean node_created;
+
+ public JJTOgnlParserState()
+ {
+ nodes = new java.util.ArrayList();
+ marks = new java.util.ArrayList();
+ 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.
+ */
+ public boolean nodeCreated()
+ {
+ return node_created;
+ }
+
+ /*
+ * Call this to reinitialize the node stack. It is called automatically by the parser's ReInit() method.
+ */
+ public void reset()
+ {
+ nodes.clear();
+ marks.clear();
+ sp = 0;
+ mk = 0;
+ }
+
+ /*
+ * Returns the root node of the AST. It only makes sense to call this after a successful parse.
+ */
+ public Node rootNode()
+ {
+ return (Node) nodes.get( 0 );
+ }
+
+ /* Pushes a node on to the stack. */
+ public void pushNode( Node n )
+ {
+ nodes.add( n );
+ ++sp;
+ }
+
+ /*
+ * Returns the node on the top of the stack, and remove it from the stack.
+ */
+ public Node popNode()
+ {
+ if ( --sp < mk )
+ {
+ mk = ( (Integer) marks.remove( marks.size() - 1 ) ).intValue();
+ }
+ return (Node) nodes.remove( nodes.size() - 1 );
+ }
+
+ /* Returns the node currently on the top of the stack. */
+ public Node peekNode()
+ {
+ return (Node) nodes.get( nodes.size() - 1 );
+ }
+
+ /*
+ * Returns the number of children on the stack in the current node scope.
+ */
+ public int nodeArity()
+ {
+ return sp - mk;
+ }
+
+ public void clearNodeScope( Node n )
+ {
+ while ( sp > mk )
+ {
+ popNode();
+ }
+ mk = ( (Integer) marks.remove( marks.size() - 1 ) ).intValue();
+ }
+
+ public void openNodeScope( Node n )
+ {
+ marks.add( 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.
+ */
+ public void closeNodeScope( Node n, int num )
+ {
+ mk = ( (Integer) marks.remove( marks.size() - 1 ) ).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 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.
+ */
+ public void closeNodeScope( Node n, boolean condition )
+ {
+ if ( condition )
+ {
+ int a = nodeArity();
+ mk = ( (Integer) marks.remove( marks.size() - 1 ) ).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.remove( marks.size() - 1 ) ).intValue();
+ node_created = false;
+ }
}
- }
}
/* JavaCC - OriginalChecksum=61071c68a05e7c9104307c34a2e37165 (do not edit this line) */