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());
}
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;
}
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;
}
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) {
}
}
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);
}
}
Aggregations