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;
}
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 "";
}
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;
}
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 "";
}
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);
}
Aggregations