Specialised BasicPropertyDescriptorFactory

This commit is contained in:
oowekyala
2017-06-28 17:48:11 +02:00
parent c51cab446a
commit b103d8f011
73 changed files with 361 additions and 255 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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<String> 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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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<String> 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);
}

View File

@ -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);
}

View File

@ -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<String, Boolean> 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);
}

View File

@ -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<ApexNode<?>, 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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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<String> 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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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<String> staticPrefixes;
private List<String> staticSuffixes;
private List<String> memberPrefixes;
private List<String> memberSuffixes;
private List<String> localPrefixes;
private List<String> localSuffixes;
private List<String> parameterPrefixes;
private List<String> 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<String> prefixes, List<String> 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<String> prefixes, List<String> suffixes) {
return stripSuffix(stripPrefix(varName, prefixes), suffixes);
}
private String stripSuffix(String varName, String[] suffixes) {
private String stripSuffix(String varName, List<String> 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<String> 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<String> values = getProperty((StringMultiProperty) desc);
if (!values.isEmpty()) {
return true;
}
}

Some files were not shown because too many files have changed in this diff Show More