Search in sources :

Example 1 with OpenUtils

use of org.erlide.ui.actions.OpenUtils 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 2 with OpenUtils

use of org.erlide.ui.actions.OpenUtils in project erlide_eclipse by erlang.

the class SearchUtil method getSearchPatternFromOpenResultAndLimitTo.

public static ErlangSearchPattern getSearchPatternFromOpenResultAndLimitTo(final IErlModule module, final int offset, final OpenResult res, final LimitTo limitTo, final boolean matchAnyFunctionDefinition) throws ErlModelException {
    if (res == null) {
        return null;
    }
    if (res.isLocalCall()) {
        String moduleName;
        if (module != null) {
            moduleName = module.getModuleName();
            if (offset != -1) {
                final IErlElement e = module.getElementAt(offset);
                if (new OpenUtils().isTypeDefOrRecordDef(e, res)) {
                    return new TypeRefPattern(moduleName, res.getFun(), limitTo);
                }
            }
        } else {
            moduleName = res.getName();
        }
        return new FunctionPattern(moduleName, res.getFun(), res.getArity(), limitTo, matchAnyFunctionDefinition, module, true);
    }
    String moduleName = res.getName();
    if (moduleName == null) {
        return null;
    }
    final String unquoted = StringUtils.unquote(moduleName);
    if (res.isExternalCall()) {
        if (module != null && offset != -1) {
            final IErlElement e = module.getElementAt(offset);
            if (e != null && (e.getKind() == ErlElementKind.TYPESPEC || e.getKind() == ErlElementKind.RECORD_DEF)) {
                return new TypeRefPattern(moduleName, res.getFun(), limitTo);
            }
        }
        String oldName;
        moduleName = unquoted;
        do {
            oldName = moduleName;
            moduleName = ErlangEngine.getInstance().getModelFindService().resolveMacroValue(moduleName, module);
        } while (!moduleName.equals(oldName));
        return new FunctionPattern(moduleName, res.getFun(), res.getArity(), limitTo, matchAnyFunctionDefinition, module, false);
    } else if (res.isMacro()) {
        return new MacroPattern(unquoted, limitTo);
    } else if (res.isRecord()) {
        return new RecordPattern(unquoted, limitTo);
    } else if (res.isInclude()) {
        return new IncludePattern(moduleName, limitTo);
    } else if (res.isVariable()) {
        if (module != null) {
            if (offset != -1) {
                final IErlElement e = module.getElementAt(offset);
                if (e instanceof IErlFunctionClause) {
                    final IErlFunctionClause c = (IErlFunctionClause) e;
                    return new VariablePattern(c.getFunctionName(), c.getArity(), c.getHead(), res.getName(), limitTo, module);
                }
            }
        }
    } else if (res.isField()) {
        return new RecordFieldPattern(res.getFun(), unquoted, limitTo);
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) TypeRefPattern(org.erlide.engine.services.search.TypeRefPattern) FunctionPattern(org.erlide.engine.services.search.FunctionPattern) VariablePattern(org.erlide.engine.services.search.VariablePattern) IncludePattern(org.erlide.engine.services.search.IncludePattern) OpenUtils(org.erlide.ui.actions.OpenUtils) RecordPattern(org.erlide.engine.services.search.RecordPattern) RecordFieldPattern(org.erlide.engine.services.search.RecordFieldPattern) MacroPattern(org.erlide.engine.services.search.MacroPattern) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

OpenUtils (org.erlide.ui.actions.OpenUtils)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 DebugException (org.eclipse.debug.core.DebugException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Point (org.eclipse.swt.graphics.Point)1 IErlElement (org.erlide.engine.model.IErlElement)1 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)1 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)1 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IErlProject (org.erlide.engine.model.root.IErlProject)1 FunctionPattern (org.erlide.engine.services.search.FunctionPattern)1 IncludePattern (org.erlide.engine.services.search.IncludePattern)1 MacroPattern (org.erlide.engine.services.search.MacroPattern)1 OpenResult (org.erlide.engine.services.search.OpenResult)1 RecordFieldPattern (org.erlide.engine.services.search.RecordFieldPattern)1 RecordPattern (org.erlide.engine.services.search.RecordPattern)1 TypeRefPattern (org.erlide.engine.services.search.TypeRefPattern)1 VariablePattern (org.erlide.engine.services.search.VariablePattern)1