Search in sources :

Example 1 with IErlFunction

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

the class ParserDB method handleModule.

public void handleModule(final IErlModule module) throws ErlModelException {
    module.open(null);
    final int numForms = module.getChildCount();
    final String path = module.getResource().getLocation().toPortableString();
    ParserDB.out.println(path + " " + numForms + " " + isTest(path));
    System.out.println(path + " " + numForms + " " + isTest(path));
    for (final IErlElement form : module.getChildren()) {
        ParserDB.out.print(" " + form.getKind() + " ");
        if (form instanceof IErlImportExport) {
            final IErlImportExport export = (IErlImportExport) form;
            ParserDB.out.println(export.getFunctions().size());
        } else if (form instanceof IErlPreprocessorDef) {
            final IErlPreprocessorDef def = (IErlPreprocessorDef) form;
            ParserDB.out.println(fix(def.getDefinedName()));
        } else if (form instanceof IErlTypespec) {
            final IErlTypespec attribute = (IErlTypespec) form;
            ParserDB.out.println("TYPESPEC " + fix(attribute.getName()));
        } else if (form instanceof IErlAttribute) {
            final IErlAttribute attribute = (IErlAttribute) form;
            ParserDB.out.println(fix(attribute.getName()));
        } else if (form instanceof IErlFunction) {
            final IErlFunction function = (IErlFunction) form;
            int numClauses = function.getChildCount();
            numClauses = numClauses == 0 ? 1 : numClauses;
            ParserDB.out.println(fix(function.getName()) + " " + function.getArity() + " " + numClauses);
        } else {
            ParserDB.out.println("?? " + form.getClass().getName());
        }
    }
    module.close();
    module.dispose();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlImportExport(org.erlide.engine.model.erlang.IErlImportExport) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute)

Example 2 with IErlFunction

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

the class ErlTextHover method internalGetHoverInfo.

private static ErlangBrowserInformationControlInput internalGetHoverInfo(final AbstractErlangEditor editor, final ITextViewer textViewer, final IRegion hoverRegion) {
    if (editor == null) {
        return null;
    }
    final StringBuffer result = new StringBuffer();
    OpenResult element = null;
    // TODO our model is too coarse, here we need access to expressions
    final Collection<OtpErlangObject> fImports = ErlangEngine.getInstance().getModelUtilService().getImportsAsList(editor.getModule());
    final int offset = hoverRegion.getOffset();
    final int length = hoverRegion.getLength();
    final String debuggerVar = ErlTextHover.makeDebuggerVariableHover(textViewer, offset, length);
    if (!debuggerVar.isEmpty()) {
        result.append(debuggerVar);
    }
    final IErlProject erlProject = editor.getProject();
    String docPath = "";
    String anchor = "";
    try {
        if (erlProject == null) {
            return null;
        }
        final IOtpRpc backend = BackendCore.getBuildBackend(erlProject);
        if (backend == null) {
            return null;
        }
        final IErlModel model = ErlangEngine.getInstance().getModel();
        final String externalModulesString = erlProject.getProperties().getExternalModules();
        final OtpErlangTuple t = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, offset, editor.getScannerName(), fImports, externalModulesString, model.getPathVars());
        if (Util.isOk(t)) {
            element = new OpenResult(t.elementAt(2));
            final String docStr = Util.stringValue(t.elementAt(1));
            result.append(docStr);
            if (t.arity() > 4) {
                docPath = Util.stringValue(t.elementAt(3));
                anchor = Util.stringValue(t.elementAt(4));
            }
        } else {
            element = new OpenResult(t);
            final Object found = new OpenUtils().findOpenResult(editor, editor.getModule(), erlProject, element, editor.getElementAt(offset, false));
            if (found instanceof IErlFunction) {
                final IErlFunction function = (IErlFunction) found;
                final String comment = DocumentationFormatter.getDocumentationString(function.getComments(), function.getTypespec());
                if (comment.isEmpty()) {
                    return null;
                }
                result.append(comment);
            } else if (found instanceof IErlPreprocessorDef) {
                final IErlPreprocessorDef preprocessorDef = (IErlPreprocessorDef) found;
                result.append(preprocessorDef.getExtra());
            }
        }
    } catch (final Exception e) {
        ErlLogger.warn(e);
        return null;
    }
    final String strResult = HoverUtil.getHTML(result);
    return new ErlangBrowserInformationControlInput(null, editor, element, strResult, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Point(org.eclipse.swt.graphics.Point) DebugException(org.eclipse.debug.core.DebugException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) ErlangBrowserInformationControlInput(org.erlide.ui.internal.information.ErlangBrowserInformationControlInput) OpenResult(org.erlide.engine.services.search.OpenResult) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OpenUtils(org.erlide.ui.actions.OpenUtils) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 3 with IErlFunction

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

the class ErlangCompletionService method getDeclaredFunctions.

List<CompletionData> getDeclaredFunctions(final int offset, final String prefix, final boolean unexportedOnly, final boolean arityOnly) throws ErlModelException {
    final List<CompletionData> result = new ArrayList<>();
    for (final IErlElement e : module.getChildren()) {
        if (e instanceof IErlFunction) {
            final IErlFunction f = (IErlFunction) e;
            if (unexportedOnly && f.isExported()) {
                continue;
            }
            addFunctionCompletion(offset, prefix, result, f, arityOnly);
        }
    }
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) CompletionData(org.erlide.engine.services.codeassist.CompletionData) FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ArrayList(java.util.ArrayList)

Example 4 with IErlFunction

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

the class OpenUtils method findLocalCall.

private IErlElement findLocalCall(final IErlModule module, final IErlProject erlProject, final OpenResult res, final IErlElement element, final IErlElementLocator.Scope scope) throws RpcException, CoreException {
    if (isTypeDefOrRecordDef(element, res)) {
        return modelFindService.findTypespec(module, res.getFun());
    }
    final IErlFunction foundElement = module.findFunction(res.getFunction());
    if (foundElement != null) {
        return foundElement;
    }
    // imported functions
    OtpErlangObject res2 = null;
    String moduleName = null;
    final IErlImport ei = module.findImport(res.getFunction());
    if (ei != null) {
        final IErlModel model = ErlangEngine.getInstance().getModel();
        moduleName = ei.getImportModule();
        res2 = ErlangEngine.getInstance().getOpenService().getSourceFromModule(model.getPathVars(), moduleName, erlProject.getProperties().getExternalModules());
    }
    if (res2 instanceof OtpErlangString && moduleName != null) {
        // imported from otp module
        final OtpErlangString otpErlangString = (OtpErlangString) res2;
        final String modulePath = otpErlangString.stringValue();
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        return modelFindService.findFunction(model, erlProject, module, moduleName, modulePath, res.getFunction(), scope);
    }
    // functions defined in include files
    final Collection<IErlModule> allIncludedFiles = ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module);
    for (final IErlModule includedModule : allIncludedFiles) {
        final IErlFunction function = includedModule.findFunction(res.getFunction());
        if (function != null) {
            return function;
        }
    }
    return null;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlImport(org.erlide.engine.model.erlang.IErlImport) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 5 with IErlFunction

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

the class SearchPatternFactory method getSearchPatternFromErlElementAndLimitTo.

public ErlangSearchPattern getSearchPatternFromErlElementAndLimitTo(final IErlElement element, final LimitTo limitTo) {
    if (element instanceof IErlFunction) {
        final IErlFunction function = (IErlFunction) element;
        final String withoutExtension = SystemConfiguration.withoutExtension(function.getModuleName());
        return new FunctionPattern(withoutExtension, function.getFunctionName(), function.getArity(), limitTo, true, modelUtilService.getModule(function), !function.isExported());
    } else if (element instanceof IErlMacroDef) {
        final IErlMacroDef m = (IErlMacroDef) element;
        final String unquoted = StringUtils.unquote(m.getDefinedName());
        return new MacroPattern(unquoted, limitTo);
    } else if (element instanceof IErlRecordDef) {
        final IErlRecordDef r = (IErlRecordDef) element;
        final String unquoted = StringUtils.unquote(r.getDefinedName());
        return new RecordPattern(unquoted, limitTo);
    } else if (element instanceof IErlFunctionClause) {
        final IErlFunctionClause clause = (IErlFunctionClause) element;
        return getSearchPatternFromErlElementAndLimitTo((IErlElement) clause.getParent(), limitTo);
    } else if (element instanceof IErlAttribute) {
        final IErlAttribute a = (IErlAttribute) element;
        if (a.getName().startsWith("include")) {
            final String s = Util.stringValue(a.getValue());
            return new IncludePattern(s, limitTo);
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) IErlMacroDef(org.erlide.engine.model.erlang.IErlMacroDef) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

IErlFunction (org.erlide.engine.model.erlang.IErlFunction)22 IErlModule (org.erlide.engine.model.root.IErlModule)7 IErlElement (org.erlide.engine.model.IErlElement)6 ISelection (org.eclipse.jface.viewers.ISelection)5 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)4 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)3 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)3 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 PartInitException (org.eclipse.ui.PartInitException)2 IErlModel (org.erlide.engine.model.root.IErlModel)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1