Java 类org.mozilla.javascript.ast.NodeVisitor 实例源码

项目:OpenSPIFe    文件:FormulaInfo.java   
public static boolean isTrivial (String formula) {
    // No formulas, just one constant or one variable.
    final ArrayList<AstNode> result = new ArrayList<AstNode>();
    parseIntoTree(formula).visit(new NodeVisitor(){

        @Override
        public boolean visit(AstNode node) {
            if(node.depth()>1){
                result.add(node);
                return false;
            }
            return true;
        }

    });
    if(result.size()>0){
        switch (result.get(0).getType()) {
            case Token.NUMBER: return true;
            case Token.NAME: return true;
            case Token.STRING: return true;
            default: return false;
        }
    }
    return false;
}