use of org.eclipse.cdt.core.model.ICElement in project linuxtools by eclipse.
the class RemoteProxyCMainTab method handleSearchButtonSelected.
/**
* Show a dialog that lists all main types
*/
@Override
protected void handleSearchButtonSelected() {
if (getCProject() == null) {
MessageDialog.openInformation(getShell(), LaunchMessages.CMainTab_Project_required, LaunchMessages.CMainTab_Enter_project_before_searching_for_program);
return;
}
ILabelProvider programLabelProvider = new CElementLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IBinary) {
IBinary bin = (IBinary) element;
StringBuffer name = new StringBuffer();
name.append(bin.getPath().lastSegment());
return name.toString();
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (!(element instanceof ICElement)) {
return super.getImage(element);
}
ICElement celement = (ICElement) element;
if (celement.getElementType() == ICElement.C_BINARY) {
IBinary belement = (IBinary) celement;
if (belement.isExecutable()) {
return DebugUITools.getImage(IDebugUIConstants.IMG_ACT_RUN);
}
}
return super.getImage(element);
}
};
ILabelProvider qualifierLabelProvider = new CElementLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IBinary) {
IBinary bin = (IBinary) element;
StringBuffer name = new StringBuffer();
name.append(bin.getCPU() + // $NON-NLS-1$ //$NON-NLS-2$
(bin.isLittleEndian() ? "le" : "be"));
// $NON-NLS-1$
name.append(" - ");
name.append(bin.getPath().toString());
return name.toString();
}
return super.getText(element);
}
};
TwoPaneElementSelector dialog = new TwoPaneElementSelector(getShell(), programLabelProvider, qualifierLabelProvider);
dialog.setElements(getBinaryFiles(getCProject()));
dialog.setMessage(LaunchMessages.CMainTab_Choose_program_to_run);
dialog.setTitle(LaunchMessages.CMainTab_Program_Selection);
dialog.setUpperListLabel(LaunchMessages.Launch_common_BinariesColon);
dialog.setLowerListLabel(LaunchMessages.Launch_common_QualifierColon);
dialog.setMultipleSelection(false);
// dialog.set
if (dialog.open() == Window.OK) {
IBinary binary = (IBinary) dialog.getFirstResult();
fProgText.setText(binary.getResource().getProjectRelativePath().toString());
}
}
use of org.eclipse.cdt.core.model.ICElement in project arduino-eclipse-plugin by Sloeber.
the class PdePreprocessor method extendHeaderForFile.
private static String extendHeaderForFile(String header, IIndex index, ITranslationUnit tu) throws CoreException {
String localHeader = header;
// Locate All lines that are extern "C"
HashMap<Integer, Integer> externCLines = new HashMap<>();
IASTTranslationUnit astTuTest = tu.getAST(index, 0);
IASTDeclaration[] topDeclaratons = astTuTest.getDeclarations();
for (IASTDeclaration curTopDeclaration : topDeclaratons) {
ICPPASTLinkageSpecification test = curTopDeclaration instanceof ICPPASTLinkageSpecification ? (ICPPASTLinkageSpecification) curTopDeclaration : null;
if (test != null) {
if (test.getLiteral().equals("\"C\"")) {
Path curFile = new Path(curTopDeclaration.getContainingFilename());
if (curFile.equals(tu.getFile().getLocation())) {
int startLine = test.getFileLocation().getStartingLineNumber();
int endLine = test.getFileLocation().getEndingLineNumber();
for (int curline = startLine; curline <= endLine; curline++) {
externCLines.put(new Integer(curline), null);
}
}
}
}
}
// find the last line containing a include
IInclude[] includes = tu.getIncludes();
int lastHeaderLine = 0;
for (IInclude include : includes) {
int curHeaderLine = include.getSourceRange().getEndLine();
lastHeaderLine = Math.max(lastHeaderLine, curHeaderLine);
}
// parse line by line until all includes have been parsed
for (int curline = 1; curline <= lastHeaderLine; curline++) {
ICElement curElement = tu.getElementAtLine(curline);
if (curElement != null) {
switch(curElement.getElementType()) {
case ICElement.C_MACRO:
IMacro curMacro = (IMacro) curElement;
if (curMacro.isActive()) {
localHeader += curMacro.getSource() + NEWLINE;
}
break;
case ICElement.C_VARIABLE:
IVariable curVardeclar = (IVariable) curElement;
if (curVardeclar.isActive()) {
String fullTypeName = curVardeclar.getTypeName();
// ignore double arrays
if (fullTypeName.indexOf('[') == fullTypeName.lastIndexOf('[')) {
String typeName = fullTypeName.replace('[', ' ').replace(']', ' ').trim();
String typeExtensions = fullTypeName.replace(typeName, "");
localHeader += "extern " + typeName + " " + curVardeclar.getElementName() + typeExtensions + ";" + NEWLINE;
}
}
break;
case ICElement.C_INCLUDE:
IInclude curInclude = (IInclude) curElement;
int curHeaderLine = curInclude.getSourceRange().getStartLine();
if (curInclude.isActive()) {
if (externCLines.containsKey(new Integer(curHeaderLine))) {
localHeader += "extern \"C\" {" + NEWLINE;
localHeader += curInclude.getSource() + NEWLINE;
localHeader += "}" + NEWLINE;
} else {
localHeader += curInclude.getSource();
localHeader += NEWLINE;
}
}
break;
}
}
}
return localHeader;
}
Aggregations