/** * Adds all keys from the given operation list to the list of involved keys. * * @param involvedKeys list of involved keys * @param ops new operations */ public static void addInvolvedKeys( List<InvolvedKey> involvedKeys, Collection<? extends Operation> ops) { assert involvedKeys != null; assert ops != null; for (Operation op : ops) { final OtpErlangString key = op.getKey(); if (key != null) { if (op instanceof ReadOp) { involvedKeys.add(new InvolvedKey(InvolvedKey.OP.READ, key.stringValue())); } else { involvedKeys.add(new InvolvedKey(InvolvedKey.OP.WRITE, key.stringValue())); } } } }
/** * Converts an {@link OtpErlangObject} to a {@link OtpErlangList} taking special care if the OTP * library converted a list to an {@link OtpErlangString}. * * @param value the value to convert * @return the value as a OtpErlangList * @throws ClassCastException if the conversion fails */ static OtpErlangList otpObjectToOtpList(final OtpErlangObject value) throws ClassCastException { // need special handling if OTP thought that the value is a string if (value instanceof OtpErlangString) { final OtpErlangString value_string = (OtpErlangString) value; return new OtpErlangList(value_string.stringValue()); } else { return (OtpErlangList) value; } }
private String parse(OtpErlangObject otpObj) { if (otpObj instanceof OtpErlangAtom) { OtpErlangAtom atom = (OtpErlangAtom) otpObj; if (atom.atomValue().equals("null")) return null; else throw new IllegalArgumentException("Only atom null is supported"); } else if (otpObj instanceof OtpErlangString) { OtpErlangString str = (OtpErlangString) otpObj; return str.stringValue(); } throw new IllegalArgumentException("Unexpected type " + otpObj.getClass().getName()); }
private static IErlElement findLocalCall( final IErlModule module, final Backend backend, final IErlProject erlProject, final OpenResult res, final IProject project, final IErlElement element, final boolean checkAllProjects) throws ErlModelException, BackendException { if (ErlModelUtils.isTypeDefOrRecordDef(element)) { return ModelUtils.findTypespec(module, res.getFun()); } final IErlFunction foundElement = ModelUtils.findFunction(module, res.getFunction()); if (foundElement != null) { return foundElement; } // not local imports OtpErlangObject res2 = null; String moduleName = null; if (module != null) { final IErlImport ei = module.findImport(res.getFunction()); if (ei != null) { moduleName = ei.getImportModule(); final IErlModel model = ErlangCore.getModel(); res2 = ErlideOpen.getSourceFromModule( backend, model.getPathVars(), moduleName, model.getExternalModules(erlProject)); } } if (res2 instanceof OtpErlangString && moduleName != null) { final OtpErlangString otpErlangString = (OtpErlangString) res2; final String modulePath = otpErlangString.stringValue(); return ErlModelUtils.findExternalFunction( moduleName, res.getFunction(), modulePath, project, checkAllProjects, module); } else { return ErlModelUtils.findExternalFunction( moduleName, res.getFunction(), null, project, checkAllProjects, module); } }
private void refreshDirs(final IProject project, final OtpErlangObject element) { final OtpErlangList list = (OtpErlangList) element; for (final OtpErlangObject ebeam : list) { final OtpErlangString beam = (OtpErlangString) ebeam; IPath p = new Path(beam.stringValue()); p = p.removeLastSegments(1); p = p.removeFirstSegments(project.getLocation().segmentCount()); final String projectName = project.getName(); // FIXME hardcoded "_erl" suffix if (projectName.endsWith("_erl")) { final String linkname = projectName.substring(0, projectName.length() - 4); p = new Path(linkname).append(p); } final IResource dir = project.findMember(p); if (dir != null) { try { dir.refreshLocal(IResource.DEPTH_ONE, null); } catch (final CoreException e) { } } } }