Search in sources :

Example 1 with BaseTree

use of org.antlr.runtime.tree.BaseTree in project SQLWindowing by hbutani.

the class SerializationUtils method addAntlrPersistenceDelegates.

public static void addAntlrPersistenceDelegates(XMLEncoder e) {
    e.setPersistenceDelegate(ASTNode.class, new PersistenceDelegate() {

        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] { ((ASTNode) oldInstance).getToken() });
        }
    });
    e.setPersistenceDelegate(CommonTree.class, new PersistenceDelegate() {

        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] { ((CommonTree) oldInstance).getToken() });
        }
    });
    e.setPersistenceDelegate(BaseTree.class, new PersistenceDelegate() {

        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] {});
        }

        @SuppressWarnings("rawtypes")
        protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out) {
            super.initialize(type, oldInstance, newInstance, out);
            BaseTree t = (BaseTree) oldInstance;
            for (int i = 0; i < t.getChildCount(); i++) {
                out.writeStatement(new Statement(oldInstance, "addChild", new Object[] { t.getChild(i) }));
            }
        }
    });
    e.setPersistenceDelegate(CommonToken.class, new PersistenceDelegate() {

        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] { ((CommonToken) oldInstance).getType(), ((CommonToken) oldInstance).getText() });
        }
    });
}
Also used : BaseTree(org.antlr.runtime.tree.BaseTree) Expression(java.beans.Expression) CommonTree(org.antlr.runtime.tree.CommonTree) XMLEncoder(java.beans.XMLEncoder) Encoder(java.beans.Encoder) Statement(java.beans.Statement) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) CommonToken(org.antlr.runtime.CommonToken) PersistenceDelegate(java.beans.PersistenceDelegate)

Example 2 with BaseTree

use of org.antlr.runtime.tree.BaseTree in project scheduler by btrplace.

the class TemplateAssignment method getTemplateOptions.

private Map<String, String> getTemplateOptions() {
    Map<String, String> opts = new HashMap<>();
    BaseTree t = getChild(1);
    for (int i = 0; i < t.getChildCount(); i++) {
        TemplateOptionTree opt = (TemplateOptionTree) t.getChild(i);
        opt.go(this);
        opts.put(opt.getKey(), opt.getValue());
    }
    return opts;
}
Also used : BaseTree(org.antlr.runtime.tree.BaseTree) HashMap(java.util.HashMap)

Aggregations

BaseTree (org.antlr.runtime.tree.BaseTree)2 Encoder (java.beans.Encoder)1 Expression (java.beans.Expression)1 PersistenceDelegate (java.beans.PersistenceDelegate)1 Statement (java.beans.Statement)1 XMLEncoder (java.beans.XMLEncoder)1 HashMap (java.util.HashMap)1 CommonToken (org.antlr.runtime.CommonToken)1 CommonTree (org.antlr.runtime.tree.CommonTree)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1