use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class EvalHelper method eval.
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;
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class InterpretEvent method execute.
@Override
public void execute(final ErlangDebugTarget debugTarget) {
final OtpErlangAtom m = (OtpErlangAtom) cmds[1];
debugTarget.getInterpretedModules().add(m.atomValue());
debugTarget.fireEvent(new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, ErlangDebugTarget.INTERPRETED_MODULES_CHANGED));
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class ErlParser method addRecordDef.
private IErlRecordDef addRecordDef(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra) {
if (val instanceof OtpErlangTuple) {
final OtpErlangTuple recordTuple = (OtpErlangTuple) val;
if (recordTuple.elementAt(0) instanceof OtpErlangAtom) {
final String s = extra instanceof OtpErlangString ? ((OtpErlangString) extra).stringValue() : null;
final OtpErlangList fields = (OtpErlangList) recordTuple.elementAt(1);
final ErlRecordDef r = new ErlRecordDef(module, null, s);
setPos(r, pos);
if (fields != null) {
final List<ErlRecordField> children = Lists.newArrayListWithCapacity(fields.arity());
for (final OtpErlangObject o : fields) {
if (o instanceof OtpErlangTuple) {
final OtpErlangTuple fieldTuple = (OtpErlangTuple) o;
final OtpErlangAtom fieldNameAtom = (OtpErlangAtom) fieldTuple.elementAt(0);
final String fieldName = fieldNameAtom.atomValue();
final ErlRecordField field = new ErlRecordField(r, fieldName);
final OtpErlangTuple posTuple = (OtpErlangTuple) fieldTuple.elementAt(1);
if (fieldTuple.arity() > 2) {
final OtpErlangObject fieldExtra = fieldTuple.elementAt(2);
field.setExtra(Util.stringValue(fieldExtra));
}
setPos(field, posTuple);
children.add(field);
} else {
ErlLogger.error("bad record def: %s", o);
}
}
r.setChildren(children);
} else {
r.setChildren(new ArrayList<>());
}
return r;
}
}
if (val instanceof OtpErlangAtom) {
final String s = extra instanceof OtpErlangString ? ((OtpErlangString) extra).stringValue() : null;
final ErlRecordDef r = new ErlRecordDef(module, null, s);
setPos(r, pos);
return r;
}
return null;
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class ErlParser method parse.
public boolean parse(final IErlModule module, final String scannerName, final boolean initialParse, final String path, final String initialText, final boolean updateSearchServer) {
if (module == null) {
return false;
}
OtpErlangList forms = null;
OtpErlangList comments = null;
OtpErlangTuple res = null;
if (initialParse) {
final String stateDir = ErlangEngine.getInstance().getStateDir();
final String pathNotNull = path == null ? "" : path;
res = ErlideNoparse.initialParse(backend, scannerName, pathNotNull, initialText, stateDir, updateSearchServer);
} else {
res = ErlideNoparse.reparse(backend, scannerName, updateSearchServer);
}
if (Util.isOk(res)) {
final OtpErlangTuple t = (OtpErlangTuple) res.elementAt(1);
forms = (OtpErlangList) t.elementAt(1);
comments = (OtpErlangList) t.elementAt(2);
} else {
ErlLogger.error("error when parsing %s: %s", path, res);
}
if (forms == null) {
module.setChildren(null);
} else {
final List<IErlElement> children = createForms(module, forms);
module.setChildren(children);
}
if (comments == null) {
module.setComments(null);
} else {
final List<IErlComment> moduleComments = createComments(module, comments);
module.setComments(moduleComments);
}
attachFunctionComments(module);
String cached = "reparsed";
if (res != null && res.arity() > 2) {
final OtpErlangObject res2 = res.elementAt(2);
if (res2 instanceof OtpErlangAtom) {
final OtpErlangAtom atom = (OtpErlangAtom) res2;
cached = atom.atomValue();
}
}
if (ErlParser.TRACE) {
ErlLogger.debug("Parsed %d forms and %d comments (%s)", forms != null ? forms.arity() : 0, comments != null ? comments.arity() : 0, cached);
}
return forms != null && comments != null;
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class ErlideDoc method getOtpDoc.
@Override
public OtpErlangObject getOtpDoc(final IOtpRpc b, final ErlangFunctionCall functionCall) {
OtpErlangObject res = null;
final OtpErlangTuple input = new OtpErlangTuple(new OtpErlangObject[] { new OtpErlangAtom("external"), new OtpErlangAtom(functionCall.getModule()), new OtpErlangAtom(functionCall.getName()), new OtpErlangInt(functionCall.getArity()), new OtpErlangString("") });
try {
res = b.call(ErlideDoc.ERLIDE_OTP_DOC, "get_doc", "sxs", functionCall.getModule(), input, stateDir);
} catch (final RpcException e) {
ErlLogger.warn(e);
}
return res;
}
Aggregations