| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| JJTOgnlParserState |
|
| 1.4166666666666667;1.417 |
| 1 | package org.apache.commons.ognl; | |
| 2 | ||
| 3 | /* | |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 5 | * or more contributor license agreements. See the NOTICE file | |
| 6 | * distributed with this work for additional information | |
| 7 | * regarding copyright ownership. The ASF licenses this file | |
| 8 | * to you under the Apache License, Version 2.0 (the | |
| 9 | * "License"); you may not use this file except in compliance | |
| 10 | * with the License. You may obtain a copy of the License at | |
| 11 | * | |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 13 | * | |
| 14 | * Unless required by applicable law or agreed to in writing, | |
| 15 | * software distributed under the License is distributed on an | |
| 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 17 | * KIND, either express or implied. See the License for the | |
| 18 | * specific language governing permissions and limitations | |
| 19 | * under the License. | |
| 20 | */ | |
| 21 | ||
| 22 | /* Generated By:JavaCC: Do not edit this line. JJTOgnlParserState.java Version 4.1d1 */ | |
| 23 | ||
| 24 | import java.util.ArrayList; | |
| 25 | import java.util.List; | |
| 26 | ||
| 27 | /** | |
| 28 | * $Id: JJTOgnlParserState.java 1194866 2011-10-29 10:51:32Z mcucchiara $ | |
| 29 | */ | |
| 30 | public class JJTOgnlParserState | |
| 31 | { | |
| 32 | private List<Node> nodes; | |
| 33 | ||
| 34 | private List<Integer> marks; | |
| 35 | ||
| 36 | private int numNodesOnStack; | |
| 37 | ||
| 38 | private int currentMark; | |
| 39 | ||
| 40 | private boolean nodeCreated; | |
| 41 | ||
| 42 | public JJTOgnlParserState() | |
| 43 | 1148 | { |
| 44 | 1148 | nodes = new ArrayList<Node>(); |
| 45 | 1148 | marks = new ArrayList<Integer>(); |
| 46 | 1148 | numNodesOnStack = 0; |
| 47 | 1148 | currentMark = 0; |
| 48 | 1148 | } |
| 49 | ||
| 50 | /* | |
| 51 | * Determines whether the current node was actually closed and pushed. This should only be called in the final user | |
| 52 | * action of a node scope. | |
| 53 | */ | |
| 54 | public boolean nodeCreated() | |
| 55 | { | |
| 56 | 0 | return nodeCreated; |
| 57 | } | |
| 58 | ||
| 59 | /* | |
| 60 | * Call this to reinitialize the node stack. It is called automatically by the parser's ReInit() method. | |
| 61 | */ | |
| 62 | public void reset() | |
| 63 | { | |
| 64 | 0 | nodes.clear(); |
| 65 | 0 | marks.clear(); |
| 66 | 0 | numNodesOnStack = 0; |
| 67 | 0 | currentMark = 0; |
| 68 | 0 | } |
| 69 | ||
| 70 | /* | |
| 71 | * Returns the root node of the AST. It only makes sense to call this after a successful parse. | |
| 72 | */ | |
| 73 | public Node rootNode() | |
| 74 | { | |
| 75 | 1143 | return nodes.get( 0 ); |
| 76 | } | |
| 77 | ||
| 78 | /* Pushes a node on to the stack. */ | |
| 79 | public void pushNode( Node node ) | |
| 80 | { | |
| 81 | 5580 | nodes.add( node ); |
| 82 | 5580 | ++numNodesOnStack; |
| 83 | 5580 | } |
| 84 | ||
| 85 | /* | |
| 86 | * Returns the node on the top of the stack, and remove it from the stack. | |
| 87 | */ | |
| 88 | public Node popNode() | |
| 89 | { | |
| 90 | 4436 | if ( --numNodesOnStack < currentMark ) |
| 91 | { | |
| 92 | 0 | currentMark = marks.remove( marks.size() - 1 ); |
| 93 | } | |
| 94 | 4436 | return nodes.remove( nodes.size() - 1 ); |
| 95 | } | |
| 96 | ||
| 97 | /* Returns the node currently on the top of the stack. */ | |
| 98 | public Node peekNode() | |
| 99 | { | |
| 100 | 0 | return nodes.get( nodes.size() - 1 ); |
| 101 | } | |
| 102 | ||
| 103 | /* | |
| 104 | * Returns the number of children on the stack in the current node scope. | |
| 105 | */ | |
| 106 | public int nodeArity() | |
| 107 | { | |
| 108 | 2685 | return numNodesOnStack - currentMark; |
| 109 | } | |
| 110 | ||
| 111 | public void clearNodeScope( Node unused ) | |
| 112 | { | |
| 113 | 0 | while ( numNodesOnStack > currentMark ) |
| 114 | { | |
| 115 | 0 | popNode(); |
| 116 | } | |
| 117 | 0 | currentMark = marks.remove( marks.size() - 1 ); |
| 118 | 0 | } |
| 119 | ||
| 120 | public void openNodeScope( Node node ) | |
| 121 | { | |
| 122 | 5580 | marks.add( currentMark ); |
| 123 | 5580 | currentMark = numNodesOnStack; |
| 124 | 5580 | node.jjtOpen(); |
| 125 | 5580 | } |
| 126 | ||
| 127 | /* | |
| 128 | * A definite node is constructed from a specified number of children. That number of nodes are popped from the | |
| 129 | * stack and made the children of the definite node. Then the definite node is pushed on to the stack. | |
| 130 | */ | |
| 131 | public void closeNodeScope( Node node, int num ) | |
| 132 | { | |
| 133 | 2895 | currentMark = marks.remove( marks.size() - 1 ); |
| 134 | 5641 | while ( num-- > 0 ) |
| 135 | { | |
| 136 | 2746 | Node poppedNode = popNode(); |
| 137 | 2746 | poppedNode.jjtSetParent( node ); |
| 138 | 2746 | node.jjtAddChild( poppedNode, num ); |
| 139 | 2746 | } |
| 140 | 2895 | node.jjtClose(); |
| 141 | 2895 | pushNode( node ); |
| 142 | 2895 | nodeCreated = true; |
| 143 | 2895 | } |
| 144 | ||
| 145 | /* | |
| 146 | * A conditional node is constructed if its condition is true. All the nodes that have been pushed since the node | |
| 147 | * was opened are made children of the conditional node, which is then pushed on to the stack. If the condition is | |
| 148 | * false the node is not constructed and they are left on the stack. | |
| 149 | */ | |
| 150 | public void closeNodeScope( Node node, boolean condition ) | |
| 151 | { | |
| 152 | 2685 | if ( condition ) |
| 153 | { | |
| 154 | 2685 | int arity = nodeArity(); |
| 155 | 2685 | currentMark = marks.remove( marks.size() - 1 ); |
| 156 | 4375 | while ( arity-- > 0 ) |
| 157 | { | |
| 158 | 1690 | Node poppedNode = popNode(); |
| 159 | 1690 | poppedNode.jjtSetParent( node ); |
| 160 | 1690 | node.jjtAddChild( poppedNode, arity ); |
| 161 | 1690 | } |
| 162 | 2685 | node.jjtClose(); |
| 163 | 2685 | pushNode( node ); |
| 164 | 2685 | nodeCreated = true; |
| 165 | 2685 | } |
| 166 | else | |
| 167 | { | |
| 168 | 0 | currentMark = marks.remove( marks.size() - 1 ); |
| 169 | 0 | nodeCreated = false; |
| 170 | } | |
| 171 | 2685 | } |
| 172 | } | |
| 173 | /* JavaCC - OriginalChecksum=61071c68a05e7c9104307c34a2e37165 (do not edit this line) */ |