diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessivePublicCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessivePublicCountRule.java new file mode 100644 index 0000000000..3fa72355f2 --- /dev/null +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/codesize/ExcessivePublicCountRule.java @@ -0,0 +1,52 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ +package net.sourceforge.pmd.lang.apex.rule.codesize; + +import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; +import net.sourceforge.pmd.lang.apex.rule.design.ExcessiveNodeCountRule; + +import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.PUBLIC; +import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.STATIC; + +import net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclarationStatements; +import net.sourceforge.pmd.lang.apex.ast.ASTMethod; +import net.sourceforge.pmd.lang.apex.ast.AccessNode; +import net.sourceforge.pmd.util.NumericConstants; + +/** + * @author aglover + *
+ * Class Name: ExcessivePublicCount + * + * Rule attempts to count all public methods and public attributes defined in a class. + * + * If a class has a high number of public operations, it might be wise to consider whether + * it would be appropriate to divide it into subclasses. + * + * A large proportion of public members and operations means the class has high potential to be + * affected by external classes. Futhermore, increased effort will be required to + * thoroughly test the class. + */ +public class ExcessivePublicCountRule extends ExcessiveNodeCountRule { + + public ExcessivePublicCountRule() { + super(ASTUserClass.class); + setProperty(MINIMUM_DESCRIPTOR, 45d); + } + + public Object visit(ASTMethod node, Object data) { + if (node.getNode().getModifiers().has(PUBLIC)) { + return NumericConstants.ONE; + } + return NumericConstants.ZERO; + } + + public Object visit(ASTFieldDeclarationStatements node, Object data) { + System.out.println(node.getNode().getModifiers()); + if (node.getNode().getModifiers().has(PUBLIC) && !node.getNode().getModifiers().has(STATIC)) { + return NumericConstants.ONE; + } + return NumericConstants.ZERO; + } +} diff --git a/pmd-apex/src/main/resources/rulesets/apex/codesize.xml b/pmd-apex/src/main/resources/rulesets/apex/codesize.xml index e136565244..c8c9283470 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/codesize.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/codesize.xml @@ -168,5 +168,34 @@ public class Person { // this is more manageable ]]> + +
+
+
+
+
+