use of org.eclipse.cdt.core.dom.ast.IBinding 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;
}
use of org.eclipse.cdt.core.dom.ast.IBinding in project linuxtools by eclipse.
the class ProfileUIUtils method findFunctionsInProject.
/**
* Get a mapping between a file name, and the data relevant to locating
* the corresponding function name for a given project.
*
* @param project : C Project Type
* @param functionName : Name of a function
* @param numArgs : The number of arguments this function is expected to have.
* A value of -1 will ignore the number of arguments when searching.
* @param fileHint : The name of the file where we expect to find functionName.
* It is null if we do not want to use this option.
* @return Absolute paths of files and the function's corresponding node-offset and length.
* @since 3.0
*/
public static Map<String, int[]> findFunctionsInProject(ICProject project, String functionName, int numArgs, String fileHint) {
HashMap<String, int[]> files = new HashMap<>();
IIndexManager manager = CCorePlugin.getIndexManager();
IIndex index = null;
try {
index = manager.getIndex(project);
index.acquireReadLock();
IBinding[] bindings = index.findBindings(functionName.toCharArray(), IndexFilter.ALL, null);
for (IBinding bind : bindings) {
if (bind instanceof IFunction && (numArgs == -1 || ((IFunction) bind).getParameters().length == numArgs)) {
IFunction ifunction = (IFunction) bind;
IIndexName[] names = index.findNames(ifunction, IIndex.FIND_DEFINITIONS);
for (IIndexName iname : names) {
IIndexFile file = iname.getFile();
if (file != null) {
String loc = file.getLocation().getURI().getPath();
if (fileHint != null) {
if (loc.equals(new File(fileHint).getCanonicalPath())) {
// TODO: Consider changing data structure so that we can
// store multiple same-named functions (different args)
// from the same file.
files.put(loc, new int[] { iname.getNodeOffset(), iname.getNodeLength() });
}
} else {
files.put(loc, new int[] { iname.getNodeOffset(), iname.getNodeLength() });
}
}
}
}
}
} catch (CoreException | InterruptedException | IOException e) {
e.printStackTrace();
} finally {
index.releaseReadLock();
}
return files;
}
use of org.eclipse.cdt.core.dom.ast.IBinding in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class NodeWidget method displayBindings.
private void displayBindings(final IASTNode node) {
try {
if (node instanceof IASTName) {
final IBinding binding = ((IASTName) node).resolveBinding();
final TreeItem parent = createTreeItem(tree, "Bindings;");
displayBindings(parent, node, binding);
}
} catch (final Exception e) {
PastaPlugin.log(e);
}
}
Aggregations