Deprecate integer property

This commit is contained in:
Clément Fournier
2018-11-26 23:05:11 +01:00
parent 1db950bec6
commit 71713026ce
24 changed files with 215 additions and 96 deletions
@@ -4,20 +4,24 @@
package net.sourceforge.pmd.lang.apex.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import net.sourceforge.pmd.lang.apex.ast.ASTIfBlockStatement;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
public class AvoidDeeplyNestedIfStmtsRule extends AbstractApexRule {
private int depth;
private int depthLimit;
private static final IntegerProperty PROBLEM_DEPTH_DESCRIPTOR
= IntegerProperty.named("problemDepth")
private static final PropertyDescriptor<Integer> PROBLEM_DEPTH_DESCRIPTOR
= PropertyFactory.intProperty("problemDepth")
.desc("The if statement depth reporting threshold")
.range(1, 25).defaultValue(3).uiOrder(1.0f).build();
.require(positive()).defaultValue(3).build();
public AvoidDeeplyNestedIfStmtsRule() {
definePropertyDescriptor(PROBLEM_DEPTH_DESCRIPTOR);
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.apex.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRange;
import java.util.Stack;
import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
@@ -21,7 +23,9 @@ import net.sourceforge.pmd.lang.apex.ast.ASTUserTrigger;
import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
import net.sourceforge.pmd.properties.BooleanProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* Implements the standard cyclomatic complexity rule
@@ -36,10 +40,12 @@ import net.sourceforge.pmd.properties.IntegerProperty;
*/
public class StdCyclomaticComplexityRule extends AbstractApexRule {
public static final IntegerProperty REPORT_LEVEL_DESCRIPTOR
= IntegerProperty.named("reportLevel")
public static final PropertyDescriptor<Integer> REPORT_LEVEL_DESCRIPTOR
= PropertyFactory.intProperty("reportLevel")
.desc("Cyclomatic Complexity reporting threshold")
.range(1, 30).defaultValue(10).uiOrder(1.0f).build();
.require(inRange(1, 30))
.defaultValue(10)
.build();
public static final BooleanProperty SHOW_CLASSES_COMPLEXITY_DESCRIPTOR = new BooleanProperty(
"showClassesComplexity", "Add class average violations to the report", true, 2.0f);
@@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.apex.rule.design;
import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.FINAL;
import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.STATIC;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.HashMap;
import java.util.List;
@@ -15,7 +16,8 @@ import net.sourceforge.pmd.lang.apex.ast.ASTField;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
import net.sourceforge.pmd.util.NumericConstants;
public class TooManyFieldsRule extends AbstractApexRule {
@@ -25,8 +27,13 @@ public class TooManyFieldsRule extends AbstractApexRule {
private Map<String, Integer> stats;
private Map<String, ASTUserClass> nodes;
private static final IntegerProperty MAX_FIELDS_DESCRIPTOR = new IntegerProperty("maxfields",
"Max allowable fields", 1, 300, DEFAULT_MAXFIELDS, 1.0f);
private static final PropertyDescriptor<Integer> MAX_FIELDS_DESCRIPTOR
= PropertyFactory.intProperty("maxfields")
.desc("Max allowable fields")
.defaultValue(DEFAULT_MAXFIELDS)
.require(positive())
.build();
public TooManyFieldsRule() {
definePropertyDescriptor(MAX_FIELDS_DESCRIPTOR);
@@ -71,7 +78,7 @@ public class TooManyFieldsRule extends AbstractApexRule {
stats.put(key, NumericConstants.ZERO);
nodes.put(key, clazz);
}
Integer i = Integer.valueOf(stats.get(key) + 1);
Integer i = stats.get(key) + 1;
stats.put(key, i);
}
}
@@ -4,13 +4,16 @@
package net.sourceforge.pmd.lang.rule;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRange;
import java.util.List;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RulePriority;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* This is a Rule implementation which can be used in scenarios where an actual
@@ -23,7 +26,7 @@ public class MockRule extends AbstractRule {
public MockRule() {
super();
setLanguage(LanguageRegistry.getLanguage("Dummy"));
definePropertyDescriptor(IntegerProperty.named("testIntProperty").desc("testIntProperty").range(0, 100).defaultValue(1).uiOrder(0).build());
definePropertyDescriptor(PropertyFactory.intProperty("testIntProperty").desc("testIntProperty").require(inRange(1, 100)).defaultValue(1).build());
}
public MockRule(String name, String description, String message, String ruleSetName, RulePriority priority) {
@@ -14,7 +14,11 @@ import net.sourceforge.pmd.properties.builders.SingleNumericPropertyBuilder;
* Defines a datatype that supports single Integer property values within an upper and lower boundary.
*
* @author Brian Remedios
*
* @deprecated Use a {@code PropertyDescriptor<Integer>} instead. A builder is available from {@link PropertyFactory#intProperty(String)}.
* Will be removed in 7.0.0.
*/
@Deprecated
public final class IntegerProperty extends AbstractNumericProperty<Integer> {
@@ -29,7 +33,10 @@ public final class IntegerProperty extends AbstractNumericProperty<Integer> {
* @param theUIOrder UI order
*
* @throws IllegalArgumentException if {@literal min > max} or one of the defaults is not between the bounds
*
* @deprecated Use {@link PropertyFactory#intProperty(String)}
*/
@Deprecated
public IntegerProperty(String theName, String theDescription, Integer min, Integer max, Integer theDefault,
float theUIOrder) {
this(theName, theDescription, min, max, theDefault, theUIOrder, false);
@@ -65,11 +72,19 @@ public final class IntegerProperty extends AbstractNumericProperty<Integer> {
}
/**
* @deprecated Use {@link PropertyFactory#intProperty(String)}
*/
@Deprecated
public static IntegerPBuilder named(String name) {
return new IntegerPBuilder(name);
}
/**
* @deprecated Use {@link PropertyFactory#intProperty(String)}
*/
@Deprecated
public static final class IntegerPBuilder extends SingleNumericPropertyBuilder<Integer, IntegerPBuilder> {
private IntegerPBuilder(String name) {
super(name);
@@ -9,6 +9,8 @@ import java.util.Map;
import net.sourceforge.pmd.properties.PropertyBuilder.GenericCollectionPropertyBuilder;
import net.sourceforge.pmd.properties.PropertyBuilder.GenericPropertyBuilder;
import net.sourceforge.pmd.properties.constraints.NumericConstraints;
import net.sourceforge.pmd.properties.constraints.PropertyConstraint;
/**
@@ -28,6 +30,20 @@ public final class PropertyFactory {
}
/**
* Returns a builder for an integer property. The property descriptor
* will by default accept any value conforming to the format specified
* by {@link Integer#parseInt(String)}, e.g. {@code 1234} or {@code -123}.
* Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}.
* The class {@link NumericConstraints} provides some useful ready-made constraints
* for that purpose.
*
* @param name Name of the property to build
*
* @return A new builder
*
* @see NumericConstraints
*/
public static GenericPropertyBuilder<Integer> intProperty(String name) {
return new GenericPropertyBuilder<>(name, ValueParserConstants.INTEGER_PARSER, Integer.class);
}
@@ -4,6 +4,7 @@
package net.sourceforge.pmd;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -20,10 +21,11 @@ import net.sourceforge.pmd.lang.ast.DummyNode;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.AbstractRule;
import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
import net.sourceforge.pmd.properties.StringProperty;
public class AbstractRuleTest {
public static class MyRule extends AbstractRule {
@@ -86,7 +88,7 @@ public class AbstractRuleTest {
DummyNode s = new DummyNode(1);
s.testingOnlySetBeginColumn(5);
s.testingOnlySetBeginLine(5);
RuleViolation rv = new ParametricRuleViolation(r, ctx, s, "specificdescription");
RuleViolation rv = new ParametricRuleViolation<>(r, ctx, s, "specificdescription");
assertEquals("Line number mismatch!", 5, rv.getBeginLine());
assertEquals("Filename mismatch!", "filename", rv.getFilename());
assertEquals("Rule object mismatch!", r, rv.getRule());
@@ -96,7 +98,7 @@ public class AbstractRuleTest {
@Test
public void testRuleWithVariableInMessage() {
MyRule r = new MyRule();
r.definePropertyDescriptor(IntegerProperty.named("testInt").desc("description").range(0, 100).defaultValue(10).uiOrder(0).build());
r.definePropertyDescriptor(PropertyFactory.intProperty("testInt").desc("description").require(inRange(0, 100)).defaultValue(10).build());
r.setMessage("Message ${packageName} ${className} ${methodName} ${variableName} ${testInt} ${noSuchProperty}");
RuleContext ctx = new RuleContext();
ctx.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
@@ -123,7 +125,7 @@ public class AbstractRuleTest {
DummyNode n = new DummyNode(1);
n.testingOnlySetBeginColumn(5);
n.testingOnlySetBeginLine(5);
RuleViolation rv = new ParametricRuleViolation(r, ctx, n, "specificdescription");
RuleViolation rv = new ParametricRuleViolation<>(r, ctx, n, "specificdescription");
ctx.getReport().addRuleViolation(rv);
assertTrue(ctx.getReport().isEmpty());
}
@@ -15,6 +15,7 @@ import java.util.List;
*
* @author Brian Remedios
*/
@Deprecated
public class IntegerPropertyTest extends AbstractNumericPropertyDescriptorTester<Integer> {
private static final int MIN = 1;
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRange;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
@@ -34,7 +36,7 @@ public class NonRuleWithAllPropertyTypes extends AbstractRule {
public static final StringProperty SINGLE_STR = new StringProperty("singleStr", "String value", "hello world", 3.0f);
public static final StringMultiProperty MULTI_STR = new StringMultiProperty("multiStr", "Multiple string values",
new String[] {"hello", "world"}, 5.0f, '|');
public static final IntegerProperty SINGLE_INT = IntegerProperty.named("singleInt").desc("Single integer value").range(1, 10).defaultValue(8).uiOrder(3.0f).build();
public static final PropertyDescriptor<Integer> SINGLE_INT = PropertyFactory.intProperty("singleInt").desc("Single integer value").require(inRange(1, 10)).defaultValue(8).build();
public static final IntegerMultiProperty MULTI_INT = new IntegerMultiProperty("multiInt", "Multiple integer values",
0, 10, new Integer[] {1, 2, 3, 4}, 5.0f);
public static final LongProperty SINGLE_LONG = new LongProperty("singleLong", "Single long value", 1L, 10L, 8L,
@@ -4,20 +4,24 @@
package net.sourceforge.pmd.lang.java.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.ASTIfStatement;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
public class AvoidDeeplyNestedIfStmtsRule extends AbstractJavaRule {
private int depth;
private int depthLimit;
private static final IntegerProperty PROBLEM_DEPTH_DESCRIPTOR
= IntegerProperty.named("problemDepth")
private static final PropertyDescriptor<Integer> PROBLEM_DEPTH_DESCRIPTOR
= PropertyFactory.intProperty("problemDepth")
.desc("The if statement depth reporting threshold")
.range(1, 25).defaultValue(3).uiOrder(1.0f).build();
.require(positive()).defaultValue(3).build();
public AvoidDeeplyNestedIfStmtsRule() {
definePropertyDescriptor(PROBLEM_DEPTH_DESCRIPTOR);
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.HashSet;
import java.util.Set;
@@ -20,7 +22,9 @@ import net.sourceforge.pmd.lang.java.ast.ASTType;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.lang.java.symboltable.ClassScope;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* CouplingBetweenObjects attempts to capture all unique Class attributes, local
@@ -36,10 +40,10 @@ public class CouplingBetweenObjectsRule extends AbstractJavaRule {
private int couplingCount;
private Set<String> typesFoundSoFar;
private static final IntegerProperty THRESHOLD_DESCRIPTOR
= IntegerProperty.named("threshold")
private static final PropertyDescriptor<Integer> THRESHOLD_DESCRIPTOR
= PropertyFactory.intProperty("threshold")
.desc("Unique type reporting threshold")
.range(2, 100).defaultValue(20).uiOrder(1.0f).build();
.require(positive()).defaultValue(20).build();
public CouplingBetweenObjectsRule() {
definePropertyDescriptor(THRESHOLD_DESCRIPTOR);
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -21,7 +23,8 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaMetricsRule;
import net.sourceforge.pmd.lang.metrics.MetricOptions;
import net.sourceforge.pmd.lang.metrics.ResultOption;
import net.sourceforge.pmd.properties.EnumeratedMultiProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
@@ -37,21 +40,21 @@ public class CyclomaticComplexityRule extends AbstractJavaMetricsRule {
// Deprecated, kept for backwards compatibility (6.0.0)
@Deprecated
private static final IntegerProperty REPORT_LEVEL_DESCRIPTOR
= IntegerProperty.named("reportLevel")
private static final PropertyDescriptor<Integer> REPORT_LEVEL_DESCRIPTOR
= PropertyFactory.intProperty("reportLevel")
.desc("Deprecated! Cyclomatic Complexity reporting threshold")
.range(1, 30).defaultValue(10).uiOrder(1.0f).build();
.require(positive()).defaultValue(10).build();
private static final IntegerProperty CLASS_LEVEL_DESCRIPTOR
= IntegerProperty.named("classReportLevel")
private static final PropertyDescriptor<Integer> CLASS_LEVEL_DESCRIPTOR
= PropertyFactory.intProperty("classReportLevel")
.desc("Total class complexity reporting threshold")
.range(1, 600).defaultValue(80).uiOrder(1.0f).build();
.require(positive()).defaultValue(80).build();
private static final IntegerProperty METHOD_LEVEL_DESCRIPTOR
= IntegerProperty.named("methodReportLevel")
private static final PropertyDescriptor<Integer> METHOD_LEVEL_DESCRIPTOR
= PropertyFactory.intProperty("methodReportLevel")
.desc("Cyclomatic complexity reporting threshold")
.range(1, 50).defaultValue(10).uiOrder(1.0f).build();
.require(positive()).defaultValue(10).build();
private static final Map<String, CycloOption> OPTION_MAP;
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.logging.Logger;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
@@ -14,7 +16,8 @@ import net.sourceforge.pmd.lang.java.metrics.JavaMetrics;
import net.sourceforge.pmd.lang.java.metrics.api.JavaOperationMetricKey;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaMetricsRule;
import net.sourceforge.pmd.properties.DoubleProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
@@ -33,9 +36,9 @@ public class NPathComplexityRule extends AbstractJavaMetricsRule {
.range(0d, 2000d).defaultValue(200d).uiOrder(2.0f).build();
private static final IntegerProperty REPORT_LEVEL_DESCRIPTOR
= IntegerProperty.named("reportLevel").desc("N-Path Complexity reporting threshold")
.range(1, 2000).defaultValue(200).uiOrder(1.0f).build();
private static final PropertyDescriptor<Integer> REPORT_LEVEL_DESCRIPTOR
= PropertyFactory.intProperty("reportLevel").desc("N-Path Complexity reporting threshold")
.require(positive()).defaultValue(200).build();
private int reportLevel = 200;
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
@@ -21,7 +23,9 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaMetricsRule;
import net.sourceforge.pmd.lang.metrics.MetricOptions;
import net.sourceforge.pmd.lang.metrics.ResultOption;
import net.sourceforge.pmd.properties.EnumeratedMultiProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* Simple rule for Ncss. Maybe to be enriched with type specific thresholds.
@@ -31,17 +35,17 @@ import net.sourceforge.pmd.properties.IntegerProperty;
public final class NcssCountRule extends AbstractJavaMetricsRule {
private static final IntegerProperty METHOD_REPORT_LEVEL_DESCRIPTOR =
IntegerProperty.named("methodReportLevel")
private static final PropertyDescriptor<Integer> METHOD_REPORT_LEVEL_DESCRIPTOR =
PropertyFactory.intProperty("methodReportLevel")
.desc("NCSS reporting threshold for methods")
.range(1, 2000)
.require(positive())
.defaultValue(60)
.build();
private static final IntegerProperty CLASS_REPORT_LEVEL_DESCRIPTOR =
IntegerProperty.named("classReportLevel")
private static final PropertyDescriptor<Integer> CLASS_REPORT_LEVEL_DESCRIPTOR =
PropertyFactory.intProperty("classReportLevel")
.desc("NCSS reporting threshold for classes")
.range(1, 20000)
.require(positive())
.defaultValue(1500)
.build();
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.ArrayDeque;
import java.util.Deque;
@@ -25,7 +27,9 @@ import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement;
import net.sourceforge.pmd.lang.java.ast.ASTWhileStatement;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.properties.BooleanProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* Implements the standard cyclomatic complexity rule
@@ -40,10 +44,10 @@ import net.sourceforge.pmd.properties.IntegerProperty;
@Deprecated
public class StdCyclomaticComplexityRule extends AbstractJavaRule {
public static final IntegerProperty REPORT_LEVEL_DESCRIPTOR
= IntegerProperty.named("reportLevel")
public static final PropertyDescriptor<Integer> REPORT_LEVEL_DESCRIPTOR
= PropertyFactory.intProperty("reportLevel")
.desc("Cyclomatic Complexity reporting threshold")
.range(1, 30).defaultValue(10).uiOrder(1.0f).build();
.require(positive()).defaultValue(10).build();
public static final BooleanProperty SHOW_CLASSES_COMPLEXITY_DESCRIPTOR = new BooleanProperty(
"showClassesComplexity", "Add class average violations to the report", true, 2.0f);
@@ -4,19 +4,27 @@
package net.sourceforge.pmd.lang.java.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.List;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
public class TooManyFieldsRule extends AbstractJavaRule {
private static final int DEFAULT_MAXFIELDS = 15;
private static final IntegerProperty MAX_FIELDS_DESCRIPTOR = new IntegerProperty("maxfields",
"Max allowable fields", 1, 300, DEFAULT_MAXFIELDS, 1.0f);
private static final PropertyDescriptor<Integer> MAX_FIELDS_DESCRIPTOR
= PropertyFactory.intProperty("maxfields")
.desc("Max allowable fields")
.defaultValue(DEFAULT_MAXFIELDS)
.require(positive())
.build();
public TooManyFieldsRule() {
definePropertyDescriptor(MAX_FIELDS_DESCRIPTOR);
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.documentation;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.ArrayList;
import java.util.List;
@@ -11,7 +13,8 @@ import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.Comment;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
import net.sourceforge.pmd.util.StringUtil;
/**
@@ -21,15 +24,15 @@ import net.sourceforge.pmd.util.StringUtil;
*/
public class CommentSizeRule extends AbstractCommentRule {
public static final IntegerProperty MAX_LINES
= IntegerProperty.named("maxLines")
public static final PropertyDescriptor<Integer> MAX_LINES
= PropertyFactory.intProperty("maxLines")
.desc("Maximum lines")
.range(2, 200).defaultValue(6).uiOrder(2.0f).build();
.require(positive()).defaultValue(6).build();
public static final IntegerProperty MAX_LINE_LENGTH
= IntegerProperty.named("maxLineLength")
public static final PropertyDescriptor<Integer> MAX_LINE_LENGTH
= PropertyFactory.intProperty("maxLineLength")
.desc("Maximum line length")
.range(1, 200).defaultValue(80).uiOrder(2.0f).build();
.require(positive()).defaultValue(80).build();
private static final String CR = "\n";
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.errorprone;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.io.File;
import java.io.IOException;
import java.io.LineNumberReader;
@@ -25,19 +27,20 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.properties.BooleanProperty;
import net.sourceforge.pmd.properties.CharacterProperty;
import net.sourceforge.pmd.properties.FileProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
import net.sourceforge.pmd.properties.PropertySource;
import net.sourceforge.pmd.properties.StringProperty;
public class AvoidDuplicateLiteralsRule extends AbstractJavaRule {
public static final IntegerProperty THRESHOLD_DESCRIPTOR
= IntegerProperty.named("maxDuplicateLiterals")
public static final PropertyDescriptor<Integer> THRESHOLD_DESCRIPTOR
= PropertyFactory.intProperty("maxDuplicateLiterals")
.desc("Max duplicate literals")
.range(1, 20).defaultValue(4).uiOrder(1.0f).build();
.require(positive()).defaultValue(4).build();
public static final IntegerProperty MINIMUM_LENGTH_DESCRIPTOR = new IntegerProperty("minimumLength",
"Minimum string length to check", 1, Integer.MAX_VALUE, 3, 1.5f);
public static final PropertyDescriptor<Integer> MINIMUM_LENGTH_DESCRIPTOR = PropertyFactory.intProperty("minimumLength").desc("Minimum string length to check").require(positive()).defaultValue(3).build();
public static final BooleanProperty SKIP_ANNOTATIONS_DESCRIPTOR = new BooleanProperty("skipAnnotations",
"Skip literals within annotations", false, 2.0f);
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.errorprone;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRange;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
@@ -20,7 +22,9 @@ import net.sourceforge.pmd.lang.dfa.pathfinder.Executable;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* Starts path search for each method and runs code if found.
@@ -29,18 +33,18 @@ import net.sourceforge.pmd.properties.IntegerProperty;
* @author Sven Jacob
*/
public class DataflowAnomalyAnalysisRule extends AbstractJavaRule implements Executable {
private static final IntegerProperty MAX_PATH_DESCRIPTOR
= IntegerProperty.named("maxPaths")
private static final PropertyDescriptor<Integer> MAX_PATH_DESCRIPTOR
= PropertyFactory.intProperty("maxPaths")
.desc("Maximum number of checked paths per method. A lower value will increase the performance of the rule but may decrease anomalies found.")
.range(100, 8000)
.require(inRange(100, 8000))
.defaultValue(1000)
.uiOrder(1.0f).build();
private static final IntegerProperty MAX_VIOLATIONS_DESCRIPTOR
= IntegerProperty.named("maxViolations")
.build();
private static final PropertyDescriptor<Integer> MAX_VIOLATIONS_DESCRIPTOR
= PropertyFactory.intProperty("maxViolations")
.desc("Maximum number of anomalies per class")
.range(1, 2000)
.require(inRange(1, 2000))
.defaultValue(100)
.uiOrder(2.0f).build();
.build();
private RuleContext rc;
private List<DaaRuleViolation> daaRuleViolations;
private int maxRuleViolations;
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.rule.performance;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRange;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -33,7 +35,9 @@ import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence;
import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration;
import net.sourceforge.pmd.lang.java.typeresolution.TypeHelper;
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* This rule finds concurrent calls to StringBuffer/Builder.append where String
@@ -72,10 +76,10 @@ public class ConsecutiveLiteralAppendsRule extends AbstractJavaRule {
BLOCK_PARENTS.add(ASTMethodDeclaration.class);
}
private static final IntegerProperty THRESHOLD_DESCRIPTOR
= IntegerProperty.named("threshold")
private static final PropertyDescriptor<Integer> THRESHOLD_DESCRIPTOR
= PropertyFactory.intProperty("threshold")
.desc("Max consecutive appends")
.range(1, 10).defaultValue(1).uiOrder(1.0f).build();
.require(inRange(1, 10)).defaultValue(1).build();
private int threshold = 1;
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.plsql.rule.codestyle;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRange;
import java.util.List;
import net.sourceforge.pmd.lang.ast.Node;
@@ -23,12 +25,14 @@ import net.sourceforge.pmd.lang.plsql.ast.ASTSubqueryOperation;
import net.sourceforge.pmd.lang.plsql.ast.ASTUnqualifiedID;
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclarator;
import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
public class CodeFormatRule extends AbstractPLSQLRule {
private static final IntegerProperty INDENTATION_PROPERTY = IntegerProperty.named("indentation")
.desc("Indentation to be used for blocks").defaultValue(2).range(0, 20).build();
private static final PropertyDescriptor<Integer> INDENTATION_PROPERTY = PropertyFactory.intProperty("indentation")
.desc("Indentation to be used for blocks").defaultValue(2).require(inRange(0, 32)).build();
private int indentation = INDENTATION_PROPERTY.defaultValue();
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.plsql.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -30,7 +32,9 @@ import net.sourceforge.pmd.lang.plsql.ast.ASTTypeSpecification;
import net.sourceforge.pmd.lang.plsql.ast.ASTWhileStatement;
import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule;
import net.sourceforge.pmd.properties.BooleanProperty;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
/**
* @author Donald A. Leckie,
@@ -43,10 +47,10 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
private static final Logger LOGGER = Logger.getLogger(CyclomaticComplexityRule.class.getName());
private static final String CLASS_NAME = CyclomaticComplexityRule.class.getName();
public static final IntegerProperty REPORT_LEVEL_DESCRIPTOR
= IntegerProperty.named("reportLevel")
public static final PropertyDescriptor<Integer> REPORT_LEVEL_DESCRIPTOR
= PropertyFactory.intProperty("reportLevel")
.desc("Cyclomatic Complexity reporting threshold")
.range(1, 30).defaultValue(10).uiOrder(1.0f).build();
.require(positive()).defaultValue(10).build();
public static final BooleanProperty SHOW_CLASSES_COMPLEXITY_DESCRIPTOR = new BooleanProperty(
"showClassesComplexity", "Add class average violations to the report", true, 2.0f);
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.plsql.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -15,7 +17,8 @@ import net.sourceforge.pmd.lang.plsql.ast.ASTTypeSpecification;
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode;
import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
import net.sourceforge.pmd.util.NumericConstants;
public class TooManyFieldsRule extends AbstractPLSQLRule {
@@ -25,8 +28,12 @@ public class TooManyFieldsRule extends AbstractPLSQLRule {
private Map<String, Integer> stats;
private Map<String, PLSQLNode> nodes;
private static final IntegerProperty MAX_FIELDS_DESCRIPTOR = new IntegerProperty("maxfields",
"Max allowable fields", 1, 300, DEFAULT_MAXFIELDS, 1.0f);
private static final PropertyDescriptor<Integer> MAX_FIELDS_DESCRIPTOR
= PropertyFactory.intProperty("maxfields")
.desc("Max allowable fields")
.defaultValue(DEFAULT_MAXFIELDS)
.require(positive())
.build();
public TooManyFieldsRule() {
definePropertyDescriptor(MAX_FIELDS_DESCRIPTOR);
@@ -87,7 +94,7 @@ public class TooManyFieldsRule extends AbstractPLSQLRule {
stats.put(key, NumericConstants.ZERO);
nodes.put(key, clazz);
}
Integer i = Integer.valueOf(stats.get(key) + 1);
Integer i = stats.get(key) + 1;
stats.put(key, i);
}
}
@@ -4,22 +4,26 @@
package net.sourceforge.pmd.lang.vm.rule.design;
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
import net.sourceforge.pmd.lang.vm.ast.ASTElseIfStatement;
import net.sourceforge.pmd.lang.vm.ast.ASTIfStatement;
import net.sourceforge.pmd.lang.vm.ast.ASTprocess;
import net.sourceforge.pmd.lang.vm.ast.AbstractVmNode;
import net.sourceforge.pmd.lang.vm.rule.AbstractVmRule;
import net.sourceforge.pmd.properties.IntegerProperty;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
public class AvoidDeeplyNestedIfStmtsRule extends AbstractVmRule {
private int depth;
private int depthLimit;
private static final IntegerProperty PROBLEM_DEPTH_DESCRIPTOR
= IntegerProperty.named("problemDepth")
private static final PropertyDescriptor<Integer> PROBLEM_DEPTH_DESCRIPTOR
= PropertyFactory.intProperty("problemDepth")
.desc("The if statement depth reporting threshold")
.range(1, 25).defaultValue(3).uiOrder(1.0f).build();
.require(positive()).defaultValue(3).build();
public AvoidDeeplyNestedIfStmtsRule() {
definePropertyDescriptor(PROBLEM_DEPTH_DESCRIPTOR);