[java] SwitchDensityRule - use common report level property for "minimum"

While we calculate the ratio between number of statements and number of labels,
we shouldn't pretend that this is an exact rule - it's anyway a best guess,
that high switch density is a problem. I don't think, it makes a big difference
between 10.2 and 10. You e.g. want to report, when the density is bigger than 10
or bigger than 5. We don't need the report level accuracy here.

Refs #3123
This commit is contained in:
Andreas Dangel
2023-04-27 09:06:01 +02:00
parent aa38d6023b
commit 3fab198010

View File

@ -12,8 +12,8 @@ import net.sourceforge.pmd.lang.java.ast.ASTSwitchExpression;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchLike;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.rule.internal.CommonPropertyDescriptors;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* Switch Density - This is the number of statements over the number of
@ -28,12 +28,11 @@ import net.sourceforge.pmd.properties.PropertyFactory;
*/
public class SwitchDensityRule extends AbstractJavaRulechainRule {
private static final PropertyDescriptor<Double> REPORT_LEVEL =
// can't use CommonPropertyDescriptors because we need a double property
PropertyFactory.doubleProperty("minimum")
.desc("Threshold above which a node is reported")
private static final PropertyDescriptor<Integer> REPORT_LEVEL =
CommonPropertyDescriptors.reportLevelProperty()
.desc("Threshold above which a switch statement or expression is reported")
.require(positive())
.defaultValue(10d)
.defaultValue(10)
.build();
public SwitchDensityRule() {