cfml.parsing.cfscript.CFVarDeclExpression Maven / Gradle / Ivy
package cfml.parsing.cfscript;
import java.util.ArrayList;
import java.util.List;
import org.antlr.v4.runtime.Token;
import cfml.parsing.cfscript.script.CFScriptStatement;
import cfml.parsing.util.ArrayBuilder;
public class CFVarDeclExpression extends CFExpression {
private static final long serialVersionUID = 1L;
private String name;
private CFExpression init; // null if none
List otherVars = new ArrayList();
List otherIds = new ArrayList();
public List getOtherVars() {
return otherVars;
}
public List getOtherIds() {
return otherIds;
}
public CFVarDeclExpression(Token _t, CFIdentifier _var, CFExpression _init) {
super(_t);
name = _var.getName();
init = _init;
}
@Override
public String Decompile(int indent) {
StringBuilder s = new StringBuilder(Indent(indent));
s.append("var ");
s.append(name);
for (CFIdentifier id : otherVars) {
s.append(" = var ");
s.append(id.Decompile(indent));
}
for (CFIdentifier id : otherIds) {
s.append(" = ");
s.append(id.Decompile(indent));
}
if (init != null) {
s.append(" = ");
s.append(init.Decompile(indent + 2));
}
return s.toString();
}
public String getName() {
return name;
}
public CFExpression getInit() {
return init;
}
@Override
public List decomposeExpression() {
List retval = new ArrayList();
retval.add(init);
retval.addAll(otherIds);
retval.addAll(otherVars);
return retval;
}
@Override
public List decomposeScript() {
return ArrayBuilder.createCFScriptStatement();
}
}