ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
String shortType = new String("short"); //$NON-NLS-1$
Statement declStmt = new DeclareStatement(var1, shortType);
//ifblock
List symbols = new ArrayList();
symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
Select select = new Select(symbols);
From from = new From();
from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
new Constant(new Integer(5)));
Query query = new Query();
query.setSelect(select);
query.setFrom(from);
query.setCriteria(criteria);
AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
Block ifBlock = new Block();
ifBlock.addStatement(queryStmt);
//else block
ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
Statement elseDeclStmt = new DeclareStatement(var2, shortType);
List elseSymbols = new ArrayList();
elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
Select elseSelect = new Select(elseSymbols);
Query elseQuery = new Query();
elseQuery.setSelect(elseSelect);
From elseFrom = (From)from.clone();
UnaryFromClause ufc = new UnaryFromClause();
ufc.setGroup(new GroupSymbol("h")); //$NON-NLS-1$
ufc.setOptional(true);
elseFrom.addClause(ufc);
elseQuery.setFrom(elseFrom);
elseQuery.setCriteria(criteria);
AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
Block elseBlock = new Block();
List elseStmts = new ArrayList();
elseStmts.add(elseDeclStmt);
elseStmts.add(elseQueryStmt);
elseBlock.setStatements(elseStmts);
//has criteria
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
List elements = new ArrayList();
elements.add(a);
CriteriaSelector critSelector = new CriteriaSelector();
critSelector.setSelectorType(CriteriaSelector.IN);
critSelector.setElements(elements);