Search in sources :

Example 1 with FunctionInfo

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

the class CDoxygenLibhoverGen method doGenerate.

@Override
public LibHoverInfo doGenerate() {
    LibHoverInfo libHoverInfo = new LibHoverInfo();
    // Create a hash table of all the class nodes mapped by class name.  Trim any template info
    // for the class name key value.
    NodeList nl = document.getElementsByTagName(COMPOUNDDEF);
    for (int i = 0; i < nl.getLength(); ++i) {
        Node n = nl.item(i);
        NamedNodeMap attrs = n.getAttributes();
        // $NON-NLS-1$
        Node kind = attrs.getNamedItem("kind");
        // $NON-NLS-1$
        Node id = attrs.getNamedItem("id");
        Node prot = attrs.getNamedItem(PROT3);
        // C functions
        if (id != null && kind != null && FILE.equals(kind.getNodeValue())) {
            NodeList nl2 = n.getChildNodes();
            FunctionInfo fi = null;
            String include = null;
            for (int j = 0; j < nl2.getLength(); ++j) {
                Node n2 = nl2.item(j);
                String name2 = n2.getNodeName();
                if (COMPOUNDNAME.equals(name2)) {
                    // compoundname for a file node is the filename
                    // this can be a .c or .h file
                    String filename = getElementText(n2);
                    if (filename.endsWith(".h")) {
                        // $NON-NLS-1$
                        include = filename;
                    }
                } else if (SECTIONDEF.equals(name2)) {
                    // We are only interested in functions
                    NamedNodeMap m = n2.getAttributes();
                    if (m != null) {
                        // $NON-NLS-1$
                        Node kind2 = m.getNamedItem("kind");
                        if (kind2 != null && FUNC.equals(kind2.getNodeValue())) {
                            NodeList pubfuncs = n2.getChildNodes();
                            int pubfuncLength = pubfuncs.getLength();
                            for (int j1 = 0; j1 < pubfuncLength; ++j1) {
                                Node n3 = pubfuncs.item(j1);
                                // Add all public member functions to the list of members
                                if (MEMBERDEF.equals(n3.getNodeName())) {
                                    NamedNodeMap m3 = n3.getAttributes();
                                    if (m3 != null) {
                                        // $NON-NLS-1$
                                        Node m3Kind = m3.getNamedItem("kind");
                                        if (m3Kind != null && FUNCTION.equals(m3Kind.getNodeValue())) {
                                            String name = null;
                                            String type = null;
                                            String args = null;
                                            String desc = null;
                                            boolean briefDescriptionProcessed = false;
                                            boolean detailedDescriptionProcessed = false;
                                            boolean parameterListProcessed = false;
                                            boolean retValProcessed = false;
                                            boolean locationProcessed = false;
                                            ArrayList<String> parms = new ArrayList<>();
                                            NodeList nl4 = n3.getChildNodes();
                                            int memberLength = nl4.getLength();
                                            for (int k = 0; k < memberLength; ++k) {
                                                Node n4 = nl4.item(k);
                                                String n4Name = n4.getNodeName();
                                                if (TYPE2.equals(n4Name)) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    // $NON-NLS-1$
                                                    type = "";
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (n5.getNodeType() == Node.TEXT_NODE)
                                                            type += n5.getNodeValue();
                                                    }
                                                } else if (NAME3.equals(n4Name)) {
                                                    name = n4.getTextContent();
                                                } else if (ARGSSTRING.equals(n4Name)) {
                                                    args = getElementText(n4);
                                                } else if (PARAM.equals(n4Name)) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (TYPE2.equals(n5.getNodeName())) {
                                                            parms.add(getElementText(n5));
                                                        }
                                                    }
                                                } else if (BRIEFDESCRIPTION.equals(n4Name) && !briefDescriptionProcessed) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (PARA.equals(n5.getNodeName())) {
                                                            if (desc == null) {
                                                                // $NON-NLS-1$
                                                                desc = "";
                                                            }
                                                            // $NON-NLS-1$ //$NON-NLS-2$
                                                            desc += "<p>" + getElementText(n5) + "</p>";
                                                            briefDescriptionProcessed = true;
                                                        }
                                                    }
                                                } else if (DETAILEDDESCRIPTION.equals(n4Name)) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (n5.getNodeName().equals(PARA)) {
                                                            if (desc == null)
                                                                // $NON-NLS-1$
                                                                desc = new String("");
                                                            NodeList nl6 = n5.getChildNodes();
                                                            Node n6 = nl6.item(0);
                                                            if (n6.getNodeType() == Node.TEXT_NODE && !detailedDescriptionProcessed) {
                                                                // $NON-NLS-1$ //$NON-NLS-2$
                                                                desc += "<p>" + getElementText(n5) + "</p>";
                                                                detailedDescriptionProcessed = true;
                                                            } else {
                                                                for (int x2 = 0; x2 < nl6.getLength(); ++x2) {
                                                                    n6 = nl6.item(x2);
                                                                    if (PARAMETERLIST.equals(n6.getNodeName()) && !parameterListProcessed) {
                                                                        desc += getParameters(n6, false);
                                                                        parameterListProcessed = true;
                                                                    } else if (SIMPLESECT.equals(n6.getNodeName()) & !retValProcessed) {
                                                                        desc += getReturn(n6);
                                                                        retValProcessed = true;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                } else if (LOCATION.equals(n4Name) && !locationProcessed) {
                                                    // Location is after all descriptions so we can now add the function
                                                    if (name != null) {
                                                        // Try to update existing function, in case information is split between .c and .h files
                                                        fi = libHoverInfo.functions.get(name);
                                                        if (fi == null) {
                                                            fi = new FunctionInfo(name);
                                                        }
                                                        if (type != null) {
                                                            fi.setReturnType(type);
                                                        }
                                                        if (args != null) {
                                                            // Strip ()s, as the plugin adds them back in
                                                            if (args.charAt(0) == '(' && args.charAt(args.length() - 1) == ')')
                                                                fi.setPrototype(args.substring(1, args.length() - 1));
                                                            else
                                                                fi.setPrototype(args);
                                                        }
                                                        if (desc != null) {
                                                            fi.setDescription(desc);
                                                        }
                                                        if (include != null) {
                                                            fi.addHeader(include);
                                                        }
                                                        // System.out.println(name + "|" + type +  "|" + args +  "|" + desc +  "|" + include);
                                                        libHoverInfo.functions.put(name, fi);
                                                        locationProcessed = true;
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // We are only interested in cataloging public classes.
        if (id != null && prot != null && PUBLIC.equals(prot.getNodeValue()) && kind != null && CLASS.equals(kind.getNodeValue())) {
            NodeList nl2 = n.getChildNodes();
            ClassInfo d = null;
            String hashName = null;
            for (int j = 0; j < nl2.getLength(); ++j) {
                Node n2 = nl2.item(j);
                String name2 = n2.getNodeName();
                if (name2.equals(COMPOUNDNAME)) {
                    String text = n2.getTextContent();
                    if (text != null && !text.equals("")) {
                        // $NON-NLS-1$
                        String className = text;
                        // $NON-NLS-1$ //$NON-NLS-2$
                        text = text.replaceAll("<\\s*", "<");
                        // $NON-NLS-1$ //$NON-NLS-2$
                        text = text.replaceAll("\\s*>", ">");
                        int index = text.indexOf('<');
                        hashName = text;
                        if (index > 0)
                            hashName = text.substring(0, index);
                        d = new ClassInfo(className, n);
                        classesById.put(id.getNodeValue(), d);
                        ClassInfo e = libHoverInfo.classes.get(hashName);
                        if (e != null) {
                            /* We are dealing with a partial specific template...add it to list  */
                            if (!d.areTemplateParmsFilled())
                                d.setTemplateParms(getTemplateParms(n));
                            String[] templateParms = d.getTemplateParms();
                            // any instance, more refinement of the initial value to replace will be required.
                            for (int k = 0; k < templateParms.length; ++k) {
                                // $NON-NLS-1$
                                text = text.replaceAll(templateParms[k], "[a-zA-Z0-9_: *]+");
                            }
                            d.setClassName(text);
                            e.addTemplate(d);
                        } else
                            libHoverInfo.classes.put(hashName, d);
                    }
                } else if (TEMPLATEPARAMLIST.equals(name2)) {
                    ArrayList<String> templates = new ArrayList<>();
                    NodeList params = n2.getChildNodes();
                    int paramsLength = params.getLength();
                    for (int j2 = 0; j2 < paramsLength; ++j2) {
                        Node n3 = params.item(j2);
                        if (n3.getNodeName().equals(PARAM)) {
                            NodeList types = n3.getChildNodes();
                            int typesLength = types.getLength();
                            for (int j3 = 0; j3 < typesLength; ++j3) {
                                Node n4 = types.item(j3);
                                if (DECLNAME.equals(n4.getNodeName())) {
                                    templates.add(getElementText(n4));
                                }
                            }
                        }
                    }
                    String[] templateNames = new String[templates.size()];
                    d.setTemplateParms(templates.toArray(templateNames));
                } else if (INCLUDES.equals(name2)) {
                    String include = getElementText(n2);
                    if (d != null)
                        d.setInclude(include);
                } else if (BASECOMPOUNDREF.equals(name2)) {
                    // We have a base class.  If public, add it to the list of nodes to look at in case we don't find the member
                    // in the current class definition.
                    NamedNodeMap m = n2.getAttributes();
                    if (m != null) {
                        Node refid = m.getNamedItem(REFID2);
                        Node prot2 = m.getNamedItem(PROT3);
                        if (prot2 != null && PUBLIC.equals(prot2.getNodeValue())) {
                            ClassInfo baseClass = null;
                            if (refid != null) {
                                // If we have been given the id of the base class, fetch it directly
                                baseClass = classesById.get(refid.getNodeValue());
                            } else {
                                // We probably have a template that needs resolution
                                String baseClassName = n2.getTextContent();
                                // System.out.println("base class name is " + baseClassName);
                                baseClass = getClassInfo(libHoverInfo, baseClassName);
                            }
                            if (d != null && baseClass != null)
                                d.addBaseClass(baseClass);
                        }
                    }
                } else if (SECTIONDEF.equals(name2)) {
                    // We are only interested in public member functions which are in their own section.
                    NamedNodeMap m = n2.getAttributes();
                    if (m != null) {
                        // $NON-NLS-1$
                        Node kind2 = m.getNamedItem("kind");
                        if (kind2 != null && PUBLIC_FUNC.equals(kind2.getNodeValue())) {
                            NodeList pubfuncs = n2.getChildNodes();
                            int pubfuncLength = pubfuncs.getLength();
                            for (int j1 = 0; j1 < pubfuncLength; ++j1) {
                                Node n3 = pubfuncs.item(j1);
                                // Add all public member functions to the list of members
                                if (MEMBERDEF.equals(n3.getNodeName())) {
                                    NamedNodeMap m3 = n3.getAttributes();
                                    if (m3 != null) {
                                        // $NON-NLS-1$
                                        Node m3Kind = m3.getNamedItem("kind");
                                        if (m3Kind != null && FUNCTION.equals(m3Kind.getNodeValue())) {
                                            String name = null;
                                            String type = null;
                                            String args = null;
                                            String desc = null;
                                            ArrayList<String> parms = new ArrayList<>();
                                            NodeList nl4 = n3.getChildNodes();
                                            int memberLength = nl4.getLength();
                                            for (int k = 0; k < memberLength; ++k) {
                                                Node n4 = nl4.item(k);
                                                String n4Name = n4.getNodeName();
                                                if (TYPE2.equals(n4Name)) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    // $NON-NLS-1$
                                                    type = "";
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (n5.getNodeType() == Node.TEXT_NODE)
                                                            type += n5.getNodeValue();
                                                        else if (REF.equals(n5.getNodeName())) {
                                                            NamedNodeMap n5m = n5.getAttributes();
                                                            Node n5id = n5m.getNamedItem(REFID2);
                                                            if (n5id != null) {
                                                                String refid = n5id.getNodeValue();
                                                                ClassInfo refClass = classesById.get(refid);
                                                                if (refClass != null)
                                                                    type += refClass.getClassName();
                                                            }
                                                        }
                                                    }
                                                } else if (NAME3.equals(n4Name)) {
                                                    name = n4.getTextContent();
                                                } else if (ARGSSTRING.equals(n4Name)) {
                                                    args = getElementText(n4);
                                                } else if (PARAM.equals(n4Name)) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (TYPE2.equals(n5.getNodeName())) {
                                                            parms.add(getElementText(n5));
                                                        }
                                                    }
                                                } else if (BRIEFDESCRIPTION.equals(n4Name)) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (PARA.equals(n5.getNodeName())) {
                                                            if (desc == null) {
                                                                // $NON-NLS-1$
                                                                desc = "";
                                                            }
                                                            // $NON-NLS-1$ //$NON-NLS-2$
                                                            desc += "<p>" + getElementText(n5) + "</p>";
                                                        }
                                                    }
                                                } else if (DETAILEDDESCRIPTION.equals(n4Name)) {
                                                    NodeList nl5 = n4.getChildNodes();
                                                    for (int x = 0; x < nl5.getLength(); ++x) {
                                                        Node n5 = nl5.item(x);
                                                        if (PARA.equals(n5.getNodeName())) {
                                                            if (desc == null)
                                                                // $NON-NLS-1$
                                                                desc = new String("");
                                                            NodeList nl6 = n5.getChildNodes();
                                                            Node n6 = nl6.item(0);
                                                            if (n6.getNodeType() == Node.TEXT_NODE)
                                                                // $NON-NLS-1$ //$NON-NLS-2$
                                                                desc += "<p>" + getElementText(n5) + "</p>";
                                                            else {
                                                                for (int x2 = 0; x2 < nl6.getLength(); ++x2) {
                                                                    n6 = nl6.item(x2);
                                                                    if (PARAMETERLIST.equals(n6.getNodeName())) {
                                                                        desc += getParameters(n6, true);
                                                                    } else if (SIMPLESECT.equals(n6.getNodeName())) {
                                                                        desc += getReturn(n6);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                } else if (LOCATION.equals(n4Name)) {
                                                    // Location is after all descriptions so we can now add the member
                                                    if (name != null) {
                                                        MemberInfo member = new MemberInfo(name);
                                                        member.setReturnType(type);
                                                        member.setPrototype(args);
                                                        member.setDescription(desc);
                                                        String[] argNames = new String[parms.size()];
                                                        member.setParamTypes(parms.toArray(argNames));
                                                        d.addMember(member);
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Create a hash table of all the typedefs.  Keep any template info.
    nl = document.getElementsByTagName(MEMBERDEF);
    for (int i = 0; i < nl.getLength(); ++i) {
        Node n = nl.item(i);
        NamedNodeMap attrs = n.getAttributes();
        if (attrs != null) {
            // $NON-NLS-1$
            Node kind = attrs.getNamedItem("kind");
            Node prot = attrs.getNamedItem(PROT3);
            if (kind != null && TYPEDEF2.equals(kind.getNodeValue()) && prot != null && PUBLIC.equals(prot.getNodeValue())) {
                NodeList list = n.getChildNodes();
                for (int x = 0; x < list.getLength(); ++x) {
                    Node n2 = list.item(x);
                    if (DEFINITION.equals(n2.getNodeName())) {
                        String def = n2.getTextContent();
                        if (def != null && !def.equals("")) {
                            // $NON-NLS-1$
                            // $NON-NLS-1$ //$NON-NLS-2$
                            def = def.replaceAll("<\\s*", "<");
                            // $NON-NLS-1$ //$NON-NLS-2$
                            def = def.replaceAll("\\s*>", ">");
                            String[] types = getTypedefTypes(def);
                            if (types == null) {
                                continue;
                            }
                            TypedefInfo d = new TypedefInfo(types[1], types[0]);
                            String hashName = d.getTypedefName();
                            int index = hashName.indexOf('<');
                            if (index > 0) {
                                String className = hashName.substring(0, index);
                                // $NON-NLS-1$ //$NON-NLS-2$
                                hashName = hashName.replaceAll("<.*>", "<>");
                                ClassInfo e = libHoverInfo.classes.get(className);
                                if (e == null)
                                    break;
                                ArrayList<ClassInfo> children = e.getChildren();
                                if (children != null && children.size() > 0) {
                                    for (int y = 0; y < children.size(); ++y) {
                                        ClassInfo child = children.get(y);
                                        // $NON-NLS-1$ //$NON-NLS-2$
                                        String childName = child.getClassName().replaceAll("\\*", "\\\\*");
                                        // $NON-NLS-1$ //$NON-NLS-2$
                                        childName = childName.replace("[]", "\\[\\]");
                                        if (types[1].matches(childName.concat("::.*"))) {
                                            // $NON-NLS-1$
                                            e = child;
                                            break;
                                        }
                                    }
                                }
                                String[] templates = e.getTemplateParms();
                                d.copyTemplates(templates);
                                TypedefInfo f = libHoverInfo.typedefs.get(hashName);
                                if (f != null) {
                                    String typedefName = d.getTypedefName();
                                    for (int z = 0; z < templates.length; ++z) {
                                        // $NON-NLS-1$
                                        typedefName = typedefName.replaceAll(templates[z], "[a-zA-Z0-9_: ]+");
                                    }
                                    d.setTypedefName(typedefName);
                                    f.addTypedef(d);
                                } else
                                    libHoverInfo.typedefs.put(hashName, d);
                                break;
                            } else {
                                // Otherwise we have a non-template typedef name.  Just add it to the list.
                                libHoverInfo.typedefs.put(hashName, d);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return libHoverInfo;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) TypedefInfo(org.eclipse.linuxtools.cdt.libhover.TypedefInfo) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) MemberInfo(org.eclipse.linuxtools.cdt.libhover.MemberInfo) ClassInfo(org.eclipse.linuxtools.cdt.libhover.ClassInfo)

Example 2 with FunctionInfo

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

the class CheckDevhelp method testParseMyApp.

@Test
public void testParseMyApp() throws IOException {
    // We need to have a devhelp directory with contents to test.
    // Copy over the needed devhelp/html2 contents in this test plug-in
    // to the workspace.  This test verifies: bug 433507 and also
    // tests non-breaking spaces used in latest gtk-doc devhelp generation.
    ClassLoader cl = getClass().getClassLoader();
    Bundle bundle = null;
    if (cl instanceof BundleReference) {
        bundle = ((BundleReference) cl).getBundle();
    }
    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IPath wslocpath = ws.getRoot().getLocation();
    // $NON-NLS-1$
    IPath outfilepath = wslocpath.append("devhelp/html2/myapp");
    File outfiledir = outfilepath.toFile();
    assertTrue(outfiledir.mkdirs());
    // $NON-NLS-1$
    outfilepath = outfilepath.append("myapp.devhelp2");
    File outfile = outfilepath.toFile();
    // $NON-NLS-1$
    IPath outfilepath2 = wslocpath.append("devhelp/html2/myapp/myapp.html");
    File outfile2 = outfilepath2.toFile();
    // $NON-NLS-1$
    IPath outfilepath3 = wslocpath.append("devhelp/html2/myapp/myapp2.html");
    File outfile3 = outfilepath3.toFile();
    // $NON-NLS-1$
    IPath outfilepath4 = wslocpath.append("devhelp/html2/myapp/style.css");
    File outfile4 = outfilepath4.toFile();
    outfile.createNewFile();
    outfile2.createNewFile();
    outfile3.createNewFile();
    outfile4.createNewFile();
    try (InputStream in = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp.devhelp2"), false)) {
        // $NON-NLS-1$
        Files.copy(in, Paths.get(outfile.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    try (InputStream in2 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp.html"), false)) {
        // $NON-NLS-1$
        Files.copy(in2, Paths.get(outfile2.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    try (InputStream in3 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp2.html"), false)) {
        // $NON-NLS-1$
        Files.copy(in3, Paths.get(outfile3.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    try (InputStream in4 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp2.html"), false)) {
        // $NON-NLS-1$
        Files.copy(in4, Paths.get(outfile4.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    // $NON-NLS-1$
    IPath x = wslocpath.append("devhelp/html2");
    ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(x.toOSString());
    LibHoverInfo hover = p.parse(new NullProgressMonitor());
    assertNotNull(hover);
    Map<String, FunctionInfo> functions = hover.functions;
    assertNotNull(functions);
    assertFalse(functions.isEmpty());
    // $NON-NLS-1$
    FunctionInfo f = functions.get("myapp_init");
    assertNotNull(f);
    String desc = f.getDescription();
    assertFalse(desc.isEmpty());
    String endOfDesc = desc.substring(desc.length() - 50);
    // $NON-NLS-1$
    assertEquals("pointer to application's argv. </p></dd>\n\n\n</dl>\n\n", endOfDesc);
    // $NON-NLS-1$
    FunctionInfo g = functions.get("myapp_init_check");
    assertNotNull(g);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) BundleReference(org.osgi.framework.BundleReference) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) IWorkspace(org.eclipse.core.resources.IWorkspace) File(java.io.File) Test(org.junit.Test)

Example 3 with FunctionInfo

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

the class LibHover method getFunctionSummary.

private IFunctionSummary getFunctionSummary(LibHoverLibrary l, String name) {
    FunctionInfo x = l.getFunctionInfo(name);
    if (x != null) {
        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 i = 0; i < headers.size(); ++i) {
            f.setIncludeName(headers.get(i));
        }
        return f;
    }
    return null;
}
Also used : IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo)

Example 4 with FunctionInfo

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

the class CheckDevhelp method testParse.

@Test
public void testParse() throws IOException {
    ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(// $NON-NLS-1$
    "/usr/share/gtk-doc/html");
    LibHoverInfo hover = p.parse(new NullProgressMonitor());
    assertNotNull(hover);
    Map<String, FunctionInfo> functions = hover.functions;
    assertNotNull(functions);
    assertFalse(functions.isEmpty());
    // Now, output the LibHoverInfo for caching later
    IPath location = LibhoverPlugin.getDefault().getStateLocation().append(// $NON-NLS-1$
    "C");
    File ldir = new File(location.toOSString());
    ldir.mkdir();
    // $NON-NLS-1$
    location = location.append("devhelp.libhover");
    try (FileOutputStream f = new FileOutputStream(location.toOSString());
        ObjectOutputStream out = new ObjectOutputStream(f)) {
        out.writeObject(hover);
    }
    IPreferenceStore ps = LibhoverPlugin.getDefault().getPreferenceStore();
    ps.setValue(CACHE_EXT_LIBHOVER, true);
    LibHover.getLibHoverDocs();
    Collection<LibHoverLibrary> c = LibHover.getLibraries();
    assertFalse(c.isEmpty());
    boolean found = false;
    for (LibHoverLibrary l : c) {
        if (l.getName().equals("devhelp")) {
            // $NON-NLS-1$
            found = true;
        }
    }
    assertTrue(found);
}
Also used : LibHoverLibrary(org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) ObjectOutputStream(java.io.ObjectOutputStream) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) FileOutputStream(java.io.FileOutputStream) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File) Test(org.junit.Test)

Example 5 with FunctionInfo

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

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