Search in sources :

Example 1 with IType

use of org.eclipse.cdt.core.dom.ast.IType in project linuxtools by eclipse.

the class LibHover method getClassName.

// Get the class name for a type, including any instance template parameters
// e.g. std::basic_string<char>
private String getClassName(ICPPClassType c) {
    String className = null;
    try {
        String[] qualified = c.getQualifiedName();
        className = qualified[0];
        for (int k = 1; k < qualified.length; ++k) {
            // $NON-NLS-1$
            className += "::" + qualified[k];
        }
        // Check if we have an instance of a template class.
        if (c instanceof ICPPTemplateInstance) {
            ICPPTemplateInstance ti = (ICPPTemplateInstance) c;
            // Get a map which tells us the values of the template
            // arguments (e.g. _CharT maps to char in the instance).
            ICPPTemplateParameterMap tiMap = ti.getTemplateParameterMap();
            ICPPTemplateDefinition td = ti.getTemplateDefinition();
            ICPPTemplateParameter[] templateArgs = td.getTemplateParameters();
            // $NON-NLS-1$
            className += "<";
            // $NON-NLS-1$
            String separator = "";
            for (int x = 0; x < templateArgs.length; ++x) {
                ICPPTemplateParameter tp = templateArgs[x];
                ICPPTemplateArgument ta = tiMap.getArgument(tp);
                IType type = null;
                // that when we do a lookup.
                if (ta.isTypeValue()) {
                    type = ta.getTypeValue();
                } else {
                    type = ta.getTypeOfNonTypeValue();
                }
                if (tp.getTemplateNestingLevel() == 0) {
                    // get its class name including template parameters
                    if (type instanceof ICPPClassType) {
                        className += separator + getClassName((ICPPClassType) type);
                    } else {
                        className += separator + type.toString();
                    }
                    // $NON-NLS-1$
                    separator = ",";
                }
            }
            // $NON-NLS-1$
            className += ">";
        }
    } catch (DOMException e) {
        return null;
    }
    return className;
}
Also used : DOMException(org.eclipse.cdt.core.dom.ast.DOMException) ICPPTemplateArgument(org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument) ICPPTemplateInstance(org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance) ICPPTemplateDefinition(org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition) ICPPTemplateParameterMap(org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap) ICPPTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter) ICPPClassType(org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType) IType(org.eclipse.cdt.core.dom.ast.IType)

Example 2 with IType

use of org.eclipse.cdt.core.dom.ast.IType 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

DOMException (org.eclipse.cdt.core.dom.ast.DOMException)2 IType (org.eclipse.cdt.core.dom.ast.IType)2 ArrayList (java.util.ArrayList)1 ICPPClassType (org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType)1 ICPPTemplateArgument (org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument)1 ICPPTemplateDefinition (org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition)1 ICPPTemplateInstance (org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance)1 ICPPTemplateParameter (org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter)1 ICPPTemplateParameterMap (org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap)1 IFunctionSummary (org.eclipse.cdt.ui.IFunctionSummary)1 CoreException (org.eclipse.core.runtime.CoreException)1 ClassInfo (org.eclipse.linuxtools.cdt.libhover.ClassInfo)1 MemberInfo (org.eclipse.linuxtools.cdt.libhover.MemberInfo)1