Package javarepl.rendering

Source Code of javarepl.rendering.MethodNameRenderer

package javarepl.rendering;

import com.googlecode.totallylazy.annotations.multimethod;
import com.googlecode.totallylazy.multi;
import javarepl.expressions.*;

import static java.lang.String.format;

public class MethodNameRenderer {
    @multimethod
    public static String renderMethodName(Expression expression) {
        return new multi() {
        }.<String>methodOption(expression)
                .getOrThrow(new IllegalArgumentException(expression + " not mapped"));
    }

    @multimethod
    private static String renderMethodName(Statement expression) {
        return methodNameWithType(void.class);
    }

    @multimethod
    private static String renderMethodName(Import expression) {
        return methodNameWithType(void.class);
    }

    @multimethod
    private static String renderMethodName(Method expression) {
        return methodNameWithType(void.class);
    }

    @multimethod
    private static String renderMethodName(Assignment expression) {
        return methodNameWithType(Object.class);
    }

    @multimethod
    private static String renderMethodName(AssignmentWithType expression) {
        return methodNameWithType(expression.type());
    }

    @multimethod
    private static String renderMethodName(Value expression) {
        return methodNameWithType(Object.class);
    }

    private static String methodNameWithType(java.lang.reflect.Type returnType) {
        return format("  public %s evaluate() throws Exception {", TypeRenderer.renderType(returnType));
    }
}
TOP

Related Classes of javarepl.rendering.MethodNameRenderer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.