@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; }
@Override public boolean hasChildren(Object element) { if (element instanceof ICContainer) { try { if (((ICContainer) element).getChildren().length > 0) return true; } catch (CModelException e) { e.printStackTrace(); } } return false; }
/** * A container is valid if any of its children are valid c/cpp elements or if it contains another * container for which the above holds * * @param cont * @return */ private boolean checkForValidChildren(ICContainer cont) { try { for (ICElement child : cont.getChildren()) { if ((child != null) && SystemTapLaunchShortcut.validElement(child)) return true; if ((child instanceof ICContainer) && checkForValidChildren((ICContainer) child)) { return true; } } } catch (CModelException e) { e.printStackTrace(); } return false; }
private IFile getFileForPathImpl(IPath path, IProject project) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (path.isAbsolute()) { IFile c = root.getFileForLocation(path); return c; } if (project != null && project.exists()) { ICProject cproject = CoreModel.getDefault().create(project); if (cproject != null) { try { ISourceRoot[] roots = cproject.getAllSourceRoots(); for (ISourceRoot sourceRoot : roots) { IResource r = sourceRoot.getResource(); if (r instanceof IContainer) { IContainer parent = (IContainer) r; IResource res = parent.findMember(path); if (res != null && res.exists() && res instanceof IFile) { IFile file = (IFile) res; return file; } } } 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) { IFile file = (IFile) res; return file; } } } } catch (CModelException _) { Activator.getDefault().getLog().log(_.getStatus()); } } } return null; }
@Override public Object[] getChildren(Object parentElement) { ArrayList<Object> output = new ArrayList<>(); if (parentElement instanceof ICContainer) { try { Object[] list = ((ICContainer) parentElement).getChildren(); for (Object item : list) { if (item instanceof ICContainer) { if (checkForValidChildren((ICContainer) item)) output.add(item); } else if (item instanceof ICElement) { ICElement el = (ICElement) item; if (SystemTapLaunchShortcut.validElement(el)) output.add(el); } } return output.toArray(); } catch (CModelException e) { e.printStackTrace(); } } return null; }