use of org.eclipse.cdt.core.index.IIndexBinding in project arduino-eclipse-plugin by Sloeber.
the class IndexHelper method findParameterInFunction.
/**
* given a project look in the source code for the line of code that sets
* the password;
*
* return the password string of no_pwd_found_in_code
*
* @param iProject
* @return
*/
public static String findParameterInFunction(IProject project, String parentFunctionName, String childFunctionName, String defaultValue) {
ICProject curProject = CoreModel.getDefault().getCModel().getCProject(project.getName());
IIndex index = null;
try {
index = CCorePlugin.getIndexManager().getIndex(curProject);
index.acquireReadLock();
IIndexBinding[] bindings = index.findBindings(parentFunctionName.toCharArray(), IndexFilter.ALL_DECLARED, new NullProgressMonitor());
ICPPFunction parentFunction = null;
for (IIndexBinding curbinding : bindings) {
if (curbinding instanceof ICPPFunction) {
parentFunction = (ICPPFunction) curbinding;
}
}
if (parentFunction == null) {
// that on found binding must be a function
return defaultValue;
}
IIndexName[] names = index.findNames(parentFunction, org.eclipse.cdt.core.index.IIndex.FIND_DEFINITIONS);
return findParameterInFunction(names, childFunctionName, defaultValue);
} catch (CoreException | InterruptedException e) {
e.printStackTrace();
} finally {
if (index != null) {
index.releaseReadLock();
}
}
return defaultValue;
}
Aggregations