private AST createFromElement(String text) { AST ast = ASTUtil.create( fromClause.getASTFactory(), implied ? IMPLIED_FROM : FROM_FRAGMENT, // This causes the factory to instantiate the desired class. text); // Reset the node type, because the rest of the system is expecting FROM_FRAGMENT, all we wanted // was // for the factory to create the right sub-class. This might get reset again later on anyway to // make the // SQL generation simpler. ast.setType(FROM_FRAGMENT); return ast; }
/** * Returns an equivalent tree for (NOT (a relop b) ), for example: * * <pre> * (NOT (GT a b) ) => (LE a b) * </pre> * * @param x The sub tree to transform, the parent is assumed to be NOT. * @return AST - The equivalent sub-tree. */ public AST negateNode(AST x) { // TODO: switch statements are always evil! We already had bugs because // of forgotten token types. Use polymorphism for this! switch (x.getType()) { case OR: x.setType(AND); x.setText("{and}"); negateNode(x.getFirstChild()); negateNode(x.getFirstChild().getNextSibling()); return x; case AND: x.setType(OR); x.setText("{or}"); negateNode(x.getFirstChild()); negateNode(x.getFirstChild().getNextSibling()); return x; case EQ: x.setType(NE); x.setText("{not}" + x.getText()); return x; // (NOT (EQ a b) ) => (NE a b) case NE: x.setType(EQ); x.setText("{not}" + x.getText()); return x; // (NOT (NE a b) ) => (EQ a b) case GT: x.setType(LE); x.setText("{not}" + x.getText()); return x; // (NOT (GT a b) ) => (LE a b) case LT: x.setType(GE); x.setText("{not}" + x.getText()); return x; // (NOT (LT a b) ) => (GE a b) case GE: x.setType(LT); x.setText("{not}" + x.getText()); return x; // (NOT (GE a b) ) => (LT a b) case LE: x.setType(GT); x.setText("{not}" + x.getText()); return x; // (NOT (LE a b) ) => (GT a b) case LIKE: x.setType(NOT_LIKE); x.setText("{not}" + x.getText()); return x; // (NOT (LIKE a b) ) => (NOT_LIKE a b) case NOT_LIKE: x.setType(LIKE); x.setText("{not}" + x.getText()); return x; // (NOT (NOT_LIKE a b) ) => (LIKE a b) case IN: x.setType(NOT_IN); x.setText("{not}" + x.getText()); return x; case NOT_IN: x.setType(IN); x.setText("{not}" + x.getText()); return x; case IS_NULL: x.setType(IS_NOT_NULL); x.setText("{not}" + x.getText()); return x; // (NOT (IS_NULL a b) ) => (IS_NOT_NULL a b) case IS_NOT_NULL: x.setType(IS_NULL); x.setText("{not}" + x.getText()); return x; // (NOT (IS_NOT_NULL a b) ) => (IS_NULL a b) case BETWEEN: x.setType(NOT_BETWEEN); x.setText("{not}" + x.getText()); return x; // (NOT (BETWEEN a b) ) => (NOT_BETWEEN a b) case NOT_BETWEEN: x.setType(BETWEEN); x.setText("{not}" + x.getText()); return x; // (NOT (NOT_BETWEEN a b) ) => (BETWEEN a b) /* This can never happen because this rule will always eliminate the child NOT. case NOT: return x.getFirstChild(); // (NOT (NOT x) ) => (x) */ default: return super.negateNode(x); // Just add a 'not' parent. } }
public void initializeMethodNode(AST name, boolean inSelect) { name.setType(SqlTokenTypes.METHOD_NAME); String text = name.getText(); methodName = text.toLowerCase(); // Use the lower case function name. this.inSelect = inSelect; // Remember whether we're in a SELECT clause or not. }