public static boolean hasSymbolKeys(OtpErlangMap map) { for (OtpErlangObject key : map.keys()) { if (!(key instanceof OtpErlangAtom) || ((OtpErlangAtom) key).atomValue().startsWith("Elixir.")) return false; } return true; }
@Nullable private static String structType(OtpErlangMap map) { OtpErlangObject structValue = map.get(new OtpErlangAtom("__struct__")); if (structValue instanceof OtpErlangAtom) { return ElixirModulesUtil.INSTANCE.erlangModuleNameToElixir(((OtpErlangAtom) structValue).atomValue()); } else { return null; } }
@Nullable public static OtpErlangPid whereis(OtpMbox localMbox, OtpNode localNode, String remoteName, String remoteNode, int timeout) throws OtpErlangExit, OtpErlangDecodeException { OtpErlangObject response = RPC.INSTANCE.unmonitoredCall( remoteNode, localMbox, localNode, timeout, new OtpErlangAtom("Elixir.Process"), new OtpErlangAtom("whereis"), new OtpErlangAtom(remoteName) ); OtpErlangPid pid; if (response instanceof OtpErlangAtom) { if (response.equals(NIL)) { pid = null; } else { throw new NotImplementedException("Expected atoms to be nil, but got" + response); } } else { pid = (OtpErlangPid) response; } return pid; } }
private boolean atomNeedsQuoting(final String s) { char c; if (s.length() == 0) { return true; } if (!isErlangLower(s.charAt(0))) { return true; } final int len = s.length(); for (int i = 1; i < len; i++) { c = s.charAt(i); if (!isErlangLetter(c) && !isErlangDigit(c) && c != '@') { return true; } } return false; }
/** * Get the printname of the atom represented by this object. The difference * between this method and {link #atomValue atomValue()} is that the * printname is quoted and escaped where necessary, according to the Erlang * rules for atom naming. * * @return the printname representation of this atom object. * * @see #atomValue */ @Override public String toString() { if (atomNeedsQuoting(atom)) { return "'" + escapeSpecialChars(atom) + "'"; } return atom; }
return new Cell(v.booleanValue());
/** * <p> * Equivalent to <code>OtpErlangExit(new * OtpErlangAtom(reason)</code>. * </p> * * @param reason * the reason this exit signal has been sent. * * @see #OtpErlangExit(OtpErlangObject) */ public OtpErlangExit(final String reason) { this(new OtpErlangAtom(reason)); }
private static void renderAtom(OtpErlangAtom atom, XValueTextRenderer renderer) { renderer.renderKeywordValue(ElixirModulesUtil.INSTANCE.erlangModuleNameToElixir(atom.atomValue())); }
header.write_long(regSendTag); header.write_atom(cookie.atomValue()); // important: his cookie, final OtpErlangObject[] msgbody = new OtpErlangObject[3]; msgbody[0] = new OtpErlangAtom("print"); msgbody[1] = new OtpErlangString("~n** Bad cookie sent to " + local + " **~n"); msg[0] = new OtpErlangAtom("$gen_cast"); msg[1] = new OtpErlangTuple(msgbody); + cookie.atomValue());
OtpMsg(final int tag, final OtpErlangPid from, final OtpErlangPid to, final String reason) { this.tag = tag; this.from = from; this.to = to; paybuf = null; payload = new OtpErlangAtom(reason); }
name = keywordKeyAtom.atomValue(); } else { name = keywordKey.getText();
/** * <p> * Equivalent to <code>OtpErlangExit(new OtpErlangAtom(reason), * pid)</code>. * </p> * * @param reason * the reason this exit signal has been sent. * * @param pid * the pid that sent this exit. * * @see #OtpErlangExit(OtpErlangObject, OtpErlangPid) */ public OtpErlangExit(final String reason, final OtpErlangPid pid) { this(new OtpErlangAtom(reason), pid); }
/** * Equivalent to <code>exit(new OtpErlangAtom(reason))</code>. * * @see #exit(OtpErlangObject) */ public void exit(final String reason) { exit(new OtpErlangAtom(reason)); }
public static void assertError(PsiFile file) { final String text = file.getText(); try { OtpErlangTuple quotedMessage = Quoter.quote(text); Quoter.assertMessageReceived(quotedMessage); OtpErlangAtom status = (OtpErlangAtom) quotedMessage.elementAt(0); String statusString = status.atomValue(); assertEquals(statusString, "error"); } catch (IOException | OtpErlangDecodeException | OtpErlangExit e) { throw new RuntimeException(e); } }
/** * <p> * Equivalent to <code>exit(to, new * OtpErlangAtom(reason))</code>. * </p> * * @see #exit(OtpErlangPid, OtpErlangObject) */ public void exit(final OtpErlangPid to, final String reason) { exit(to, new OtpErlangAtom(reason)); }
public static void assertQuotedCorrectly(PsiFile file) { final String text = file.getText(); try { OtpErlangTuple quotedMessage = Quoter.quote(text); Quoter.assertMessageReceived(quotedMessage); OtpErlangAtom status = (OtpErlangAtom) quotedMessage.elementAt(0); String statusString = status.atomValue(); OtpErlangObject expectedQuoted = quotedMessage.elementAt(1); if (statusString.equals("ok")) { OtpErlangObject actualQuoted = ElixirPsiImplUtil.quote(file); assertQuotedCorrectly(expectedQuoted, actualQuoted); } else if (statusString.equals("error")) { OtpErlangTuple error = (OtpErlangTuple) expectedQuoted; OtpErlangLong line = (OtpErlangLong) error.elementAt(0); OtpErlangBinary messageBinary = (OtpErlangBinary) error.elementAt(1); String message = ElixirPsiImplUtil.javaString(messageBinary); OtpErlangBinary tokenBinary = (OtpErlangBinary) error.elementAt(2); String token = ElixirPsiImplUtil.javaString(tokenBinary); throw new AssertionError( "intellij_elixir returned \"" + message + "\" on line " + line + " due to " + token + ", use assertQuotesAroundError if error is expect in Elixir natively, " + "but not in intellij-elixir plugin" ); } } catch (IOException | OtpErlangDecodeException | OtpErlangExit e) { throw new RuntimeException(e); } }
/** * Close the specified mailbox with reason 'normal'. * * @param mbox * the mailbox to close. * * <p> * After this operation, the mailbox will no longer be able to * receive messages. Any delivered but as yet unretrieved * messages can still be retrieved however. * </p> * * <p> * If there are links from the mailbox to other * {@link OtpErlangPid pids}, they will be broken when this * method is called and exit signals with reason 'normal' will be * sent. * </p> * */ public void closeMbox(final OtpMbox mbox) { closeMbox(mbox, new OtpErlangAtom("normal")); }
/** * The boolean value of this atom. * * @return the value of this atom expressed as a boolean value. If the atom * consists of the characters "true" (independent of case) the value * will be true. For any other values, the value will be false. * */ public boolean booleanValue() { return Boolean.valueOf(atomValue()).booleanValue(); }
private OtpErlangTuple getPingTuple(final OtpMbox mbox) { final OtpErlangObject[] ping = new OtpErlangObject[3]; final OtpErlangObject[] pid = new OtpErlangObject[2]; final OtpErlangObject[] anode = new OtpErlangObject[2]; pid[0] = mbox.self(); pid[1] = createRef(); anode[0] = new OtpErlangAtom("is_auth"); anode[1] = new OtpErlangAtom(node()); ping[0] = new OtpErlangAtom("$gen_call"); ping[1] = new OtpErlangTuple(pid); ping[2] = new OtpErlangTuple(anode); return new OtpErlangTuple(ping); }