/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { Block otherIf = this.ifBlock.clone(); Criteria otherCrit = (Criteria) this.condition.clone(); Block otherElse = null; if(this.hasElseBlock()) { otherElse = this.elseBlock.clone(); } return new IfStatement(otherCrit, otherIf, otherElse); }
@Override public void visit( IfStatement obj ) { append(IF); append("("); //$NON-NLS-1$ visitNode(obj.getCondition()); append(")\n"); //$NON-NLS-1$ addTabs(0); visitNode(obj.getIfBlock()); if (obj.hasElseBlock()) { append("\n"); //$NON-NLS-1$ addTabs(0); append(ELSE); append("\n"); //$NON-NLS-1$ addTabs(0); visitNode(obj.getElseBlock()); } }
/** * Compare two IfStatements for equality. They will only evaluate to equal if * they are IDENTICAL: their if, else blocks are same and the condition on the * ifBlock is same. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof IfStatement)) { return false; } IfStatement other = (IfStatement) obj; return // Compare the condition EquivalenceUtil.areEqual(getCondition(), other.getCondition()) && // Compare the if block EquivalenceUtil.areEqual(getIfBlock(), other.getIfBlock()) && // Compare the else block EquivalenceUtil.areEqual(this.getElseBlock(), other.getElseBlock()); }
case Statement.TYPE_IF: IfStatement ifStmt = (IfStatement) statement; Criteria ifCrit = ifStmt.getCondition(); Criteria evalCrit = rewriteCriteria(ifCrit); ifStmt.setCondition(evalCrit); if(evalCrit.equals(TRUE_CRITERIA)) { Block ifblock = rewriteBlock(ifStmt.getIfBlock()); if (ifblock.isAtomic()) { newStmts.add(ifblock); if(ifStmt.hasElseBlock()) { Block elseBlock = rewriteBlock(ifStmt.getElseBlock()); if (elseBlock.isAtomic()) { newStmts.add(elseBlock); Block ifblock = rewriteBlock(ifStmt.getIfBlock()); ifStmt.setIfBlock(ifblock); if(ifStmt.hasElseBlock()) { Block elseBlock = rewriteBlock(ifStmt.getElseBlock()); ifStmt.setElseBlock(elseBlock);
newInsert.setVariables(LanguageObject.Util.deepClone(insert.getVariables(), ElementSymbol.class)); ArrayList<Expression> values = new ArrayList<Expression>(); IfStatement ifStatement = new IfStatement(); Query exists = new Query(); exists.setSelect(new Select(Arrays.asList(new Constant(1)))); exists.setFrom(new From(Arrays.asList(new UnaryFromClause(insert.getGroup().clone())))); ifStatement.setCondition(new ExistsCriteria(exists)); Update update = new Update(); update.setGroup(insert.getGroup().clone()); update.setCriteria((Criteria) Criteria.combineCriteria(crits).clone()); exists.setCriteria((Criteria) Criteria.combineCriteria(crits).clone()); ifStatement.setIfBlock(new Block(new CommandStatement(update))); ifStatement.setElseBlock(new Block(new CommandStatement(newInsert)));
final public IfStatement ifStatement(ParseInfo info) throws ParseException { IfStatement ifStmt = null; Criteria criteria = null; Statement ifStatement = null; Statement elseStatement = null; String groupID = null; String groupID2 = null; boolean not = false; jj_consume_token(IF); jj_consume_token(LPAREN); criteria = criteria(info); jj_consume_token(RPAREN); ifStatement = statement(info); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ELSE: jj_consume_token(ELSE); elseStatement = statement(info); break; default: jj_la1[43] = jj_gen; ; } ifStmt = new IfStatement(criteria, asBlock(ifStatement)); ifStmt.setElseBlock(asBlock(elseStatement)); {if (true) return ifStmt;} throw new Error("Missing return statement in function"); }
@Test public void testIfElseWithoutBeginEnd() { String sql = "CREATE VIRTUAL PROCEDURE BEGIN IF (x > 1) select 1; IF (x > 1) select 1; ELSE select 1; END"; //$NON-NLS-1$ String expected = "BEGIN\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nELSE\nBEGIN\nSELECT 1;\nEND\nEND"; //$NON-NLS-1$ Query query = new Query(); query.setSelect(new Select(Arrays.asList(new Constant(1)))); //$NON-NLS-1$ CommandStatement commandStmt = new CommandStatement(query); CompareCriteria criteria = new CompareCriteria(new ElementSymbol("x"), CompareCriteria.GT, new Constant(1)); //$NON-NLS-1$ Block block = new Block(); block.addStatement(commandStmt); IfStatement ifStmt = new IfStatement(criteria, block); IfStatement ifStmt1 = (IfStatement)ifStmt.clone(); Block block2 = new Block(); block2.addStatement(commandStmt); ifStmt1.setElseBlock(block2); Block block3 = new Block(); block3.addStatement(ifStmt); block3.addStatement(ifStmt1); CreateProcedureCommand command = new CreateProcedureCommand(block3); helpTest(sql, expected, command); }
public static final IfStatement sample1() { Block ifBlock = TestBlock.sample1(); Block elseBlock = TestBlock.sample2(); Criteria criteria = TestSetCriteria.sample1(); return new IfStatement(criteria, ifBlock, elseBlock); }
public void testGetCondition() { IfStatement b1 = sample1(); assertTrue("Incorrect IfBlock on statement", b1.getCondition().equals(TestSetCriteria.sample1())); //$NON-NLS-1$ }
public void testGetIfBlock() { IfStatement b1 = sample1(); assertTrue("Incorrect IfBlock on statement", b1.getIfBlock().equals(TestBlock.sample1())); //$NON-NLS-1$ }
public void testGetElseBlock() { IfStatement b1 = sample1(); assertTrue("Incorrect IfBlock on statement", b1.getElseBlock().equals(TestBlock.sample2())); //$NON-NLS-1$ }
case Statement.TYPE_IF: IfStatement ifStmt = (IfStatement) statement; Criteria ifCrit = ifStmt.getCondition(); Criteria evalCrit = rewriteCriteria(ifCrit); ifStmt.setCondition(evalCrit); if(evalCrit.equals(TRUE_CRITERIA)) { Block ifblock = rewriteBlock(ifStmt.getIfBlock()); if (ifblock.isAtomic()) { newStmts.add(ifblock); if(ifStmt.hasElseBlock()) { Block elseBlock = rewriteBlock(ifStmt.getElseBlock()); if (elseBlock.isAtomic()) { newStmts.add(elseBlock); Block ifblock = rewriteBlock(ifStmt.getIfBlock()); ifStmt.setIfBlock(ifblock); if(ifStmt.hasElseBlock()) { Block elseBlock = rewriteBlock(ifStmt.getElseBlock()); ifStmt.setElseBlock(elseBlock);
/** * Compare two IfStatements for equality. They will only evaluate to equal if * they are IDENTICAL: their if, else blocks are same and the condition on the * ifBlock is same. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof IfStatement)) { return false; } IfStatement other = (IfStatement) obj; return // Compare the condition EquivalenceUtil.areEqual(getCondition(), other.getCondition()) && // Compare the if block EquivalenceUtil.areEqual(getIfBlock(), other.getIfBlock()) && // Compare the else block EquivalenceUtil.areEqual(this.getElseBlock(), other.getElseBlock()); }
newInsert.setVariables(LanguageObject.Util.deepClone(insert.getVariables(), ElementSymbol.class)); ArrayList<Expression> values = new ArrayList<Expression>(); IfStatement ifStatement = new IfStatement(); Query exists = new Query(); exists.setSelect(new Select(Arrays.asList(new Constant(1)))); exists.setFrom(new From(Arrays.asList(new UnaryFromClause(insert.getGroup().clone())))); ifStatement.setCondition(new ExistsCriteria(exists)); Update update = new Update(); update.setGroup(insert.getGroup().clone()); update.setCriteria((Criteria) Criteria.combineCriteria(crits).clone()); exists.setCriteria((Criteria) Criteria.combineCriteria(crits).clone()); ifStatement.setIfBlock(new Block(new CommandStatement(update))); ifStatement.setElseBlock(new Block(new CommandStatement(newInsert)));
final public IfStatement ifStatement(ParseInfo info) throws ParseException { IfStatement ifStmt = null; Criteria criteria = null; Statement ifStatement = null; Statement elseStatement = null; String groupID = null; String groupID2 = null; boolean not = false; jj_consume_token(IF); jj_consume_token(LPAREN); criteria = criteria(info); jj_consume_token(RPAREN); ifStatement = statement(info); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ELSE: jj_consume_token(ELSE); elseStatement = statement(info); break; default: jj_la1[43] = jj_gen; ; } ifStmt = new IfStatement(criteria, asBlock(ifStatement)); ifStmt.setElseBlock(asBlock(elseStatement)); {if (true) return ifStmt;} throw new Error("Missing return statement in function"); }
public static final IfStatement sample2() { Block ifBlock = TestBlock.sample2(); Block elseBlock = TestBlock.sample1(); Criteria criteria = TestSetCriteria.sample2(); return new IfStatement(criteria, ifBlock, elseBlock); }
@Override public void visit( IfStatement obj ) { append(IF); append("("); //$NON-NLS-1$ visitNode(obj.getCondition()); append(")\n"); //$NON-NLS-1$ addTabs(0); visitNode(obj.getIfBlock()); if (obj.hasElseBlock()) { append("\n"); //$NON-NLS-1$ addTabs(0); append(ELSE); append("\n"); //$NON-NLS-1$ addTabs(0); visitNode(obj.getElseBlock()); } }
case Statement.TYPE_IF: IfStatement ifStmt = (IfStatement) statement; Criteria ifCrit = ifStmt.getCondition(); Criteria evalCrit = rewriteCriteria(ifCrit); ifStmt.setCondition(evalCrit); if(evalCrit.equals(TRUE_CRITERIA)) { Block ifblock = rewriteBlock(ifStmt.getIfBlock()); if (ifblock.isAtomic()) { newStmts.add(ifblock); if(ifStmt.hasElseBlock()) { Block elseBlock = rewriteBlock(ifStmt.getElseBlock()); if (elseBlock.isAtomic()) { newStmts.add(elseBlock); Block ifblock = rewriteBlock(ifStmt.getIfBlock()); ifStmt.setIfBlock(ifblock); if(ifStmt.hasElseBlock()) { Block elseBlock = rewriteBlock(ifStmt.getElseBlock()); ifStmt.setElseBlock(elseBlock);
/** * Compare two IfStatements for equality. They will only evaluate to equal if * they are IDENTICAL: their if, else blocks are same and the condition on the * ifBlock is same. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof IfStatement)) { return false; } IfStatement other = (IfStatement) obj; return // Compare the condition EquivalenceUtil.areEqual(getCondition(), other.getCondition()) && // Compare the if block EquivalenceUtil.areEqual(getIfBlock(), other.getIfBlock()) && // Compare the else block EquivalenceUtil.areEqual(this.getElseBlock(), other.getElseBlock()); }
newInsert.setVariables(LanguageObject.Util.deepClone(insert.getVariables(), ElementSymbol.class)); ArrayList<Expression> values = new ArrayList<Expression>(); IfStatement ifStatement = new IfStatement(); Query exists = new Query(); exists.setSelect(new Select(Arrays.asList(new Constant(1)))); exists.setFrom(new From(Arrays.asList(new UnaryFromClause(insert.getGroup().clone())))); ifStatement.setCondition(new ExistsCriteria(exists)); Update update = new Update(); update.setGroup(insert.getGroup().clone()); update.setCriteria((Criteria) Criteria.combineCriteria(crits).clone()); exists.setCriteria((Criteria) Criteria.combineCriteria(crits).clone()); ifStatement.setIfBlock(new Block(new CommandStatement(update))); ifStatement.setElseBlock(new Block(new CommandStatement(newInsert)));