Skip to content

Commit a59940e

Browse files
committed
Do not rerun PMD when the priority filter is changed
Now only ViolationOutline/ViolationOverview reflect the priority filter
1 parent 7464859 commit a59940e

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ public void resourceChanged(IResourceChangeEvent arg0) {
265265
* Get a list of all the files that are open in eclipse currently
266266
*
267267
* @return
268+
* @deprecated will be removed since it is not needed
268269
*/
270+
@Deprecated
269271
public Set<IFile> getOpenFiles() {
270272
Set<IFile> files = new HashSet<IFile>();
271273
IEditorReference[] refs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
@@ -279,7 +281,7 @@ public Set<IFile> getOpenFiles() {
279281
}
280282
return files;
281283
}
282-
284+
283285
/**
284286
* Open a view to the id passed in.
285287
*

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
4848
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
4949
import net.sourceforge.pmd.eclipse.util.IOUtil;
50-
import net.sourceforge.pmd.eclipse.util.PriorityUtil;
5150
import net.sourceforge.pmd.lang.LanguageRegistry;
5251
import net.sourceforge.pmd.lang.LanguageVersion;
5352
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
@@ -521,11 +520,6 @@ private void updateMarkers(IFile file, Iterator<RuleViolation> violations, boole
521520
review.ruleName = rule.getName();
522521
review.lineNumber = violation.getBeginLine();
523522

524-
/* Only show active violations */
525-
if (!PriorityUtil.isPriorityActive(rule.getPriority())) {
526-
continue;
527-
}
528-
529523
if (reviewsList.contains(review)) {
530524
LOG.debug("Ignoring violation of rule " + rule.getName() + " at line " + violation.getBeginLine()
531525
+ " because of a review.");

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/PriorityFilter.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,31 +184,47 @@ public List<Integer> getPriorityFilterList() {
184184
return priorityList;
185185
}
186186

187+
public void enablePriority(RulePriority priority) {
188+
if (priority != null) {
189+
if (enabledPriorities.add(priority)) {
190+
notifyPriorityEnabled(priority);
191+
}
192+
}
193+
}
194+
195+
public void disablePriority(RulePriority priority) {
196+
if (priority != null) {
197+
if (enabledPriorities.remove(priority)) {
198+
notifyPriorityDisabled(priority);
199+
}
200+
}
201+
}
202+
187203
/**
188204
* Adds a Priority to The List
189205
*
190206
* @param priority
207+
* @deprecated use {@link #enablePriority(RulePriority)}
191208
*/
209+
@Deprecated
192210
public void addPriorityToList(Integer priority) {
193211
if (priority != null) {
194212
RulePriority rulePriority = RulePriority.valueOf(priority);
195-
if (enabledPriorities.add(rulePriority)) {
196-
notifyPriorityEnabled(rulePriority);
197-
}
213+
enablePriority(rulePriority);
198214
}
199215
}
200216

201217
/**
202218
* Removes a Priority From the List
203219
*
204220
* @param priority
221+
* @deprecated use {@link #disablePriority(RulePriority)}
205222
*/
223+
@Deprecated
206224
public void removePriorityFromList(Integer priority) {
207225
if (priority != null) {
208226
RulePriority rulePriority = RulePriority.valueOf(priority);
209-
if (enabledPriorities.remove(rulePriority)) {
210-
notifyPriorityDisabled(rulePriority);
211-
}
227+
disablePriority(rulePriority);
212228
}
213229
}
214230

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/actions/PriorityFilterAction.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44

55
package net.sourceforge.pmd.eclipse.ui.views.actions;
66

7-
import org.apache.log4j.Logger;
87
import org.eclipse.jface.action.Action;
98
import org.eclipse.jface.resource.ImageDescriptor;
109
import org.eclipse.jface.viewers.ViewerFilter;
1110

1211
import net.sourceforge.pmd.RulePriority;
13-
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1412
import net.sourceforge.pmd.eclipse.plugin.UISettings;
15-
import net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd;
1613
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptor;
1714
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
1815
import net.sourceforge.pmd.eclipse.ui.views.PriorityFilter;
16+
import net.sourceforge.pmd.eclipse.ui.views.PriorityFilter.PriorityFilterChangeListener;
1917
import net.sourceforge.pmd.eclipse.ui.views.ViolationOutline;
2018
import net.sourceforge.pmd.eclipse.ui.views.ViolationOverview;
21-
import net.sourceforge.pmd.eclipse.ui.views.PriorityFilter.PriorityFilterChangeListener;
2219

2320
/**
2421
* Filters elements by the Marker priorities
@@ -32,7 +29,6 @@ public class PriorityFilterAction extends Action implements PriorityFilterChange
3229
private ViolationOverview overviewView;
3330
private PriorityFilter priorityFilter;
3431
private final RulePriority priority;
35-
private static final Logger LOG = Logger.getLogger(PriorityFilterAction.class);
3632

3733
private PriorityFilterAction(ViewerFilter[] filters, RulePriority thePriority) {
3834
priority = thePriority;
@@ -102,36 +98,33 @@ public void run() {
10298
// we add or remove an Integer with the Priority to a List
10399
// of Priorities, the Filter does the Rest
104100
if (isChecked()) {
105-
priorityFilter.addPriorityToList(priority.getPriority());
101+
priorityFilter.enablePriority(priority);
106102
} else {
107-
priorityFilter.removePriorityFromList(priority.getPriority());
103+
priorityFilter.disablePriority(priority);
108104
}
105+
}
109106

107+
private void refreshView() {
110108
if (outlineView != null) {
111109
outlineView.refresh();
112110
} else if (overviewView != null) {
113111
overviewView.refresh();
114112
}
115-
116-
/* Get all the opened files and tell them to run a "review code" on the file */
117-
try {
118-
ReviewCodeCmd.runCodeReviewOnFiles(PMDPlugin.getDefault().getOpenFiles());
119-
} catch (RuntimeException e) {
120-
LOG.error(e);
121-
}
122113
}
123114

124115
@Override
125116
public void priorityEnabled(RulePriority priority) {
126117
if (this.priority == priority) {
127118
this.setChecked(true);
119+
refreshView();
128120
}
129121
}
130122

131123
@Override
132124
public void priorityDisabled(RulePriority priority) {
133125
if (this.priority == priority) {
134126
this.setChecked(false);
127+
refreshView();
135128
}
136129
}
137130
}

0 commit comments

Comments
 (0)