All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.uscexp.blockformatpropertyfile.parser.AstArrayValueTreeNode Maven / Gradle / Ivy

There is a newer version: 0.2.0-Beta
Show newest version
/*
 * Copyright (C) 2014 by haui - all rights reserved
 */
package com.github.uscexp.blockformatpropertyfile.parser;

import java.util.ArrayList;
import java.util.List;

import com.github.uscexp.grappa.extension.util.IStack;

/**
 * Command implementation for the PropertyFileParser rule: arrayValue.
 */
public class AstArrayValueTreeNode extends AstBaseCommandTreeNode {

	public AstArrayValueTreeNode(String rule, String value) {
		super(rule, value);
	}

	@Override
	protected void interpretAfterChilds(Long id)
		throws Exception {
		super.interpretAfterChilds(id);

		IStack stack = processStore.getStack();
		List result = new ArrayList<>();
		if(!stack.isEmpty()) {
			while (!stack.isEmpty()) {
				Object object = stack.pop();
				result.add(object);
			}
		} else {
			IStack arrayStack = arrayStructStore.getStack();
			while (!arrayStack.isEmpty()) {
				Object object = arrayStack.pop();
				result.add(object);
			}
		}
		stack.push(result.toArray(new Object[result.size()]));
	}

}