Search in sources :

Example 1 with LibHoverInfo

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

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

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

the class ParseDevHelp method main.

public static void main(String[] args) {
    long startParse = System.currentTimeMillis();
    // $NON-NLS-1$
    String devhelpHtmlDirectory = "/usr/share/gtk-doc/html";
    DevHelpParser p = new DevHelpParser(devhelpHtmlDirectory, false);
    File dir = new File(devhelpHtmlDirectory);
    for (File f : dir.listFiles()) {
        String name = f.getName();
        // $NON-NLS-1$ //$NON-NLS-2$
        p.parse(// $NON-NLS-1$ //$NON-NLS-2$
        f.getAbsolutePath() + "/" + name + ".devhelp2", new NullProgressMonitor());
    }
    long endParse = System.currentTimeMillis();
    // $NON-NLS-1$
    System.out.println("Parse Complete:" + (endParse - startParse));
    long startSerialize = System.currentTimeMillis();
    LibHoverInfo hover = p.getLibHoverInfo();
    try {
        // Now, output the LibHoverInfo for caching later
        IPath workspaceDir = new Path(args[1]);
        // $NON-NLS-1$
        IPath location = workspaceDir.append("org.eclipse.linuxtools.cdt.libhover/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);
        }
    } catch (IOException e) {
    }
    long endSerialize = System.currentTimeMillis();
    // $NON-NLS-1$
    System.out.println("Parse Complete:" + (endSerialize - startSerialize));
}
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) FileOutputStream(java.io.FileOutputStream) XMLString(org.apache.xerces.xni.XMLString) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)

Example 4 with LibHoverInfo

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

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

the class LibHoverPreferencePage method regenerate.

private synchronized void regenerate() {
    generateButton.setEnabled(false);
    Job k = new Job(LibHoverMessages.getString(REGENERATE_MSG)) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IPreferenceStore ps = DevHelpPlugin.getDefault().getPreferenceStore();
            ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(ps.getString(PreferenceConstants.DEVHELP_DIRECTORY));
            LibHoverInfo hover = p.parse(monitor);
            // Update the devhelp library info if it is on library list
            Collection<LibHoverLibrary> libs = LibHover.getLibraries();
            for (LibHoverLibrary l : libs) {
                if (l.getName().equals("devhelp")) {
                    // $NON-NLS-1$
                    l.setHoverinfo(hover);
                    break;
                }
            }
            try {
                // Now, output the LibHoverInfo for caching later
                // $NON-NLS-1$
                IPath location = LibhoverPlugin.getDefault().getStateLocation().append("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);
                }
                monitor.done();
            } catch (IOException e) {
                monitor.done();
                return new Status(IStatus.ERROR, DevHelpPlugin.PLUGIN_ID, e.getLocalizedMessage(), e);
            }
            return Status.OK_STATUS;
        }
    };
    k.setUser(true);
    k.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            Display.getDefault().syncExec(() -> {
                if (generateButton != null)
                    generateButton.setEnabled(true);
            });
        }
    });
    k.schedule();
}
Also used : LibHoverLibrary(org.eclipse.linuxtools.internal.cdt.libhover.LibHoverLibrary) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ObjectOutputStream(java.io.ObjectOutputStream) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) FileOutputStream(java.io.FileOutputStream) Job(org.eclipse.core.runtime.jobs.Job) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File)

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