use of org.eclipse.cdt.core.index.IIndex 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;
}
use of org.eclipse.cdt.core.index.IIndex in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class SourceFileBaseTest method assertEqualsWithAST.
private void assertEqualsWithAST(final String testSourceFileName, EnumSet<ComparisonArg> args, int astStyle) {
IIndex expectedIndex = null;
IIndex currentIndex = null;
try {
// TODO parallelize creation of index and ast
expectedIndex = CCorePlugin.getIndexManager().getIndex(getExpectedCProject(), IIndexManager.ADD_DEPENDENCIES & IIndexManager.ADD_DEPENDENT);
currentIndex = CCorePlugin.getIndexManager().getIndex(getCurrentCProject(), IIndexManager.ADD_DEPENDENCIES & IIndexManager.ADD_DEPENDENT);
expectedIndex.acquireReadLock();
currentIndex.acquireReadLock();
ITranslationUnit expectedTU = CoreModelUtil.findTranslationUnit(getExpectedIFile(testSourceFileName));
ITranslationUnit currentTU = CoreModelUtil.findTranslationUnit(getCurrentIFile(testSourceFileName));
// ASTComparison.assertEqualsAST(expectedTU.getAST(), currentTU.getAST(), args);
ASTComparison.assertEqualsAST(expectedTU.getAST(expectedIndex, astStyle), currentTU.getAST(currentIndex, astStyle), args);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (expectedIndex != null)
expectedIndex.releaseReadLock();
if (currentIndex != null)
currentIndex.releaseReadLock();
}
}
use of org.eclipse.cdt.core.index.IIndex 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.index.IIndex in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class ASTView method getAST.
private IASTTranslationUnit getAST() {
final IEditorInput editorInput = CUIPlugin.getActivePage().getActiveEditor().getEditorInput();
final IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
IIndex index;
try {
index = CCorePlugin.getIndexManager().getIndex(workingCopy.getCProject());
} catch (final CoreException e) {
throw new RuntimeException(e);
}
try {
index.acquireReadLock();
return workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS).copy(IASTNode.CopyStyle.withoutLocations);
} catch (final CoreException | InterruptedException e) {
throw new RuntimeException(e);
} finally {
index.releaseReadLock();
}
}
use of org.eclipse.cdt.core.index.IIndex in project arduino-eclipse-plugin by Sloeber.
the class Libraries method getUnresolvedProjectIncludes.
private static Set<String> getUnresolvedProjectIncludes(IProject iProject) {
Set<String> ret = new TreeSet<>();
ICProject tt = CoreModel.getDefault().create(iProject);
IIndex index = null;
try {
index = CCorePlugin.getIndexManager().getIndex(tt);
index.acquireReadLock();
try {
IIndexFile[] allFiles = index.getFilesWithUnresolvedIncludes();
for (IIndexFile curUnesolvedIncludeFile : allFiles) {
IIndexInclude[] includes = curUnesolvedIncludeFile.getIncludes();
for (IIndexInclude curinclude : includes) {
if (curinclude.isActive() && !curinclude.isResolved()) {
ret.add(new Path(curinclude.getName()).removeFileExtension().toString());
}
}
}
} finally {
index.releaseReadLock();
}
} catch (CoreException e1) {
// ignore
e1.printStackTrace();
} catch (InterruptedException e) {
// ignore
e.printStackTrace();
}
return ret;
}
Aggregations