webit.script.core.ast.statements.IfPart Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webit-script Show documentation
Show all versions of webit-script Show documentation
a template-like script and engine, all writen with Java.
The newest version!
// Copyright (c) 2013-2014, Webit Team. All Rights Reserved.
package webit.script.core.ast.statements;
import webit.script.core.ast.Expression;
import webit.script.core.ast.Statement;
import webit.script.util.StatementUtil;
/**
*
* @author Zqq
*/
public final class IfPart {
protected final int line;
protected final int column;
private Expression ifExpr;
private Statement thenStatement;
public IfPart(Expression ifExpr, Statement thenStatement, int line, int column) {
this.line = line;
this.column = column;
this.ifExpr = ifExpr;
this.thenStatement = StatementUtil.optimize(thenStatement);
}
public Statement pop() {
return pop(null);
}
public Statement pop(Statement elseStatement) {
elseStatement = StatementUtil.optimize(elseStatement);
if (this.thenStatement != null) {
if (elseStatement != null) {
return new IfElse(ifExpr, thenStatement, elseStatement, line, column);
} else {
return new If(ifExpr, thenStatement, line, column);
}
} else if (elseStatement != null) {
return new IfNot(ifExpr, elseStatement, line, column);
} else {
return NoneStatement.INSTANCE;
}
}
}