Add the possibility to use the PMD violation review style
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4379 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
pmd-eclipse
CHANGELOG.txtmessages.properties
nl/fr
src/net/sourceforge/pmd/eclipse
@ -13,6 +13,7 @@ Runtime
|
||||
. make CPD "working set aware"
|
||||
. remove some dead code
|
||||
. limit the number of reported violations per file and per rule (default to 5)
|
||||
. Add the possibility to use the PMD violation review style
|
||||
|
||||
|
||||
----------------------------------------------------------------------------------------
|
||||
|
@ -24,6 +24,7 @@ preference.pmd.label.use_dfa = Enable dataflow anomaly analysis (experimental)
|
||||
preference.pmd.label.max_violations_pfpr = Maximum reported violations per file per rules
|
||||
preference.pmd.tooltip.max_violations_pfpr = This helps limiting the report size and improving overall performances
|
||||
preference.pmd.message.invalid_numeric_value = Incorrect numeric value entered
|
||||
preference.pmd.label.review_pmd_style = Use PMD style (// NOPMD comment)
|
||||
|
||||
# PMD Rule set preference page
|
||||
preference.ruleset.title = PMD RuleSet Configuration Options
|
||||
|
@ -23,6 +23,7 @@ preference.pmd.label.use_dfa = Activer l'analyse d'anomalie de flots de donn
|
||||
preference.pmd.label.max_violations_pfpr = Nombre maximal de violations reportées par fichier et par règle
|
||||
preference.pmd.tooltip.max_violations_pfpr = Permet de limiter le nombre total de violations et d'améliorer sensiblement les performances
|
||||
preference.pmd.message.invalid_numeric_value = Valeur numérique incorrecte
|
||||
preference.pmd.label.review_pmd_style = Employer le style PMD (commentaire // NOPMD)
|
||||
|
||||
# PMD Rule set preference page
|
||||
preference.ruleset.title = Options de configuration des règles PMD
|
||||
|
@ -6,6 +6,9 @@ package net.sourceforge.pmd.eclipse;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.15 2006/05/07 12:01:50 phherlin
|
||||
* Add the possibility to use the PMD violation review style
|
||||
*
|
||||
* Revision 1.14 2006/05/02 20:10:49 phherlin
|
||||
* Limit the number of reported violations per file and per rule
|
||||
*
|
||||
@ -79,6 +82,7 @@ public interface PMDConstants {
|
||||
public static final String MSGKEY_PREF_GENERAL_LABEL_MAX_VIOLATIONS_PFPR = "preference.pmd.label.max_violations_pfpr";
|
||||
public static final String MSGKEY_PREF_GENERAL_TOOLTIP_MAX_VIOLATIONS_PFPR = "preference.pmd.tooltip.max_violations_pfpr";
|
||||
public static final String MSGKEY_PREF_GENERAL_MESSAGE_INVALID_NUMERIC_VALUE ="preference.pmd.message.invalid_numeric_value";
|
||||
public static final String MSGKEY_PREF_GENERAL_REVIEW_PMD_STYLE = "preference.pmd.label.review_pmd_style";
|
||||
|
||||
public static final String MSGKEY_PREF_RULESET_TITLE = "preference.ruleset.title";
|
||||
public static final String MSGKEY_PREF_RULESET_LIST = "preference.ruleset.list";
|
||||
|
@ -50,6 +50,9 @@ import org.osgi.framework.BundleContext;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.33 2006/05/07 12:01:50 phherlin
|
||||
* Add the possibility to use the PMD violation review style
|
||||
*
|
||||
* Revision 1.32 2006/05/02 20:10:49 phherlin
|
||||
* Limit the number of reported violations per file and per rule
|
||||
*
|
||||
@ -140,6 +143,7 @@ public class PMDPlugin extends AbstractUIPlugin implements PMDPluginConstants {
|
||||
private String[] priorityLabels;
|
||||
private String reviewAdditionalComment;
|
||||
private int maxViolationsPerFilePerRule;
|
||||
private boolean reviewPmdStyle;
|
||||
|
||||
/**
|
||||
* Private constructor ensures it remains a singleton.
|
||||
@ -558,4 +562,24 @@ public class PMDPlugin extends AbstractUIPlugin implements PMDPluginConstants {
|
||||
getPreferenceStore().setValue(MAX_VIOLATIONS_PER_FILE_PER_RULE_PREFERENCE, this.maxViolationsPerFilePerRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style of violation reviews
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isReviewPmdStyle() {
|
||||
this.reviewPmdStyle = getPreferenceStore().getBoolean(REVIEW_PMD_STYLE_PREFERENCE);
|
||||
return this.reviewPmdStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style of violation reviews
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
public void setReviewPmdStyle(boolean reviewPmdStyle) {
|
||||
this.reviewPmdStyle = reviewPmdStyle;
|
||||
getPreferenceStore().setValue(REVIEW_PMD_STYLE_PREFERENCE, this.reviewPmdStyle);
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,9 @@ package net.sourceforge.pmd.eclipse;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.12 2006/05/07 12:01:50 phherlin
|
||||
* Add the possibility to use the PMD violation review style
|
||||
*
|
||||
* Revision 1.11 2006/05/02 20:10:49 phherlin
|
||||
* Limit the number of reported violations per file and per rule
|
||||
*
|
||||
@ -120,7 +123,8 @@ public interface PMDPluginConstants {
|
||||
public static final String SETTINGS_VIEW_WARNING_FILTER = "view.warning_filter";
|
||||
public static final String SETTINGS_VIEW_INFORMATION_FILTER = "view.information_filter";
|
||||
|
||||
public static final String REVIEW_MARKER = "// @PMD:REVIEWED:";
|
||||
public static final String PLUGIN_STYLE_REVIEW_COMMENT = "// @PMD:REVIEWED:";
|
||||
public static final String PMD_STYLE_REVIEW_COMMENT = "// NOPMD";
|
||||
public static final String REVIEW_ADDITIONAL_COMMENT_DEFAULT = "by {0} on {1}";
|
||||
public static final String REVIEW_ADDITIONAL_COMMENT_PREFERENCE = PLUGIN_ID + ".review_additional_comment";
|
||||
public static final int SHOW_PERSPECTIVE_ON_CHECK_DEFAULT = 1;
|
||||
@ -129,6 +133,7 @@ public interface PMDPluginConstants {
|
||||
public static final String USE_DFA_PREFERENCE = PLUGIN_ID + ".use_dfa";
|
||||
public static final String MAX_VIOLATIONS_PER_FILE_PER_RULE_PREFERENCE = PLUGIN_ID + ".max_violations_per_file_per_rule";
|
||||
public static final int MAX_VIOLATIONS_PER_FILE_PER_RULE_DEFAULT = 5;
|
||||
public static final String REVIEW_PMD_STYLE_PREFERENCE = PLUGIN_ID + ".review_pmd_style";
|
||||
|
||||
|
||||
public static final String REPORT_FOLDER = "reports";
|
||||
|
@ -44,6 +44,7 @@ import java.util.Iterator;
|
||||
|
||||
import net.sourceforge.pmd.eclipse.PMDConstants;
|
||||
import net.sourceforge.pmd.eclipse.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.PMDPluginConstants;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -77,6 +78,9 @@ import org.eclipse.ui.IWorkbenchPart;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.5 2006/05/07 12:03:08 phherlin
|
||||
* Add the possibility to use the PMD violation review style
|
||||
*
|
||||
* Revision 1.4 2006/01/27 00:03:11 phherlin
|
||||
* Fix BUG#1365407 Problems with PMD in Eclipse/Issue 3
|
||||
* Revision 1.3 2005/10/24 22:39:00 phherlin Integrating Sebastian Raffel's work Refactor command
|
||||
@ -267,6 +271,8 @@ public class ClearReviewsAction implements IObjectActionDelegate, IResourceVisit
|
||||
while (reader.ready()) {
|
||||
String origLine = reader.readLine();
|
||||
String line = origLine.trim();
|
||||
int index = origLine.indexOf(PMDPluginConstants.PMD_STYLE_REVIEW_COMMENT);
|
||||
|
||||
if (line.startsWith("/*")) {
|
||||
if (line.indexOf("*/") == -1) {
|
||||
comment = true;
|
||||
@ -275,8 +281,11 @@ public class ClearReviewsAction implements IObjectActionDelegate, IResourceVisit
|
||||
} else if (comment && (line.indexOf("*/") != -1)) {
|
||||
comment = false;
|
||||
out.println(origLine);
|
||||
} else if (!comment && line.startsWith(PMDPlugin.REVIEW_MARKER)) {
|
||||
} else if (!comment && line.startsWith(PMDPluginConstants.PLUGIN_STYLE_REVIEW_COMMENT)) {
|
||||
noChange = false;
|
||||
} else if (!comment && (index != -1)) {
|
||||
noChange = false;
|
||||
out.println(origLine.substring(0, index));
|
||||
} else {
|
||||
out.println(origLine);
|
||||
}
|
||||
|
@ -67,6 +67,9 @@ import org.eclipse.ui.ResourceWorkingSetFilter;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.12 2006/05/07 12:03:09 phherlin
|
||||
* Add the possibility to use the PMD violation review style
|
||||
*
|
||||
* Revision 1.11 2006/05/02 20:10:26 phherlin
|
||||
* Limit the number of reported violations per file and per rule
|
||||
*
|
||||
@ -424,7 +427,7 @@ public class BaseVisitor {
|
||||
comment = line.indexOf("*/") == -1;
|
||||
} else if (comment && (line.indexOf("*/") != -1)) {
|
||||
comment = false;
|
||||
} else if (!comment && line.startsWith(PMDPlugin.REVIEW_MARKER)) {
|
||||
} else if (!comment && line.startsWith(PMDPlugin.PLUGIN_STYLE_REVIEW_COMMENT)) {
|
||||
final String tail = line.substring(17);
|
||||
final String ruleName = tail.substring(0, tail.indexOf(':'));
|
||||
pendingReviews.push(ruleName);
|
||||
|
@ -34,6 +34,9 @@ import net.sourceforge.pmd.eclipse.PMDPluginConstants;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.11 2006/05/07 12:03:08 phherlin
|
||||
* Add the possibility to use the PMD violation review style
|
||||
*
|
||||
* Revision 1.10 2006/05/02 20:11:13 phherlin
|
||||
* Limit the number of reported violations per file and per rule
|
||||
*
|
||||
@ -51,6 +54,7 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
|
||||
private Button showPerspectiveBox;
|
||||
private Button useDFABox;
|
||||
private Text maxViolationsPerFilePerRule;
|
||||
private Button reviewPmdStyleBox;
|
||||
|
||||
/**
|
||||
* Initialize the page
|
||||
@ -144,9 +148,10 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
|
||||
group.setLayout(new GridLayout(1, false));
|
||||
|
||||
// build children
|
||||
this.reviewPmdStyleBox = buildReviewPmdStyleBoxButton(group);
|
||||
Label separator = new Label(group, SWT.SEPARATOR | SWT.SHADOW_IN | SWT.HORIZONTAL);
|
||||
buildLabel(group, PMDConstants.MSGKEY_PREF_GENERAL_LABEL_ADDCOMMENT);
|
||||
this.additionalCommentText = buildAdditionalCommentText(group);
|
||||
Label separator = new Label(group, SWT.SEPARATOR | SWT.SHADOW_IN | SWT.HORIZONTAL);
|
||||
buildLabel(group, PMDConstants.MSGKEY_PREF_GENERAL_LABEL_SAMPLE);
|
||||
this.sampleLabel = buildSampleLabel(group);
|
||||
updateSampleLabel();
|
||||
@ -155,13 +160,18 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
|
||||
GridData data = new GridData();
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
data.grabExcessHorizontalSpace = true;
|
||||
this.additionalCommentText.setLayoutData(data);
|
||||
this.reviewPmdStyleBox.setLayoutData(data);
|
||||
|
||||
data = new GridData();
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
data.grabExcessHorizontalSpace = true;
|
||||
separator.setLayoutData(data);
|
||||
|
||||
data = new GridData();
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
data.grabExcessHorizontalSpace = true;
|
||||
this.additionalCommentText.setLayoutData(data);
|
||||
|
||||
data = new GridData();
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
data.grabExcessHorizontalSpace = true;
|
||||
@ -266,6 +276,20 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the check box for enabling PMD review style
|
||||
* @param viewGroup the parent composite
|
||||
*
|
||||
*/
|
||||
private Button buildReviewPmdStyleBoxButton(final Composite parent) {
|
||||
Button button = new Button(parent, SWT.CHECK);
|
||||
button.setText(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PREF_GENERAL_REVIEW_PMD_STYLE));
|
||||
button.setSelection(PMDPlugin.getDefault().isReviewPmdStyle());
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
|
||||
*/
|
||||
@ -329,12 +353,12 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
|
||||
}
|
||||
|
||||
if (this.showPerspectiveBox != null) {
|
||||
PMDPlugin.getDefault().getPreferenceStore().setValue(PMDPlugin.SHOW_PERSPECTIVE_ON_CHECK_PREFERENCE,
|
||||
PMDPlugin.getDefault().getPreferenceStore().setValue(PMDPluginConstants.SHOW_PERSPECTIVE_ON_CHECK_PREFERENCE,
|
||||
this.showPerspectiveBox.getSelection() ? 1 : -1);
|
||||
}
|
||||
|
||||
if (this.useDFABox != null) {
|
||||
PMDPlugin.getDefault().getPreferenceStore().setValue(PMDPlugin.USE_DFA_PREFERENCE,
|
||||
PMDPlugin.getDefault().getPreferenceStore().setValue(PMDPluginConstants.USE_DFA_PREFERENCE,
|
||||
this.useDFABox.getSelection() ? 1 : -1);
|
||||
}
|
||||
|
||||
@ -342,6 +366,10 @@ public class GeneralPreferencesPage extends PreferencePage implements IWorkbench
|
||||
PMDPlugin.getDefault().setMaxViolationsPerFilePerRule(Integer.valueOf(this.maxViolationsPerFilePerRule.getText()).intValue());
|
||||
}
|
||||
|
||||
if (this.reviewPmdStyleBox != null) {
|
||||
PMDPlugin.getDefault().setReviewPmdStyle(this.reviewPmdStyleBox.getSelection());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,7 @@ import java.util.Date;
|
||||
|
||||
import net.sourceforge.pmd.eclipse.PMDConstants;
|
||||
import net.sourceforge.pmd.eclipse.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.PMDPluginConstants;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -35,6 +36,9 @@ import org.eclipse.swt.widgets.Shell;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/05/07 12:03:09 phherlin
|
||||
* Add the possibility to use the PMD violation review style
|
||||
*
|
||||
* Revision 1.1 2005/10/24 22:45:58 phherlin
|
||||
* Integrating Sebastian Raffel's work
|
||||
* Move orginal Violations view to legacy
|
||||
@ -72,11 +76,14 @@ public class ReviewAction extends Action {
|
||||
*/
|
||||
public void run() {
|
||||
final IMarker[] markers = violationView.getSelectedViolations();
|
||||
final boolean reviewPmdStyle = PMDPlugin.getDefault().isReviewPmdStyle();
|
||||
|
||||
if (markers != null) {
|
||||
|
||||
// Get confirmation if multiple markers are selected
|
||||
// Not necessary when using PMD style
|
||||
boolean go = true;
|
||||
if (markers.length > 1) {
|
||||
if ((markers.length > 1) && (!reviewPmdStyle)) {
|
||||
String title = PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_CONFIRM_TITLE);
|
||||
String message = PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_CONFIRM_REVIEW_MULTIPLE_MARKERS);
|
||||
Shell shell = Display.getCurrent().getActiveShell();
|
||||
@ -91,7 +98,7 @@ public class ReviewAction extends Action {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
setMonitor(monitor);
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_MONITOR_REVIEW, ""), 5);
|
||||
insertReview(markers[0]);
|
||||
insertReview(markers[0], reviewPmdStyle);
|
||||
monitor.done();
|
||||
}
|
||||
});
|
||||
@ -108,7 +115,7 @@ public class ReviewAction extends Action {
|
||||
* Do the insertion of the review comment
|
||||
* @param marker
|
||||
*/
|
||||
protected void insertReview(IMarker marker) {
|
||||
protected void insertReview(IMarker marker, boolean reviewPmdStyle) {
|
||||
try {
|
||||
IResource resource = marker.getResource();
|
||||
if (resource instanceof IFile) {
|
||||
@ -122,7 +129,11 @@ public class ReviewAction extends Action {
|
||||
|
||||
monitorWorked();
|
||||
|
||||
sourceCode = addReviewComment(sourceCode, offset, marker);
|
||||
if (reviewPmdStyle) {
|
||||
sourceCode = addPmdReviewComment(sourceCode, offset, marker);
|
||||
} else {
|
||||
sourceCode = addPluginReviewComment(sourceCode, offset, marker);
|
||||
}
|
||||
|
||||
monitorWorked();
|
||||
|
||||
@ -130,10 +141,9 @@ public class ReviewAction extends Action {
|
||||
|
||||
monitorWorked();
|
||||
} else {
|
||||
MessageDialog.openError(
|
||||
Display.getCurrent().getActiveShell(),
|
||||
getMessage(PMDConstants.MSGKEY_ERROR_TITLE),
|
||||
"The file " + file.getName() + " doesn't exists ! Review aborted. Try to refresh the workspace and retry.");
|
||||
MessageDialog.openError(Display.getCurrent().getActiveShell(), getMessage(PMDConstants.MSGKEY_ERROR_TITLE),
|
||||
"The file " + file.getName()
|
||||
+ " doesn't exists ! Review aborted. Try to refresh the workspace and retry.");
|
||||
}
|
||||
|
||||
}
|
||||
@ -205,25 +215,69 @@ public class ReviewAction extends Action {
|
||||
}
|
||||
|
||||
/**
|
||||
* Insère un commentaire de révision juste au dessus de la ligne du marker
|
||||
* Insert a review comment with the Plugin style
|
||||
*/
|
||||
private String addReviewComment(String sourceCode, int offset, IMarker marker) {
|
||||
private String addPluginReviewComment(String sourceCode, int offset, IMarker marker) {
|
||||
String additionalCommentPattern = PMDPlugin.getDefault().getReviewAdditionalComment();
|
||||
String additionalComment =
|
||||
MessageFormat.format(additionalCommentPattern, new Object[] { System.getProperty("user.name", ""), new Date()});
|
||||
String additionalComment = MessageFormat.format(additionalCommentPattern, new Object[] {
|
||||
System.getProperty("user.name", ""), new Date() });
|
||||
|
||||
// Copy the source code until the violation line not included
|
||||
StringBuffer sb = new StringBuffer(sourceCode.substring(0, offset));
|
||||
|
||||
// Add the review comment
|
||||
sb.append(computeIndent(sourceCode, offset));
|
||||
sb.append(PMDPlugin.REVIEW_MARKER);
|
||||
sb.append(marker.getAttribute(PMDPlugin.KEY_MARKERATT_RULENAME, ""));
|
||||
sb.append(PMDPluginConstants.PLUGIN_STYLE_REVIEW_COMMENT);
|
||||
sb.append(marker.getAttribute(PMDPluginConstants.KEY_MARKERATT_RULENAME, ""));
|
||||
sb.append(": ");
|
||||
sb.append(additionalComment);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
|
||||
// Copy the rest of the source code
|
||||
sb.append(sourceCode.substring(offset));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a review comment with the PMD style
|
||||
*/
|
||||
private String addPmdReviewComment(String sourceCode, int offset, IMarker marker) {
|
||||
String result = sourceCode;
|
||||
String additionalCommentPattern = PMDPlugin.getDefault().getReviewAdditionalComment();
|
||||
String additionalComment = MessageFormat.format(additionalCommentPattern, new Object[] {
|
||||
System.getProperty("user.name", ""), new Date() });
|
||||
|
||||
// Find the end of line
|
||||
int index = sourceCode.substring(offset).indexOf('\r');
|
||||
if (index == -1) {
|
||||
index = sourceCode.substring(offset).indexOf('\n');
|
||||
if (index == -1) {
|
||||
index = sourceCode.substring(offset).length();
|
||||
}
|
||||
}
|
||||
index += offset;
|
||||
|
||||
// Insert comment only if it does not already exist
|
||||
if (sourceCode.substring(offset, index).indexOf(PMDPluginConstants.PMD_STYLE_REVIEW_COMMENT) == -1) {
|
||||
|
||||
// Copy the source code until the violation line included
|
||||
StringBuffer sb = new StringBuffer(sourceCode.substring(0, index));
|
||||
|
||||
// Add the review comment
|
||||
sb.append(' ');
|
||||
sb.append(PMDPlugin.PMD_STYLE_REVIEW_COMMENT);
|
||||
sb.append(' ');
|
||||
sb.append(additionalComment);
|
||||
|
||||
// Copy the rest of the code
|
||||
sb.append(sourceCode.substring(index));
|
||||
result = sb.toString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcul l'indentation employée sur la ligne du marker
|
||||
*/
|
||||
|
Reference in New Issue
Block a user