Search in sources :

Example 6 with LibHoverInfo

use of org.eclipse.linuxtools.cdt.libhover.LibHoverInfo in project linuxtools by eclipse.

the class LibHover method getMatchingFunctions.

@Override
public IFunctionSummary[] getMatchingFunctions(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String prefix) {
    ArrayList<IFunctionSummary> fList = new ArrayList<>();
    ITranslationUnit t = context.getTranslationUnit();
    boolean qualifiedCPP = false;
    if (t.isCXXLanguage()) {
        try {
            if (context instanceof IContentAssistHelpInvocationContext) {
                // We know the file offset of the member reference.
                IASTCompletionNode node = ((IContentAssistHelpInvocationContext) context).getCompletionNode();
                IASTName[] names = node.getNames();
                for (IASTName name : names) {
                    if (name.isQualified()) {
                        qualifiedCPP = true;
                        break;
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    if (!qualifiedCPP) {
        for (int di = 0; di < helpBooks.length; ++di) {
            LibHoverLibrary l = libraries.get(helpBooks[di]);
            LibHoverInfo cppInfo = l.getHoverInfo();
            SortedMap<String, FunctionInfo> map = cppInfo.functions.tailMap(prefix);
            Set<Map.Entry<String, FunctionInfo>> c = map.entrySet();
            for (Iterator<Entry<String, FunctionInfo>> i = c.iterator(); i.hasNext(); ) {
                Map.Entry<String, FunctionInfo> e = i.next();
                FunctionInfo x = e.getValue();
                String name = x.getName();
                // never be offered as a choice for an empty prefix.
                if (name.startsWith(prefix) && !name.startsWith("0")) {
                    // $NON-NLS-1$
                    FunctionSummary f = new FunctionSummary();
                    f.ReturnType = x.getReturnType();
                    f.Prototype = x.getPrototype();
                    f.Summary = x.getDescription();
                    f.Name = x.getName();
                    ArrayList<String> headers = x.getHeaders();
                    for (int i1 = 0; i1 < headers.size(); ++i1) {
                        f.setIncludeName(headers.get(i1));
                    }
                    fList.add(f);
                }
            }
        }
    }
    IFunctionSummary[] summaries = new IFunctionSummary[fList.size()];
    for (int k = 0; k < summaries.length; k++) {
        summaries[k] = fList.get(k);
    }
    return summaries;
}
Also used : IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) ArrayList(java.util.ArrayList) IContentAssistHelpInvocationContext(org.eclipse.cdt.ui.text.IContentAssistHelpInvocationContext) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) Entry(java.util.Map.Entry) ITranslationUnit(org.eclipse.cdt.core.model.ITranslationUnit) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) CoreException(org.eclipse.core.runtime.CoreException) DOMException(org.eclipse.cdt.core.dom.ast.DOMException) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IASTCompletionNode(org.eclipse.cdt.core.dom.ast.IASTCompletionNode) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) ICPPTemplateParameterMap(org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap)

Example 7 with LibHoverInfo

use of org.eclipse.linuxtools.cdt.libhover.LibHoverInfo in project linuxtools by eclipse.

the class CXmlLibhoverGen method doGenerate.

@Override
protected LibHoverInfo doGenerate() {
    LibHoverInfo hoverInfo = new LibHoverInfo();
    // $NON-NLS-1$
    NodeList nl = document.getElementsByTagName("construct");
    for (int i = 0; i < nl.getLength(); ++i) {
        Node n = nl.item(i);
        NamedNodeMap m = n.getAttributes();
        // $NON-NLS-1$
        Node id = m.getNamedItem("id");
        if (id != null && id.getNodeValue().startsWith("function-")) {
            // $NON-NLS-1$
            String name = id.getNodeValue().substring(9);
            NodeList nl2 = n.getChildNodes();
            for (int j = 0; j < nl2.getLength(); ++j) {
                Node n2 = nl2.item(j);
                if (n2.getNodeName().equals("function")) {
                    // $NON-NLS-1$
                    FunctionInfo f = getFunctionInfoFromNode(name, n2, document);
                    hoverInfo.functions.put(name, f);
                }
            }
        }
    }
    return hoverInfo;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)

Example 8 with LibHoverInfo

use of org.eclipse.linuxtools.cdt.libhover.LibHoverInfo in project linuxtools by eclipse.

the class LibhoverInfoGenerator method generate.

public void generate(String outputFile) {
    LibHoverInfo hoverInfo = doGenerate();
    save(hoverInfo, outputFile);
}
Also used : LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)

Aggregations

LibHoverInfo (org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)8 FunctionInfo (org.eclipse.linuxtools.cdt.libhover.FunctionInfo)5 File (java.io.File)4 IPath (org.eclipse.core.runtime.IPath)4 FileOutputStream (java.io.FileOutputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 ParseDevHelp (org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 LibHoverLibrary (org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary)2 Test (org.junit.Test)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1