Search in sources :

Example 1 with IFunctionSummary

use of org.eclipse.cdt.ui.IFunctionSummary in project linuxtools by eclipse.

the class LibHover method getFunctionSummary.

private IFunctionSummary getFunctionSummary(LibHoverLibrary l, String name) {
    FunctionInfo x = l.getFunctionInfo(name);
    if (x != null) {
        FunctionSummary f = new FunctionSummary();
        f.ReturnType = x.getReturnType();
        f.Prototype = x.getPrototype();
        f.Summary = x.getDescription();
        f.Name = x.getName();
        ArrayList<String> headers = x.getHeaders();
        for (int i = 0; i < headers.size(); ++i) {
            f.setIncludeName(headers.get(i));
        }
        return f;
    }
    return null;
}
Also used : IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo)

Example 2 with IFunctionSummary

use of org.eclipse.cdt.ui.IFunctionSummary 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 3 with IFunctionSummary

use of org.eclipse.cdt.ui.IFunctionSummary in project linuxtools by eclipse.

the class LibHover method getMatchingFunctions.

@Override
public IFunctionSummary[] getMatchingFunctions(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String prefix) {
    ArrayList<IFunctionSummary> fList = new ArrayList<>();
    ITranslationUnit t = context.getTranslationUnit();
    boolean qualifiedCPP = false;
    if (t.isCXXLanguage()) {
        try {
            if (context instanceof IContentAssistHelpInvocationContext) {
                // We know the file offset of the member reference.
                IASTCompletionNode node = ((IContentAssistHelpInvocationContext) context).getCompletionNode();
                IASTName[] names = node.getNames();
                for (IASTName name : names) {
                    if (name.isQualified()) {
                        qualifiedCPP = true;
                        break;
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    if (!qualifiedCPP) {
        for (int di = 0; di < helpBooks.length; ++di) {
            LibHoverLibrary l = libraries.get(helpBooks[di]);
            LibHoverInfo cppInfo = l.getHoverInfo();
            SortedMap<String, FunctionInfo> map = cppInfo.functions.tailMap(prefix);
            Set<Map.Entry<String, FunctionInfo>> c = map.entrySet();
            for (Iterator<Entry<String, FunctionInfo>> i = c.iterator(); i.hasNext(); ) {
                Map.Entry<String, FunctionInfo> e = i.next();
                FunctionInfo x = e.getValue();
                String name = x.getName();
                // never be offered as a choice for an empty prefix.
                if (name.startsWith(prefix) && !name.startsWith("0")) {
                    // $NON-NLS-1$
                    FunctionSummary f = new FunctionSummary();
                    f.ReturnType = x.getReturnType();
                    f.Prototype = x.getPrototype();
                    f.Summary = x.getDescription();
                    f.Name = x.getName();
                    ArrayList<String> headers = x.getHeaders();
                    for (int i1 = 0; i1 < headers.size(); ++i1) {
                        f.setIncludeName(headers.get(i1));
                    }
                    fList.add(f);
                }
            }
        }
    }
    IFunctionSummary[] summaries = new IFunctionSummary[fList.size()];
    for (int k = 0; k < summaries.length; k++) {
        summaries[k] = fList.get(k);
    }
    return summaries;
}
Also used : IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) IFunctionSummary(org.eclipse.cdt.ui.IFunctionSummary) ArrayList(java.util.ArrayList) IContentAssistHelpInvocationContext(org.eclipse.cdt.ui.text.IContentAssistHelpInvocationContext) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) Entry(java.util.Map.Entry) ITranslationUnit(org.eclipse.cdt.core.model.ITranslationUnit) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) CoreException(org.eclipse.core.runtime.CoreException) DOMException(org.eclipse.cdt.core.dom.ast.DOMException) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IASTCompletionNode(org.eclipse.cdt.core.dom.ast.IASTCompletionNode) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) ICPPTemplateParameterMap(org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap)

Example 4 with IFunctionSummary

use of org.eclipse.cdt.ui.IFunctionSummary 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

IFunctionSummary (org.eclipse.cdt.ui.IFunctionSummary)4 DOMException (org.eclipse.cdt.core.dom.ast.DOMException)3 CoreException (org.eclipse.core.runtime.CoreException)3 ArrayList (java.util.ArrayList)2 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)2 ITranslationUnit (org.eclipse.cdt.core.model.ITranslationUnit)2 FunctionInfo (org.eclipse.linuxtools.cdt.libhover.FunctionInfo)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 SortedMap (java.util.SortedMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IASTCompletionNode (org.eclipse.cdt.core.dom.ast.IASTCompletionNode)1 IBinding (org.eclipse.cdt.core.dom.ast.IBinding)1 IType (org.eclipse.cdt.core.dom.ast.IType)1 ICPPClassType (org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType)1 ICPPFunction (org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction)1 ICPPFunctionType (org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType)1 ICPPTemplateParameterMap (org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap)1 IContentAssistHelpInvocationContext (org.eclipse.cdt.ui.text.IContentAssistHelpInvocationContext)1