use of org.eclipse.linuxtools.internal.gcov.parser.SourceFile in project linuxtools by eclipse.
the class CovView method displayCovDetailedResult.
public static void displayCovDetailedResult(String binaryPath, String gcda) {
try {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile binary = root.getFileForLocation(new Path(binaryPath));
IProject project = null;
if (binary != null) {
project = binary.getProject();
}
// parse and process coverage data
CovManager cvrgeMnger = new CovManager(binaryPath, project);
List<String> gcdaPaths = new LinkedList<>();
gcdaPaths.add(gcda);
cvrgeMnger.processCovFiles(gcdaPaths, gcda);
// generate model for view
cvrgeMnger.fillGcovView();
for (SourceFile sf : cvrgeMnger.getSourceMap().values()) {
OpenSourceFileAction.openAnnotatedSourceFile(project, binary, sf, 0);
}
} catch (CoreException | IOException e) {
reportError(e);
}
}
use of org.eclipse.linuxtools.internal.gcov.parser.SourceFile in project linuxtools by eclipse.
the class GcovAnnotationModel method findSourceCoverageForElement.
private SourceFile findSourceCoverageForElement(ICElement element) {
List<SourceFile> sources = new ArrayList<>();
ICProject cProject = element.getCProject();
IResource elementResource = element.getResource();
IPath target = GcovAnnotationModelTracker.getInstance().getBinaryPath(cProject.getProject());
if (target == null) {
// We cannot find a target for this element, using it's project.
// This can be caused by linking in a file to the project which may
// not have a project or may point to another unseen project if the file originated
// there.
IProject[] trackedProjects = GcovAnnotationModelTracker.getInstance().getTrackedProjects();
for (IProject proj : trackedProjects) {
// element is linked in.
try {
FindLinkedResourceVisitor visitor = new FindLinkedResourceVisitor(element);
proj.accept(visitor, IResource.DEPTH_INFINITE);
// If we find a match, make note of the target and the real C project.
if (visitor.foundElement()) {
target = GcovAnnotationModelTracker.getInstance().getBinaryPath(proj);
cProject = CoreModel.getDefault().getCModel().getCProject(proj.getName());
elementResource = visitor.getResource();
break;
}
} catch (CoreException e) {
}
}
if (target == null) {
return null;
}
}
try {
IBinary[] binaries = cProject.getBinaryContainer().getBinaries();
for (IBinary b : binaries) {
if (b.getResource().getLocation().equals(target)) {
CovManager covManager = new CovManager(b.getResource().getLocation().toOSString());
covManager.processCovFiles(covManager.getGCDALocations(), null);
sources.addAll(covManager.getAllSrcs());
}
}
} catch (IOException | CoreException | InterruptedException e) {
}
if (elementResource != null) {
IPath elementLocation = elementResource.getLocation();
if (elementLocation != null) {
for (SourceFile sf : sources) {
IPath sfPath = new Path(sf.getName());
IFile file = STLink2SourceSupport.getFileForPath(sfPath, cProject.getProject());
if (file != null && elementLocation.equals(file.getLocation())) {
return sf;
}
// the sources. Fixes Bug 447554
if (!sfPath.isAbsolute()) {
sfPath = target.removeLastSegments(1).append(sf.getName());
if (elementLocation.equals(sfPath.makeAbsolute()) && sfPath.toFile().exists())
return sf;
}
}
}
}
URI elementURI = element.getLocationURI();
if (elementURI != null) {
IPath binFolder = target.removeLastSegments(1);
for (SourceFile sf : sources) {
String sfPath = Paths.get(binFolder.toOSString()).resolve(sf.getName()).normalize().toString();
if (sfPath.equals(elementURI.getPath())) {
return sf;
}
}
}
return null;
}
use of org.eclipse.linuxtools.internal.gcov.parser.SourceFile in project linuxtools by eclipse.
the class CovViewer method handleOpenEvent.
@Override
protected void handleOpenEvent(OpenEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
TreeElement element = (TreeElement) selection.getFirstElement();
if (element != null) {
if (element.getParent() != null) {
// $NON-NLS-1$
String sourceLoc = "";
long lineNumber = 0;
if (element.getClass() == CovFileTreeElement.class) {
sourceLoc = element.getName();
} else if (element.getClass() == CovFunctionTreeElement.class) {
sourceLoc = ((CovFunctionTreeElement) element).getSourceFilePath();
lineNumber = ((CovFunctionTreeElement) element).getFirstLnNmbr();
}
CovManager cvm = (CovManager) this.getInput();
SourceFile sourceFile = cvm.getSourceFile(sourceLoc);
if (sourceFile != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String binaryLoc = cvm.getBinaryPath();
IPath binaryPath = new Path(binaryLoc);
IFile binary = root.getFileForLocation(binaryPath);
IProject project = null;
if (binary != null) {
project = binary.getProject();
}
OpenSourceFileAction.openAnnotatedSourceFile(project, binary, sourceFile, (int) lineNumber);
}
}
}
}
use of org.eclipse.linuxtools.internal.gcov.parser.SourceFile in project linuxtools by eclipse.
the class STAnnotatedSourceNotFoundEditor method openSourceFileAtLocation.
@Override
protected void openSourceFileAtLocation(IProject project, IPath sourceLoc, int lineNumber) {
IEditorInput input = this.getEditorInput();
if (input instanceof STAnnotatedSourceNotFoundEditorInput) {
STAnnotatedSourceNotFoundEditorInput editorInput = (STAnnotatedSourceNotFoundEditorInput) input;
SourceFile sf = editorInput.getSourceFile();
OpenSourceFileAction.openAnnotatedSourceFile(project, null, sf, sourceLoc, lineNumber);
} else {
super.openSourceFileAtLocation(project, sourceLoc, lineNumber);
}
}
Aggregations