Search in sources :

Example 1 with CModelException

use of org.eclipse.cdt.core.model.CModelException 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 2 with CModelException

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

the class OpenGCAction method getDefaultBinary.

private String getDefaultBinary(IPath file) {
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
    if (c != null) {
        IProject project = c.getProject();
        if (project != null && project.exists()) {
            IContainer folder = c.getParent();
            // $NON-NLS-1$
            IFile infoFile = folder.getFile(new Path("AnalysisInfo.txt"));
            try {
                String defaultBinaryFromUserPref = getDefaultBinaryFromUserPref(project, infoFile);
                if (defaultBinaryFromUserPref != null) {
                    return defaultBinaryFromUserPref;
                }
            } catch (IOException | CoreException ex) {
            // do nothing here.
            }
            ICProject cproject = CoreModel.getDefault().create(project);
            if (cproject != null) {
                try {
                    IBinary[] b = cproject.getBinaryContainer().getBinaries();
                    if (b != null && b.length > 0 && b[0] != null) {
                        IResource r = b[0].getResource();
                        return r.getLocation().toOSString();
                    }
                } catch (CModelException e) {
                }
            }
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) IOException(java.io.IOException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 3 with CModelException

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

the class ListTreeContentProvider method getElements.

@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof List) {
        for (Object element : (List<?>) inputElement) if (element instanceof ICContainer)
            try {
                ICElement[] array = ((ICContainer) element).getChildren();
                ArrayList<ICElement> output = new ArrayList<>();
                for (ICElement item : array) {
                    if ((item instanceof ICContainer) && checkForValidChildren((ICContainer) item)) {
                        output.add(item);
                    }
                    if (SystemTapLaunchShortcut.validElement(item)) {
                        output.add(item);
                    }
                }
                return output.toArray();
            } catch (CModelException e) {
                e.printStackTrace();
            }
    }
    return null;
}
Also used : ICContainer(org.eclipse.cdt.core.model.ICContainer) CModelException(org.eclipse.cdt.core.model.CModelException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ICElement(org.eclipse.cdt.core.model.ICElement)

Example 4 with CModelException

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

the class OpenGmonAction method getDefaultBinary.

private String getDefaultBinary(IPath file) {
    IProject project = null;
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
    if (c != null) {
        project = c.getProject();
        if (project != null && project.exists()) {
            ICProject cproject = CoreModel.getDefault().create(project);
            if (cproject != null) {
                try {
                    IBinary[] b = cproject.getBinaryContainer().getBinaries();
                    if (b != null && b.length > 0 && b[0] != null) {
                        IResource r = b[0].getResource();
                        return r.getLocation().toOSString();
                    }
                } catch (CModelException e) {
                }
            }
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 5 with CModelException

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

the class CachegrindViewPart method createPartControl.

@Override
public void createPartControl(Composite parent) {
    Composite top = new Composite(parent, SWT.NONE);
    GridLayout topLayout = new GridLayout();
    topLayout.marginHeight = topLayout.marginWidth = 0;
    top.setLayout(topLayout);
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer = new TreeViewer(top, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    labelProvider = new CachegrindLabelProvider();
    ColumnViewerToolTipSupport.enableFor(viewer);
    Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
    // $NON-NLS-1$
    column.getColumn().setText(Messages.getString("CachegrindViewPart.Location"));
    column.getColumn().setWidth(COLUMN_SIZE * 4);
    column.getColumn().setResizable(true);
    column.getColumn().addSelectionListener(getHeaderListener());
    column.setLabelProvider(labelProvider);
    contentProvider = new CachegrindTreeContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(labelProvider);
    viewer.setAutoExpandLevel(2);
    doubleClickListener = event -> {
        Object selection = ((StructuredSelection) event.getSelection()).getFirstElement();
        String path = null;
        int line = 0;
        if (selection instanceof CachegrindFile) {
            path = ((CachegrindFile) selection).getPath();
        } else if (selection instanceof CachegrindLine) {
            CachegrindLine element = (CachegrindLine) selection;
            CachegrindFile file = (CachegrindFile) element.getParent().getParent();
            path = file.getPath();
            line = element.getLine();
        } else if (selection instanceof CachegrindFunction) {
            CachegrindFunction function = (CachegrindFunction) selection;
            path = ((CachegrindFile) function.getParent()).getPath();
            if (function.getModel() instanceof ISourceReference) {
                ISourceReference model = (ISourceReference) function.getModel();
                try {
                    ISourceRange sr = model.getSourceRange();
                    if (sr != null) {
                        line = sr.getStartLine();
                    }
                } catch (CModelException e1) {
                    e1.printStackTrace();
                }
            }
        }
        if (path != null) {
            try {
                ProfileUIUtils.openEditorAndSelect(path, line, ValgrindUIPlugin.getDefault().getProfiledProject());
            } catch (BadLocationException | CoreException e2) {
                e2.printStackTrace();
            }
        }
    };
    viewer.addDoubleClickListener(doubleClickListener);
    expandAction = new ExpandAction(viewer);
    collapseAction = new CollapseAction(viewer);
    MenuManager manager = new MenuManager();
    manager.addMenuListener(manager1 -> {
        ITreeSelection selection = (ITreeSelection) viewer.getSelection();
        ICachegrindElement element = (ICachegrindElement) selection.getFirstElement();
        if (contentProvider.hasChildren(element)) {
            manager1.add(expandAction);
            manager1.add(collapseAction);
        }
    });
    manager.setRemoveAllWhenShown(true);
    Menu contextMenu = manager.createContextMenu(viewer.getTree());
    viewer.getControl().setMenu(contextMenu);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) CModelException(org.eclipse.cdt.core.model.CModelException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) Tree(org.eclipse.swt.widgets.Tree) CachegrindLine(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine) Menu(org.eclipse.swt.widgets.Menu) ISourceRange(org.eclipse.cdt.core.model.ISourceRange) ICachegrindElement(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement) Composite(org.eclipse.swt.widgets.Composite) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) CoreException(org.eclipse.core.runtime.CoreException) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) ExpandAction(org.eclipse.linuxtools.valgrind.ui.ExpandAction) ISourceReference(org.eclipse.cdt.core.model.ISourceReference) CollapseAction(org.eclipse.linuxtools.valgrind.ui.CollapseAction) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

CModelException (org.eclipse.cdt.core.model.CModelException)7 ICProject (org.eclipse.cdt.core.model.ICProject)4 IResource (org.eclipse.core.resources.IResource)4 CoreException (org.eclipse.core.runtime.CoreException)4 ArrayList (java.util.ArrayList)3 IBinary (org.eclipse.cdt.core.model.IBinary)3 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 List (java.util.List)2 ICContainer (org.eclipse.cdt.core.model.ICContainer)2 ICElement (org.eclipse.cdt.core.model.ICElement)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 Collections (java.util.Collections)1 CoreModel (org.eclipse.cdt.core.model.CoreModel)1 IOutputEntry (org.eclipse.cdt.core.model.IOutputEntry)1 ISourceRange (org.eclipse.cdt.core.model.ISourceRange)1