package yokohama.unit.ast_junit;

import lombok.Value;
import org.apache.commons.lang3.StringUtils;
import yokohama.unit.ast.Kind;

@Value
public class Type {
    private NonArrayType nonArrayType;
    private int dims;

    public static final Type OBJECT = new Type(new ClassType("java.lang.Object", Span.dummySpan()), 0);
    public static final Type THROWABLE = new Type(new ClassType("java.lang.Throwable", Span.dummySpan()), 0);
    public static final Type CLASS = new Type(new ClassType("java.lang.Class", Span.dummySpan()), 0);
    public static final Type STRING = new Type(new ClassType("java.lang.String", Span.dummySpan()), 0);
    public static final Type MATCHER = new Type(new ClassType("org.hamcrest.Matcher", Span.dummySpan()), 0);
    public static final Type BOOLEAN = new Type(new PrimitiveType(Kind.BOOLEAN), 0);
    public static final Type BYTE = new Type(new PrimitiveType(Kind.BYTE), 0);
    public static final Type SHORT = new Type(new PrimitiveType(Kind.SHORT), 0);
    public static final Type INT = new Type(new PrimitiveType(Kind.INT), 0);
    public static final Type LONG = new Type(new PrimitiveType(Kind.LONG), 0);
    public static final Type CHAR = new Type(new PrimitiveType(Kind.CHAR), 0);
    public static final Type FLOAT = new Type(new PrimitiveType(Kind.FLOAT), 0);
    public static final Type DOUBLE = new Type(new PrimitiveType(Kind.DOUBLE), 0);

    public String getText() {
        return nonArrayType.getText() + StringUtils.repeat("[]", dims);
    }

    public Type box() {
        if (dims > 0) return this;

        return nonArrayType.accept(
                primitiveType ->
                        new Type(primitiveType.box(), dims),
                classType -> this);
    }

    public Type toArray() {
        return new Type(nonArrayType, dims + 1);
    }

    public static Type of(yokohama.unit.ast.Type type) {
        return new Type(NonArrayType.of(type.getNonArrayType()), type.getDims());
    }
}

@@ -1871,136 +1871,2152 @@
 lic 
-static Type of(yokohama.unit.ast.Type type) %7B%0D%0A        return new Type(NonArrayType.of(type.getNonArrayType()), type.getDims());
+Class%3C?%3E toClass() %7B%0D%0A        if (dims %3E 0) %7B%0D%0A            throw new UnsupportedOperationException(%22Not supported yet.%22);%0D%0A        %7D else %7B%0D%0A            return nonArrayType.accept(%0D%0A                    primitiveType -%3E %7B%0D%0A                            switch (primitiveType.getKind()) %7B%0D%0A                                case BOOLEAN: return Boolean.TYPE;%0D%0A                                case BYTE:    return Byte.TYPE;%0D%0A                                case SHORT:   return Short.TYPE;%0D%0A                                case INT:     return Integer.TYPE;%0D%0A                                case LONG:    return Long.TYPE;%0D%0A                                case CHAR:    return Character.TYPE;%0D%0A                                case FLOAT:   return Float.TYPE;%0D%0A                                case DOUBLE:  return Double.TYPE;%0D%0A                            %7D%0D%0A                            throw new RuntimeException(%22should not reach here%22);%0D%0A                    %7D,%0D%0A                    classType -%3E classType.toClass());%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    public static Type of(yokohama.unit.ast.Type type) %7B%0D%0A        return new Type(NonArrayType.of(type.getNonArrayType()), type.getDims());%0D%0A    %7D%0D%0A%0D%0A    public static Type fromClass(Class%3C?%3E clazz) %7B%0D%0A        if (clazz.isArray()) %7B%0D%0A            throw new UnsupportedOperationException(%22Not supported yet.%22);%0D%0A        %7D else if (clazz.isPrimitive()) %7B%0D%0A            if      (clazz.equals(  Boolean.TYPE)) %7B return BOOLEAN; %7D%0D%0A            else if (clazz.equals(     Byte.TYPE)) %7B return BYTE;    %7D%0D%0A            else if (clazz.equals(    Short.TYPE)) %7B return SHORT;   %7D%0D%0A            else if (clazz.equals(  Integer.TYPE)) %7B return INT;     %7D%0D%0A            else if (clazz.equals(     Long.TYPE)) %7B return LONG;    %7D%0D%0A            else if (clazz.equals(Character.TYPE)) %7B return CHAR;    %7D%0D%0A            else if (clazz.equals(    Float.TYPE)) %7B return FLOAT;   %7D%0D%0A            else if (clazz.equals(   Double.TYPE)) %7B return DOUBLE;  %7D%0D%0A            else %7B throw new RuntimeException(%22should not reach here%22); %7D%0D%0A        %7D else %7B%0D%0A            return new ClassType(clazz.getName(), Span.dummySpan()).toType();%0D%0A        %7D
 %0D%0A  

Add toClass/fromClass (array not supported)