diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/apexunit/AbstractApexUnitTestRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/apexunit/AbstractApexUnitTestRule.java index 5902df2768..d4bb22d466 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/apexunit/AbstractApexUnitTestRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/apexunit/AbstractApexUnitTestRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.apexunit; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ApexNode; @@ -19,7 +21,7 @@ import apex.jorje.services.Version; public abstract class AbstractApexUnitTestRule extends AbstractApexRule { public AbstractApexUnitTestRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Bug Risk" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Bug Risk")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java index c2bdf71f42..9f6b69386c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AbstractNcssCountRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTBreakStatement; import net.sourceforge.pmd.lang.apex.ast.ASTContinueStatement; import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement; @@ -43,7 +45,7 @@ public abstract class AbstractNcssCountRule extends AbstractStatisticalApexRule this.nodeClass = nodeClass; setProperty(MINIMUM_DESCRIPTOR, 1000d); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AvoidDeeplyNestedIfStmtsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AvoidDeeplyNestedIfStmtsRule.java index 9e3d56aab6..758080f9d3 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AvoidDeeplyNestedIfStmtsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/AvoidDeeplyNestedIfStmtsRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTIfBlockStatement; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; @@ -20,7 +22,7 @@ public class AvoidDeeplyNestedIfStmtsRule extends AbstractApexRule { public AvoidDeeplyNestedIfStmtsRule() { definePropertyDescriptor(PROBLEM_DEPTH_DESCRIPTOR); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); // Note: Remedy needs better OO design and therefore high effort setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 200); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveClassLengthRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveClassLengthRule.java index 967ee88d8e..c4addbf62d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveClassLengthRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveClassLengthRule.java @@ -6,6 +6,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; import static apex.jorje.semantic.symbol.type.AnnotationTypeInfos.IS_TEST; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; /** @@ -17,7 +19,7 @@ public class ExcessiveClassLengthRule extends ExcessiveLengthRule { super(ASTUserClass.class); setProperty(MINIMUM_DESCRIPTOR, 1000d); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 150); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveParameterListRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveParameterListRule.java index 33d7f426db..192cea0aeb 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveParameterListRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessiveParameterListRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTParameter; import net.sourceforge.pmd.util.NumericConstants; @@ -17,7 +19,7 @@ public class ExcessiveParameterListRule extends ExcessiveNodeCountRule { public ExcessiveParameterListRule() { super(ASTMethod.class); setProperty(MINIMUM_DESCRIPTOR, 4d); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessivePublicCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessivePublicCountRule.java index 0e1ba3ff10..5f0406bf78 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessivePublicCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/ExcessivePublicCountRule.java @@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.PUBLIC; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.STATIC; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclarationStatements; import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; @@ -31,7 +33,7 @@ public class ExcessivePublicCountRule extends ExcessiveNodeCountRule { public ExcessivePublicCountRule() { super(ASTUserClass.class); setProperty(MINIMUM_DESCRIPTOR, 20d); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 150); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssConstructorCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssConstructorCountRule.java index 9ed2f50619..9536f5729b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssConstructorCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssConstructorCountRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.stat.DataPoint; import net.sourceforge.pmd.util.NumericConstants; @@ -21,7 +23,7 @@ public class NcssConstructorCountRule extends AbstractNcssCountRule { public NcssConstructorCountRule() { super(ASTMethod.class); setProperty(MINIMUM_DESCRIPTOR, 20d); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssMethodCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssMethodCountRule.java index dca48fea62..b0606c53ef 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssMethodCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssMethodCountRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.stat.DataPoint; import net.sourceforge.pmd.util.NumericConstants; @@ -21,7 +23,7 @@ public class NcssMethodCountRule extends AbstractNcssCountRule { public NcssMethodCountRule() { super(ASTMethod.class); setProperty(MINIMUM_DESCRIPTOR, 40d); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssTypeCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssTypeCountRule.java index b6bf892da8..671d6df53e 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssTypeCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/NcssTypeCountRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclaration; import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; @@ -26,7 +28,7 @@ public class NcssTypeCountRule extends AbstractNcssCountRule { public NcssTypeCountRule() { super(ASTUserClass.class); setProperty(MINIMUM_DESCRIPTOR, 500d); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 250); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/StdCyclomaticComplexityRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/StdCyclomaticComplexityRule.java index f718e5aa33..9428990be3 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/StdCyclomaticComplexityRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/StdCyclomaticComplexityRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; +import java.util.Arrays; import java.util.Stack; import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression; @@ -78,7 +79,7 @@ public class StdCyclomaticComplexityRule extends AbstractApexRule { definePropertyDescriptor(SHOW_CLASSES_COMPLEXITY_DESCRIPTOR); definePropertyDescriptor(SHOW_METHODS_COMPLEXITY_DESCRIPTOR); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 250); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/TooManyFieldsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/TooManyFieldsRule.java index 34b8350192..fa5fca8883 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/TooManyFieldsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/complexity/TooManyFieldsRule.java @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.apex.rule.complexity; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.FINAL; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.STATIC; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,7 +32,7 @@ public class TooManyFieldsRule extends AbstractApexRule { public TooManyFieldsRule() { definePropertyDescriptor(MAX_FIELDS_DESCRIPTOR); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Complexity")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 200); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidDmlStatementsInLoopsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidDmlStatementsInLoopsRule.java index a6a08a81e4..cdeaf0ef25 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidDmlStatementsInLoopsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidDmlStatementsInLoopsRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.performance; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTDmlDeleteStatement; import net.sourceforge.pmd.lang.apex.ast.ASTDmlInsertStatement; import net.sourceforge.pmd.lang.apex.ast.ASTDmlMergeStatement; @@ -21,7 +23,7 @@ import net.sourceforge.pmd.lang.ast.Node; public class AvoidDmlStatementsInLoopsRule extends AbstractApexRule { public AvoidDmlStatementsInLoopsRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Performance" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Performance")); // Note: Often more complicated as just moving the SOQL a few lines. // Involves Maps... setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 150); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidSoqlInLoopsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidSoqlInLoopsRule.java index f974cd15e1..345bcae677 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidSoqlInLoopsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/performance/AvoidSoqlInLoopsRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.performance; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement; import net.sourceforge.pmd.lang.apex.ast.ASTForEachStatement; import net.sourceforge.pmd.lang.apex.ast.ASTForLoopStatement; @@ -16,7 +18,7 @@ import net.sourceforge.pmd.lang.ast.Node; public class AvoidSoqlInLoopsRule extends AbstractApexRule { public AvoidSoqlInLoopsRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Performance" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Performance")); // Note: Often more complicated as just moving the SOQL a few lines. // Involves Maps... setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 150); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexBadCryptoRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexBadCryptoRule.java index ec78cd699e..deffa03d2d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexBadCryptoRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexBadCryptoRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -34,7 +35,7 @@ public class ApexBadCryptoRule extends AbstractApexRule { private final Set potentiallyStaticBlob = new HashSet<>(); public ApexBadCryptoRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java index 654bb5bbdf..c715e5db57 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java @@ -90,7 +90,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule { private static final String[] RESERVED_KEYS_FLS = new String[] { "Schema", S_OBJECT_TYPE, }; public ApexCRUDViolationRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCSRFRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCSRFRule.java index 7f9641c926..7c55adf594 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCSRFRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCSRFRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ApexNode; @@ -20,7 +22,7 @@ public class ApexCSRFRule extends AbstractApexRule { public static final String INIT = "init"; public ApexCSRFRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexDangerousMethodsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexDangerousMethodsRule.java index 54fd0b4ddf..d80b21de92 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexDangerousMethodsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexDangerousMethodsRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.regex.Pattern; @@ -39,7 +40,7 @@ public class ApexDangerousMethodsRule extends AbstractApexRule { public ApexDangerousMethodsRule() { super.addRuleChainVisit(ASTUserClass.class); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexInsecureEndpointRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexInsecureEndpointRule.java index 8366c40a7a..b8819f35e2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexInsecureEndpointRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexInsecureEndpointRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -32,7 +33,7 @@ public class ApexInsecureEndpointRule extends AbstractApexRule { private final Set httpEndpointStrings = new HashSet<>(); public ApexInsecureEndpointRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java index ac4b3b188e..0c23b3a7f4 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexOpenRedirectRule.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -37,7 +38,7 @@ public class ApexOpenRedirectRule extends AbstractApexRule { public ApexOpenRedirectRule() { super.addRuleChainVisit(ASTUserClass.class); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSOQLInjectionRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSOQLInjectionRule.java index 5b372fa7f5..01365fa4e2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSOQLInjectionRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSOQLInjectionRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -49,7 +50,7 @@ public class ApexSOQLInjectionRule extends AbstractApexRule { private final HashMap selectContainingVariables = new HashMap<>(); public ApexSOQLInjectionRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java index 7359e26dde..c2ff1787db 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.List; import java.util.WeakHashMap; @@ -26,7 +27,7 @@ public class ApexSharingViolationsRule extends AbstractApexRule { private WeakHashMap, Object> localCacheOfReportedNodes = new WeakHashMap<>(); public ApexSharingViolationsRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSuggestUsingNamedCredRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSuggestUsingNamedCredRule.java index a256a4d2da..c8124e8f37 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSuggestUsingNamedCredRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSuggestUsingNamedCredRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -34,7 +35,7 @@ public class ApexSuggestUsingNamedCredRule extends AbstractApexRule { public ApexSuggestUsingNamedCredRule() { super.addRuleChainVisit(ASTUserClass.class); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromEscapeFalseRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromEscapeFalseRule.java index 53dff5bc6b..748d97e552 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromEscapeFalseRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromEscapeFalseRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.List; import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression; @@ -22,7 +23,7 @@ public class ApexXSSFromEscapeFalseRule extends AbstractApexRule { private static final String ADD_ERROR = "addError"; public ApexXSSFromEscapeFalseRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java index 1cb85f11d1..e96dc6b1a7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexXSSFromURLParamRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.security; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -50,7 +51,7 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule { private final Set urlParameterStrings = new HashSet<>(); public ApexXSSFromURLParamRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Security")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidGlobalModifierRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidGlobalModifierRule.java index 9b55610caa..742a8c140a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidGlobalModifierRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidGlobalModifierRule.java @@ -6,6 +6,8 @@ package net.sourceforge.pmd.lang.apex.rule.style; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.GLOBAL; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface; @@ -15,7 +17,7 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; public class AvoidGlobalModifierRule extends AbstractApexRule { public AvoidGlobalModifierRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Style")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 100); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidLogicInTriggerRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidLogicInTriggerRule.java index 02b819e624..f6d871acbf 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidLogicInTriggerRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidLogicInTriggerRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.style; +import java.util.Arrays; import java.util.List; import net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement; @@ -13,7 +14,7 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; public class AvoidLogicInTriggerRule extends AbstractApexRule { public AvoidLogicInTriggerRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Style")); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 200); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/ClassNamingConventionsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/ClassNamingConventionsRule.java index 15895262be..6d9554559b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/ClassNamingConventionsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/ClassNamingConventionsRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.apex.rule.style; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; @@ -11,7 +13,7 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; public class ClassNamingConventionsRule extends AbstractApexRule { public ClassNamingConventionsRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Style")); // Note: x10 as Apex has not automatic refactoring setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 5); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodNamingConventionsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodNamingConventionsRule.java index 08b78c6b3d..301d5be2c9 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodNamingConventionsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodNamingConventionsRule.java @@ -6,6 +6,8 @@ package net.sourceforge.pmd.lang.apex.rule.style; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.OVERRIDE; +import java.util.Arrays; + import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTProperty; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; @@ -14,7 +16,7 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; public class MethodNamingConventionsRule extends AbstractApexRule { public MethodNamingConventionsRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Style")); // Note: x10 as Apex has not automatic refactoring setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 1); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodWithSameNameAsEnclosingClassRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodWithSameNameAsEnclosingClassRule.java index ea0544d0c2..177299ac01 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodWithSameNameAsEnclosingClassRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/MethodWithSameNameAsEnclosingClassRule.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.rule.style; +import java.util.Arrays; import java.util.List; import net.sourceforge.pmd.lang.apex.ast.ASTMethod; @@ -13,7 +14,7 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; public class MethodWithSameNameAsEnclosingClassRule extends AbstractApexRule { public MethodWithSameNameAsEnclosingClassRule() { - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Style")); // Note: x10 as Apex has not automatic refactoring setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/VariableNamingConventionsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/VariableNamingConventionsRule.java index 4efeebaa67..911f288bb9 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/VariableNamingConventionsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/VariableNamingConventionsRule.java @@ -7,6 +7,9 @@ package net.sourceforge.pmd.lang.apex.rule.style; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.FINAL; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.STATIC; +import java.util.Arrays; +import java.util.List; + import net.sourceforge.pmd.PropertyDescriptor; import net.sourceforge.pmd.lang.apex.ast.ASTField; import net.sourceforge.pmd.lang.apex.ast.ASTParameter; @@ -17,21 +20,20 @@ import net.sourceforge.pmd.lang.apex.ast.ApexNode; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; import net.sourceforge.pmd.lang.rule.properties.BooleanProperty; import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty; -import net.sourceforge.pmd.util.CollectionUtil; public class VariableNamingConventionsRule extends AbstractApexRule { private boolean checkMembers; private boolean checkLocals; private boolean checkParameters; - private String[] staticPrefixes; - private String[] staticSuffixes; - private String[] memberPrefixes; - private String[] memberSuffixes; - private String[] localPrefixes; - private String[] localSuffixes; - private String[] parameterPrefixes; - private String[] parameterSuffixes; + private List staticPrefixes; + private List staticSuffixes; + private List memberPrefixes; + private List memberSuffixes; + private List localPrefixes; + private List localSuffixes; + private List parameterPrefixes; + private List parameterSuffixes; private static final BooleanProperty CHECK_MEMBERS_DESCRIPTOR = new BooleanProperty("checkMembers", "Check member variables", true, 1.0f); @@ -79,7 +81,7 @@ public class VariableNamingConventionsRule extends AbstractApexRule { definePropertyDescriptor(PARAMETER_PREFIXES_DESCRIPTOR); definePropertyDescriptor(PARAMETER_SUFFIXES_DESCRIPTOR); - setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); + setProperty(CODECLIMATE_CATEGORIES, Arrays.asList("Style")); // Note: x10 as Apex has not automatic refactoring setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 5); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); @@ -139,7 +141,7 @@ public class VariableNamingConventionsRule extends AbstractApexRule { return checkName(parameterPrefixes, parameterSuffixes, node, false, isFinal, data); } - private Object checkName(String[] prefixes, String[] suffixes, ApexNode node, boolean isStatic, boolean isFinal, + private Object checkName(List prefixes, List suffixes, ApexNode node, boolean isStatic, boolean isFinal, Object data) { String varName = node.getImage(); @@ -174,15 +176,15 @@ public class VariableNamingConventionsRule extends AbstractApexRule { return data; } - private String normalizeVariableName(String varName, String[] prefixes, String[] suffixes) { + private String normalizeVariableName(String varName, List prefixes, List suffixes) { return stripSuffix(stripPrefix(varName, prefixes), suffixes); } - private String stripSuffix(String varName, String[] suffixes) { + private String stripSuffix(String varName, List suffixes) { if (suffixes != null) { - for (int i = 0; i < suffixes.length; i++) { - if (varName.endsWith(suffixes[i])) { - varName = varName.substring(0, varName.length() - suffixes[i].length()); + for (String suffix : suffixes) { + if (varName.endsWith(suffix)) { + varName = varName.substring(0, varName.length() - suffix.length()); break; } } @@ -190,11 +192,11 @@ public class VariableNamingConventionsRule extends AbstractApexRule { return varName; } - private String stripPrefix(String varName, String[] prefixes) { + private String stripPrefix(String varName, List prefixes) { if (prefixes != null) { - for (int i = 0; i < prefixes.length; i++) { - if (varName.startsWith(prefixes[i])) { - return varName.substring(prefixes[i].length()); + for (String prefix : prefixes) { + if (varName.startsWith(prefix)) { + return varName.substring(prefix.length()); } } } @@ -205,8 +207,8 @@ public class VariableNamingConventionsRule extends AbstractApexRule { for (PropertyDescriptor desc : getPropertyDescriptors()) { if (desc instanceof StringMultiProperty) { - String[] values = getProperty((StringMultiProperty) desc); - if (CollectionUtil.isNotEmpty(values)) { + List values = getProperty((StringMultiProperty) desc); + if (!values.isEmpty()) { return true; } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java index f2d66cc9fa..cbb1b4fd2e 100755 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java @@ -9,6 +9,7 @@ import java.util.Map; /** * A factory to create {@link PropertyDescriptor}s based on a map of values. * + * @param the type of values property descriptor returned by this factory. This can be a list. * @author Brian Remedios */ public interface PropertyDescriptorFactory { @@ -21,6 +22,8 @@ public interface PropertyDescriptorFactory { */ Class valueType(); + boolean isMultiValue(); + /** * Denote the identifiers of the expected fields paired with booleans * denoting whether they are required (non-null) or not. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java index edf7068713..47dbf5da56 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java @@ -265,21 +265,11 @@ public class RuleSetWriter { Element propertiesElement = null; if (propertyDescriptors != null) { - for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { // For - // each - // provided - // PropertyDescriptor + for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { + // For each provided PropertyDescriptor - if (propertyDescriptor instanceof PropertyDescriptorWrapper) { // Any - // wrapper - // property - // needs - // to - // go - // out - // as - // a - // definition. + if (propertyDescriptor instanceof PropertyDescriptorWrapper) { + // Any wrapper property needs to go out as a definition. if (propertiesElement == null) { propertiesElement = createPropertiesElement(); } @@ -288,17 +278,8 @@ public class RuleSetWriter { ((PropertyDescriptorWrapper) propertyDescriptor).getPropertyDescriptor()); propertiesElement.appendChild(propertyElement); } else { - if (propertiesByPropertyDescriptor != null) { // Otherwise, - // any - // property - // which has a - // value - // different - // than the - // default - // needs to go - // out as a - // value. + if (propertiesByPropertyDescriptor != null) { + // Otherwise, any property which has a value different than the default needs to go out as a value. Object defaultValue = propertyDescriptor.defaultValue(); Object value = propertiesByPropertyDescriptor.get(propertyDescriptor); if (value != defaultValue && (value == null || !value.equals(defaultValue))) { @@ -385,7 +366,8 @@ public class RuleSetWriter { final Element propertyElement = createPropertyValueElement(propertyDescriptor, propertyDescriptor.defaultValue()); propertyElement.setAttribute(PropertyDescriptorField.TYPE.attributeName, - PropertyDescriptorUtil.typeIdFor(propertyDescriptor.type())); + PropertyDescriptorUtil.typeIdFor(propertyDescriptor.type(), + propertyDescriptor.isMultiValue())); Map propertyValuesById = propertyDescriptor.attributeValuesById(); for (Map.Entry entry : propertyValuesById.entrySet()) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BasicPropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BasicPropertyDescriptorFactory.java index c6973ecd31..e6c5889d02 100755 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BasicPropertyDescriptorFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BasicPropertyDescriptorFactory.java @@ -31,7 +31,7 @@ import net.sourceforge.pmd.util.StringUtil; * * @author Brian Remedios */ -public class BasicPropertyDescriptorFactory implements PropertyDescriptorFactory { +public abstract class BasicPropertyDescriptorFactory implements PropertyDescriptorFactory { protected static final Map CORE_FIELD_TYPES_BY_KEY = CollectionUtil.mapFrom(new PropertyDescriptorField[] {NAME, DESCRIPTION, DEFAULT_VALUE, DELIMITER}, diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java index aa32bcfd71..3fc5e35d07 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java @@ -21,8 +21,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class BooleanMultiProperty extends AbstractMultiValueProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Boolean.class) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Boolean.class) { @Override public BooleanMultiProperty createWith(Map valuesById) { char delimiter = delimiterIn(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java index 5989a82d46..294d383fd4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java @@ -19,8 +19,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; */ public final class BooleanProperty extends AbstractSingleValueProperty { - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Boolean.class) { + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Boolean.class) { @Override public BooleanProperty createWith(Map valuesById) { return new BooleanProperty(nameIn(valuesById), diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java index 61c30b8e7b..811f3352fd 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java @@ -22,8 +22,8 @@ import net.sourceforge.pmd.util.StringUtil; public final class CharacterMultiProperty extends AbstractMultiValueProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Character.class) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Character.class) { @Override public CharacterMultiProperty createWith(Map valuesById) { char delimiter = delimiterIn(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java index 8659b1741a..43af6603a8 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java @@ -19,8 +19,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; */ public final class CharacterProperty extends AbstractSingleValueProperty { - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Character.class) { + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Character.class) { @Override public CharacterProperty createWith(Map valuesById) { return new CharacterProperty(nameIn(valuesById), diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleMultiProperty.java index b6618737b5..7d4e90815a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleMultiProperty.java @@ -23,8 +23,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class DoubleMultiProperty extends AbstractMultiNumericProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Double.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Double.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public DoubleMultiProperty createWith(Map valuesById) { String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java index 81844bacff..2b3f1da8ae 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java @@ -20,8 +20,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; */ public final class DoubleProperty extends AbstractNumericProperty { - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Double.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Double.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public DoubleProperty createWith(Map valuesById) { final String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java index 4f84de0ae8..c0a62ce3f4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java @@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.rule.properties; import java.util.ArrayList; import java.util.Collections; -import java.util.Enumeration; import java.util.List; import java.util.Map; @@ -14,6 +13,7 @@ import net.sourceforge.pmd.EnumeratedPropertyDescriptor; import net.sourceforge.pmd.PropertyDescriptorFactory; import net.sourceforge.pmd.PropertyDescriptorField; import net.sourceforge.pmd.util.CollectionUtil; +import net.sourceforge.pmd.util.StringUtil; /** * Multi-valued property which can take only a fixed set of values of any type, then selected via String labels. The @@ -28,8 +28,8 @@ public final class EnumeratedMultiProperty extends AbstractMultiValueProperty implements EnumeratedPropertyDescriptor> { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Enumeration.class) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Object.class) { // TODO:cf is Object the right type? @Override public EnumeratedMultiProperty createWith(Map valuesById) { return new EnumeratedMultiProperty<>(nameIn(valuesById), @@ -142,6 +142,9 @@ public final class EnumeratedMultiProperty extends AbstractMultiValueProperty private E choiceFrom(String label) { + if (StringUtil.isEmpty(label)) { + return null; + } E result = choicesByLabel.get(label); if (result == null) { throw new IllegalArgumentException(label); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java index 113159bd8d..96a3ee6a22 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java @@ -29,7 +29,7 @@ public final class EnumeratedProperty extends AbstractSingleValueProperty /** Factory. */ public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Enumeration.class) { + = new SingleValuePropertyDescriptorFactory(Enumeration.class) { // TODO:cf Enumeration? Object? @Override public EnumeratedProperty createWith(Map valuesById) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java index 4458d7cf31..bfed9815e1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java @@ -20,12 +20,13 @@ import net.sourceforge.pmd.util.StringUtil; public final class FileProperty extends AbstractSingleValueProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory(File.class) { - @Override - public FileProperty createWith(Map valuesById) { - return new FileProperty(nameIn(valuesById), descriptionIn(valuesById), null, 0f); - } - }; + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(File.class) { + @Override + public FileProperty createWith(Map valuesById) { + return new FileProperty(nameIn(valuesById), descriptionIn(valuesById), null, 0f); + } + }; // @formatter:on public FileProperty(String theName, String theDescription, File theDefault, float theUIOrder) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java index caaf38d3d5..99382bd738 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java @@ -23,8 +23,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class FloatMultiProperty extends AbstractMultiNumericProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Float.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Float.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public FloatMultiProperty createWith(Map valuesById) { String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java index 4689776e9c..5db204c0d9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java @@ -20,8 +20,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class FloatProperty extends AbstractNumericProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Float.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Float.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public FloatProperty createWith(Map valuesById) { final String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java index 32965e1a31..51f02f1588 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java @@ -23,8 +23,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class IntegerMultiProperty extends AbstractMultiNumericProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public IntegerMultiProperty createWith(Map valuesById) { String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java index e0f7a74929..5658f289aa 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java @@ -19,8 +19,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; */ public final class IntegerProperty extends AbstractNumericProperty { - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public IntegerProperty createWith(Map valuesById) { final String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java index 642603239a..12f7616385 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java @@ -23,8 +23,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class LongMultiProperty extends AbstractMultiNumericProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Long.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Long.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public LongMultiProperty createWith(Map valuesById) { String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java index c94d3c5062..7fbbe87581 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java @@ -20,8 +20,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class LongProperty extends AbstractNumericProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Long.class, NUMBER_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Long.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override public LongProperty createWith(Map valuesById) { final String[] minMax = minMaxFrom(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java index e3763d07a9..747c7ccf6c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java @@ -28,8 +28,8 @@ import net.sourceforge.pmd.util.StringUtil; public final class MethodMultiProperty extends AbstractMultiPackagedProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override public MethodMultiProperty createWith(Map valuesById) { char delimiter = delimiterIn(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodProperty.java index e9f48afa0d..797e3922a2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodProperty.java @@ -30,8 +30,8 @@ public final class MethodProperty extends AbstractPackagedProperty { public static final char CLASS_METHOD_DELIMITER = '#'; public static final char METHOD_ARG_DELIMITER = ','; public static final char[] METHOD_GROUP_DELIMITERS = {'(', ')'}; - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override public MethodProperty createWith(Map valuesById) { char delimiter = delimiterIn(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MultiValuePropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MultiValuePropertyDescriptorFactory.java new file mode 100644 index 0000000000..f935a65331 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MultiValuePropertyDescriptorFactory.java @@ -0,0 +1,32 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.rule.properties; + +import java.util.List; +import java.util.Map; + +import net.sourceforge.pmd.PropertyDescriptorField; + +/** + * @author Clément Fournier + */ +public class MultiValuePropertyDescriptorFactory extends BasicPropertyDescriptorFactory> { + + public MultiValuePropertyDescriptorFactory(Class theValueType) { + super(theValueType); + } + + + public MultiValuePropertyDescriptorFactory(Class theValueType, Map + additionalFieldTypesByKey) { + super(theValueType, additionalFieldTypesByKey); + } + + + @Override + public boolean isMultiValue() { + return true; + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java index dfc41101ed..7cad68b59f 100755 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java @@ -69,11 +69,11 @@ public class PropertyDescriptorUtil { } - public static String typeIdFor(Class valueType) { + public static String typeIdFor(Class valueType, boolean multiValue) { // a reverse lookup, not very efficient but fine for now for (Map.Entry> entry : DESCRIPTOR_FACTORIES_BY_TYPE.entrySet()) { - if (entry.getValue().valueType() == valueType) { + if (entry.getValue().valueType() == valueType && entry.getValue().isMultiValue() == multiValue) { return entry.getKey(); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/SingleValuePropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/SingleValuePropertyDescriptorFactory.java new file mode 100644 index 0000000000..2fa5c8c955 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/SingleValuePropertyDescriptorFactory.java @@ -0,0 +1,31 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.rule.properties; + +import java.util.Map; + +import net.sourceforge.pmd.PropertyDescriptorField; + +/** + * @author Clément Fournier + */ +public class SingleValuePropertyDescriptorFactory extends BasicPropertyDescriptorFactory { + + public SingleValuePropertyDescriptorFactory(Class theValueType) { + super(theValueType); + } + + + public SingleValuePropertyDescriptorFactory(Class theValueType, + Map additionalFieldTypesByKey) { + super(theValueType, additionalFieldTypesByKey); + } + + + @Override + public boolean isMultiValue() { + return false; + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java index 2bc1997746..4030eae324 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java @@ -22,8 +22,8 @@ import net.sourceforge.pmd.util.StringUtil; public final class StringMultiProperty extends AbstractMultiValueProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(String.class) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(String.class) { @Override public StringMultiProperty createWith(Map valuesById) { char delimiter = delimiterIn(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java index 262fdf110a..83f8426b94 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java @@ -18,12 +18,13 @@ import net.sourceforge.pmd.PropertyDescriptorField; public final class StringProperty extends AbstractSingleValueProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory(String.class) { - @Override - public StringProperty createWith(Map valuesById) { - return new StringProperty(nameIn(valuesById), descriptionIn(valuesById), defaultValueIn(valuesById), 0f); - } - }; + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(String.class) { + @Override + public StringProperty createWith(Map valuesById) { + return new StringProperty(nameIn(valuesById), descriptionIn(valuesById), defaultValueIn(valuesById), 0f); + } + }; // @formatter:on /** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java index 142a38b18e..766b08f56f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java @@ -24,8 +24,8 @@ import net.sourceforge.pmd.util.StringUtil; public final class TypeMultiProperty extends AbstractMultiPackagedProperty { /** Factory. */ - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory>(Class.class, PACKAGED_FIELD_TYPES_BY_KEY) { + public static final PropertyDescriptorFactory> FACTORY // @formatter:off + = new MultiValuePropertyDescriptorFactory(Class.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override public TypeMultiProperty createWith(Map valuesById) { char delimiter = delimiterIn(valuesById); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java index 2144c60342..d7ae7d3a56 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java @@ -21,8 +21,9 @@ import net.sourceforge.pmd.util.StringUtil; */ public final class TypeProperty extends AbstractPackagedProperty { - public static final PropertyDescriptorFactory FACTORY // @formatter:off - = new BasicPropertyDescriptorFactory(Class.class, PACKAGED_FIELD_TYPES_BY_KEY) { + /** Factory. */ + public static final PropertyDescriptorFactory FACTORY // @formatter:off + = new SingleValuePropertyDescriptorFactory(Class.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override public TypeProperty createWith(Map valuesById) { char delimiter = delimiterIn(valuesById); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/properties/IntegerPropertyTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/properties/IntegerPropertyTest.java index 441700c39d..b8c644f6da 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/properties/IntegerPropertyTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/properties/IntegerPropertyTest.java @@ -49,7 +49,7 @@ public class IntegerPropertyTest extends AbstractPropertyDescriptorTester VERSION_MAP; - private static final MetricVersion[] CYCLO_VERSIONS = {Metric.Version.STANDARD, CycloMetric.Version.IGNORE_BOOLEAN_PATHS}; + static { + VERSION_MAP = new HashMap<>(); + VERSION_MAP.put("standard", Version.STANDARD); + VERSION_MAP.put("ignoreBooleanPaths", CycloMetric.Version.IGNORE_BOOLEAN_PATHS); + } public static final EnumeratedProperty CYCLO_VERSION_DESCRIPTOR = new EnumeratedProperty<>( "cycloVersion", "Choose a variant of Cyclo or the standard", - VERSION_LABELS, CYCLO_VERSIONS, 0, 3.0f); + VERSION_MAP, Version.STANDARD, MetricVersion.class, 3.0f); private int reportLevel; private boolean showClassesComplexity = true; @@ -65,8 +71,7 @@ public class CyclomaticComplexityRule extends AbstractJavaRule { reportLevel = getProperty(REPORT_LEVEL_DESCRIPTOR); showClassesComplexity = getProperty(SHOW_CLASSES_COMPLEXITY_DESCRIPTOR); showMethodsComplexity = getProperty(SHOW_METHODS_COMPLEXITY_DESCRIPTOR); - Object version = getProperty(CYCLO_VERSION_DESCRIPTOR); - cycloVersion = version instanceof MetricVersion ? (MetricVersion) version : Version.STANDARD; + cycloVersion = getProperty(CYCLO_VERSION_DESCRIPTOR); super.visit(node, data); return data; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidBranchingStatementAsLastInLoopRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidBranchingStatementAsLastInLoopRule.java index 008195c95c..d405c61d08 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidBranchingStatementAsLastInLoopRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidBranchingStatementAsLastInLoopRule.java @@ -4,6 +4,12 @@ package net.sourceforge.pmd.lang.java.rule.basic; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import net.sourceforge.pmd.PropertySource; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.ast.ASTBreakStatement; @@ -22,19 +28,27 @@ public class AvoidBranchingStatementAsLastInLoopRule extends AbstractJavaRule { public static final String CHECK_DO = "do"; public static final String CHECK_WHILE = "while"; - private static final String[] ALL_LOOP_TYPES_LABELS = new String[] { CHECK_FOR, CHECK_DO, CHECK_WHILE }; - private static final String[] ALL_LOOP_TYPES_VALUES = ALL_LOOP_TYPES_LABELS; - private static final int[] ALL_LOOP_TYPES_DEFAULTS = new int[] { 0, 1, 2 }; + private static final Map LOOP_TYPES_MAPPINGS; + private static final List DEFAULTS = Arrays.asList(CHECK_FOR, CHECK_DO, CHECK_WHILE); + + static { + Map mappings = new HashMap<>(); + mappings.put(CHECK_FOR, CHECK_FOR); + mappings.put(CHECK_DO, CHECK_DO); + mappings.put(CHECK_WHILE, CHECK_WHILE); + LOOP_TYPES_MAPPINGS = Collections.unmodifiableMap(mappings); + } public static final EnumeratedMultiProperty CHECK_BREAK_LOOP_TYPES = new EnumeratedMultiProperty<>( - "checkBreakLoopTypes", "Check for break statements in loop types", ALL_LOOP_TYPES_LABELS, - ALL_LOOP_TYPES_VALUES, ALL_LOOP_TYPES_DEFAULTS, 1); + "checkBreakLoopTypes", "Check for break statements in loop types", LOOP_TYPES_MAPPINGS, DEFAULTS, + String.class, 1); public static final EnumeratedMultiProperty CHECK_CONTINUE_LOOP_TYPES = new EnumeratedMultiProperty<>( - "checkContinueLoopTypes", "Check for continue statements in loop types", ALL_LOOP_TYPES_LABELS, - ALL_LOOP_TYPES_VALUES, ALL_LOOP_TYPES_DEFAULTS, 2); + "checkContinueLoopTypes", "Check for continue statements in loop types", LOOP_TYPES_MAPPINGS, DEFAULTS, + String.class, 2); public static final EnumeratedMultiProperty CHECK_RETURN_LOOP_TYPES = new EnumeratedMultiProperty<>( - "checkReturnLoopTypes", "Check for return statements in loop types", ALL_LOOP_TYPES_LABELS, - ALL_LOOP_TYPES_VALUES, ALL_LOOP_TYPES_DEFAULTS, 3); + "checkReturnLoopTypes", "Check for return statements in loop types", LOOP_TYPES_MAPPINGS, DEFAULTS, + String.class, 3); + public AvoidBranchingStatementAsLastInLoopRule() { definePropertyDescriptor(CHECK_BREAK_LOOP_TYPES); @@ -46,6 +60,7 @@ public class AvoidBranchingStatementAsLastInLoopRule extends AbstractJavaRule { addRuleChainVisit(ASTReturnStatement.class); } + @Override public Object visit(ASTBreakStatement node, Object data) { // skip breaks, that are within a switch statement @@ -55,15 +70,6 @@ public class AvoidBranchingStatementAsLastInLoopRule extends AbstractJavaRule { return check(CHECK_BREAK_LOOP_TYPES, node, data); } - @Override - public Object visit(ASTContinueStatement node, Object data) { - return check(CHECK_CONTINUE_LOOP_TYPES, node, data); - } - - @Override - public Object visit(ASTReturnStatement node, Object data) { - return check(CHECK_RETURN_LOOP_TYPES, node, data); - } protected Object check(EnumeratedMultiProperty property, Node node, Object data) { Node parent = node.getNthParent(5); @@ -83,22 +89,24 @@ public class AvoidBranchingStatementAsLastInLoopRule extends AbstractJavaRule { return data; } + protected boolean hasPropertyValue(EnumeratedMultiProperty property, String value) { - final Object[] values = getProperty(property); - for (int i = 0; i < values.length; i++) { - if (value.equals(values[i])) { - return true; - } - } - return false; + return getProperty(property).contains(value); } - public boolean checksNothing() { - return getProperty(CHECK_BREAK_LOOP_TYPES).length == 0 && getProperty(CHECK_CONTINUE_LOOP_TYPES).length == 0 - && getProperty(CHECK_RETURN_LOOP_TYPES).length == 0; + @Override + public Object visit(ASTContinueStatement node, Object data) { + return check(CHECK_CONTINUE_LOOP_TYPES, node, data); } + + @Override + public Object visit(ASTReturnStatement node, Object data) { + return check(CHECK_RETURN_LOOP_TYPES, node, data); + } + + /** * @see PropertySource#dysfunctionReason() */ @@ -106,4 +114,11 @@ public class AvoidBranchingStatementAsLastInLoopRule extends AbstractJavaRule { public String dysfunctionReason() { return checksNothing() ? "All loop types are ignored" : null; } + + + public boolean checksNothing() { + + return getProperty(CHECK_BREAK_LOOP_TYPES).size() == 0 && getProperty(CHECK_CONTINUE_LOOP_TYPES).size() == 0 + && getProperty(CHECK_RETURN_LOOP_TYPES).size() == 0; + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidUsingHardCodedIPRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidUsingHardCodedIPRule.java index 281f9c374c..735c9220a3 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidUsingHardCodedIPRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/AvoidUsingHardCodedIPRule.java @@ -21,7 +21,7 @@ public class AvoidUsingHardCodedIPRule extends AbstractJavaRule { public static final EnumeratedMultiProperty CHECK_ADDRESS_TYPES_DESCRIPTOR = new EnumeratedMultiProperty<>( "checkAddressTypes", "Check for IP address types.", new String[] { IPV4, IPV6, IPV4_MAPPED_IPV6 }, - new String[] { IPV4, IPV6, IPV4_MAPPED_IPV6 }, new int[] { 0, 1, 2 }, 2.0f); + new String[] { IPV4, IPV6, IPV4_MAPPED_IPV6 }, new int[] { 0, 1, 2 }, String.class, 2.0f); // Provides 4 capture groups that can be used for additional validation protected static final String IPV4_REGEXP = "([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})"; @@ -195,7 +195,7 @@ public class AvoidUsingHardCodedIPRule extends AbstractJavaRule { } public boolean hasChosenAddressTypes() { - return getProperty(CHECK_ADDRESS_TYPES_DESCRIPTOR).length > 0; + return getProperty(CHECK_ADDRESS_TYPES_DESCRIPTOR).size() > 0; } /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java index a788d6926e..85c34ae537 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java @@ -18,7 +18,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; import net.sourceforge.pmd.lang.java.ast.Comment; import net.sourceforge.pmd.lang.rule.properties.BooleanProperty; import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty; -import net.sourceforge.pmd.util.CollectionUtil; import net.sourceforge.pmd.util.StringUtil; /** @@ -32,11 +31,11 @@ public class CommentContentRule extends AbstractCommentRule { private boolean caseSensitive; private boolean wordsAreRegex; - private String[] originalBadWords; - private String[] currentBadWords; + private List originalBadWords; + private List currentBadWords; // FIXME need some better defaults (or none?) - private static final String[] BAD_WORDS = new String[] { "idiot", "jerk" }; + private static final String[] BAD_WORDS = {"idiot", "jerk" }; public static final BooleanProperty WORDS_ARE_REGEX_DESCRIPTOR = new BooleanProperty("wordsAreRegex", "Use regular expressions", false, 1.0f); @@ -72,19 +71,21 @@ public class CommentContentRule extends AbstractCommentRule { if (caseSensitive) { currentBadWords = originalBadWords; } else { - currentBadWords = new String[originalBadWords.length]; - for (int i = 0; i < currentBadWords.length; i++) { - currentBadWords[i] = originalBadWords[i].toUpperCase(); + currentBadWords = new ArrayList<>(); + for (String badWord : originalBadWords) { + currentBadWords.add(badWord.toUpperCase()); } } } @Override public Set> ignoredProperties() { - return getProperty(WORDS_ARE_REGEX_DESCRIPTOR) ? NON_REGEX_PROPERTIES : Collections.EMPTY_SET; + return getProperty(WORDS_ARE_REGEX_DESCRIPTOR) ? NON_REGEX_PROPERTIES + : Collections.>emptySet(); } /** + * . * @see Rule#end(RuleContext) */ @Override @@ -94,7 +95,7 @@ public class CommentContentRule extends AbstractCommentRule { private List illegalTermsIn(Comment comment) { - if (currentBadWords.length == 0) { + if (currentBadWords.isEmpty()) { return Collections.emptyList(); } @@ -109,9 +110,9 @@ public class CommentContentRule extends AbstractCommentRule { List foundWords = new ArrayList<>(); - for (int i = 0; i < currentBadWords.length; i++) { - if (commentText.indexOf(currentBadWords[i]) >= 0) { - foundWords.add(originalBadWords[i]); + for (int i = 0; i < currentBadWords.size(); i++) { + if (commentText.contains(currentBadWords.get(i))) { + foundWords.add(originalBadWords.get(i)); } } @@ -154,8 +155,8 @@ public class CommentContentRule extends AbstractCommentRule { } public boolean hasDissallowedTerms() { - String[] terms = getProperty(DISSALLOWED_TERMS_DESCRIPTOR); - return CollectionUtil.isNotEmpty(terms); + List terms = getProperty(DISSALLOWED_TERMS_DESCRIPTOR); + return !terms.isEmpty(); } /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentRequiredRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentRequiredRule.java index 2a7e3bb365..7813187a57 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentRequiredRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/CommentRequiredRule.java @@ -43,31 +43,31 @@ public class CommentRequiredRule extends AbstractCommentRule { public static final EnumeratedProperty HEADER_CMT_REQUIREMENT_DESCRIPTOR = new EnumeratedProperty<>( "headerCommentRequirement", "Header comments. Possible values: " + Arrays.toString(CommentRequirement.values()), - CommentRequirement.labels(), CommentRequirement.values(), 0, 1.0f); + CommentRequirement.labels(), CommentRequirement.values(), 0, CommentRequirement.class, 1.0f); public static final EnumeratedProperty FIELD_CMT_REQUIREMENT_DESCRIPTOR = new EnumeratedProperty<>( "fieldCommentRequirement", "Field comments. Possible values: " + Arrays.toString(CommentRequirement.values()), - CommentRequirement.labels(), CommentRequirement.values(), 0, 2.0f); + CommentRequirement.labels(), CommentRequirement.values(), 0, CommentRequirement.class, 2.0f); public static final EnumeratedProperty PUB_METHOD_CMT_REQUIREMENT_DESCRIPTOR = new EnumeratedProperty<>( "publicMethodCommentRequirement", "Public method and constructor comments. Possible values: " + Arrays.toString(CommentRequirement.values()), - CommentRequirement.labels(), CommentRequirement.values(), 0, 3.0f); + CommentRequirement.labels(), CommentRequirement.values(), 0, CommentRequirement.class, 3.0f); public static final EnumeratedProperty PROT_METHOD_CMT_REQUIREMENT_DESCRIPTOR = new EnumeratedProperty<>( "protectedMethodCommentRequirement", "Protected method constructor comments. Possible values: " + Arrays.toString(CommentRequirement.values()), - CommentRequirement.labels(), CommentRequirement.values(), 0, 4.0f); + CommentRequirement.labels(), CommentRequirement.values(), 0, CommentRequirement.class, 4.0f); public static final EnumeratedProperty ENUM_CMT_REQUIREMENT_DESCRIPTOR = new EnumeratedProperty<>( "enumCommentRequirement", "Enum comments. Possible values: " + Arrays.toString(CommentRequirement.values()), - CommentRequirement.labels(), CommentRequirement.values(), 0, 5.0f); + CommentRequirement.labels(), CommentRequirement.values(), 0, CommentRequirement.class, 5.0f); - public static final EnumeratedProperty SERIAL_VERSION_UID_CMT_REQUIREMENT_DESCRIPTOR = new EnumeratedProperty( - "serialVersionUIDCommentRequired", - "serial version UID commts. Possible values: " + Arrays.toString(CommentRequirement.values()), - CommentRequirement.labels(), CommentRequirement.values(), 1, 6.0f); + public static final EnumeratedProperty SERIAL_VERSION_UID_CMT_REQUIREMENT_DESCRIPTOR = new EnumeratedProperty<>( + "serialVersionUIDCommentRequired", + "serial version UID commts. Possible values: " + Arrays.toString(CommentRequirement.values()), + CommentRequirement.labels(), CommentRequirement.values(), 1, CommentRequirement.class, 6.0f); public CommentRequiredRule() { definePropertyDescriptor(HEADER_CMT_REQUIREMENT_DESCRIPTOR); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/HeaderCommentsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/HeaderCommentsRule.java index b94d92d9a5..5fac0e5770 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/HeaderCommentsRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/comments/HeaderCommentsRule.java @@ -48,7 +48,7 @@ public class HeaderCommentsRule extends AbstractCommentRule { public static final EnumeratedProperty HEADER_PLACEMENT_DESCRIPTOR = new EnumeratedProperty<>( "headerPlacement", "Placement of the header comment", RequiredHeaderPlacement.labels(), - RequiredHeaderPlacement.values(), 0, 3.0f); + RequiredHeaderPlacement.values(), 0, RequiredHeaderPlacement.class, 3.0f); public HeaderCommentsRule() { definePropertyDescriptor(REQUIRED_TERMS_DESCRIPTOR); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java index b7c9bac329..8a058a5050 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.java.rule.coupling; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -15,7 +14,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty; -import net.sourceforge.pmd.util.CollectionUtil; /** * The loose package coupling Rule can be used to ensure coupling outside of a @@ -65,7 +63,7 @@ public class LoosePackageCouplingRule extends AbstractJavaRule { // Sort the restricted packages in reverse order. This will ensure the // child packages are in the list before their parent packages. - this.restrictedPackages = new ArrayList<>(Arrays.asList(super.getProperty(PACKAGES_DESCRIPTOR))); + this.restrictedPackages = new ArrayList<>(super.getProperty(PACKAGES_DESCRIPTOR)); Collections.sort(restrictedPackages, Collections.reverseOrder()); return data; @@ -132,8 +130,7 @@ public class LoosePackageCouplingRule extends AbstractJavaRule { public boolean checksNothing() { - return CollectionUtil.isEmpty(getProperty(PACKAGES_DESCRIPTOR)) - && CollectionUtil.isEmpty(getProperty(CLASSES_DESCRIPTOR)); + return getProperty(PACKAGES_DESCRIPTOR).isEmpty() && getProperty(CLASSES_DESCRIPTOR).isEmpty(); } /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CloseResourceRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CloseResourceRule.java index 887c55c9c7..7f61080811 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CloseResourceRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CloseResourceRule.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.java.rule.design; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -77,13 +76,13 @@ public class CloseResourceRule extends AbstractJavaRule { @Override public Object visit(ASTCompilationUnit node, Object data) { if (closeTargets.isEmpty() && getProperty(CLOSE_TARGETS_DESCRIPTOR) != null) { - closeTargets.addAll(Arrays.asList(getProperty(CLOSE_TARGETS_DESCRIPTOR))); + closeTargets.addAll(getProperty(CLOSE_TARGETS_DESCRIPTOR)); } if (getProperty(USE_CLOSE_AS_DEFAULT_TARGET) && !closeTargets.contains("close")) { closeTargets.add("close"); } if (types.isEmpty() && getProperty(TYPES_DESCRIPTOR) != null) { - types.addAll(Arrays.asList(getProperty(TYPES_DESCRIPTOR))); + types.addAll(getProperty(TYPES_DESCRIPTOR)); } if (simpleTypes.isEmpty() && getProperty(TYPES_DESCRIPTOR) != null) { for (String type : getProperty(TYPES_DESCRIPTOR)) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GenericClassCounterRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GenericClassCounterRule.java index 8ace6a78d0..e45db8c2c2 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GenericClassCounterRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GenericClassCounterRule.java @@ -84,22 +84,13 @@ public class GenericClassCounterRule extends AbstractJavaRule { definePropertyDescriptor(THRESHOLD_DESCRIPTOR); } - private List arrayAsList(String[] array) { - List list = new ArrayList<>(array.length); - int nbItem = 0; - while (nbItem < array.length) { - list.add(array[nbItem++]); - } - return list; - } - protected void init() { // Creating the attribute name for the rule context counterLabel = this.getClass().getSimpleName() + ".number of match"; // Constructing the request from the input parameters - this.namesMatch = RegexHelper.compilePatternsFromList(arrayAsList(getProperty(NAME_MATCH_DESCRIPTOR))); + this.namesMatch = RegexHelper.compilePatternsFromList(getProperty(NAME_MATCH_DESCRIPTOR)); this.operand = getProperty(OPERAND_DESCRIPTOR); - this.typesMatch = RegexHelper.compilePatternsFromList(arrayAsList(getProperty(TYPE_MATCH_DESCRIPTOR))); + this.typesMatch = RegexHelper.compilePatternsFromList(getProperty(TYPE_MATCH_DESCRIPTOR)); String thresholdAsString = getProperty(THRESHOLD_DESCRIPTOR); this.threshold = Integer.valueOf(thresholdAsString); // Initializing list of match diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementJavaUtilRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementJavaUtilRule.java index a4b3cef746..e1eca01b9c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementJavaUtilRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementJavaUtilRule.java @@ -29,8 +29,8 @@ public class GuardLogStatementJavaUtilRule extends GuardLogStatementRule { return data; } - String[] logLevels = getProperty(LOG_LEVELS); - String[] guardMethods = getProperty(GUARD_METHODS); + String[] logLevels = getProperty(LOG_LEVELS).toArray(new String[0]); // TODO:cf convert to list + String[] guardMethods = getProperty(GUARD_METHODS).toArray(new String[0]); if (super.guardStmtByLogLevel.isEmpty() && logLevels.length > 0 && guardMethods.length > 0) { configureGuards(logLevels, guardMethods); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementRule.java index b4a1d20bf0..13e4acf283 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/logging/GuardLogStatementRule.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.java.rule.logging; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -96,8 +95,8 @@ public class GuardLogStatementRule extends AbstractOptimizationRule implements R protected void extractProperties() { if (guardStmtByLogLevel.isEmpty()) { - List logLevels = new ArrayList<>(Arrays.asList(super.getProperty(LOG_LEVELS))); - List guardMethods = new ArrayList<>(Arrays.asList(super.getProperty(GUARD_METHODS))); + List logLevels = new ArrayList<>(super.getProperty(LOG_LEVELS)); + List guardMethods = new ArrayList<>(super.getProperty(GUARD_METHODS)); if (guardMethods.isEmpty() && !logLevels.isEmpty()) { throw new IllegalArgumentException("Can't specify guardMethods without specifiying logLevels."); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/VariableNamingConventionsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/VariableNamingConventionsRule.java index c190b2a621..70516a59d5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/VariableNamingConventionsRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/naming/VariableNamingConventionsRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.java.rule.naming; +import java.util.List; + import net.sourceforge.pmd.PropertyDescriptor; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration; @@ -19,7 +21,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.lang.rule.properties.BooleanProperty; import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty; -import net.sourceforge.pmd.util.CollectionUtil; public class VariableNamingConventionsRule extends AbstractJavaRule { @@ -27,14 +28,14 @@ public class VariableNamingConventionsRule extends AbstractJavaRule { private boolean checkLocals; private boolean checkParameters; private boolean checkNativeMethodParameters; - private String[] staticPrefixes; - private String[] staticSuffixes; - private String[] memberPrefixes; - private String[] memberSuffixes; - private String[] localPrefixes; - private String[] localSuffixes; - private String[] parameterPrefixes; - private String[] parameterSuffixes; + private List staticPrefixes; + private List staticSuffixes; + private List memberPrefixes; + private List memberSuffixes; + private List localPrefixes; + private List localSuffixes; + private List parameterPrefixes; + private List parameterSuffixes; private static final BooleanProperty CHECK_MEMBERS_DESCRIPTOR = new BooleanProperty("checkMembers", "Check member variables", true, 1.0f); @@ -152,7 +153,7 @@ public class VariableNamingConventionsRule extends AbstractJavaRule { return data; } - private Object checkVariableDeclarators(String[] prefixes, String[] suffixes, Node root, boolean isStatic, + private Object checkVariableDeclarators(List prefixes, List suffixes, Node root, boolean isStatic, boolean isFinal, Object data) { for (ASTVariableDeclarator variableDeclarator : root.findChildrenOfType(ASTVariableDeclarator.class)) { for (ASTVariableDeclaratorId variableDeclaratorId : variableDeclarator @@ -163,7 +164,7 @@ public class VariableNamingConventionsRule extends AbstractJavaRule { return data; } - private Object checkVariableDeclaratorId(String[] prefixes, String[] suffixes, Node root, boolean isStatic, + private Object checkVariableDeclaratorId(List prefixes, List suffixes, Node root, boolean isStatic, boolean isFinal, ASTVariableDeclaratorId variableDeclaratorId, Object data) { // Get the variable name @@ -199,15 +200,15 @@ public class VariableNamingConventionsRule extends AbstractJavaRule { return data; } - private String normalizeVariableName(String varName, String[] prefixes, String[] suffixes) { + private String normalizeVariableName(String varName, List prefixes, List suffixes) { return stripSuffix(stripPrefix(varName, prefixes), suffixes); } - private String stripSuffix(String varName, String[] suffixes) { + private String stripSuffix(String varName, List suffixes) { if (suffixes != null) { - for (int i = 0; i < suffixes.length; i++) { - if (varName.endsWith(suffixes[i])) { - varName = varName.substring(0, varName.length() - suffixes[i].length()); + for (String suffix : suffixes) { + if (varName.endsWith(suffix)) { + varName = varName.substring(0, varName.length() - suffix.length()); break; } } @@ -215,11 +216,11 @@ public class VariableNamingConventionsRule extends AbstractJavaRule { return varName; } - private String stripPrefix(String varName, String[] prefixes) { + private String stripPrefix(String varName, List prefixes) { if (prefixes != null) { - for (int i = 0; i < prefixes.length; i++) { - if (varName.startsWith(prefixes[i])) { - return varName.substring(prefixes[i].length()); + for (String prefix : prefixes) { + if (varName.startsWith(prefix)) { + return varName.substring(prefix.length()); } } } @@ -230,8 +231,8 @@ public class VariableNamingConventionsRule extends AbstractJavaRule { for (PropertyDescriptor desc : getPropertyDescriptors()) { if (desc instanceof StringMultiProperty) { - String[] values = getProperty((StringMultiProperty) desc); - if (CollectionUtil.isNotEmpty(values)) { + List values = getProperty((StringMultiProperty) desc); + if (!values.isEmpty()) { return true; } } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptions.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptions.java index e40bb86fe3..2173b60556 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptions.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptions.java @@ -43,10 +43,11 @@ public class EcmascriptParserOptions extends ParserOptions { } } - private static final String[] VERSION_LABELS = new String[] { Version.VERSION_DEFAULT.getLabel(), - Version.VERSION_1_0.getLabel(), Version.VERSION_1_1.getLabel(), Version.VERSION_1_2.getLabel(), - Version.VERSION_1_3.getLabel(), Version.VERSION_1_4.getLabel(), Version.VERSION_1_5.getLabel(), - Version.VERSION_1_6.getLabel(), Version.VERSION_1_7.getLabel(), Version.VERSION_1_8.getLabel(), }; + private static final String[] VERSION_LABELS = {Version.VERSION_DEFAULT.getLabel(), + Version.VERSION_1_0.getLabel(), Version.VERSION_1_1.getLabel(), Version.VERSION_1_2.getLabel(), + Version.VERSION_1_3.getLabel(), Version.VERSION_1_4.getLabel(), Version.VERSION_1_5.getLabel(), + Version.VERSION_1_6.getLabel(), Version.VERSION_1_7.getLabel(), + Version.VERSION_1_8.getLabel(), }; // Note: The UI order values are chosen to be larger than those built into // XPathRule. @@ -58,24 +59,22 @@ public class EcmascriptParserOptions extends ParserOptions { public static final EnumeratedProperty RHINO_LANGUAGE_VERSION = new EnumeratedProperty<>( "rhinoLanguageVersion", "Specifies the Rhino Language Version to use for parsing. Defaults to Rhino default.", VERSION_LABELS, - Version.values(), 0, 5.0f); + Version.values(), 0, Version.class, 5.0f); private boolean recordingComments; private boolean recordingLocalJsDocComments; private Version rhinoLanguageVersion; public EcmascriptParserOptions() { - this.recordingComments = RECORDING_COMMENTS_DESCRIPTOR.defaultValue().booleanValue(); - this.recordingLocalJsDocComments = RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR.defaultValue().booleanValue(); - this.rhinoLanguageVersion = (Version) RHINO_LANGUAGE_VERSION - .valueFrom((String) RHINO_LANGUAGE_VERSION.defaultValue()); + this.recordingComments = RECORDING_COMMENTS_DESCRIPTOR.defaultValue(); + this.recordingLocalJsDocComments = RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR.defaultValue(); + this.rhinoLanguageVersion = RHINO_LANGUAGE_VERSION.defaultValue(); } public EcmascriptParserOptions(Rule rule) { this.recordingComments = rule.getProperty(RECORDING_COMMENTS_DESCRIPTOR); this.recordingLocalJsDocComments = rule.getProperty(RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR); - this.rhinoLanguageVersion = (Version) RHINO_LANGUAGE_VERSION - .valueFrom((String) rule.getProperty(RHINO_LANGUAGE_VERSION)); + this.rhinoLanguageVersion = rule.getProperty(RHINO_LANGUAGE_VERSION); } public boolean isRecordingComments() { diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptionsTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptionsTest.java index e323a8dfb8..3580e88418 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptionsTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptParserOptionsTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import net.sourceforge.pmd.lang.ParserOptions; +import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions.Version; import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule; import net.sourceforge.pmd.lang.rule.properties.BooleanProperty; @@ -46,10 +47,10 @@ public class EcmascriptParserOptionsTest { rule.setProperty(EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR, false); assertFalse(((EcmascriptParserOptions) rule.getParserOptions()).isRecordingLocalJsDocComments()); - rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, "default"); + rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, Version.VERSION_DEFAULT); assertEquals(EcmascriptParserOptions.Version.VERSION_DEFAULT, ((EcmascriptParserOptions) rule.getParserOptions()).getRhinoLanguageVersion()); - rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, "1.8"); + rule.setProperty(EcmascriptParserOptions.RHINO_LANGUAGE_VERSION, Version.VERSION_1_8); assertEquals(EcmascriptParserOptions.Version.VERSION_1_8, ((EcmascriptParserOptions) rule.getParserOptions()).getRhinoLanguageVersion()); } @@ -66,8 +67,8 @@ public class EcmascriptParserOptionsTest { @Test public void testEqualsHashcode() throws Exception { - BooleanProperty[] properties = new BooleanProperty[] { EcmascriptParserOptions.RECORDING_COMMENTS_DESCRIPTOR, - EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR, }; + BooleanProperty[] properties = {EcmascriptParserOptions.RECORDING_COMMENTS_DESCRIPTOR, + EcmascriptParserOptions.RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR, }; for (int i = 0; i < properties.length; i++) { BooleanProperty property = properties[i]; diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java index 38c7c12b59..d076e07a23 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.StringTokenizer; - import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -212,6 +211,7 @@ public abstract class AbstractRuleSetFactoryTest { for (String fileName : ruleSetFileNames) { testRuleSet(fileName); } + } // Gets all test PMD Ruleset XML files @@ -397,8 +397,7 @@ public abstract class AbstractRuleSetFactoryTest { Rule rule2 = ((List) ruleSet2.getRules()).get(i); assertFalse(message + ", Different RuleReference", - rule1 instanceof RuleReference && !(rule2 instanceof RuleReference) - || !(rule1 instanceof RuleReference) && rule2 instanceof RuleReference); + rule1 instanceof RuleReference != rule2 instanceof RuleReference); if (rule1 instanceof RuleReference) { RuleReference ruleReference1 = (RuleReference) rule1;