Skip to content

Commit 06d1473

Browse files
vodorokgamesh411
authored andcommitted
Clear checker report view when needed (#185)
When changing from a project which isn't CodeChecker enabled or when changing between files, the report views will show no reports.
1 parent 684d3ea commit 06d1473

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CodeCheckerContext.java

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,23 @@ public void refreshChangeEditorPart(IEditorPart partRef) {
254254
activeEditorPart = partRef;
255255
IFile file = ((IFileEditorInput) partRef.getEditorInput()).getFile();
256256
IProject project = file.getProject();
257-
try {
258-
if (project.hasNature(CodeCheckerNature.NATURE_ID)) {
259-
String filename = projects.get(project).getAsProjectRelativePath(file.getProjectRelativePath().toString());
260257

261-
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
262-
if (activeWindow == null) {
263-
Logger.log(IStatus.ERROR, NULL_WINDOW);
264-
return;
265-
}
266-
IWorkbenchPage[] pages = activeWindow.getPages();
258+
CodeCheckerProject ccProj = projects.get(project);
259+
String filename = "";
260+
if (ccProj != null)
261+
filename = ccProj.getAsProjectRelativePath(file.getProjectRelativePath().toString());
267262

268-
this.refreshProject(pages, project, true);
269-
this.refreshCurrent(pages, project, filename, true);
270-
this.refreshCustom(pages, project, "", true);
271-
this.activeProject = project;
272-
}
273-
} catch (CoreException e) {
274-
// TODO Auto-generated catch block
275-
e.printStackTrace();
263+
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
264+
if (activeWindow == null) {
265+
Logger.log(IStatus.ERROR, NULL_WINDOW);
266+
return;
276267
}
268+
IWorkbenchPage[] pages = activeWindow.getPages();
269+
270+
this.refreshProject(pages, project, true);
271+
this.refreshCurrent(pages, project, filename, true);
272+
this.refreshCustom(pages, project, "", true);
273+
this.activeProject = project;
277274
}
278275
}
279276

@@ -333,7 +330,19 @@ public void refreshAddCustomReportListView(String secondaryId) {
333330
*/
334331
public void runReportJob(ReportListView target, String currentFileName) {
335332
IProject project = target.getCurrentProject();
336-
if (project == null) return;
333+
if (project == null)
334+
return;
335+
try {
336+
if (!project.hasNature(CodeCheckerNature.NATURE_ID)) {
337+
target.clearModel();
338+
return;
339+
}
340+
} catch (CoreException e) {
341+
// If there is a problem with the project, clear it anyway.
342+
target.clearModel();
343+
return;
344+
}
345+
337346
Logger.log(IStatus.INFO, "Started Filtering Reports for project: "+project.getName());
338347

339348
ReportParser parser = new ReportParser(reports.get(project), currentFileName);

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/init/ProjectExplorerSelectionListener.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package org.codechecker.eclipse.plugin.init;
22

3+
import org.codechecker.eclipse.plugin.config.CodeCheckerContext;
34
import org.eclipse.core.resources.IProject;
45
import org.eclipse.core.resources.IResource;
5-
import org.eclipse.core.runtime.CoreException;
66
import org.eclipse.core.runtime.IAdaptable;
77
import org.eclipse.jface.viewers.ISelection;
88
import org.eclipse.jface.viewers.IStructuredSelection;
99
import org.eclipse.ui.ISelectionListener;
1010
import org.eclipse.ui.IWorkbenchPart;
1111

12-
import org.codechecker.eclipse.plugin.CodeCheckerNature;
13-
import org.codechecker.eclipse.plugin.config.CodeCheckerContext;
14-
1512
public class ProjectExplorerSelectionListener implements ISelectionListener {
1613

1714
@Override
@@ -22,13 +19,9 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
2219
IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
2320
if (resource != null) {
2421
final IProject project = resource.getProject();
25-
try {
26-
if (project != null && project.hasNature(CodeCheckerNature.NATURE_ID))
27-
CodeCheckerContext.getInstance().refreshChangeProject(project);
28-
} catch (CoreException e) {
29-
// TODO Auto-generated catch block
30-
e.printStackTrace();
31-
}
22+
if (project != null)
23+
CodeCheckerContext.getInstance().refreshChangeProject(project);
24+
3225
}
3326
}
3427
}

0 commit comments

Comments
 (0)