io.github.kiryu1223.expressionTree.expressions.LambdaExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ExpressionTree Show documentation
Show all versions of ExpressionTree Show documentation
java static expressionTree
package io.github.kiryu1223.expressionTree.expressions;
import io.github.kiryu1223.expressionTree.delegate.Delegate;
import java.util.List;
public class LambdaExpression extends Expression
{
private final Expression body;
private final List parameters;
private final Class> returnType;
public LambdaExpression(Expression body, List parameters, Class> returnType)
{
this.body = body;
this.parameters = parameters;
this.returnType = returnType;
}
public Expression getBody()
{
return body;
}
public List getParameters()
{
return parameters;
}
public Class> getReturnType()
{
return returnType;
}
@Override
public Kind getKind()
{
return Kind.Lambda;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("(");
for (ParameterExpression parameter : parameters)
{
sb.append(parameter.getName()).append(",");
}
if (sb.charAt(sb.length() - 1) == ',')
{
sb.deleteCharAt(sb.length() - 1);
}
sb.append(") -> ");
sb.append(body);
return sb.toString();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
LambdaExpression that = (LambdaExpression) obj;
return body.equals(that.body) && parameters.equals(that.parameters)
&& returnType.equals(that.returnType);
}
// public T compile()
// {
// return DynamicCompilerUtil.dynamicCompile(this);
// }
}