
javarepl.client.JavaREPLClient Maven / Gradle / Ivy
package javarepl.client;
import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Sequence;
import com.googlecode.totallylazy.functions.Function1;
import com.googlecode.utterlyidle.Response;
import com.googlecode.utterlyidle.handlers.ClientHttpHandler;
import javarepl.completion.CompletionResult;
import javarepl.console.ConsoleStatus;
import javarepl.rendering.ExpressionTemplate;
import java.util.List;
import java.util.Map;
import static com.googlecode.totallylazy.Option.none;
import static com.googlecode.totallylazy.Option.some;
import static com.googlecode.totallylazy.Sequences.sequence;
import static com.googlecode.totallylazy.json.Json.map;
import static com.googlecode.utterlyidle.RequestBuilder.get;
import static com.googlecode.utterlyidle.RequestBuilder.post;
import static javarepl.client.EvaluationLog.Type;
import static javarepl.completion.CompletionResult.methods.fromJson;
import static javarepl.console.ConsoleStatus.Idle;
public final class JavaREPLClient {
private final String hostname;
private final Integer port;
private final ClientHttpHandler client;
public JavaREPLClient(String hostname, Integer port) {
this.hostname = hostname;
this.port = port;
this.client = new ClientHttpHandler();
}
public synchronized ExpressionTemplate template(String expression) throws Exception {
Map model = map(client.handle(get(url("template")).query("expression", expression).build()).entity().toString());
return new ExpressionTemplate(model.get("template").toString(), model.get("token").toString());
}
public synchronized Option execute(String expr) throws Exception {
String json = client.handle(post(url("execute")).form("expression", expr).build()).entity().toString();
if (json.isEmpty())
return none();
Map model = map(json);
Sequence
© 2015 - 2025 Weber Informatics LLC | Privacy Policy