All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javarepl.rendering.ExpressionSourceRenderer Maven / Gradle / Ivy

There is a newer version: 431
Show newest version
package javarepl.rendering;

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

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

    @multimethod
    private static String renderExpressionSource(Statement expression) {
        return expression.source();
    }

    @multimethod
    private static String renderExpressionSource(Assignment expression) {
        return expression.value();
    }

    @multimethod
    private static String renderExpressionSource(AssignmentWithType expression) {
        return expression.value();
    }

    @multimethod
    private static String renderExpressionSource(Value expression) {
        return expression.source();
    }

    @multimethod
    private static String renderExpressionSource(Method expression) {
        return expression.source().replaceAll("\n", "\n  ");
    }

    @multimethod
    private static String renderExpressionSource(Import expression) {
        return expression.source();
    }

    @multimethod
    private static String renderExpressionSource(Type expression) {
        return expression.source();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy