Search in sources :

Example 1 with ICPPClassType

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

the class LibHover method getFunctionInfo.

@Override
public IFunctionSummary getFunctionInfo(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) {
    IFunctionSummary f;
    f = null;
    ITranslationUnit t = context.getTranslationUnit();
    String className = null;
    ICPPFunctionType methodType = null;
    if (t.isCXXLanguage()) {
        try {
            if (context instanceof IHoverHelpInvocationContext) {
                // We know the file offset of the member reference.
                IRegion region = ((IHoverHelpInvocationContext) context).getHoverRegion();
                // Now, let's find the declaration of the method.  We need to do this because we want the specific
                // member prototype to go searching for.  There could be many members called "x" which have different
                // documentation.
                final IASTName[] result = { null };
                EnclosingASTNameJob job = new EnclosingASTNameJob(t, region.getOffset(), region.getLength());
                job.schedule();
                try {
                    job.join();
                } catch (InterruptedException e) {
                    // just return
                    return null;
                }
                if (job.getResult() == Status.OK_STATUS) {
                    result[0] = job.getASTName();
                }
                if (result[0] != null) {
                    final IBinding binding = result[0].getBinding();
                    // Check to see we have a member function.
                    if (binding instanceof ICPPFunction) {
                        methodType = ((ICPPFunction) binding).getType();
                        // We have a member function, find the class name.
                        IBinding owner = ((ICPPFunction) binding).getOwner();
                        if (owner instanceof ICPPClassType) {
                            className = getClassName((ICPPClassType) owner);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    // Loop through all the documents we have and report first match.
    for (int i = 0; i < helpBooks.length; ++i) {
        LibHoverLibrary l = libraries.get(helpBooks[i]);
        if (name != null) {
            if (className != null) {
                if (l.isCPP()) {
                    f = getMemberSummary(l, className, name, methodType);
                }
            } else {
                f = getFunctionSummary(l, name);
            }
            if (f != null) {
                return f;
            }
        }
    }
    return null;
}
Also used : IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) IBinding(org.eclipse.cdt.core.dom.ast.IBinding) IRegion(org.eclipse.jface.text.IRegion) CoreException(org.eclipse.core.runtime.CoreException) DOMException(org.eclipse.cdt.core.dom.ast.DOMException) IHoverHelpInvocationContext(org.eclipse.cdt.ui.text.IHoverHelpInvocationContext) ICPPFunction(org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) ICPPFunctionType(org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType) ICPPClassType(org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType) ITranslationUnit(org.eclipse.cdt.core.model.ITranslationUnit)

Example 2 with ICPPClassType

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

Aggregations

DOMException (org.eclipse.cdt.core.dom.ast.DOMException)2 ICPPClassType (org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType)2 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)1 IBinding (org.eclipse.cdt.core.dom.ast.IBinding)1 IType (org.eclipse.cdt.core.dom.ast.IType)1 ICPPFunction (org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction)1 ICPPFunctionType (org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType)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 ITranslationUnit (org.eclipse.cdt.core.model.ITranslationUnit)1 IFunctionSummary (org.eclipse.cdt.ui.IFunctionSummary)1 IHoverHelpInvocationContext (org.eclipse.cdt.ui.text.IHoverHelpInvocationContext)1 CoreException (org.eclipse.core.runtime.CoreException)1 IRegion (org.eclipse.jface.text.IRegion)1