Skip to content

Commit ae41cb1

Browse files
committed
Properly refresh and clear BugPathList
1 parent 7ca16bf commit ae41cb1

File tree

6 files changed

+47
-23
lines changed

6 files changed

+47
-23
lines changed

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/config/CodeCheckerContext.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,22 @@ public void autoRefresh() {
104104

105105
if (activeEditor == null) return;
106106

107-
CodeCheckerContext.getInstance().setActiveEditorPart(activeEditor);
107+
CodeCheckerContext.getInstance().setActiveEditorPart(activeEditor,true);
108108
}
109109

110110
public void cleanCache(IProject project) {
111111
jobRunner.getActionCacheFilter().removeAll();
112112
System.out.println("CLEARING CACHE");
113113
}
114114

115-
public void setActiveEditorPart(IEditorPart partRef) {
115+
public void setActiveEditorPart(IEditorPart partRef,boolean refresh) {
116116

117117
if (!(partRef.getEditorInput() instanceof IFileEditorInput)) {
118118
return;
119119
}
120-
120+
if (partRef == activeEditorPart && !refresh) {
121+
return;
122+
}
121123
activeEditorPart = partRef;
122124
IFile file = ((IFileEditorInput) partRef.getEditorInput()).getFile();
123125
IProject project = file.getProject();
@@ -156,6 +158,10 @@ public void setActiveEditorPart(IEditorPart partRef) {
156158
rlv.onEditorChanged(project, filename);
157159
}
158160
}
161+
if (vp.getId().equals(BugPathListView.ID)) {
162+
BugPathListView bplv = (BugPathListView) vp.getView(true);
163+
bplv.clear();
164+
}
159165
}
160166
}
161167
}

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/init/EditorPartListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void partActivated(IWorkbenchPart partRef) {
1515
return;
1616
}
1717
System.out.println("Editor changed");
18-
CodeCheckerContext.getInstance().setActiveEditorPart((IEditorPart) partRef);
18+
CodeCheckerContext.getInstance().setActiveEditorPart((IEditorPart) partRef, false);
1919
}
2020

2121
@Override

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/views/report/details/BugPathContentProvider.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
import org.eclipse.jface.viewers.Viewer;
66

77
import com.google.common.base.Optional;
8+
import com.google.common.base.Predicate;
9+
import com.google.common.collect.Iterables;
810

11+
import cc.codechecker.api.action.BugPathItem;
912
import cc.codechecker.api.action.bug.path.ProblemInfo;
1013

14+
import java.util.ArrayList;
15+
1116
public class BugPathContentProvider implements IStructuredContentProvider {
1217

1318
@Override
@@ -24,7 +29,14 @@ public Object[] getElements(Object inputElement) {
2429
@SuppressWarnings("unchecked") Optional<ProblemInfo> bp = (Optional<ProblemInfo>)
2530
inputElement;
2631
if (bp.isPresent()) {
27-
return bp.get().getItems().toArray();
32+
ArrayList<BugPathItem> result = new ArrayList<>(bp.get().getItems());
33+
Iterables.removeIf(result, new Predicate<BugPathItem>() {
34+
@Override
35+
public boolean apply(BugPathItem pi) {
36+
return "".equals(pi.getMessage());
37+
}
38+
});
39+
return result.toArray();
2840
}
2941
}
3042
return ArrayUtils.toArray();

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/views/report/details/BugPathLabelProvider.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package cc.codechecker.plugin.views.report.details;
22

33
import org.eclipse.jface.viewers.LabelProvider;
4+
import org.eclipse.core.runtime.Path;
5+
import org.eclipse.core.resources.IFile;
6+
import org.eclipse.core.resources.ResourcesPlugin;
47

58
import cc.codechecker.api.action.BugPathItem;
69

710
public class BugPathLabelProvider extends LabelProvider {
811

912
@Override
1013
public String getText(Object element) {
11-
BugPathItem bpi = (BugPathItem) element;
12-
13-
String file = bpi.getFile();
14-
String[] parts = file.split("/");
1514

16-
return parts[parts.length - 1] + " : " + bpi.getStartPosition().getLine() + " : " + bpi.getMessage();
15+
BugPathItem bpi = (BugPathItem) element;
16+
Path path = new Path(bpi.getFile());
17+
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
18+
19+
return file.getName() + " : " + bpi.getStartPosition().getLine() + " : " + bpi.getMessage();
1720

1821
}
1922

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/views/report/details/BugPathListView.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33

44
import org.eclipse.swt.widgets.Composite;
5+
import org.eclipse.swt.widgets.Display;
56
import org.eclipse.ui.IActionBars;
67
import org.eclipse.ui.part.*;
8+
79
import org.eclipse.core.resources.IProject;
810
import org.eclipse.jface.action.IMenuManager;
911
import org.eclipse.jface.viewers.*;
@@ -17,7 +19,7 @@ public class BugPathListView extends ViewPart {
1719

1820
public static final String ID = "cc.codechecker.plugin.views.BugPathList";
1921

20-
ListViewer viewer;
22+
ListViewer viewer = null;
2123

2224
Optional<ProblemInfo> bugPath;
2325

@@ -74,4 +76,13 @@ public void setName(String value) {
7476
setPartName(value);
7577
}
7678

79+
public void clear() {
80+
Display.getDefault().asyncExec(new Runnable() {
81+
public void run() {
82+
viewer.setInput(null);
83+
viewer.refresh();
84+
}
85+
});
86+
}
87+
7788
}

eclipse-plugin/service/cc.codechecker.service.api/src/main/java/cc/codechecker/api/action/bug/path/ProblemInfo.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,20 @@
55
import com.google.common.base.MoreObjects;
66
import com.google.common.collect.ImmutableList;
77

8-
import java.util.List;
9-
import java.util.ArrayList;
108
import java.util.Objects;
119

1210
/**
1311
* Contains every information about the problem
1412
*/
1513
public class ProblemInfo {
1614

17-
private final List<BugPathItem> items;
15+
private final ImmutableList<BugPathItem> items;
1816

19-
public ProblemInfo(List<BugPathItem> items) {
20-
List<BugPathItem> result = new ArrayList<>();
21-
for(BugPathItem bpi : items) {
22-
if(bpi.getMessage() != "") {
23-
result.add(bpi);
24-
}
25-
}
26-
this.items = result;
17+
public ProblemInfo(ImmutableList<BugPathItem> items) {
18+
this.items = items;
2719
}
2820

29-
public List<BugPathItem> getItems() {
21+
public ImmutableList<BugPathItem> getItems() {
3022
return items;
3123
}
3224

0 commit comments

Comments
 (0)