Java源码示例:org.eclipse.cdt.core.model.ICElement
示例1
public static String getCurrentProject() {
ISelectionService selectionService = Workbench.getInstance()
.getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
IProject project = null;
if (element instanceof IResource) {
project = ((IResource) element).getProject();
}
else if (element instanceof ICElement) {
project = ((ICElement) element).getResource().getProject();
}
if (project != null) {
return project.getLocation().toOSString();
}
}
return null;
}
示例2
public IExplorable getFromCDT(ICElement cele) {
String path = null;
// project
if (cele instanceof ICProject) {
path = ((ICProject) cele).getProject().getLocation().toOSString();
return new Explorer(path, null);
}
else if (cele instanceof IIncludeFileEntry) {
path = ((IIncludeFileEntry) cele).getFullIncludeFilePath()
.toOSString();
return new Explorer(null, path);
}
else if (cele instanceof IInclude) {
path = ((IInclude) cele).getParent().getPath().toOSString();
return new Explorer(null, path);
}
// other
else {
IResource res = cele.getResource();
if (res != null) {
return ExplorerPlugin.getFromResource(res);
}
}
return null;
}
示例3
@Override
public IExplorable getExplorable(Object adaptableObject) {
IExplorable ret = null;
// for c/c++ element
if (adaptableObject instanceof ICElement) {
ret = getFromCDT((ICElement) adaptableObject);
}
if (ret != null) {
ret.setIdentifier("explorer4cdt");
}
return ret;
}