io.github.kiryu1223.expressionTree.expressions.CaseExpression Maven / Gradle / Ivy
package io.github.kiryu1223.expressionTree.expressions;
import java.util.List;
public class CaseExpression extends Expression
{
private final Expression part;
private final List stats;
public CaseExpression(Expression part, List stats)
{
this.part = part;
this.stats = stats;
}
public Expression getPart()
{
return part;
}
public List getStats()
{
return stats;
}
@Override
public Kind getKind()
{
return Kind.Case;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder("case " + part + ":");
for (Expression stat : stats)
{
sb.append("\n ").append(stat);
switch (stat.getKind())
{
case Block:
case Lambda:
case If:
case Foreach:
case For:
case While:
case Switch:
case Catch:
case Try:
break;
default:
sb.append(";");
break;
}
}
return sb.toString();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
CaseExpression that = (CaseExpression) obj;
return part.equals(that.part) && stats.equals(that.stats);
}
}