org.zodiac.template.velocity.impl.parser.SimpleNodeUtil Maven / Gradle / Ivy
package org.zodiac.template.velocity.impl.parser;
import java.lang.reflect.Field;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
public abstract class SimpleNodeUtil {
private SimpleNodeUtil() {
super();
}
private static final Field CHILDREN_FIELD;
static {
try {
CHILDREN_FIELD = SimpleNode.class.getDeclaredField("children");
CHILDREN_FIELD.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException("Could not reflect on SimpleNode", e);
}
}
public static void jjtSetChild(SimpleNode parent, Node child, int index) {
Node[] children;
try {
children = (Node[])CHILDREN_FIELD.get(parent);
} catch (Exception e) {
throw new IllegalArgumentException("Could not get children for node", e);
}
children[index] = child;
}
public static Node[] jjtGetChildren(SimpleNode parent) {
Node[] children;
try {
children = (Node[])CHILDREN_FIELD.get(parent);
} catch (Exception e) {
throw new IllegalArgumentException("Could not get children for node", e);
}
return children;
}
}