Search in sources :

Example 1 with FunctionRef

use of org.erlide.engine.model.erlang.FunctionRef in project erlide_eclipse by erlang.

the class ErlangXref method functionUse.

@SuppressWarnings("boxing")
public FunctionRef[] functionUse(final String mod, final String fun, final int arity) {
    try {
        final OtpErlangObject r = backend.call(ErlangXref.ERLIDE_XREF, "function_use", "aai", mod.substring(0, mod.length() - 4), fun, arity);
        final OtpBindings bind = OtpErlang.match("{ok, L}", r);
        if (bind == null) {
            return new FunctionRef[0];
        }
        final OtpErlangList l = (OtpErlangList) bind.get("L");
        final List<FunctionRef> result = new ArrayList<>();
        for (final OtpErlangObject e : l) {
            result.add(new FunctionRef(e));
        }
        return result.toArray(new FunctionRef[result.size()]);
    } catch (final Exception e) {
        ErlLogger.debug(e);
    }
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpBindings(org.erlide.util.erlang.OtpBindings) ArrayList(java.util.ArrayList) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 2 with FunctionRef

use of org.erlide.engine.model.erlang.FunctionRef 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;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 3 with FunctionRef

use of org.erlide.engine.model.erlang.FunctionRef in project erlide_eclipse by erlang.

the class CallHierarchyAction method run.

@Override
public void run() {
    if (module == null) {
        return;
    }
    final IErlElement el = editor.getElementAt(editor.getViewer().getSelectedRange().x, false);
    IErlFunction f = null;
    if (el instanceof IErlFunction) {
        f = (IErlFunction) el;
    } else if (el instanceof IErlFunctionClause) {
        f = (IErlFunction) el.getParent();
    }
    if (f == null) {
        return;
    }
    String name = module.getName();
    final int i = name.lastIndexOf('.');
    if (i > 0) {
        name = name.substring(0, i);
    }
    final FunctionRef ref = new FunctionRef(name, f.getFunctionName(), f.getArity());
    final IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    final IWorkbenchPage page = dw.getActivePage();
    final AsyncCaller<CallHierarchyView> ac = new AsyncCaller<CallHierarchyView>(100) {

        @Override
        protected CallHierarchyView prepare() {
            try {
                final IViewPart p = page.showView("org.erlide.ui.callhierarchy");
                final CallHierarchyView cvh = p.getAdapter(CallHierarchyView.class);
                if (cvh == null) {
                    return null;
                }
                cvh.setMessage("<searching... project " + ErlangEngine.getInstance().getModelUtilService().getProject(module).getName() + ">");
                return cvh;
            } catch (final PartInitException e) {
                ErlLogger.error("could not open Call hierarchy view: ", e.getMessage());
                return null;
            }
        }

        @Override
        protected RpcFuture call() throws BackendException {
            final RpcFuture result = xrefService.addProject(ErlangEngine.getInstance().getModelUtilService().getProject(module));
            return result;
        }

        @Override
        protected void handleResult(final CallHierarchyView context, final RpcFuture result) {
            page.activate(context);
            try {
                context.setRoot(ErlangEngine.getInstance().getModel().findFunction(ref));
            } catch (final ErlModelException e) {
                ErlLogger.error(e);
            }
        }
    };
    ac.run();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) IErlElement(org.erlide.engine.model.IErlElement) CallHierarchyView(org.erlide.ui.views.CallHierarchyView) ErlModelException(org.erlide.engine.model.ErlModelException) AsyncCaller(org.erlide.ui.jinterface.AsyncCaller) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) RpcFuture(org.erlide.runtime.rpc.RpcFuture) PartInitException(org.eclipse.ui.PartInitException) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Aggregations

FunctionRef (org.erlide.engine.model.erlang.FunctionRef)3 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 ArrayList (java.util.ArrayList)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PartInitException (org.eclipse.ui.PartInitException)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 IErlElement (org.erlide.engine.model.IErlElement)1 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 RpcFuture (org.erlide.runtime.rpc.RpcFuture)1 AsyncCaller (org.erlide.ui.jinterface.AsyncCaller)1 CallHierarchyView (org.erlide.ui.views.CallHierarchyView)1 OtpBindings (org.erlide.util.erlang.OtpBindings)1