Search in sources :

Example 51 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class IErlAttributeTest method getValue.

@Test
public void getValue() throws Exception {
    module.open(null);
    final IErlElement element = module.getElementAtLine(0);
    final IErlAttribute attribute = (IErlAttribute) element;
    final IErlElement element2 = module.getElementAtLine(1);
    final IErlAttribute attribute2 = (IErlAttribute) element2;
    final OtpErlangAtom xx = new OtpErlangAtom("xx");
    final OtpErlangString yyHrl = new OtpErlangString("yy.hrl");
    assertEquals(xx, attribute.getValue());
    assertEquals(yyHrl, attribute2.getValue());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) Test(org.junit.Test)

Example 52 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class Util method stringValue.

/**
 * Get the string value of an Erlang string, empty if empty list
 *
 * @param o
 *            Erlang string or list
 * @return string value
 */
public static String stringValue(final OtpErlangObject o) {
    if (o instanceof OtpErlangString) {
        final OtpErlangString s = (OtpErlangString) o;
        return s.stringValue();
    } else if (o instanceof OtpErlangList) {
        final OtpErlangList l = (OtpErlangList) o;
        if (l.arity() == 0) {
            return "";
        }
        try {
            return l.stringValue();
        } catch (final OtpErlangException e) {
            ErlLogger.error(e);
            return null;
        }
    } else if (o instanceof OtpErlangBinary) {
        final OtpErlangBinary b = (OtpErlangBinary) o;
        String result;
        result = Util.decode(b.binaryValue(), Charsets.UTF_8);
        if (result == null) {
            result = Util.decode(b.binaryValue(), Charsets.ISO_8859_1);
        }
        if (result == null) {
            ErlLogger.error("bad binary value in stringValue" + " (can't decode): " + o);
        }
        return result;
    }
    // ErlLogger.warn("bad value in stringValue: " + o);
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 53 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class Util method ioListToStringBuilder.

private static StringBuilder ioListToStringBuilder(final OtpErlangObject o, final StringBuilder sb0, final int maxLength) {
    StringBuilder sb = sb0;
    if (sb.length() >= maxLength) {
        return sb;
    }
    if (o instanceof OtpErlangLong) {
        final OtpErlangLong l = (OtpErlangLong) o;
        try {
            sb.append(l.charValue());
        } catch (final OtpErlangRangeException e) {
        }
    } else if (o instanceof OtpErlangString) {
        final OtpErlangString s = (OtpErlangString) o;
        sb.append(s.stringValue());
    } else if (o instanceof OtpErlangList) {
        final OtpErlangList l = (OtpErlangList) o;
        for (final OtpErlangObject i : l) {
            if (sb.length() < maxLength) {
                Util.ioListToStringBuilder(i, sb, maxLength);
            }
        }
        if (sb.length() < maxLength) {
            Util.ioListToStringBuilder(l.getLastTail(), sb, maxLength);
        }
    } else if (o instanceof OtpErlangBinary) {
        final OtpErlangBinary b = (OtpErlangBinary) o;
        String s = Util.decode(b.binaryValue(), Charsets.UTF_8);
        if (s == null) {
            s = new String(b.binaryValue(), Charsets.ISO_8859_1);
        }
        sb.append(s);
    } else if (o != null) {
        sb.append(o.toString());
    }
    if (sb.length() > maxLength) {
        sb = new StringBuilder(sb.substring(0, maxLength));
        sb.append("... <truncated>");
    }
    return sb;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 54 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class ErlangCode method removePath.

public static void removePath(final IOtpRpc backend, final String path0) {
    String path = path0;
    try {
        // workaround for bug in code:del_path
        try {
            final OtpErlangObject rr = backend.call("filename", "join", "x", new OtpErlangList(new OtpErlangString(path)));
            path = ((OtpErlangString) rr).stringValue();
        } catch (final Exception e) {
        // ignore
        }
        backend.call(ErlangCode.CODE, "del_path", "s", path);
    } catch (final Exception e) {
    }
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 55 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString in project erlide_eclipse by erlang.

the class BuilderHelper method createMarkersForDuplicateModuleNames.

private void createMarkersForDuplicateModuleNames(final IOtpRpc backend, final IProject project) {
    try {
        final IErlProject erlProject = ErlangEngine.getInstance().getModel().getErlangProject(project);
        final Collection<IPath> sd = erlProject.getProperties().getSourceDirs();
        final String[] dirList = new String[sd.size()];
        int j = 0;
        for (final IPath sp : sd) {
            dirList[j++] = project.getLocation().toPortableString() + "/" + sp;
        }
        final OtpErlangList res = BuilderHelper.getSourceClashes(backend, dirList);
        for (int i = 0; i < res.arity(); i++) {
            final OtpErlangTuple t = (OtpErlangTuple) res.elementAt(i);
            final String f1 = ((OtpErlangString) t.elementAt(0)).stringValue();
            final String f2 = ((OtpErlangString) t.elementAt(1)).stringValue();
            MarkerUtils.createProblemMarker(project, null, "duplicated module name in " + f1 + " and " + f2, 0, IMarker.SEVERITY_WARNING);
        }
    } catch (final Exception e) {
        ErlLogger.debug(e);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Aggregations

OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)56 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)36 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)31 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)22 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)15 ArrayList (java.util.ArrayList)9 RpcResult (org.erlide.runtime.rpc.RpcResult)8 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)7 RpcException (org.erlide.runtime.rpc.RpcException)7 Test (org.junit.Test)7 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)6 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)5 IPath (org.eclipse.core.runtime.IPath)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 IErlElement (org.erlide.engine.model.IErlElement)5 WranglerRpcParsingException (org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)5 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)5 CoreException (org.eclipse.core.runtime.CoreException)4 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)4 Map (java.util.Map)3