Search in sources :

Example 1 with ICProject

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

the class PerfDoubleClickAction method run.

@Override
public void run() {
    IStructuredSelection selection = viewer.getStructuredSelection();
    Object obj = selection.getFirstElement();
    try {
        if (obj instanceof PMLineRef) {
            // Open in editor
            PMLineRef line = (PMLineRef) obj;
            PMFile file = (PMFile) ((PMSymbol) line.getParent()).getParent();
            ProfileUIUtils.openEditorAndSelect(file.getPath(), Integer.parseInt(line.getName()), PerfPlugin.getDefault().getProfiledProject());
        } else if (obj instanceof PMFile) {
            PMFile file = (PMFile) obj;
            ProfileUIUtils.openEditorAndSelect(file.getName(), 1);
        } else if (obj instanceof PMSymbol) {
            PMSymbol sym = (PMSymbol) obj;
            PMFile file = (PMFile) sym.getParent();
            PMDso dso = (PMDso) file.getParent();
            if (file.getName().equals(PerfPlugin.STRINGS_UnfiledSymbols))
                // Don't try to do anything if we don't know where or what the symbol is.
                return;
            String binaryPath = dso.getPath();
            ICProject project;
            project = ProfileUIUtils.findCProjectWithAbsolutePath(binaryPath);
            Map<String, int[]> map = ProfileUIUtils.findFunctionsInProject(project, sym.getFunctionName(), -1, file.getPath(), true);
            boolean bFound = false;
            for (Map.Entry<String, int[]> entry : map.entrySet()) {
                ProfileUIUtils.openEditorAndSelect(entry.getKey(), entry.getValue()[0], entry.getValue()[1]);
                bFound = true;
            }
            if (!bFound) {
                ProfileUIUtils.openEditorAndSelect(file.getPath(), 1, ResourcesPlugin.getWorkspace().getRoot().getProject(dso.getName()));
            }
        }
    // if we encounter an exception, act as though no corresponding source exists
    } catch (NumberFormatException | BadLocationException | CoreException e) {
    }
}
Also used : PMLineRef(org.eclipse.linuxtools.internal.perf.model.PMLineRef) ICProject(org.eclipse.cdt.core.model.ICProject) PMDso(org.eclipse.linuxtools.internal.perf.model.PMDso) PMSymbol(org.eclipse.linuxtools.internal.perf.model.PMSymbol) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CoreException(org.eclipse.core.runtime.CoreException) PMFile(org.eclipse.linuxtools.internal.perf.model.PMFile) Map(java.util.Map) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with ICProject

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

the class STLink2SourceSupport method getFileForPathImpl.

private static IFile getFileForPathImpl(IPath path, IProject project) {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    if (path.isAbsolute()) {
        return root.getFileForLocation(path);
    }
    if (project != null && project.exists()) {
        ICProject cproject = CoreModel.getDefault().create(project);
        if (cproject != null) {
            try {
                ISourceRoot[] roots = cproject.getAllSourceRoots();
                for (ISourceRoot sourceRoot : roots) {
                    IContainer r = sourceRoot.getResource();
                    IResource res = r.findMember(path);
                    if (res != null && res.exists() && res instanceof IFile) {
                        return (IFile) res;
                    }
                }
                IOutputEntry[] entries = cproject.getOutputEntries();
                for (IOutputEntry pathEntry : entries) {
                    IPath p = pathEntry.getPath();
                    IResource r = root.findMember(p);
                    if (r instanceof IContainer) {
                        IContainer parent = (IContainer) r;
                        IResource res = parent.findMember(path);
                        if (res != null && res.exists() && res instanceof IFile) {
                            return (IFile) res;
                        }
                    }
                }
            } catch (CModelException e) {
                Activator.getDefault().getLog().log(e.getStatus());
            }
        }
    }
    // no match found...try and see if we are dealing with a link
    IPath realPath = project.getLocation().append(path).makeAbsolute();
    URI realURI = URIUtil.toURI(realPath.toString());
    try {
        FindLinkedResourceVisitor visitor = new STLink2SourceSupport.FindLinkedResourceVisitor(realURI);
        project.accept(visitor, IResource.DEPTH_INFINITE);
        // If we find a match, make note of the target and the real C project.
        if (visitor.foundElement()) {
            return (IFile) visitor.getResource();
        }
    } catch (CoreException e) {
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) IPath(org.eclipse.core.runtime.IPath) CModelException(org.eclipse.cdt.core.model.CModelException) URI(java.net.URI) ISourceRoot(org.eclipse.cdt.core.model.ISourceRoot) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IOutputEntry(org.eclipse.cdt.core.model.IOutputEntry) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 3 with ICProject

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

the class CProjectHelper method createCProject2.

/**
 * Creates a ICProject.
 */
private static ICProject createCProject2(final String projectName, String binFolderName) throws CoreException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final ICProject[] newProject = new ICProject[1];
    ws.run((IWorkspaceRunnable) monitor -> {
        IWorkspaceRoot root = ws.getRoot();
        IProject project = root.getProject(projectName);
        if (!project.exists()) {
            project.create(null);
        } else {
            project.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
        if (!project.isOpen()) {
            project.open(null);
        }
        if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
            String projectId = PLUGIN_ID + ".TestProject";
            addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
            CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
        }
        addDefaultBinaryParser(project);
        newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
    }, null);
    return newProject[0];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) Assert.fail(org.junit.Assert.fail) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject)

Example 4 with ICProject

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

the class AbstractTest method createProject.

protected ICProject createProject(Bundle bundle, String projname) throws CoreException, URISyntaxException, IOException, InvocationTargetException, InterruptedException {
    // Turn off auto-building
    IWorkspace wsp = ResourcesPlugin.getWorkspace();
    IWorkspaceDescription desc = wsp.getDescription();
    desc.setAutoBuilding(false);
    wsp.setDescription(desc);
    ICProject proj = CProjectHelper.createCProject(projname, BIN_DIR);
    URL location = FileLocator.find(bundle, new Path("resources/" + projname), // $NON-NLS-1$
    null);
    File testDir = new File(FileLocator.toFileURL(location).toURI());
    IProject project = proj.getProject();
    // Add these natures before project is imported due to #273079
    ManagedCProjectNature.addManagedNature(project, null);
    ScannerConfigNature.addScannerConfigNature(project);
    ImportOperation op = new ImportOperation(project.getFullPath(), testDir, FileSystemStructureProvider.INSTANCE, pathString -> IOverwriteQuery.ALL);
    op.setCreateContainerStructure(false);
    op.run(null);
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        throw new CoreException(status);
    }
    // Index the project
    IIndexManager indexManager = CCorePlugin.getIndexManager();
    indexManager.reindex(proj);
    indexManager.joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
    // These natures must be enabled at this point to continue
    assertTrue(project.isNatureEnabled(ScannerConfigNature.NATURE_ID));
    assertTrue(project.isNatureEnabled(ManagedCProjectNature.MNG_NATURE_ID));
    return proj;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) File(java.io.File) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject)

Example 5 with ICProject

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

the class CProjectHelper method createCCProject.

public static ICProject createCCProject(final String projectName, final String binFolderName, final String indexerID) throws CoreException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final ICProject[] newProject = new ICProject[1];
    ws.run((IWorkspaceRunnable) monitor -> {
        ICProject cproject = createCProject(projectName, binFolderName, indexerID);
        if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
            addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
        }
        newProject[0] = cproject;
    }, null);
    return newProject[0];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) IndexerPreferences(org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

ICProject (org.eclipse.cdt.core.model.ICProject)18 CoreException (org.eclipse.core.runtime.CoreException)14 IProject (org.eclipse.core.resources.IProject)10 IResource (org.eclipse.core.resources.IResource)10 IBinary (org.eclipse.cdt.core.model.IBinary)7 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)6 IPath (org.eclipse.core.runtime.IPath)6 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)5 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)5 IFile (org.eclipse.core.resources.IFile)5 IWorkspace (org.eclipse.core.resources.IWorkspace)5 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 CCProjectNature (org.eclipse.cdt.core.CCProjectNature)4 CProjectNature (org.eclipse.cdt.core.CProjectNature)4 CModelException (org.eclipse.cdt.core.model.CModelException)4 ICConfigExtensionReference (org.eclipse.cdt.core.settings.model.ICConfigExtensionReference)4 IProjectDescription (org.eclipse.core.resources.IProjectDescription)4 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)4 Path (org.eclipse.core.runtime.Path)4