Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to Get The Scope of a Node

Thanks for the help, here's the code I did up in case someone is interested
next time. I can call file directly because my class is a subclass of
CRefactoring.

BTW how can I go about getting an IASTName from IIndexName?
	
private IIndexName[] findGlobalReferences (IBinding binding) {
		IProject project = file.getProject();
		ICProject cProject =
CoreModel.getDefault().getCModel().getCProject(project.getName()); 
		IIndexManager iManager = CCorePlugin.getIndexManager(); 		
		IIndex index = null;
		
		try {
			index = iManager.getIndex(cProject);
		}
		catch (CoreException e) {
			IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
IStatus.OK, e.getMessage(), e);
			CUIPlugin.log(status);			
		}
		
		IIndexName[] globalReferences = null;
		
		if (index != null) {
			try { 
				index.acquireReadLock();
				globalReferences = index.findNames(binding, IIndex.FIND_REFERENCES);
			} catch (Exception e) {
				IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
IStatus.OK, e.getMessage(), e);
				CUIPlugin.log(status);
			} finally {
				index.releaseReadLock();
			}
		}
		return globalReferences;
	}
	
	private Vector<IIndexName> findExternalReferences (IBinding binding) {
		final Vector<IIndexName> externalReferences = new Vector<IIndexName>();	
		
		IIndexName[] globalReferences = findGlobalReferences(binding);
		
		// Weed out the references that are from this file
		try {
			for (int i = 0; i < globalReferences.length; i++) {
				String fileLocation =
globalReferences[i].getFile().getLocation().getFullPath().toString();
				
				if (!fileLocation.equalsIgnoreCase(file.getFullPath().toString())) {
					externalReferences.add(globalReferences[i]);
				}
			}
		}
		catch (CoreException e) {
			IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
IStatus.OK, e.getMessage(), e);
			CUIPlugin.log(status);				
		}
		return externalReferences;
	}




-- 
View this message in context: http://www.nabble.com/How-to-Get-The-Scope-of-a-Node-tp17261038p17276106.html
Sent from the Eclipse CDT - Development mailing list archive at Nabble.com.



Back to the top