use of org.eclipse.cdt.core.model.ICContainer 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.ICContainer in project linuxtools by eclipse.
the class SystemTapLaunchShortcut method getFunctionsFromBinary.
/**
* Retrieves the names of all functions referenced by the binary. If
* searchForResource is true, this function will return all function names
* belonging to an element with name matching the String held by
* resourceToSearchFor. Otherwise it will create a dialog prompting the user
* to select from a list of files to profile, or select the only available
* file if only one file is available.
*
* @param bin
* @return
*/
protected String getFunctionsFromBinary(IBinary bin, String targetResource) {
// $NON-NLS-1$
String funcs = "";
if (bin == null) {
return funcs;
}
try {
ArrayList<ICContainer> list = new ArrayList<>();
TranslationUnitVisitor v = new TranslationUnitVisitor();
for (ICElement b : bin.getCProject().getChildrenOfType(ICElement.C_CCONTAINER)) {
ICContainer c = (ICContainer) b;
for (ITranslationUnit tu : c.getTranslationUnits()) {
if (searchForResource && tu.getElementName().contains(targetResource)) {
tu.accept(v);
funcs += v.getFunctions();
return funcs;
} else {
if (!list.contains(c)) {
list.add(c);
}
}
}
// Iterate down to all children, checking for more C_Containers
while (c.getChildrenOfType(ICElement.C_CCONTAINER).size() > 0) {
ICContainer e = null;
for (ICElement d : c.getChildrenOfType(ICElement.C_CCONTAINER)) {
e = (ICContainer) d;
for (ITranslationUnit tu : e.getTranslationUnits()) {
if (searchForResource && tu.getElementName().contains(targetResource)) {
tu.accept(v);
funcs += (v.getFunctions());
return funcs;
} else {
if (!list.contains(c)) {
list.add(c);
}
}
}
}
c = e;
}
}
int numberOfFiles = numberOfValidFiles(list.toArray());
if (numberOfFiles == 1) {
for (ICContainer c : list) {
for (ITranslationUnit e : c.getTranslationUnits()) {
if (validElement(e)) {
e.accept(v);
funcs += v.getFunctions();
}
}
}
} else {
Object[] unitList = chooseUnit(list, numberOfFiles);
if (unitList == null || unitList.length == 0) {
return null;
} else if (unitList.length == 1 && unitList[0].toString().equals(USER_SELECTED_ALL)) {
// $NON-NLS-1$
funcs = "*";
return funcs;
}
StringBuilder tmpFunc = new StringBuilder();
for (String item : getAllFunctions(bin.getCProject(), unitList)) {
tmpFunc.append(item);
// $NON-NLS-1$
tmpFunc.append(" ");
}
funcs = tmpFunc.toString();
}
return funcs;
} catch (CoreException e) {
e.printStackTrace();
}
return null;
}
use of org.eclipse.cdt.core.model.ICContainer in project linuxtools by eclipse.
the class SystemTapLaunchShortcut method chooseUnit.
/**
* Creates a dialog that prompts the user to select from the given list of
* ICElements
*
* @param list
* : list of ICElements
* @return
*/
private Object[] chooseUnit(List<ICContainer> list, int numberOfValidFiles) {
ListTreeContentProvider prov = new ListTreeContentProvider();
RuledTreeSelectionDialog dialog = new RuledTreeSelectionDialog(getActiveWorkbenchShell(), new WorkbenchLabelProvider(), prov);
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapLaunchShortcut.SelectFiles"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapLaunchShortcut.SelectFilesMsg"));
dialog.setInput(list);
dialog.setHelpAvailable(false);
dialog.setStatusLineAboveButtons(false);
dialog.setEmptyListMessage(Messages.getString(// $NON-NLS-1$
"SystemTapLaunchShortcut.NoFiles"));
dialog.setContainerMode(true);
Object[] topLevel = prov.findElements(list);
dialog.setInitialSelections(topLevel);
dialog.setSize(cap(topLevel.length * 10, 30, 55), cap((int) (topLevel.length * 1.5), 3, 13));
dialog.create();
Button okButton = dialog.getOkButton();
Object[] result = null;
if (testMode) {
okButton.setSelection(true);
result = list.toArray();
ArrayList<Object> output = new ArrayList<>();
try {
for (Object obj : result) {
if (obj instanceof ICContainer) {
ICElement[] array = ((ICContainer) obj).getChildren();
for (ICElement c : array) {
if (!(validElement(c))) {
continue;
}
if (c.getElementName().contains(MAIN_FUNC_NAME) && !output.contains(c)) {
output.add(c);
}
}
}
}
if (output.size() >= numberOfValidFiles) {
output.clear();
output.add(USER_SELECTED_ALL);
}
} catch (CModelException e) {
e.printStackTrace();
}
result = output.toArray();
} else {
if (dialog.open() == Window.CANCEL) {
return null;
}
result = dialog.getResult();
}
if (result == null) {
return null;
}
ArrayList<Object> output = new ArrayList<>();
try {
for (Object obj : result) {
if (obj instanceof ICContainer) {
ICElement[] array = ((ICContainer) obj).getChildren();
for (ICElement c : array) {
if (!(validElement(c))) {
continue;
}
if (!output.contains(c)) {
output.add(c);
}
}
} else if ((obj instanceof ICElement) && validElement((ICElement) obj) && !output.contains(obj)) {
output.add(obj);
}
}
if (output.size() >= numberOfValidFiles) {
output.clear();
output.add(USER_SELECTED_ALL);
}
} catch (CModelException e) {
e.printStackTrace();
}
return output.toArray();
}
Aggregations