Search in sources :

Example 1 with IIndexBinding

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;
}
Also used : IIndex(org.eclipse.cdt.core.index.IIndex) IIndexBinding(org.eclipse.cdt.core.index.IIndexBinding) ICPPFunction(org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IIndexName(org.eclipse.cdt.core.index.IIndexName)

Aggregations

ICPPFunction (org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction)1 IIndex (org.eclipse.cdt.core.index.IIndex)1 IIndexBinding (org.eclipse.cdt.core.index.IIndexBinding)1 IIndexName (org.eclipse.cdt.core.index.IIndexName)1 ICProject (org.eclipse.cdt.core.model.ICProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1