package yokohama.unit.ast_junit;

import lombok.Value;
import static org.apache.commons.lang3.StringEscapeUtils.escapeJava;
import yokohama.unit.util.SBuilder;

@Value
public class VarAssignStatement implements Statement {
    private final String name;
    private final Expr value;

    @Override
    public void toString(SBuilder sb, ExpressionStrategy expressionStrategy, MockStrategy mockStrategy) {
        value.<Void>accept(
                varExpr -> {
                    sb.appendln(name, " = ", varExpr.getName(), ";");
                    return null;
                },
                quotedExpr -> {
                    sb.appendln(name, " = ", expressionStrategy.getValue(quotedExpr), ";");
                    return null;
                },
                stubExpr -> {
                    // TODO: need fix, this results in variable initialization, not assignment
                    mockStrategy.stub(sb, name, stubExpr, expressionStrategy);
                    return null;
                },
                matcherExpr -> {
                    // TODO: need fix, this results in variable initialization, not assignment
                    matcherExpr.getExpr(sb, name, expressionStrategy, mockStrategy);
                    return null;
                },
                newExpr -> {
                    // TODO: need fix, this results in variable initialization, not assignment
                    newExpr.getExpr(sb, name);
                    return null;
                },
                strLitExpr -> {
                    sb.appendln(name, " = \"", escapeJava(strLitExpr.getText()), "\";");
                    return null;
                },
                nullExpr -> {
                    sb.appendln(name, " = null;");
                    return null;
                },
                invokeExpr -> {
                    // TODO: need fix, this results in variable initialization, not assignment
                    invokeExpr.getExpr(sb, name);
                    return null;
                });
    }

    @Override
    public <T> T accept(StatementVisitor<T> visitor) {
        return visitor.visitVarAssignStatement(this);
    }
}

@@ -29,16 +29,44 @@
 nit;%0D%0A%0D%0A
+import java.util.Optional;%0D%0A
 import l
@@ -79,16 +79,16 @@
 Value;%0D%0A
-
 import s
@@ -284,16 +284,61 @@
  name;%0D%0A
+    private final Optional%3CClassType%3E cast;%0D%0A
     priv
@@ -535,32 +535,126 @@
   varExpr -%3E %7B%0D%0A
+                    String cast_ = cast.isPresent() ? %22(%22 + cast.get().getName() + %22)%22 : %22%22;%0D%0A
                 
@@ -681,16 +681,23 @@
 , %22 = %22,
+ cast_,
  varExpr

Add cast member to VarAssignStatement