Search in sources :

Example 1 with ClassInfo

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

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

the class DoxygenCPPInfo method getClassInfo.

private ClassInfo getClassInfo(String className) {
    // $NON-NLS-1$ //$NON-NLS-2$
    String typedefName = className.replaceAll("<.*>", "<>");
    TypedefInfo typedef = cppInfo.typedefs.get(typedefName);
    if (typedef != null) {
        // Reset class name to typedef transformation
        className = typedef.getTransformedType(className);
    }
    int index = className.indexOf('<');
    // Check if it is a template reference.
    if (index != -1) {
        // It is.  We want to see if there are partial specific templates
        // and we choose the first match.  If nothing matches our particular
        // case, we fall back on the initial generic template.
        ClassInfo info = cppInfo.classes.get(className.substring(0, index));
        if (info == null)
            return null;
        ArrayList<ClassInfo> children = info.getChildren();
        if (children != null && children.size() > 0) {
            for (int x = 0; x < children.size(); ++x) {
                ClassInfo child = children.get(x);
                if (className.matches(child.getClassName())) {
                    info = child;
                    break;
                }
            }
        }
        return info;
    }
    // Otherwise no template, just fetch the class info directly.
    return cppInfo.classes.get(className);
}
Also used : TypedefInfo(org.eclipse.linuxtools.cdt.libhover.TypedefInfo) ClassInfo(org.eclipse.linuxtools.cdt.libhover.ClassInfo)

Example 3 with ClassInfo

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

the class LibHoverLibrary method getClassInfo.

/**
 * Fetch the class info for a given class.
 *
 * @param className the name of the class to fetch info for
 * @return ClassInfo or null if no class info can be found
 */
public ClassInfo getClassInfo(String className, ArrayList<String> templateTypes) {
    // $NON-NLS-1$ //$NON-NLS-2$
    String typedefName = className.replaceAll("<.*>", "<>");
    TypedefInfo typedef = getHoverInfo().typedefs.get(typedefName);
    if (typedef != null) {
        // Reset class name to typedef transformation
        className = typedef.getTransformedType(className);
    }
    int index = className.indexOf('<');
    // Check if it is a template reference.
    if (index != -1) {
        resolveTemplateTypes(className, templateTypes, index);
        // It is.  We want to see if there are partial specific templates
        // and we choose the first match.  If nothing matches our particular
        // case, we fall back on the initial generic template.
        ClassInfo info = getHoverInfo().classes.get(className.substring(0, index));
        if (info != null) {
            ArrayList<ClassInfo> children = info.getChildren();
            if (children != null && children.size() > 0) {
                for (int x = 0; x < children.size(); ++x) {
                    ClassInfo child = children.get(x);
                    if (className.matches(child.getClassName())) {
                        info = child;
                        break;
                    }
                }
            }
        }
        return info;
    }
    // Otherwise no template, just fetch the class info directly.
    return getHoverInfo().classes.get(className);
}
Also used : TypedefInfo(org.eclipse.linuxtools.cdt.libhover.TypedefInfo) ClassInfo(org.eclipse.linuxtools.cdt.libhover.ClassInfo)

Example 4 with ClassInfo

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

the class DoxygenCPPInfo method buildDoxygenCPPInfo.

private void buildDoxygenCPPInfo(String fileName) {
    try {
        // Create a hash table of all the class nodes mapped by class name.  Trim any template info
        // for the class name key value.
        // $NON-NLS-1$
        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");
            // $NON-NLS-1$
            Node prot = attrs.getNamedItem("prot");
            // We are only interested in cataloging public classes.
            if (// $NON-NLS-1$
            id != null && prot != null && prot.getNodeValue().equals("public") && kind != null && kind.getNodeValue().equals("class")) {
                // $NON-NLS-1$
                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")) {
                        // $NON-NLS-1$
                        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 = cppInfo.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
                                cppInfo.classes.put(hashName, d);
                        }
                    } else if (name2.equals("templateparamlist")) {
                        // $NON-NLS-1$
                        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")) {
                                // $NON-NLS-1$
                                NodeList types = n3.getChildNodes();
                                int typesLength = types.getLength();
                                for (int j3 = 0; j3 < typesLength; ++j3) {
                                    Node n4 = types.item(j3);
                                    if (n4.getNodeName().equals("declname")) {
                                        // $NON-NLS-1$
                                        templates.add(getElementText(n4));
                                    }
                                }
                            }
                        }
                        String[] templateNames = new String[templates.size()];
                        d.setTemplateParms(templates.toArray(templateNames));
                    } else if (name2.equals("includes")) {
                        // $NON-NLS-1$
                        String include = getElementText(n2);
                        if (d != null)
                            d.setInclude(include);
                    } else if (name2.equals("basecompoundref")) {
                        // $NON-NLS-1$
                        // 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) {
                            // $NON-NLS-1$
                            Node refid = m.getNamedItem("refid");
                            // $NON-NLS-1$
                            Node prot2 = m.getNamedItem("prot");
                            if (prot2 != null && prot2.getNodeValue().equals("public")) {
                                // $NON-NLS-1$
                                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(baseClassName);
                                }
                                if (d != null && baseClass != null)
                                    d.addBaseClass(baseClass);
                            }
                        }
                    } else if (name2.equals("sectiondef")) {
                        // $NON-NLS-1$
                        // 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 && kind2.getNodeValue().equals("public-func")) {
                                // $NON-NLS-1$
                                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 (n3.getNodeName().equals("memberdef")) {
                                        // $NON-NLS-1$
                                        NamedNodeMap m3 = n3.getAttributes();
                                        if (m3 != null) {
                                            // $NON-NLS-1$
                                            Node m3Kind = m3.getNamedItem("kind");
                                            if (m3Kind != null && m3Kind.getNodeValue().equals("function")) {
                                                // $NON-NLS-1$
                                                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 (n4Name.equals("type")) {
                                                        // $NON-NLS-1$
                                                        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 (n5.getNodeName().equals("ref")) {
                                                                // $NON-NLS-1$
                                                                NamedNodeMap n5m = n5.getAttributes();
                                                                // $NON-NLS-1$
                                                                Node n5id = n5m.getNamedItem("refid");
                                                                if (n5id != null) {
                                                                    String refid = n5id.getNodeValue();
                                                                    ClassInfo refClass = classesById.get(refid);
                                                                    if (refClass != null)
                                                                        type += refClass.getClassName();
                                                                }
                                                            }
                                                        }
                                                    } else if (n4Name.equals("name")) {
                                                        // $NON-NLS-1$
                                                        name = n4.getTextContent();
                                                    } else if (n4Name.equals("argsstring")) {
                                                        // $NON-NLS-1$
                                                        args = getElementText(n4);
                                                    } else if (n4Name.equals("param")) {
                                                        // $NON-NLS-1$
                                                        NodeList nl5 = n4.getChildNodes();
                                                        for (int x = 0; x < nl5.getLength(); ++x) {
                                                            Node n5 = nl5.item(x);
                                                            if (n5.getNodeName().equals("type")) {
                                                                // $NON-NLS-1$
                                                                parms.add(getElementText(n5));
                                                            }
                                                        }
                                                    } else if (n4Name.equals("briefdescription")) {
                                                        // $NON-NLS-1$
                                                        NodeList nl5 = n4.getChildNodes();
                                                        for (int x = 0; x < nl5.getLength(); ++x) {
                                                            Node n5 = nl5.item(x);
                                                            if (n5.getNodeName().equals("para")) {
                                                                // $NON-NLS-1$
                                                                if (desc == null) {
                                                                    // $NON-NLS-1$
                                                                    desc = "";
                                                                }
                                                                // $NON-NLS-1$ //$NON-NLS-2$
                                                                desc += "<p>" + getElementText(n5) + "</p>";
                                                            }
                                                        }
                                                    } else if (n4Name.equals("detaileddescription")) {
                                                        // $NON-NLS-1$
                                                        NodeList nl5 = n4.getChildNodes();
                                                        for (int x = 0; x < nl5.getLength(); ++x) {
                                                            Node n5 = nl5.item(x);
                                                            if (n5.getNodeName().equals("para")) {
                                                                // $NON-NLS-1$
                                                                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 (n6.getNodeName().equals("parameterlist")) {
                                                                            // $NON-NLS-1$
                                                                            desc += getParameters(n6);
                                                                        } else if (n6.getNodeName().equals("simplesect")) {
                                                                            // $NON-NLS-1$
                                                                            desc += getReturn(n6);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    } else if (n4Name.equals("location")) {
                                                        // 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.
        // $NON-NLS-1$
        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");
                // $NON-NLS-1$
                Node prot = attrs.getNamedItem("prot");
                if (// $NON-NLS-1$
                kind != null && kind.getNodeValue().equals("typedef") && prot != null && prot.getNodeValue().equals("public")) {
                    // $NON-NLS-1$
                    NodeList list = n.getChildNodes();
                    for (int x = 0; x < list.getLength(); ++x) {
                        Node n2 = list.item(x);
                        if (n2.getNodeName().equals("definition")) {
                            // $NON-NLS-1$
                            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);
                                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 = cppInfo.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 = cppInfo.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
                                        cppInfo.typedefs.put(hashName, d);
                                    break;
                                } else {
                                    // Otherwise we have a non-template typedef name.  Just add it to the list.
                                    cppInfo.typedefs.put(hashName, d);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        // Now, output the LibHoverInfo for caching later
        try (FileOutputStream f = new FileOutputStream(fileName);
            ObjectOutputStream out = new ObjectOutputStream(f)) {
            out.writeObject(cppInfo);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
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) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) MemberInfo(org.eclipse.linuxtools.cdt.libhover.MemberInfo) FileOutputStream(java.io.FileOutputStream) ClassInfo(org.eclipse.linuxtools.cdt.libhover.ClassInfo)

Example 5 with ClassInfo

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

the class LibHover method getMemberSummary.

private IFunctionSummary getMemberSummary(LibHoverLibrary l, String className, String memberName, ICPPFunctionType methodType) {
    ArrayList<String> templateTypes = new ArrayList<>();
    ClassInfo info = l.getClassInfo(className, templateTypes);
    String[] args = new String[0];
    @SuppressWarnings("unused") IType returnType = null;
    if (info == null) {
        return null;
    }
    if (methodType != null) {
        try {
            args = resolveArgs(info, methodType.getParameterTypes(), templateTypes);
            returnType = methodType.getReturnType();
        } catch (Exception e) {
            return null;
        }
    }
    MemberInfo member = info.getMember(memberName);
    if (member != null) {
        MemberInfo m = null;
        if (!isParmMatch(member, args, templateTypes, info)) {
            ArrayList<MemberInfo> members = member.getChildren();
            for (int i = 0; i < members.size(); ++i) {
                MemberInfo k = members.get(i);
                if (isParmMatch(k, args, templateTypes, info)) {
                    m = k;
                    break;
                }
            }
        } else {
            m = member;
        }
        if (m != null) {
            // FIXME: do some work to determine parameters and return type.
            FunctionSummary f = new FunctionSummary();
            f.ReturnType = m.getReturnType();
            f.Prototype = m.getPrototype();
            f.Summary = m.getDescription();
            // $NON-NLS-1$
            f.Name = className + "::" + memberName;
            String[] templateParms = info.getTemplateParms();
            for (int i = 0; i < templateTypes.size(); ++i) {
                f.ReturnType = f.ReturnType.replaceAll(templateParms[i], templateTypes.get(i));
                f.Prototype = f.Prototype.replaceAll(templateParms[i], templateTypes.get(i));
                f.Name = f.Name.replaceAll(templateParms[i], templateTypes.get(i));
            }
            if (f.ReturnType.indexOf('<') >= 0) {
                // $NON-NLS-1$ //$NON-NLS-2$
                f.ReturnType = f.ReturnType.replaceAll("<", "&lt;");
                // $NON-NLS-1$//$NON-NLS-2$
                f.ReturnType = f.ReturnType.replaceAll(">", "&gt;");
            }
            if (f.Prototype.indexOf('<') >= 0) {
                // $NON-NLS-1$ //$NON-NLS-2$
                f.Prototype = f.Prototype.replaceAll("<", "&lt;");
                // $NON-NLS-1$//$NON-NLS-2$
                f.Prototype = f.Prototype.replaceAll(">", "&gt;");
            }
            if (f.Name.indexOf('<') >= 0) {
                // $NON-NLS-1$//$NON-NLS-2$
                f.Name = f.Name.replaceAll("<", "&lt;");
                // $NON-NLS-1$ //$NON-NLS-2$
                f.Name = f.Name.replaceAll(">", "&gt;");
            }
            f.setPrototypeHasBrackets(true);
            f.setIncludeName(info.getInclude());
            return f;
        }
    }
    return null;
}
Also used : MemberInfo(org.eclipse.linuxtools.cdt.libhover.MemberInfo) IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) DOMException(org.eclipse.cdt.core.dom.ast.DOMException) ClassInfo(org.eclipse.linuxtools.cdt.libhover.ClassInfo) IType(org.eclipse.cdt.core.dom.ast.IType)

Aggregations

ClassInfo (org.eclipse.linuxtools.cdt.libhover.ClassInfo)6 TypedefInfo (org.eclipse.linuxtools.cdt.libhover.TypedefInfo)5 ArrayList (java.util.ArrayList)3 MemberInfo (org.eclipse.linuxtools.cdt.libhover.MemberInfo)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 DOMException (org.eclipse.cdt.core.dom.ast.DOMException)1 IType (org.eclipse.cdt.core.dom.ast.IType)1 IFunctionSummary (org.eclipse.cdt.ui.IFunctionSummary)1 CoreException (org.eclipse.core.runtime.CoreException)1 FunctionInfo (org.eclipse.linuxtools.cdt.libhover.FunctionInfo)1 LibHoverInfo (org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)1