Search in sources :

Example 6 with FunctionInfo

use of org.eclipse.linuxtools.cdt.libhover.FunctionInfo 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 7 with FunctionInfo

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

the class CXmlLibhoverGen method getFunctionInfoFromNode.

private FunctionInfo getFunctionInfoFromNode(String name, Node functionNode, Document document) {
    FunctionInfo f = new FunctionInfo(name);
    NamedNodeMap functionNodeMap = functionNode.getAttributes();
    Node functionNodeReturntypeNode = functionNodeMap.item(0);
    String functionNodeRtName = functionNodeReturntypeNode.getNodeName();
    if (functionNodeRtName.equals("returntype")) {
        // $NON-NLS-1$
        // return type
        String functionNodeRtValue = functionNodeReturntypeNode.getNodeValue();
        f.setReturnType(functionNodeRtValue);
    }
    // returntype
    NodeList kids = functionNode.getChildNodes();
    for (int fnk = 0; fnk < kids.getLength(); fnk++) {
        Node kid = kids.item(fnk);
        String kidName = kid.getNodeName();
        if (kidName.equals("prototype")) {
            // $NON-NLS-1$
            // prototype
            String prototype = null;
            NodeList parms = kid.getChildNodes();
            for (int fnp = 0; fnp < parms.getLength(); fnp++) {
                Node parm = parms.item(fnp);
                String parmName = parm.getNodeName();
                if (parmName.equals("parameter")) {
                    // $NON-NLS-1$
                    NamedNodeMap parmMap = parm.getAttributes();
                    Node parmNode = parmMap.item(0);
                    String parameter = parmNode.getNodeValue();
                    prototype = (null == prototype) ? parameter : prototype + ", " + // $NON-NLS-1$
                    parameter;
                }
            }
            f.setPrototype(prototype);
        } else if (kidName.equals("headers")) {
            // $NON-NLS-1$
            // headers
            NodeList headers = kid.getChildNodes();
            for (int fnh = 0; fnh < headers.getLength(); fnh++) {
                Node header = headers.item(fnh);
                String headerName = header.getNodeName();
                if (headerName.equals("header")) {
                    // $NON-NLS-1$
                    NamedNodeMap headerMap = header.getAttributes();
                    Node headerNode = headerMap.item(0);
                    f.addHeader(headerNode.getNodeValue());
                }
            }
        } else if (kidName.equals("groupsynopsis")) {
            // $NON-NLS-1$
            // group synopsis
            NamedNodeMap attr = kid.getAttributes();
            // $NON-NLS-1$
            Node idnode = attr.getNamedItem("id");
            String id = idnode.getNodeValue();
            if (id != null) {
                Element elem2 = document.getElementById(id);
                if (null != elem2) {
                    // $NON-NLS-1$
                    NodeList synopsisNode = elem2.getElementsByTagName("synopsis");
                    if (null != synopsisNode && synopsisNode.getLength() > 0) {
                        Node synopsis = synopsisNode.item(0);
                        Node textNode = synopsis.getLastChild();
                        f.setDescription(textNode.getNodeValue());
                    }
                }
            }
        } else if (kidName.equals("synopsis")) {
            // $NON-NLS-1$
            // synopsis
            Node textNode = kid.getLastChild();
            f.setDescription(textNode.getNodeValue());
        }
    }
    return f;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo)

Aggregations

FunctionInfo (org.eclipse.linuxtools.cdt.libhover.FunctionInfo)7 LibHoverInfo (org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 Node (org.w3c.dom.Node)3 NodeList (org.w3c.dom.NodeList)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 IFunctionSummary (org.eclipse.cdt.ui.IFunctionSummary)2 IPath (org.eclipse.core.runtime.IPath)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ParseDevHelp (org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp)2 Test (org.junit.Test)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 SortedMap (java.util.SortedMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1