261 * The last statement added to the context
262 * @return The last statement added to the context
263 */
264 public Statement getLastStatement() {
265 if (sp == 0) {
266 return null;
267 }
268 final ParserContextNode top = stack[sp - 1];
269 final int s = top.getStatements().size();
270 return s == 0 ? null : top.getStatements().get(s - 1);
271 }
272
273 /**
274 * Returns an iterator over all functions in the context, with the top (innermost open) function first.
275 * @return an iterator over all functions in the context.
276 */
277 public Iterator<ParserContextFunctionNode> getFunctions() {
278 return new NodeIterator<>(ParserContextFunctionNode.class);
279 }
280
281 private class NodeIterator <T extends ParserContextNode> implements Iterator<T> {
282 private int index;
283 private T next;
284 private final Class<T> clazz;
285 private ParserContextNode until;
286
287 NodeIterator(final Class<T> clazz) {
288 this(clazz, null);
289 }
290
291 NodeIterator(final Class<T> clazz, final ParserContextNode until) {
292 this.index = sp - 1;
293 this.clazz = clazz;
294 this.until = until;
295 this.next = findNext();
296 }
297
298 @Override
299 public boolean hasNext() {
300 return next != null;
301 }
|
261 * The last statement added to the context
262 * @return The last statement added to the context
263 */
264 public Statement getLastStatement() {
265 if (sp == 0) {
266 return null;
267 }
268 final ParserContextNode top = stack[sp - 1];
269 final int s = top.getStatements().size();
270 return s == 0 ? null : top.getStatements().get(s - 1);
271 }
272
273 /**
274 * Returns an iterator over all functions in the context, with the top (innermost open) function first.
275 * @return an iterator over all functions in the context.
276 */
277 public Iterator<ParserContextFunctionNode> getFunctions() {
278 return new NodeIterator<>(ParserContextFunctionNode.class);
279 }
280
281 public ParserContextModuleNode getCurrentModule() {
282 final Iterator<ParserContextModuleNode> iter = new NodeIterator<>(ParserContextModuleNode.class, getCurrentFunction());
283 return iter.hasNext() ? iter.next() : null;
284 }
285
286 private class NodeIterator<T extends ParserContextNode> implements Iterator<T> {
287 private int index;
288 private T next;
289 private final Class<T> clazz;
290 private ParserContextNode until;
291
292 NodeIterator(final Class<T> clazz) {
293 this(clazz, null);
294 }
295
296 NodeIterator(final Class<T> clazz, final ParserContextNode until) {
297 this.index = sp - 1;
298 this.clazz = clazz;
299 this.until = until;
300 this.next = findNext();
301 }
302
303 @Override
304 public boolean hasNext() {
305 return next != null;
306 }
|