use of org.eclipse.cdt.ui.text.IHoverHelpInvocationContext 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;
}
Aggregations