Package org.erlide.backend.debug

Source Code of org.erlide.backend.debug.EvalHelper

package org.erlide.backend.debug;

import org.erlide.runtime.api.IOtpRpc;

import com.ericsson.otp.erlang.OtpErlangAtom;
import com.ericsson.otp.erlang.OtpErlangObject;
import com.ericsson.otp.erlang.OtpErlangTuple;

public class EvalHelper {

    public static BackendEvalResult eval(final IOtpRpc b, final String string,
            final OtpErlangObject bindings) {
        final BackendEvalResult result = new BackendEvalResult();
        try {
            OtpErlangObject r1;
            // ErlLogger.debug("eval %s %s", string, bindings);
            if (bindings == null) {
                r1 = b.call("erlide_backend", "eval", "s", string);
            } else {
                r1 = b.call("erlide_backend", "eval", "sx", string, bindings);
            }
            // value may be something else if exception is thrown...
            final OtpErlangTuple t = (OtpErlangTuple) r1;
            final boolean ok = !"error".equals(((OtpErlangAtom) t.elementAt(0))
                    .atomValue());
            if (ok) {
                result.setValue(t.elementAt(1), t.elementAt(2));
            } else {
                result.setError(t.elementAt(1));
            }
        } catch (final Exception e) {
            result.setError("rpc failed");
        }
        return result;
    }

}
TOP

Related Classes of org.erlide.backend.debug.EvalHelper

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.