Search in sources :

Example 1 with ICElementVisitor

use of org.eclipse.cdt.core.model.ICElementVisitor in project linuxtools by eclipse.

the class ProfileUIUtils method findCProjectWithAbsolutePath.

/**
 * Find an ICProject that contains the specified absolute path.
 *
 * @param absPath An absolute path (usually to some file/folder in a project)
 * @return an ICProject corresponding to the project that contains the absolute path
 * @throws CoreException can be thrown if visiting (accepting) a project walking the ICElement tree fails.
 */
public static ICProject findCProjectWithAbsolutePath(final String absPath) throws CoreException {
    final String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
    final ArrayList<ICProject> ret = new ArrayList<>();
    // visitor object to check for the matching path string
    ICElementVisitor vis = element -> {
        if (element.getElementType() == ICElement.C_CCONTAINER || element.getElementType() == ICElement.C_PROJECT) {
            return true;
        } else if (absPath.equals(workspaceLoc + element.getPath().toFile().getAbsolutePath())) {
            ret.add(element.getCProject());
        }
        return false;
    };
    ICProject[] cProjects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects();
    for (ICProject proj : cProjects) {
        // visit every project
        proj.accept(vis);
    }
    // is it possible to find more than one matching project ?
    return ret.isEmpty() ? null : ret.get(0);
}
Also used : IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) CDebugCorePlugin(org.eclipse.cdt.debug.core.CDebugCorePlugin) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) DebugUITools(org.eclipse.debug.ui.DebugUITools) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IDocument(org.eclipse.jface.text.IDocument) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) IndexFilter(org.eclipse.cdt.core.index.IndexFilter) IFile(org.eclipse.core.resources.IFile) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) URI(java.net.URI) IIndexFile(org.eclipse.cdt.core.index.IIndexFile) RemoteProxyManager(org.eclipse.linuxtools.profiling.launch.RemoteProxyManager) ICProject(org.eclipse.cdt.core.model.ICProject) EFS(org.eclipse.core.filesystem.EFS) IEditorPart(org.eclipse.ui.IEditorPart) IFunction(org.eclipse.cdt.core.dom.ast.IFunction) IFileStore(org.eclipse.core.filesystem.IFileStore) IBinding(org.eclipse.cdt.core.dom.ast.IBinding) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IRegion(org.eclipse.jface.text.IRegion) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput) ICElement(org.eclipse.cdt.core.model.ICElement) ProfileUIPlugin(org.eclipse.linuxtools.internal.profiling.ui.ProfileUIPlugin) IOException(java.io.IOException) ISourceLookupResult(org.eclipse.debug.ui.sourcelookup.ISourceLookupResult) File(java.io.File) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IIndexName(org.eclipse.cdt.core.index.IIndexName) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) Path(org.eclipse.core.runtime.Path) ICElementVisitor(org.eclipse.cdt.core.model.ICElementVisitor) IIndex(org.eclipse.cdt.core.index.IIndex) URIUtil(org.eclipse.core.filesystem.URIUtil) ICElementVisitor(org.eclipse.cdt.core.model.ICElementVisitor) ICProject(org.eclipse.cdt.core.model.ICProject) ArrayList(java.util.ArrayList)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)1 IBinding (org.eclipse.cdt.core.dom.ast.IBinding)1 IFunction (org.eclipse.cdt.core.dom.ast.IFunction)1 IIndex (org.eclipse.cdt.core.index.IIndex)1 IIndexFile (org.eclipse.cdt.core.index.IIndexFile)1 IIndexManager (org.eclipse.cdt.core.index.IIndexManager)1 IIndexName (org.eclipse.cdt.core.index.IIndexName)1 IndexFilter (org.eclipse.cdt.core.index.IndexFilter)1 ICElement (org.eclipse.cdt.core.model.ICElement)1 ICElementVisitor (org.eclipse.cdt.core.model.ICElementVisitor)1 ICProject (org.eclipse.cdt.core.model.ICProject)1 CDebugCorePlugin (org.eclipse.cdt.debug.core.CDebugCorePlugin)1 EFS (org.eclipse.core.filesystem.EFS)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1