use of org.eclipse.cdt.core.model.ITranslationUnit in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class SourceFileBaseTest method assertEqualsWithAST.
private void assertEqualsWithAST(final String testSourceFileName, EnumSet<ComparisonArg> args, int astStyle) {
IIndex expectedIndex = null;
IIndex currentIndex = null;
try {
// TODO parallelize creation of index and ast
expectedIndex = CCorePlugin.getIndexManager().getIndex(getExpectedCProject(), IIndexManager.ADD_DEPENDENCIES & IIndexManager.ADD_DEPENDENT);
currentIndex = CCorePlugin.getIndexManager().getIndex(getCurrentCProject(), IIndexManager.ADD_DEPENDENCIES & IIndexManager.ADD_DEPENDENT);
expectedIndex.acquireReadLock();
currentIndex.acquireReadLock();
ITranslationUnit expectedTU = CoreModelUtil.findTranslationUnit(getExpectedIFile(testSourceFileName));
ITranslationUnit currentTU = CoreModelUtil.findTranslationUnit(getCurrentIFile(testSourceFileName));
// ASTComparison.assertEqualsAST(expectedTU.getAST(), currentTU.getAST(), args);
ASTComparison.assertEqualsAST(expectedTU.getAST(expectedIndex, astStyle), currentTU.getAST(currentIndex, astStyle), args);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (expectedIndex != null)
expectedIndex.releaseReadLock();
if (currentIndex != null)
currentIndex.releaseReadLock();
}
}
use of org.eclipse.cdt.core.model.ITranslationUnit in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class TestProjectHolder method formatFileAsync.
@Override
public ProjectHolderJob formatFileAsync(IPath path) {
return ProjectHolderJob.create("Formatting project " + projectName, ITestProjectHolder.FORMATT_FILE_JOB_FAMILY, mon -> {
if (!formattedDocuments.contains(path)) {
final IDocument doc = getDocument(getFile(path));
final Map<String, Object> options = new HashMap<>(cProject.getOptions(true));
try {
final ITranslationUnit tu = CoreModelUtil.findTranslationUnitForLocation(path, cProject);
options.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu);
final CodeFormatter formatter = ToolFactory.createCodeFormatter(options);
final TextEdit te = formatter.format(CodeFormatter.K_TRANSLATION_UNIT, path.toOSString(), 0, doc.getLength(), 0, NL);
te.apply(doc);
formattedDocuments.add(path);
} catch (CModelException | MalformedTreeException | BadLocationException e) {
e.printStackTrace();
}
}
});
}
use of org.eclipse.cdt.core.model.ITranslationUnit in project linuxtools by eclipse.
the class CModelLabelsTest method testFileLabelsCPP.
@Test
public void testFileLabelsCPP() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testFileLabelsCPP");
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
CachegrindOutput output = view.getOutputs()[0];
// $NON-NLS-1$
CachegrindFile file = getFileByName(output, "cpptest.cpp");
assertTrue(file.getModel() instanceof ITranslationUnit);
checkLabelProvider(file);
}
use of org.eclipse.cdt.core.model.ITranslationUnit in project linuxtools by eclipse.
the class CModelLabelsTest method testFileLabelsH.
@Test
public void testFileLabelsH() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testFileLabelsH");
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
CachegrindOutput output = view.getOutputs()[0];
// $NON-NLS-1$
CachegrindFile file = getFileByName(output, "cpptest.h");
assertTrue(file.getModel() instanceof ITranslationUnit);
assertTrue(((ITranslationUnit) file.getModel()).isHeaderUnit());
checkLabelProvider(file);
}
use of org.eclipse.cdt.core.model.ITranslationUnit 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;
}
Aggregations