use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class TraceBackend method processResult.
private TracingStatus processResult(final OtpErlangObject callResult) {
final OtpErlangTuple tuple = (OtpErlangTuple) callResult;
if ("error".equals(((OtpErlangAtom) tuple.elementAt(0)).atomValue())) {
errorObject = tuple.elementAt(1);
return TracingStatus.ERROR;
}
final OtpErlangList nodeNames = (OtpErlangList) tuple.elementAt(1);
activatedNodes = new ArrayList<>();
for (final OtpErlangObject nodeName : nodeNames) {
final String nodeNameString = ((OtpErlangAtom) nodeName).atomValue();
activatedNodes.add(nodeNameString);
notActivatedNodes.remove(nodeNameString);
}
if (activatedNodes.isEmpty()) {
return TracingStatus.NO_ACTIVATED_NODES;
} else if (!notActivatedNodes.isEmpty()) {
return TracingStatus.NOT_ALL_NODES_ACTIVATED;
} else {
return TracingStatus.OK;
}
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class TypeConverter method erlang2java.
@SuppressWarnings("boxing")
public static Object erlang2java(final OtpErlangObject obj, final Class<?> cls) throws SignatureException {
try {
if (cls == obj.getClass()) {
return obj;
}
// if the conversion method exists, use it
try {
final Method method = cls.getMethod("fromErlangObject", OtpErlangObject.class);
method.setAccessible(true);
final Object o = method.invoke(null, obj);
return o;
} catch (final NoSuchMethodException e) {
// ignore, continue
}
if (cls.isArray()) {
return TypeConverter.cvtArray(obj, cls);
}
if (cls == String.class) {
return TypeConverter.cvtString(obj);
}
if (TypeConverter.isNumericClass(cls)) {
if (obj instanceof OtpErlangLong) {
final long res = ((OtpErlangLong) obj).longValue();
if (cls == char.class || cls == Character.class) {
return (char) res;
}
if (cls == int.class || cls == Integer.class) {
return (int) res;
}
if (cls == byte.class || cls == Byte.class) {
return (byte) res;
}
if (cls == short.class || cls == Short.class) {
return (short) res;
}
if (cls == long.class || cls == Long.class) {
return res;
}
}
throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
}
if (cls == boolean.class || cls == Boolean.class) {
if (obj instanceof OtpErlangAtom) {
final String s = ((OtpErlangAtom) obj).atomValue();
if ("true".equals(s)) {
return true;
}
if ("false".equals(s)) {
return false;
}
}
throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
}
if (Map.class.isAssignableFrom(cls)) {
if (obj instanceof OtpErlangMap) {
final Map<Object, Object> result = Maps.newHashMap();
final OtpErlangMap map = (OtpErlangMap) obj;
for (final OtpErlangObject key : map.keys()) {
final OtpErlangObject value = map.get(key);
result.put(TypeConverter.erlang2java(key, key.getClass()), TypeConverter.erlang2java(value, value.getClass()));
}
return result;
}
throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
}
if (Collection.class.isAssignableFrom(cls)) {
if (obj instanceof OtpErlangList) {
final OtpErlangObject[] list = ((OtpErlangList) obj).elements();
final Object[] olist = new Object[list.length];
for (int i = 0; i < list.length; i++) {
olist[i] = TypeConverter.erlang2java(list[i], list[i].getClass());
}
return Arrays.asList(olist);
}
throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
}
if (obj instanceof OtpErlangRef) {
throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
}
return obj;
} catch (final SignatureException e) {
throw e;
} catch (final Exception e) {
throw new SignatureException(e);
}
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method handleLargeModulesCall.
private void handleLargeModulesCall(final IErlSelection wranglerSelection, final Shell shell) {
CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
final InputDialog dialog = new InputDialog(shell, "Lines of a large module", "Lines of a large module:", "", new IntegerInputValidator());
final int ret = dialog.open();
if (ret == Window.CANCEL) {
return;
}
final int lines = Integer.parseInt(dialog.getValue());
final RpcResult res = WranglerBackendManager.getRefactoringBackend().callInspection("large_modules_eclipse", "ixi", lines, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
ArrayList<IErlElement> modules = new ArrayList<>();
try {
final OtpErlangObject obj = res.getValue();
final OtpErlangTuple restuple = (OtpErlangTuple) obj;
final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
if ("ok".equals(resindicator.atomValue())) {
final OtpErlangList modList = (OtpErlangList) restuple.elementAt(1);
modules = createErlModuleList(modList);
} else {
final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
MessageDialog.openError(shell, "Error", s.stringValue());
return;
}
} catch (final Exception e) {
ErlLogger.error(e);
}
if (!modules.isEmpty()) {
CodeInspectionViewsManager.showErlElements("Large modules", modules, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
} else {
MessageDialog.openInformation(shell, "No result", "There is no large module with the specified parameter!");
}
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method extractFunction.
private IErlFunctionClause extractFunction(final OtpErlangTuple fTuple) throws OtpErlangRangeException, ErlModelException {
final IErlModule mod = extractModule(fTuple.elementAt(0));
final String function = ((OtpErlangAtom) fTuple.elementAt(1)).atomValue();
final int arity = ((OtpErlangLong) fTuple.elementAt(2)).intValue();
final IErlFunctionClause f = ErlangEngine.getInstance().getModel().findFunction(new FunctionRef(mod.getModuleName(), function, arity));
return f;
}
use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method extractModule.
private IErlModule extractModule(final OtpErlangObject m) throws ErlModelException {
String name = "";
if (m instanceof OtpErlangString) {
final OtpErlangString element = (OtpErlangString) m;
name = element.stringValue();
} else if (m instanceof OtpErlangAtom) {
final OtpErlangAtom atom = (OtpErlangAtom) m;
name = atom.atomValue();
}
final String[] modNameParts = name.split("/");
final IErlModule mod = ErlangEngine.getInstance().getModel().findModule(modNameParts[modNameParts.length - 1]);
return mod;
}
Aggregations