/** * 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); }
/** * 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); }
/** * 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); }
public static final IfStatement sample1() { Block ifBlock = TestBlock.sample1(); Block elseBlock = TestBlock.sample2(); Criteria criteria = TestSetCriteria.sample1(); return new IfStatement(criteria, ifBlock, elseBlock); }
public static final IfStatement sample2() { Block ifBlock = TestBlock.sample2(); Block elseBlock = TestBlock.sample1(); Criteria criteria = TestSetCriteria.sample2(); return new IfStatement(criteria, ifBlock, elseBlock); }
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"); }
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 testIfStatement() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String shortType = new String("short"); //$NON-NLS-1$ Statement ifStmt = new DeclareStatement(a, shortType); ElementSymbol b = new ElementSymbol("b"); //$NON-NLS-1$ Statement elseStmt = new DeclareStatement(b, shortType); Block ifBlock = new Block(); ifBlock.addStatement(ifStmt); Block elseBlock = new Block(); elseBlock.addStatement(elseStmt); ElementSymbol c = new ElementSymbol("c"); //$NON-NLS-1$ Criteria crit = new CompareCriteria(c, CompareCriteria.EQ, new Constant(new Integer(5))); IfStatement stmt = new IfStatement(crit, ifBlock, elseBlock); helpStmtTest("IF(c = 5) BEGIN DECLARE short a; END ELSE BEGIN DECLARE short b; END", //$NON-NLS-1$ "IF(c = 5)"+"\n"+ "BEGIN"+"\n"+"DECLARE short a;"+"\n"+"END"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ "ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short b;"+"\n"+"END", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ stmt); }
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))));
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))));
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))));
@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); }
Criteria crit = new CompareCriteria(x, CompareCriteria.GT, new Constant(new Integer(5))); IfStatement ifStmt = new IfStatement(crit, ifBlock); block.addStatement(ifStmt);
ifStmt = new IfStatement(criteria, asBlock(ifStatement)); ifStmt.setElseBlock(asBlock(elseStatement)); {if (true) return ifStmt;}