Skip to content

Commit 98dafb1

Browse files
committed
Add new checkbox in general preferences: Determine applicable file types automatically
1 parent 4260ef6 commit 98dafb1

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

net.sourceforge.pmd.eclipse.plugin/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ preference.pmd.label.check_after_saving = Check code after saving
3030
preference.pmd.label.use_dfa = Enable dataflow anomaly analysis (experimental)
3131
preference.pmd.label.use_project_build_path = Enable using Java Project Build Path. Disable if your Eclipse JVM version is incompatible with .class file versions.
3232
preference.pmd.label.max_violations_pfpr = Maximum reported violations per file per rule
33+
preference.pmd.label.determine_filetypes_automatically = Determine applicable file types automatically (based on rule languages)
3334
preference.pmd.tooltip.max_violations_pfpr = This helps limit report sizes and improves overall performance
3435
preference.pmd.message.invalid_numeric_value = Incorrect numeric value entered
3536
preference.pmd.label.review_pmd_style = Use PMD style (// NOPMD comment)

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/IPreferences.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public interface IPreferences {
2929
boolean PMD_CHECK_AFTER_SAVE_DEFAULT = false;
3030
boolean PMD_USE_CUSTOM_PRIORITY_NAMES_DEFAULT = true;
3131
int MAX_VIOLATIONS_PFPR_DEFAULT = 5;
32+
boolean DETERMINE_FILETYPES_AUTOMATICALLY_DEFAULT = true;
3233
String REVIEW_ADDITIONAL_COMMENT_DEFAULT = "by {0} on {1}";
3334
boolean REVIEW_PMD_STYLE_ENABLED_DEFAULT = true;
3435
int MIN_TILE_SIZE_DEFAULT = 25;
@@ -143,6 +144,19 @@ public interface IPreferences {
143144
*/
144145
void setMaxViolationsPerFilePerRule(int maxViolationPerFilePerRule);
145146

147+
/**
148+
* If true: When checking, whether a given file should be analyzed by PMD, take
149+
* the rule's language and the language's file extensions into account.
150+
* @return
151+
*/
152+
boolean isDetermineFiletypesAutomatically();
153+
154+
/**
155+
* Sets whether the rule's language file extensions should be considered or not.
156+
* @param determineFiletypesAutomatically
157+
*/
158+
void setDetermineFiletypesAutomatically(boolean determineFiletypesAutomatically);
159+
146160
/**
147161
* Get the review additional comment. This comment is a text appended to the
148162
* review comment that is inserted into the code when a violation is

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class PreferencesImpl implements IPreferences {
3939
private boolean checkAfterSaveEnabled;
4040
private boolean useCustomPriorityNames;
4141
private int maxViolationsPerFilePerRule;
42+
private boolean determineFiletypesAutomatically;
4243
private String reviewAdditionalComment;
4344
private boolean reviewPmdStyleEnabled;
4445
private int minTileSize;
@@ -146,6 +147,16 @@ public void setMaxViolationsPerFilePerRule(int maxViolationPerFilePerRule) {
146147
this.maxViolationsPerFilePerRule = maxViolationPerFilePerRule;
147148
}
148149

150+
@Override
151+
public boolean isDetermineFiletypesAutomatically() {
152+
return determineFiletypesAutomatically;
153+
}
154+
155+
@Override
156+
public void setDetermineFiletypesAutomatically(boolean determineFiletypesAutomatically) {
157+
this.determineFiletypesAutomatically = determineFiletypesAutomatically;
158+
}
159+
149160
/**
150161
* @see net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences#getReviewAdditionalComment()
151162
*/

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PreferencesManagerImpl implements IPreferencesManager {
6868
private static final String PMD_VIOLATIONS_OUTLINE_ENABLED = PMDPlugin.PLUGIN_ID + ".pmd_outline_enabled";
6969
private static final String PMD_CHECK_AFTER_SAVE_ENABLED = PMDPlugin.PLUGIN_ID + ".pmd_check_after_save_enabled";
7070
private static final String MAX_VIOLATIONS_PFPR = PMDPlugin.PLUGIN_ID + ".max_violations_pfpr";
71+
private static final String DETERMINE_FILETYPES_AUTOMATICALLY = PMDPlugin.PLUGIN_ID + ".determine_filetypes_automatically";
7172
private static final String REVIEW_ADDITIONAL_COMMENT = PMDPlugin.PLUGIN_ID + ".review_additional_comment";
7273
private static final String REVIEW_PMD_STYLE_ENABLED = PMDPlugin.PLUGIN_ID + ".review_pmd_style_enabled";
7374
private static final String PMD_USE_CUSTOM_PRIORITY_NAMES = PMDPlugin.PLUGIN_ID + ".use_custom_priority_names";
@@ -159,6 +160,7 @@ public IPreferences reloadPreferences() {
159160
loadCheckAfterSaveEnabled();
160161
loadUseCustomPriorityNames();
161162
loadMaxViolationsPerFilePerRule();
163+
loadDetermineFiletypesAutomatically();
162164
loadReviewAdditionalComment();
163165
loadReviewPmdStyleEnabled();
164166
loadMinTileSize();
@@ -231,6 +233,7 @@ public void storePreferences(IPreferences thePreferences) {
231233
storeCheckAfterSaveEnabled();
232234
storeUseCustomPriorityNames();
233235
storeMaxViolationsPerFilePerRule();
236+
storeDetermineFiletypesAutomatically();
234237
storeReviewAdditionalComment();
235238
storeReviewPmdStyleEnabled();
236239
storeMinTileSize();
@@ -305,6 +308,11 @@ private void loadMaxViolationsPerFilePerRule() {
305308
loadPreferencesStore.setDefault(MAX_VIOLATIONS_PFPR, IPreferences.MAX_VIOLATIONS_PFPR_DEFAULT);
306309
preferences.setMaxViolationsPerFilePerRule(loadPreferencesStore.getInt(MAX_VIOLATIONS_PFPR));
307310
}
311+
312+
private void loadDetermineFiletypesAutomatically() {
313+
loadPreferencesStore.setDefault(DETERMINE_FILETYPES_AUTOMATICALLY, IPreferences.DETERMINE_FILETYPES_AUTOMATICALLY_DEFAULT);
314+
preferences.setDetermineFiletypesAutomatically(loadPreferencesStore.getBoolean(DETERMINE_FILETYPES_AUTOMATICALLY));
315+
}
308316

309317
private void loadReviewAdditionalComment() {
310318
loadPreferencesStore.setDefault(REVIEW_ADDITIONAL_COMMENT, IPreferences.REVIEW_ADDITIONAL_COMMENT_DEFAULT);
@@ -486,6 +494,10 @@ private void storeMaxViolationsPerFilePerRule() {
486494
storePreferencesStore.setValue(MAX_VIOLATIONS_PFPR, preferences.getMaxViolationsPerFilePerRule());
487495
}
488496

497+
private void storeDetermineFiletypesAutomatically() {
498+
storePreferencesStore.setValue(DETERMINE_FILETYPES_AUTOMATICALLY, preferences.isDetermineFiletypesAutomatically());
499+
}
500+
489501
private void storeReviewAdditionalComment() {
490502
storePreferencesStore.setValue(REVIEW_ADDITIONAL_COMMENT, preferences.getReviewAdditionalComment());
491503
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/nls/StringKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class StringKeys {
4141
public static final String PREF_GENERAL_LABEL_USE_DFA = "preference.pmd.label.use_dfa";
4242
public static final String PREF_GENERAL_LABEL_USE_PROJECT_BUILD_PATH = "preference.pmd.label.use_project_build_path";
4343
public static final String PREF_GENERAL_LABEL_MAX_VIOLATIONS_PFPR = "preference.pmd.label.max_violations_pfpr";
44+
public static final String PREF_GENERAL_LABEL_DETERMINE_FILETYPES_AUTOMATICALLY = "preference.pmd.label.determine_filetypes_automatically";
4445
public static final String PREF_GENERAL_TOOLTIP_MAX_VIOLATIONS_PFPR = "preference.pmd.tooltip.max_violations_pfpr";
4546
public static final String PREF_GENERAL_MESSAGE_INVALID_NUMERIC_VALUE = "preference.pmd.message.invalid_numeric_value";
4647
public static final String PREF_GENERAL_REVIEW_PMD_STYLE = "preference.pmd.label.review_pmd_style";

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
100100
private TableViewer tableViewer;
101101
private IPreferences preferences;
102102
private BasicTableManager priorityTableMgr;
103+
private Button determineFiletypesAutomatically;
103104

104105
private Control[] nameFields;
105106

@@ -165,6 +166,7 @@ private Group buildGeneralGroup(final Composite parent) {
165166
showViolationsOutlineViewBox = buildShowViolationOutlineBoxButton(group);
166167
useProjectBuildPath = buildUseProjectBuildPathButton(group);
167168
checkCodeOnSave = buildCheckCodeOnSaveButton(group);
169+
determineFiletypesAutomatically = buildDetermineFiletypesAutomatically(group);
168170
Label separator = new Label(group, SWT.SEPARATOR | SWT.SHADOW_IN | SWT.HORIZONTAL);
169171
maxViolationsPerFilePerRule = buildMaxViolationsPerFilePerRuleText(group);
170172

@@ -709,6 +711,13 @@ private Spinner buildMaxViolationsPerFilePerRuleText(Composite parent) {
709711
return spinner;
710712
}
711713

714+
private Button buildDetermineFiletypesAutomatically(Composite viewGroup) {
715+
Button button = new Button(viewGroup, SWT.CHECK);
716+
button.setText(getMessage(StringKeys.PREF_GENERAL_LABEL_DETERMINE_FILETYPES_AUTOMATICALLY));
717+
button.setSelection(preferences.isDetermineFiletypesAutomatically());
718+
return button;
719+
}
720+
712721
/**
713722
* Build the check box for enabling PMD review style
714723
*
@@ -752,6 +761,7 @@ protected void performDefaults() {
752761
setSelection(useCustomPriorityNames, IPreferences.PMD_USE_CUSTOM_PRIORITY_NAMES_DEFAULT);
753762
setSelection(useProjectBuildPath, IPreferences.PROJECT_BUILD_PATH_ENABLED_DEFAULT);
754763
setSelection(reviewPmdStyleBox, IPreferences.REVIEW_PMD_STYLE_ENABLED_DEFAULT);
764+
setSelection(determineFiletypesAutomatically, IPreferences.DETERMINE_FILETYPES_AUTOMATICALLY_DEFAULT);
755765

756766
if (maxViolationsPerFilePerRule != null) {
757767
maxViolationsPerFilePerRule.setMinimum(IPreferences.MAX_VIOLATIONS_PFPR_DEFAULT);
@@ -886,6 +896,10 @@ public boolean performOk() {
886896
.setMaxViolationsPerFilePerRule(Integer.valueOf(maxViolationsPerFilePerRule.getText()).intValue());
887897
}
888898

899+
if (determineFiletypesAutomatically != null) {
900+
preferences.setDetermineFiletypesAutomatically(determineFiletypesAutomatically.getSelection());
901+
}
902+
889903
if (reviewPmdStyleBox != null) {
890904
preferences.setReviewPmdStyleEnabled(reviewPmdStyleBox.getSelection());
891905
}

0 commit comments

Comments
 (0)